com.gentics.portal
Class GCNProxyServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.gentics.portal.GCNProxyServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class GCNProxyServlet
extends javax.servlet.http.HttpServlet

Implementation of a simple proxy servlet to the GCN backend.

See Also:
Serialized Form
 

Field Summary
private static int BUFFERSIZE
          the Buffer Size for readers.
private  org.apache.commons.httpclient.MultiThreadedHttpConnectionManager connectionManager
          shared connection manager instance.
private static String[] FORWARD_COOKIES
          Cookies to be forwarded.
private static int HTTPPORT
          http port.
private  org.apache.log4j.Logger logger
          logger.
private  String proxyURLBase
          The base URL we are proxying to.
private  String proxyURLHostPort
          proxy URL without the protocol and path, will be constructed from.
private  String proxyURLHostPortPath
          proxy URL without the protocol, will be constructed from.
private static long serialVersionUID
          Serialization UID.
private static String STRING_CONTENT_LENGTH_HEADER_NAME
          Key for content length header.
private static String STRING_HOST_HEADER_NAME
          Key for host header.
private static String STRING_LOCATION_HEADER
          Key for redirect location header.
private static String TRANSFER_ENCODING_HEADER_NAME
          Key for the transfer-encoding header.
 
Constructor Summary
GCNProxyServlet()
           
 
Method Summary
 void destroy()
           
 void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
          Performs an HTTP GET request.
 void doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
          Performs an HTTP POST request.
private  void executeProxyRequest(org.apache.commons.httpclient.HttpMethod httpMethodProxyRequest, javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
          Executes the HttpMethod passed in and sends the proxy response back to the client via the given HttpServletResponse.
private  String getProxyURL(javax.servlet.http.HttpServletRequest httpServletRequest)
          Get the proxy URL from the original request.
 String getServletInfo()
           
private  void handleStandardPost(org.apache.commons.httpclient.methods.PostMethod postMethodProxyRequest, javax.servlet.http.HttpServletRequest httpServletRequest)
          Sets up the given PostMethod to send the same standard POST data as was sent in the given HttpServletRequest.
 void init()
          Initialize the GCNProxyServlet.
private  void initProxyURLBase()
          Get the proxy URL from the portal configuration.
private  void setProxyRequestHeaders(javax.servlet.http.HttpServletRequest httpServletRequest, org.apache.commons.httpclient.HttpMethod httpMethodProxyRequest)
          Retrieves all of the headers from the servlet request and sets them on the proxy request.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFERSIZE

private static final int BUFFERSIZE
the Buffer Size for readers.

See Also:
Constant Field Values

HTTPPORT

private static final int HTTPPORT
http port.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
Serialization UID.

See Also:
Constant Field Values

STRING_LOCATION_HEADER

private static final String STRING_LOCATION_HEADER
Key for redirect location header.

See Also:
Constant Field Values

STRING_CONTENT_LENGTH_HEADER_NAME

private static final String STRING_CONTENT_LENGTH_HEADER_NAME
Key for content length header.

See Also:
Constant Field Values

TRANSFER_ENCODING_HEADER_NAME

private static final String TRANSFER_ENCODING_HEADER_NAME
Key for the transfer-encoding header.

See Also:
Constant Field Values

STRING_HOST_HEADER_NAME

private static final String STRING_HOST_HEADER_NAME
Key for host header.

See Also:
Constant Field Values

FORWARD_COOKIES

private static final String[] FORWARD_COOKIES
Cookies to be forwarded.


proxyURLBase

private String proxyURLBase
The base URL we are proxying to.


proxyURLHostPort

private String proxyURLHostPort
proxy URL without the protocol and path, will be constructed from. proxyURLBase


proxyURLHostPortPath

private String proxyURLHostPortPath
proxy URL without the protocol, will be constructed from. proxyURLBase


logger

private org.apache.log4j.Logger logger
logger.


connectionManager

private org.apache.commons.httpclient.MultiThreadedHttpConnectionManager connectionManager
shared connection manager instance.

Constructor Detail

GCNProxyServlet

public GCNProxyServlet()
Method Detail

init

public void init()
Initialize the GCNProxyServlet.

Overrides:
init in class javax.servlet.GenericServlet

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

doGet

public void doGet(javax.servlet.http.HttpServletRequest httpServletRequest,
                  javax.servlet.http.HttpServletResponse httpServletResponse)
           throws IOException,
                  javax.servlet.ServletException
Performs an HTTP GET request.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
httpServletRequest - The HttpServletRequest object passed in by the servlet engine representing the client request to be proxied
httpServletResponse - The HttpServletResponse object by which we can send a proxied response to the client
Throws:
IOException - Signals that an I/O exception has occurred.
javax.servlet.ServletException - the servlet exception

doPost

public void doPost(javax.servlet.http.HttpServletRequest httpServletRequest,
                   javax.servlet.http.HttpServletResponse httpServletResponse)
            throws IOException,
                   javax.servlet.ServletException
Performs an HTTP POST request.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
httpServletRequest - The HttpServletRequest object passed in by the servlet engine representing the client request to be proxied
httpServletResponse - The HttpServletResponse object by which we can send a proxied response to the client
Throws:
IOException - Signals that an I/O exception has occurred.
javax.servlet.ServletException - the servlet exception

handleStandardPost

private void handleStandardPost(org.apache.commons.httpclient.methods.PostMethod postMethodProxyRequest,
                                javax.servlet.http.HttpServletRequest httpServletRequest)
                         throws IOException
Sets up the given PostMethod to send the same standard POST data as was sent in the given HttpServletRequest.

Parameters:
postMethodProxyRequest - The PostMethod that we are configuring to send a standard POST request
httpServletRequest - The HttpServletRequest that contains the POST data to be sent via the PostMethod
Throws:
IOException - Signals that an I/O exception has occurred.

executeProxyRequest

private void executeProxyRequest(org.apache.commons.httpclient.HttpMethod httpMethodProxyRequest,
                                 javax.servlet.http.HttpServletRequest httpServletRequest,
                                 javax.servlet.http.HttpServletResponse httpServletResponse)
                          throws IOException,
                                 javax.servlet.ServletException
Executes the HttpMethod passed in and sends the proxy response back to the client via the given HttpServletResponse.

Parameters:
httpMethodProxyRequest - An object representing the proxy request to be made
httpServletRequest - the http servlet request
httpServletResponse - An object by which we can send the proxied response back to the client
Throws:
IOException - Can be thrown by the HttpClient.executeMethod
javax.servlet.ServletException - Can be thrown to indicate that another error has occurred

getServletInfo

public String getServletInfo()
Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet

setProxyRequestHeaders

private void setProxyRequestHeaders(javax.servlet.http.HttpServletRequest httpServletRequest,
                                    org.apache.commons.httpclient.HttpMethod httpMethodProxyRequest)
Retrieves all of the headers from the servlet request and sets them on the proxy request.

Parameters:
httpServletRequest - The request object representing the client's request to the servlet engine
httpMethodProxyRequest - The request that we are about to send to the proxy host

getProxyURL

private String getProxyURL(javax.servlet.http.HttpServletRequest httpServletRequest)
                    throws UnsupportedEncodingException
Get the proxy URL from the original request.

Parameters:
httpServletRequest - original request made to the proxy servlet
Returns:
the URL to which the proxy request shall be made
Throws:
UnsupportedEncodingException - the unsupported encoding exception

initProxyURLBase

private void initProxyURLBase()
                       throws MalformedURLException
Get the proxy URL from the portal configuration.

Throws:
MalformedURLException - the malformed url exception


Copyright © 2014 Gentics Software GmbH. All Rights Reserved.