ikrs.httpd
Class AbstractPreparedResponse

java.lang.Object
  extended by ikrs.httpd.AbstractPreparedResponse
All Implemented Interfaces:
PreparedHTTPResponse
Direct Known Subclasses:
GeneralPreparedResponse

public abstract class AbstractPreparedResponse
extends java.lang.Object
implements PreparedHTTPResponse

This interface is meant to wrap prepared HTTP reply objects.


Constructor Summary
AbstractPreparedResponse(HTTPHandler handler, HTTPHeaders requestHeaders, java.util.UUID socketID, java.net.Socket socket, java.util.UUID sessionID, int statusCode, java.lang.String reasonPhrase)
          Create a new prepared response.
 
Method Summary
 void addResponseHeader(java.lang.String key, java.lang.String value)
          Add a new line (key-value-pair) to the response headers.
abstract  void dispose()
          This method will be called in the final end - even if the execute() method failed.
 void execute()
          This method executes the prepared reply; this means that all necessary resources will be accessed, the actual reply built and sent back to the client.
protected  HTTPHandler getHTTPHandler()
          Get this response's HTTP handler.
 java.lang.String getReasonPhrase()
          Get the currently set reason phrase.
protected  HTTPHeaders getRequestHeaders()
          Get this respone's HTTP request headers.
 Resource getResponseDataResource()
           
 HTTPHeaders getResponseHeaders()
          These headers are initially empty and need to be filled with the response header data.
protected  java.util.UUID getSessionID()
          Get the connection's session ID
protected  java.net.Socket getSocket()
          Get the actual connection socket.
protected  java.util.UUID getSocketID()
          Get the server side socket ID.
 java.lang.String getStatusCode()
          Get the status code of this prepared response.
 boolean isDisposed()
          The method returns true if (and only if) this response already disposed.
 boolean isExecuted()
          The method returns true if (and only if) this response was already executed.
 boolean isPrepared()
          This method return true if (and only if) this response is already prepared.
abstract  void prepare(java.util.Map<java.lang.String,BasicType> optionalReturnSettings)
          This method must be implemented by all subclasses.
protected  void setDisposed()
           
protected  void setPrepared()
           
protected  void setReasonPhrase(java.lang.String phrase)
          Set the reason phrase to a new value.
 void setResponseDataResource(Resource resource)
           
protected  void setStatusCode(java.lang.String statusCode)
          Set the status code to a new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPreparedResponse

public AbstractPreparedResponse(HTTPHandler handler,
                                HTTPHeaders requestHeaders,
                                java.util.UUID socketID,
                                java.net.Socket socket,
                                java.util.UUID sessionID,
                                int statusCode,
                                java.lang.String reasonPhrase)
                         throws java.lang.IllegalArgumentException
Create a new prepared response.

Parameters:
handler - The top level HTTP handler.
headers - The request (!) headers.
socketID - The (server) socket ID.
socket - The connection's socket.
statusCode - The response's status code.
reasonPhrase - The reason phrase (must not contain line breaks!).
Throws:
java.lang.IllegalArgumentException - If the reaons phrase contains line breaks.
Method Detail

getHTTPHandler

protected HTTPHandler getHTTPHandler()
Get this response's HTTP handler.


getRequestHeaders

protected HTTPHeaders getRequestHeaders()
Get this respone's HTTP request headers.


getSocketID

protected java.util.UUID getSocketID()
Get the server side socket ID.


getSocket

protected java.net.Socket getSocket()
Get the actual connection socket.


getSessionID

protected java.util.UUID getSessionID()
Get the connection's session ID


getResponseHeaders

public HTTPHeaders getResponseHeaders()
These headers are initially empty and need to be filled with the response header data.


addResponseHeader

public void addResponseHeader(java.lang.String key,
                              java.lang.String value)
Add a new line (key-value-pair) to the response headers.


setResponseDataResource

public void setResponseDataResource(Resource resource)

getResponseDataResource

public Resource getResponseDataResource()

setPrepared

protected void setPrepared()

setDisposed

protected void setDisposed()

getStatusCode

public java.lang.String getStatusCode()
Get the status code of this prepared response.


setStatusCode

protected void setStatusCode(java.lang.String statusCode)
Set the status code to a new value.


getReasonPhrase

public java.lang.String getReasonPhrase()
Get the currently set reason phrase.


setReasonPhrase

protected void setReasonPhrase(java.lang.String phrase)
                        throws java.lang.IllegalArgumentException
Set the reason phrase to a new value.

Throws:
java.lang.IllegalArgumentException

prepare

public abstract void prepare(java.util.Map<java.lang.String,BasicType> optionalReturnSettings)
                      throws MalformedRequestException,
                             UnsupportedVersionException,
                             UnsupportedMethodException,
                             UnknownMethodException,
                             ConfigurationException,
                             java.util.MissingResourceException,
                             AuthorizationException,
                             HeaderFormatException,
                             DataFormatException,
                             UnsupportedFormatException,
                             ParametrizedHTTPException,
                             java.lang.SecurityException,
                             java.io.IOException
This method must be implemented by all subclasses. It must prepare the HTTP response. This means that all required ressources must be acquired (use locks), all headers prepared (by the use of addResponseHeader(String,String) or getResponseHeaders()) and perform all necessary security checks. Subclasses implementing this method should call the setPrepared() method when ready.

Specified by:
prepare in interface PreparedHTTPResponse
Parameters:
optionalReturnSettings - This (optional, means may be null) map can be used to retrieve internal values for error recovery.
Throws:
MalformRequestException - If the passed HTTP request headers are malformed and cannot be processed.
UnsupportedVersionException - If the headers' HTTP version is not supported (supported versions are 1.0 and 1.1).
UnsupportedMethodException - If the request method is valid but not supported (status code 405).
UnknownMethodException - If the headers' method (from the request line) is unknown.
ConfigurationException - If the was a server configuration issue the server cannot work properly with.
java.util.MissingResourceException - If the requested resource cannot be found.
AuthorizationException - If the requested resource requires authorization.
HeaderFormatException - If the passed headers are malformed.
DataFormatException - If the passed data is malformed.
java.lang.SecurityException - If the request cannot be processed due to security reasons.
java.io.IOException - If any IO errors occur.
MalformedRequestException
UnsupportedFormatException
ParametrizedHTTPException

execute

public final void execute()
                   throws java.io.IOException
This method executes the prepared reply; this means that all necessary resources will be accessed, the actual reply built and sent back to the client.

Specified by:
execute in interface PreparedHTTPResponse
Throws:
java.io.IOException - If any IO errors occur.

dispose

public abstract void dispose()
This method will be called in the final end - even if the execute() method failed. Subclasses implementing this method should call the setDisposed() method when done. It has to clean up, release resources and all locks!

Specified by:
dispose in interface PreparedHTTPResponse

isPrepared

public boolean isPrepared()
This method return true if (and only if) this response is already prepared. In the true-case the prepare()-method should not have any effects.

Specified by:
isPrepared in interface PreparedHTTPResponse

isExecuted

public boolean isExecuted()
The method returns true if (and only if) this response was already executed.

Specified by:
isExecuted in interface PreparedHTTPResponse

isDisposed

public boolean isDisposed()
The method returns true if (and only if) this response already disposed.

Specified by:
isDisposed in interface PreparedHTTPResponse