org.sr.common.json
Class JSONRequest

java.lang.Object
  extended by org.sr.common.json.JSONRequest

public class JSONRequest
extends java.lang.Object

This class represents an incoming message structure to the remote services. The following Java Script class shows a sample request message structure.
{
"id":"64f4f4b0-79ee-45f0-9b47-77836bc74ce8",
"method":"service.methodName",
"header":{
"headerField1": "headerVal",
"headerField2": "headerVal",
},
"parameters":{"param1","param2"}
}

Message Parts

id

This part should contain a unique message identifier for the message correlation. Results of operations will be sent to the clients by using same identifier. This would help clients to correlate their responses from server.

method

The method part contains target service and method (operation) name in dotted form. (Eg service.method)

header

The header part of the message can contain anything that you want to send to the server beside parameters.The header part is not accessible by services. Interceptors can access header fields to apply generic policies to service calls. For example you can send additional security credentials to create your own security.

parameters

This part contains the target operation's parameters.

Author:
Serhat Dirik

Field Summary
static java.lang.String HEADER_ATTRIBUTE
           
static java.lang.String METHOD_ATTRIBUTE
           
static java.lang.String PARAMETERS_ATTRIBUTE
           
static java.lang.String REQUESTID_ATTRIBUTE
           
 
Constructor Summary
JSONRequest()
          Creates new empty message
JSONRequest(JSONObject jsonReq)
          Use this constructor to wrap a prepared message within this class
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.util.Map<java.lang.String,java.lang.Object> getHeader()
          Gives headers as unmodifiable collection
 java.lang.String getMethodName()
           
 JSONArray getParameters()
           
 java.lang.String getRequestId()
           
 java.lang.String getServiceName()
           
 int hashCode()
           
 void putToHeader(java.lang.String fieldName, java.lang.Object value)
          Adds given field to the header
 void removeFromHeader(java.lang.String fieldName)
          Removes the requested field form the header
 void setEnclosedRequest(JSONObject jsonReq)
          Resets all parts of the message and assigns the from the given message parts
 void setHeader(java.util.Map<java.lang.String,java.lang.Object> header)
          Sets the header part of the message
 void setMethodName(java.lang.String methodName)
          Assigns the given parameter to the method name.
 void setParameters(JSONArray parameters)
          Sets given JSONArray as parameters
 void setParameters(java.lang.Object[] parameters)
          Sets given object array as parameters
 void setRequestId(java.lang.String requestId)
          Sets the unique request id for the message correlation
 void setServiceName(java.lang.String serviceName)
          Assigns the given parameter to the service name.
 JSONObject toJSON()
          Converts message to JSONObject.
 java.lang.String toString()
          Converts message to java script.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

METHOD_ATTRIBUTE

public static final java.lang.String METHOD_ATTRIBUTE
See Also:
Constant Field Values

PARAMETERS_ATTRIBUTE

public static final java.lang.String PARAMETERS_ATTRIBUTE
See Also:
Constant Field Values

REQUESTID_ATTRIBUTE

public static final java.lang.String REQUESTID_ATTRIBUTE
See Also:
Constant Field Values

HEADER_ATTRIBUTE

public static final java.lang.String HEADER_ATTRIBUTE
See Also:
Constant Field Values
Constructor Detail

JSONRequest

public JSONRequest()
Creates new empty message


JSONRequest

public JSONRequest(JSONObject jsonReq)
            throws JSONException,
                   TransformationException,
                   TransformationNotSupportedException
Use this constructor to wrap a prepared message within this class

Parameters:
jsonReq - message prepared with javascript notation
Throws:
JSONException
TransformationException
TransformationNotSupportedException
Method Detail

setEnclosedRequest

public void setEnclosedRequest(JSONObject jsonReq)
                        throws TransformationException,
                               TransformationNotSupportedException
Resets all parts of the message and assigns the from the given message parts

Parameters:
jsonReq -
Throws:
TransformationException
TransformationNotSupportedException

setServiceName

public void setServiceName(java.lang.String serviceName)
                    throws JSONException
Assigns the given parameter to the service name. The service name and message name will be merged in method part of the message in dotted form like "servicename.methodname".

Parameters:
serviceName -
Throws:
JSONException

setMethodName

public void setMethodName(java.lang.String methodName)
                   throws JSONException
Assigns the given parameter to the method name. The method name and service name will be merged in method part of the message in dotted form like "servicename.methodname".

Parameters:
methodName -
Throws:
JSONException

setParameters

public void setParameters(java.lang.Object[] parameters)
                   throws JSONException
Sets given object array as parameters

Parameters:
parameters -
Throws:
JSONException

setParameters

public void setParameters(JSONArray parameters)
                   throws JSONException
Sets given JSONArray as parameters

Parameters:
parameters -
Throws:
JSONException

setRequestId

public void setRequestId(java.lang.String requestId)
                  throws JSONException
Sets the unique request id for the message correlation

Parameters:
requestId -
Throws:
JSONException

setHeader

public void setHeader(java.util.Map<java.lang.String,java.lang.Object> header)
               throws JSONException,
                      TransformationException,
                      TransformationNotSupportedException
Sets the header part of the message

Parameters:
header -
Throws:
JSONException
TransformationException
TransformationNotSupportedException

getHeader

public java.util.Map<java.lang.String,java.lang.Object> getHeader()
Gives headers as unmodifiable collection

Returns:
unmodifiable header part

putToHeader

public void putToHeader(java.lang.String fieldName,
                        java.lang.Object value)
                 throws JSONException,
                        TransformationException,
                        TransformationNotSupportedException
Adds given field to the header

Parameters:
fieldName -
value -
Throws:
JSONException
TransformationException
TransformationNotSupportedException

removeFromHeader

public void removeFromHeader(java.lang.String fieldName)
                      throws JSONException,
                             TransformationException,
                             TransformationNotSupportedException
Removes the requested field form the header

Parameters:
fieldName -
Throws:
JSONException
TransformationException
TransformationNotSupportedException

getServiceName

public java.lang.String getServiceName()

getMethodName

public java.lang.String getMethodName()

getParameters

public JSONArray getParameters()

getRequestId

public java.lang.String getRequestId()

toJSON

public JSONObject toJSON()
Converts message to JSONObject.

Returns:
JSON Object

toString

public java.lang.String toString()
Converts message to java script.

Overrides:
toString in class java.lang.Object
Returns:
text in javascript notation

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object