SRJRCFrames
v0.1.296

de.schwarzrot.net.http.service
Class AbstractProtocolHandler

java.lang.Object
  extended by de.schwarzrot.net.http.service.AbstractProtocolHandler
All Implemented Interfaces:
ProtocolHandler

public abstract class AbstractProtocolHandler
extends Object
implements ProtocolHandler

base class for protocol handler, where protocol is the response format of HTTP requests. Main purpose is a general handling of error- and help-messages.

Author:
Reinhard Mantey

Field Summary
protected static String HELP
           
protected static String STD_MSG_404
           
 
Constructor Summary
AbstractProtocolHandler()
           
 
Method Summary
protected  boolean checkGlobalCommands(PrintWriter out, Map<String,String> header, Map<String,String> request)
           
 void doHelp(PrintWriter out)
          prints the help about the service, the supported calls and their parameters.
 void err404(PrintWriter out, String command)
          sends an error message to the client
 Map<String,RequestHandler> getRequestHandlers()
          accessor to the map of RequestHandler.
 HTTPServer<?> getServer()
          accessor the the HTTP server engine.
 void processRequest(Socket clientSocket, Map<String,String> header, Map<String,String> request)
          the entrypoint for request processing.
 void setRequestHandlers(Map<String,RequestHandler> requestHandlerMap)
          accessor to set the map of RequestHandler.
 void setup(HTTPServer<?> srv)
          used for asynchronous setup.
 void status(PrintWriter out, HttpStatusCode status)
           
 void status(PrintWriter out, HttpStatusCode status, String message)
           
protected abstract  String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STD_MSG_404

protected static final String STD_MSG_404
See Also:
Constant Field Values

HELP

protected static final String HELP
See Also:
Constant Field Values
Constructor Detail

AbstractProtocolHandler

public AbstractProtocolHandler()
Method Detail

doHelp

public void doHelp(PrintWriter out)
Description copied from interface: ProtocolHandler
prints the help about the service, the supported calls and their parameters. Will be used by RequestHandler on invalid/incomplete calls.

Specified by:
doHelp in interface ProtocolHandler
Parameters:
out - - the printwriter to used to send a message to client

err404

public void err404(PrintWriter out,
                   String command)
Description copied from interface: ProtocolHandler
sends an error message to the client

Specified by:
err404 in interface ProtocolHandler
Parameters:
out - - the PrintWriter used to write a client response
command - - specify the requested location, that could not be resolved

getRequestHandlers

public Map<String,RequestHandler> getRequestHandlers()
Description copied from interface: ProtocolHandler
accessor to the map of RequestHandler. The request handlers are plugged in by application context configuration

Specified by:
getRequestHandlers in interface ProtocolHandler
Returns:
- the map of request handlers

getServer

public HTTPServer<?> getServer()
Description copied from interface: ProtocolHandler
accessor the the HTTP server engine. Will be used for message-handling or the like

Specified by:
getServer in interface ProtocolHandler
Returns:
- the server instance

processRequest

public void processRequest(Socket clientSocket,
                           Map<String,String> header,
                           Map<String,String> request)
                    throws Exception
Description copied from interface: ProtocolHandler
the entrypoint for request processing.

Specified by:
processRequest in interface ProtocolHandler
Parameters:
clientSocket - - the socket for client communication
header - - the parameters from HTTP header
request - - the request parameters
Throws:
Exception - - if anything goes wrong

setRequestHandlers

public void setRequestHandlers(Map<String,RequestHandler> requestHandlerMap)
Description copied from interface: ProtocolHandler
accessor to set the map of RequestHandler. The request handlers are plugged in by application context configuration

Specified by:
setRequestHandlers in interface ProtocolHandler
Parameters:
requestHandlerMap - - the map of RequestHandler

setup

public void setup(HTTPServer<?> srv)
Description copied from interface: ProtocolHandler
used for asynchronous setup. The instances will be created by application context, but are not configured completely. So the HTTPServer will start the rest of configuration, before accepting connections from clients.

Specified by:
setup in interface ProtocolHandler
Parameters:
srv - - the HTTPServer instance

status

public void status(PrintWriter out,
                   HttpStatusCode status)
Specified by:
status in interface ProtocolHandler

status

public void status(PrintWriter out,
                   HttpStatusCode status,
                   String message)
Specified by:
status in interface ProtocolHandler

checkGlobalCommands

protected boolean checkGlobalCommands(PrintWriter out,
                                      Map<String,String> header,
                                      Map<String,String> request)
                               throws Exception
Throws:
Exception

usage

protected abstract String usage()

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.