org.bbqjs.spring.ajax
Class RequestForwarder

java.lang.Object
  extended by org.bbqjs.spring.ajax.RequestForwarder
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
ServerWhitelistRequestForwarder, SingleServerRequestForwarder

@Controller
public class RequestForwarder
extends Object
implements org.springframework.beans.factory.InitializingBean

Forwards requests on to remote servers. This controller is intended to work around the Single Origin Policy enforced by most web browsers. The Single Origin Policy dictates that an AJAX request can only be sent to the domain from which the JavaScript sending the request was loaded. This is to prevent cross site scripting attacks. Sometimes though that functionality is useful though (when writing a client for a remote API based service, for example). By default this class forwards to whatever the client requests. To limit the destination servers, use SingleServerRequestForwarder or ServerWhitelistRequestForwarder

See Also:
ServerWhitelistRequestForwarder, SingleServerRequestForwarder

Field Summary
protected  String headerName
           
 
Constructor Summary
RequestForwarder()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void copyHeaders(HttpURLConnection urlConnection, javax.servlet.http.HttpServletResponse response)
           
 void forwardRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  URL getUrlToForwardTo(javax.servlet.http.HttpServletRequest request)
           
protected  HttpURLConnection sendRequest(URL url, javax.servlet.http.HttpServletRequest request, InputStream inputStream)
           
 void setForwardToSelfSignedCertificateServers(boolean forwardToSelfSignedCertificateServers)
           
 void setHeaderName(String headerName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

headerName

protected String headerName
Constructor Detail

RequestForwarder

public RequestForwarder()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

getUrlToForwardTo

protected URL getUrlToForwardTo(javax.servlet.http.HttpServletRequest request)
                         throws Exception
Throws:
Exception

copyHeaders

protected void copyHeaders(HttpURLConnection urlConnection,
                           javax.servlet.http.HttpServletResponse response)

forwardRequest

@RequestMapping(value="/forward")
public void forwardRequest(javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                    throws Exception
Throws:
Exception

sendRequest

protected HttpURLConnection sendRequest(URL url,
                                        javax.servlet.http.HttpServletRequest request,
                                        InputStream inputStream)
                                 throws IOException
Throws:
IOException

setHeaderName

public void setHeaderName(String headerName)

setForwardToSelfSignedCertificateServers

public void setForwardToSelfSignedCertificateServers(boolean forwardToSelfSignedCertificateServers)


Copyright © 2012. All Rights Reserved.