org.abstracthorizon.danube.http
Class BaseReflectionHTTPConnectionHandler

java.lang.Object
  extended by org.abstracthorizon.danube.http.BaseReflectionHTTPConnectionHandler
All Implemented Interfaces:
ConnectionHandler
Direct Known Subclasses:
BaseWebDAVResourceConnectionHandler, ReadOnlyFileConnectionHandler

public class BaseReflectionHTTPConnectionHandler
extends Object
implements ConnectionHandler

This is base http connection handler that splits different HTTP methods (GET, POST, PUT, DELETE, HEAD, TRACE, OPTIONS and possibly others) to methods with names starting with "method"l and ending with HTTP method name. For instanceof methodGET, methodPOST, etc.

This handler also defines default HEAD and TRACE method implementations (methodHEAD and methodTRACE). These can be easily disabled with setNoDefaultHead(boolean) and setNoDefaultTrace(boolean) properties. That does not affect user defined HEAD and TRACE implementations.

HTTP method OPTIONS is handled by methodOPTIONS(HTTPConnection) method. It returns all those that are defined in the class.

Author:
Daniel Sendula

Field Summary
protected  Map<String,Method> cachedMethods
           
protected  ConnectionHandler errorResponse
          Error response
protected  boolean noDefaultHead
          Flag that shows should default HEAD handling method be included or not (methodHead(HttpConnection)
protected  boolean noDefaultTrace
          Flag that shows should default TRACE handling method be included or not (methodTrace(HttpConnection)
 
Constructor Summary
BaseReflectionHTTPConnectionHandler()
          Constructor
 
Method Summary
protected  void cacheMethods()
          Caches HTTP to java methods.
 ConnectionHandler getErrorResponse()
          Returns error response connection handler
 boolean getNoDefaultHead()
          Returns if default HEAD handling method is to be included or not
 boolean getNoDefaultTrace()
          Returns if default TRACE handling method is to be included or not
 void handleConnection(Connection connection)
          Handles connection
protected  void invokeMethod(HTTPConnection httpConnection, String methodName)
          Invokes object's method
 void methodHEAD(HTTPConnection httpConnection)
          Handles OPTIONS HTTP method
 void methodOPTIONS(HTTPConnection httpConnection)
          Handles OPTIONS HTTP method
 void methodTRACE(HTTPConnection httpConnection)
          Handles OPTIONS HTTP method
 void returnError(HTTPConnection httpConnection, Status status)
           
 void returnSimpleContent(HTTPConnection httpConnection, Status status, String contentType, String content)
           
 void setErrorResponse(ConnectionHandler errorResponse)
          Sets error response connection handler
 void setNoDefaultHead(boolean noDefaultHead)
          Sets if default HEAD handling method is to be included or not
 void setNoDefaultTrace(boolean noDefaultTrace)
          Sets if default TRACE handling method is to be included or not
protected  void updateDefaultHeadMethod()
          Updates the state of default HEAD method implementation.
protected  void updateDefaultTraceMethod()
          Updates the state of default TRACE method implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedMethods

protected Map<String,Method> cachedMethods

noDefaultHead

protected boolean noDefaultHead
Flag that shows should default HEAD handling method be included or not (methodHead(HttpConnection)


noDefaultTrace

protected boolean noDefaultTrace
Flag that shows should default TRACE handling method be included or not (methodTrace(HttpConnection)


errorResponse

protected ConnectionHandler errorResponse
Error response

Constructor Detail

BaseReflectionHTTPConnectionHandler

public BaseReflectionHTTPConnectionHandler()
Constructor

Method Detail

getErrorResponse

public ConnectionHandler getErrorResponse()
Returns error response connection handler

Returns:
error response connection handler

setErrorResponse

public void setErrorResponse(ConnectionHandler errorResponse)
Sets error response connection handler

Parameters:
errorResponse - error response handler

getNoDefaultHead

public boolean getNoDefaultHead()
Returns if default HEAD handling method is to be included or not

Returns:
true if default HEAD handling method is to be included

setNoDefaultHead

public void setNoDefaultHead(boolean noDefaultHead)
Sets if default HEAD handling method is to be included or not

Parameters:
noDefaultHead - should default HEAD handling method is to be included or not

updateDefaultHeadMethod

protected void updateDefaultHeadMethod()
Updates the state of default HEAD method implementation.


getNoDefaultTrace

public boolean getNoDefaultTrace()
Returns if default TRACE handling method is to be included or not

Returns:
true if default TRACE handling method is to be included

setNoDefaultTrace

public void setNoDefaultTrace(boolean noDefaultTrace)
Sets if default TRACE handling method is to be included or not

Parameters:
noDefaultTrace - should default TRACE handling method is to be included or not

updateDefaultTraceMethod

protected void updateDefaultTraceMethod()
Updates the state of default TRACE method implementation.


cacheMethods

protected void cacheMethods()
Caches HTTP to java methods. Methods that start with "method", has HTTPConnection as a single parameter are cached.


handleConnection

public void handleConnection(Connection connection)
Handles connection

Specified by:
handleConnection in interface ConnectionHandler
Parameters:
connection - connection

invokeMethod

protected void invokeMethod(HTTPConnection httpConnection,
                            String methodName)
Invokes object's method

Parameters:
httpConnection - http connection
methodName - method name

methodOPTIONS

public void methodOPTIONS(HTTPConnection httpConnection)
Handles OPTIONS HTTP method

Parameters:
httpConnection - HTTP connection

methodTRACE

public void methodTRACE(HTTPConnection httpConnection)
Handles OPTIONS HTTP method

Parameters:
httpConnection - HTTP connection

methodHEAD

public void methodHEAD(HTTPConnection httpConnection)
Handles OPTIONS HTTP method

Parameters:
httpConnection - HTTP connection

returnError

public void returnError(HTTPConnection httpConnection,
                        Status status)

returnSimpleContent

public void returnSimpleContent(HTTPConnection httpConnection,
                                Status status,
                                String contentType,
                                String content)


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.