net.sf.j2ep.responsehandlers
Class ResponseHandlerBase

java.lang.Object
  extended by net.sf.j2ep.responsehandlers.ResponseHandlerBase
All Implemented Interfaces:
ResponseHandler
Direct Known Subclasses:
BasicResponseHandler, HeadResponseHandler, OptionsResponseHandler, TraceResponseHandler

public abstract class ResponseHandlerBase
extends java.lang.Object
implements ResponseHandler

Basic implementation of a Response Handler. This class can write the headers and process the output stream.

Author:
Anders Nyman

Field Summary
protected  org.apache.commons.httpclient.HttpMethod method
          Method we are using for this request.
 
Constructor Summary
ResponseHandlerBase(org.apache.commons.httpclient.HttpMethod method)
          Basic constructor only setting the method.
 
Method Summary
 void close()
          Will release the connection for the method.
 int getStatusCode()
          Returns the HTTP status code we received from the server
abstract  void process(HttpServletResponse response)
          Will process the response to set headers and streams for it.
protected  void sendStreamToClient(ServletResponse response)
          Writes the entire stream from the method to the response stream.
protected  void setHeaders(HttpServletResponse response)
          Will write all response headers received in the method to the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

method

protected org.apache.commons.httpclient.HttpMethod method
Method we are using for this request.

Constructor Detail

ResponseHandlerBase

public ResponseHandlerBase(org.apache.commons.httpclient.HttpMethod method)
Basic constructor only setting the method.

Parameters:
method - The method we are using
Method Detail

process

public abstract void process(HttpServletResponse response)
                      throws java.io.IOException
Description copied from interface: ResponseHandler
Will process the response to set headers and streams for it. Each implementation of ResponseHandler can also add it's one method specific actions to the process method.

Specified by:
process in interface ResponseHandler
Parameters:
response - The response to process
Throws:
java.io.IOException - An exception is thrown when there is a problem with writing the output
See Also:
net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.HttpServletResponse)

close

public void close()
Will release the connection for the method.

Specified by:
close in interface ResponseHandler
See Also:
ResponseHandler.close()

getStatusCode

public int getStatusCode()
Description copied from interface: ResponseHandler
Returns the HTTP status code we received from the server

Specified by:
getStatusCode in interface ResponseHandler
Returns:
The status code
See Also:
ResponseHandler.getStatusCode()

sendStreamToClient

protected void sendStreamToClient(ServletResponse response)
                           throws java.io.IOException
Writes the entire stream from the method to the response stream.

Parameters:
response - Response to send data to
Throws:
java.io.IOException - An IOException is thrown when we are having problems with reading the streams

setHeaders

protected void setHeaders(HttpServletResponse response)
Will write all response headers received in the method to the response. One header, connection, is however omitted since we will only want the client to keep his connection to the proxy not to the backing server.

Parameters:
response - The response that will have headers written to it