atg.rest.input
Class JSONInputCustomizer

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.rest.input.RestInputCustomizerImpl
              extended by atg.rest.input.JSONInputCustomizer
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, RestInputCustomizer, java.util.EventListener

public class JSONInputCustomizer
extends RestInputCustomizerImpl

This class implements a JSON REST input customizer. A REST input customizer is used to parse data which is sent in a REST request.

See Also:
RestInputCustomizer

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String MAP_CLASS
           
 
Fields inherited from class atg.rest.input.RestInputCustomizerImpl
SPACE
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
JSONInputCustomizer()
          Constructor
 
Method Summary
 java.util.Map<java.lang.String,java.lang.Object> convertToMap(java.lang.Object pObject, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Converts the supplied object to a Map of parameters.
 java.lang.Class<?> getContainerClass()
          Returns the JSONObject class object, the container used for JSON data.
 java.lang.Object instantiateObjectParameter(java.lang.Object pJSON, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Instantiates an object argument from the given JSONObject.
protected  boolean isMultiValued(java.lang.Class<?> pClass)
          Returns true if pClass is a Collection (List or Set) or a Map.
static JSONObject isValidJSONString(java.lang.String pString)
          Returns a JSONObject if the specified string is a valid JSON string, null otherwise
 boolean isValidTypeString(java.lang.String pData)
          Returns true if the specified string is a valid JSON string, false otherwise
 java.lang.Object parseString(java.lang.String pData, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns a JSONObject representing the data from the pData string
protected  java.lang.Object processJSONMultiValue(java.lang.Object pObj, JSONObject pMultiValueDescriptor, java.lang.Class<?> pPropType, java.lang.String pPropName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          process a json multi value, convert it into a java object
protected  java.lang.Object produceMultivalueComponentObject(java.lang.Object pCurrentValue, JSONObject pMultiValueDescriptor, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          produce a result object for a multivalue component item
 java.lang.String[] splitMultipleStringsAtCharacter(java.lang.String pData, char pChar)
          Splits multiple json strings at the specified character
 
Methods inherited from class atg.rest.input.RestInputCustomizerImpl
getAcceptableMimeTypes, getEncoding, getFormat, getInputCustomizer, getInputCustomizer, getMapKeyElementString, getMapValueElementString, javaInstanceForClass, setAcceptableMimeTypes, setEncoding, setFormat, setMapKeyElementString, setMapValueElementString
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


MAP_CLASS

public static java.lang.String MAP_CLASS
Constructor Detail

JSONInputCustomizer

public JSONInputCustomizer()
Constructor

Method Detail

getContainerClass

public java.lang.Class<?> getContainerClass()
Returns the JSONObject class object, the container used for JSON data.

Returns:
the JSONObject class object

parseString

public java.lang.Object parseString(java.lang.String pData,
                                    DynamoHttpServletRequest pRequest,
                                    DynamoHttpServletResponse pResponse)
                             throws RestException
Returns a JSONObject representing the data from the pData string

Parameters:
pData - a String which contains the data stream
pRequest - the servlet request
pResponse - the servlet response
Returns:
an JSONObject representing the data from pData
Throws:
RestException - if the string in pData cannot be parsed

convertToMap

public java.util.Map<java.lang.String,java.lang.Object> convertToMap(java.lang.Object pObject,
                                                                     DynamoHttpServletRequest pRequest,
                                                                     DynamoHttpServletResponse pResponse)
                                                              throws RestException
Converts the supplied object to a Map of parameters. The object must be a JSONObject.

Parameters:
pObject - the object to convert, a JSONObject
pRequest - the servlet request
pResponse - the servlet response
Returns:
a Map with the values from pObject
Throws:
RestException - if pObject is not a JSONObject or if an error occurs reading from pObject

instantiateObjectParameter

public java.lang.Object instantiateObjectParameter(java.lang.Object pJSON,
                                                   DynamoHttpServletRequest pRequest,
                                                   DynamoHttpServletResponse pResponse)
                                            throws RestException
Instantiates an object argument from the given JSONObject. Here's an example of nested multi-valued collections

 {arg1 : {
   "atg-rest-class-type":"foo.class.WithNestedMultis",
   "atg-rest-class-descriptor": {
     "myListOfSets": {
       "container-class": "java.util.ArrayList",
       "element-class": "java.util.HashSet"
     }
   },
   "myListOfSets": [["red","blue"],["green","yellow"]]
 }}
 

See "Nested Multiple Value Objects in Input" section of ATG Web Services and Integration Framework Guide.

Parameters:
pJSON - the JSONObject which contains the data for the object to instantiate
pRequest - the servlet request
pResponse - the servlet response
Returns:
the instantiated object
Throws:
RestException - if there is neither an "atg-rest-class-type" property or "class" property or if pJSON is not a JSONObject

isMultiValued

protected boolean isMultiValued(java.lang.Class<?> pClass)
Returns true if pClass is a Collection (List or Set) or a Map.

Parameters:
pClass - The class we are testing to see if it's multi-valued.
Returns:
true if pClass is multi-valued ISSUE: Should we return true if the class is an array?

processJSONMultiValue

protected java.lang.Object processJSONMultiValue(java.lang.Object pObj,
                                                 JSONObject pMultiValueDescriptor,
                                                 java.lang.Class<?> pPropType,
                                                 java.lang.String pPropName,
                                                 DynamoHttpServletRequest pRequest,
                                                 DynamoHttpServletResponse pResponse)
                                          throws RestException
process a json multi value, convert it into a java object

Parameters:
pObj - the json object
pMultiValueDescriptor - the type descriptor
pPropType - the property type for the object
pPropName - the name of the property
pRequest - the Dynamo request
pResponse - the Dynamo response
Returns:
the resulting java multi value object
Throws:
java.lang.Exception - if there was an error creating the java multi value object
RestException

produceMultivalueComponentObject

protected java.lang.Object produceMultivalueComponentObject(java.lang.Object pCurrentValue,
                                                            JSONObject pMultiValueDescriptor,
                                                            DynamoHttpServletRequest pRequest,
                                                            DynamoHttpServletResponse pResponse)
                                                     throws RestException
produce a result object for a multivalue component item

Parameters:
pCurrentValue - the current json value
pMultiValueDescriptor - the current type descriptor
pRequest - the dynamo request
pResponse - the dynamo response
Returns:
the java object for the given json value
Throws:
java.lang.Exception - if there was an error producing the java object
RestException

splitMultipleStringsAtCharacter

public java.lang.String[] splitMultipleStringsAtCharacter(java.lang.String pData,
                                                          char pChar)
Splits multiple json strings at the specified character

Parameters:
pData - the string to split
pChar - the character to split at
Returns:
a String array with each json string

isValidJSONString

public static JSONObject isValidJSONString(java.lang.String pString)
Returns a JSONObject if the specified string is a valid JSON string, null otherwise

Parameters:
pString - the string to test
Returns:
a JSONObject if the specified string is a valid JSON string, null otherwise

isValidTypeString

public boolean isValidTypeString(java.lang.String pData)
Returns true if the specified string is a valid JSON string, false otherwise

Parameters:
pData - the string to test
Returns:
true if the specified string is a valid JSON string, false otherwise