org.aselect.system.communication.server.raw
Class RawMessageCreator

java.lang.Object
  extended by org.aselect.system.communication.server.raw.RawMessageCreator
All Implemented Interfaces:
IInputMessage, IMessageCreatorInterface, IOutputMessage

public class RawMessageCreator
extends java.lang.Object
implements IMessageCreatorInterface

Message creator which uses CGI messages.

Description:
The RAW implementation of IMessageCreatorInterface. Processes and sends CGI URL encoded API calls.

Concurrency issues:
-

Author:
Alfa & Ariss

Constructor Summary
RawMessageCreator(SystemLogger systemLogger)
          Creates a new instance.
 
Method Summary
 java.util.Hashtable convertCGIMessage(java.lang.String sMessage)
          Convert a CGI string.
 java.lang.String[] getArray(java.lang.String sName)
          get an array parameter from a CGI query string message.
 java.lang.String getParam(java.lang.String sName)
          get a parameter from a CGI query string message.
 boolean init(IProtocolRequest oRequest, IProtocolResponse oResponse)
          Initializes the RawMessageCreator.
 boolean send()
          Send the repsonse as a CGI URL encoded query string.
 boolean setParam(java.lang.String sName, java.lang.String sValue)
          set a parameter as a CGI query string message.
 boolean setParam(java.lang.String sName, java.lang.String[] saValue)
          set an array parameter as a CGI query string message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RawMessageCreator

public RawMessageCreator(SystemLogger systemLogger)
Creates a new instance.

Description:
Creates a new RawMessageCreator. Sets the logger.

Concurrency issues:
For every request a instance of RawMessageCreator should be created.

Preconditions:
systemLogger should be initialized.

Postconditions:
The system logger is set.

Parameters:
systemLogger - The logger that should be used for system log entries.
Method Detail

init

public boolean init(IProtocolRequest oRequest,
                    IProtocolResponse oResponse)
             throws ASelectCommunicationException
Initializes the RawMessageCreator.

Description:
Initializes the RawMessageCreator:
This method should be the first that is called.

Concurrency issues:
Initialize should be performed once.

Preconditions:
Postconditions:
The input message is parsed and a empty response message is ready.

Specified by:
init in interface IMessageCreatorInterface
Parameters:
oRequest - The request to create an input message from.
oResponse - The response to write the output message to.
Returns:
true - if initialization was succesfull.
false - if initialization fails.
Throws:
ASelectCommunicationException - if communication fails.
See Also:
IMessageCreatorInterface.init(org.aselect.system.communication.server.IProtocolRequest, org.aselect.system.communication.server.IProtocolResponse)

getParam

public java.lang.String getParam(java.lang.String sName)
                          throws ASelectCommunicationException
get a parameter from a CGI query string message.

Specified by:
getParam in interface IInputMessage
Parameters:
sName - The name of the parameter to return.
Returns:
The value of the queried parameter.
Throws:
ASelectCommunicationException - If parameter retrieving fails.
See Also:
IInputMessage.getParam(java.lang.String)

getArray

public java.lang.String[] getArray(java.lang.String sName)
                            throws ASelectCommunicationException
get an array parameter from a CGI query string message.

Specified by:
getArray in interface IInputMessage
Parameters:
sName - The name of the parameter to return.
Returns:
An array of all values belonging to the queried parameter.
Throws:
ASelectCommunicationException - If parameter retrieving fails.
See Also:
IInputMessage.getArray(java.lang.String)

setParam

public boolean setParam(java.lang.String sName,
                        java.lang.String sValue)
                 throws ASelectCommunicationException
set a parameter as a CGI query string message.

Specified by:
setParam in interface IOutputMessage
Parameters:
sName - The name of the parameter
sValue - The value of the parameter
Returns:
true - if parameter succesfully set otherwise false.
Throws:
ASelectCommunicationException - If communication fails.
See Also:
IOutputMessage.setParam(java.lang.String, java.lang.String)

setParam

public boolean setParam(java.lang.String sName,
                        java.lang.String[] saValue)
                 throws ASelectCommunicationException
set an array parameter as a CGI query string message.

Specified by:
setParam in interface IOutputMessage
Parameters:
sName - The name of the parameter
saValue - The values of the parameter
Returns:
true - if parameter succesfully set otherwise false.
Throws:
ASelectCommunicationException - If communication fails.
See Also:
IOutputMessage.setParam(java.lang.String, java.lang.String[])

convertCGIMessage

public java.util.Hashtable convertCGIMessage(java.lang.String sMessage)
                                      throws ASelectCommunicationException
Convert a CGI string.

Description:
This method will convert a string of key=value&key=value etc. tuples (aka a CGI request string) into a hashtable for much easier processing. This method supports CGI array parameters.

Note: The key names are all converted to lowercase.

Concurrency issues:
The used Hashtable is threadsafe.

Preconditions:
sMessage should be a valid request string.

Postconditions:
-

Parameters:
sMessage - A CGI request string.
Returns:
The name/value pairs of the request in a Hashtable.
Throws:
ASelectCommunicationException - if decoding of value fails or internal error occurs.

send

public boolean send()
             throws ASelectCommunicationException
Send the repsonse as a CGI URL encoded query string.

Specified by:
send in interface IOutputMessage
Returns:
true if send successfully, otherwise false.
Throws:
ASelectCommunicationException - If communication fails.
See Also:
IOutputMessage.send()


Copyright © 2008 SURFnet BV. All Rights Reserved.