public abstract class AbstractBaseResourceHandler extends java.lang.Object implements IResourceHandler, DocumentedResourceHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_ATOM_XML
atom format
|
static java.lang.String |
APPLICATION_JSON
json format
|
static java.lang.String |
APPLICATION_XHTML_XML
xhtml format
|
static java.lang.String |
APPLICATION_XML
xml format
|
static java.lang.String |
CHANGE_VERB
The string constant of "Change".
|
static java.lang.String |
COPYRIGHT
IBM Copyright notice field.
|
static java.lang.String |
PARAMETER_ACTION
action
|
static java.lang.String |
PARAMETER_ACTION_DESCRIPTION
action description
|
static java.lang.String |
PARAMETER_CATALOG_ID
catalogId
|
static java.lang.String |
PARAMETER_CATALOG_ID_DESCRIPTION
catalogId description
|
static java.lang.String |
PARAMETER_CURRENCY
currency
|
static java.lang.String |
PARAMETER_CURRENCY_DESCRIPTION
currency description
|
static java.lang.String |
PARAMETER_FOR_USER
forUser
|
static java.lang.String |
PARAMETER_FOR_USER_DESCRIPTION
forUser description
|
static java.lang.String |
PARAMETER_FOR_USER_ID
forUserId
|
static java.lang.String |
PARAMETER_FOR_USER_ID_DESCRIPTION
forUserId description
|
static java.lang.String |
PARAMETER_LANG_ID
langId parameter
|
static java.lang.String |
PARAMETER_LANG_ID_DESCRIPTION
langId description
|
static java.lang.String |
PARAMETER_LOCALE
locale
|
static java.lang.String |
PARAMETER_LOCALE_DESCRIPTION
locale description
|
static java.lang.String |
PARAMETER_MODE
mode
|
static java.lang.String |
PARAMETER_MODE_DESCRIPTION
mode description
|
static java.lang.String |
PARAMETER_PAGE_NUMBER
page number
|
static java.lang.String |
PARAMETER_PAGE_NUMBER_DESCRIPTION
page number description
|
static java.lang.String |
PARAMETER_PAGE_SIZE
page size
|
static java.lang.String |
PARAMETER_PAGE_SIZE_DESCRIPTION
page size description
|
static java.lang.String |
PARAMETER_PROFILE_NAME
profileName
|
static java.lang.String |
PARAMETER_PROFILE_NAME_DESCRIPTION
profileName description
|
static java.lang.String |
PARAMETER_QUERY
q
|
static java.lang.String |
PARAMETER_QUERY_DESCRIPTION
q description
|
static java.lang.String |
PARAMETER_RESET_PASSWORD_DESCRIPTION
Reset password description
|
static java.lang.String |
PARAMETER_RESPONSE_FORMAT
response format
|
static java.lang.String |
PARAMETER_RESPONSE_FORMAT_DESCRIPTION
response format description
|
static java.lang.String |
PARAMETER_STORE_ID
store identifier
|
static java.lang.String |
PARAMETER_STORE_ID_DESCRIPTION
store identifier description
|
static java.lang.String |
PARAMETER_WORKSPACE_IDENTIFIER
workspace Identifier
|
static java.lang.String |
PARAMETER_WORKSPACE_IDENTIFIER_DESCRIPTION
workspace Identifier description
|
static java.lang.String |
PARAMETER_WORKSPACE_NAME
workspace name
|
static java.lang.String |
PARAMETER_WORKSPACE_NAME_DESCRIPTION
workspace name description
|
static java.lang.String |
PARAMETER_WORKSPACE_TASK
workspace task
|
static java.lang.String |
PARAMETER_WORKSPACE_TASK_DESCRIPTION
workspace task description
|
static java.lang.String |
PARAMETER_WORKSPACE_TASKGROUP
workspace task group
|
static java.lang.String |
PARAMETER_WORKSPACE_TASKGROUP_DESCRIPTION
workspace task group description
|
static java.lang.String |
PROCESS_VERB
The string constant of "Process".
|
static java.lang.String |
RESPONSE_200_DESCRIPTION
200 return code description
|
static java.lang.String |
RESPONSE_201_DESCRIPTION
201 return code description
|
static java.lang.String |
RESPONSE_204_DESCRIPTION
204 return code description
|
static java.lang.String |
RESPONSE_400_DESCRIPTION
400 return code description
|
static java.lang.String |
RESPONSE_401_DESCRIPTION
401 return code description
|
static java.lang.String |
RESPONSE_403_DESCRIPTION
403 return code description
|
static java.lang.String |
RESPONSE_404_DESCRIPTION
404 return code description
|
static java.lang.String |
RESPONSE_500_DESCRIPTION
500 return code description
|
Constructor and Description |
---|
AbstractBaseResourceHandler() |
Modifier and Type | Method and Description |
---|---|
void |
addError(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToAdd)
Add an error to the list of detected errors.
|
java.util.Map<java.lang.String,java.lang.Object> |
createMapForProviderWithResultData(java.util.Map<java.lang.String,java.lang.Object> resultData,
java.lang.String resourceName)
This method create a Map for entity providers using the result map
instead of DataObject.
|
org.apache.commons.json.JSONObject |
documentApi(java.lang.String urlContextRoot,
AbstractBaseResourceHandler executionHandler,
java.util.Map<java.lang.String,java.lang.String> bundle,
java.util.Locale locale)
(non-Javadoc)
|
javax.ws.rs.core.Response |
generateResponseFromHttpStatusCodeAndRespData(java.lang.String responseFormat,
java.util.Map<java.lang.String,java.lang.Object> responseData,
org.apache.wink.common.http.HttpStatus statusCode)
This method generates REST response for a given response map.
|
OperationRegistry |
getActionRegistry()
Get the action registry for this handler.
|
boolean |
getBooleanParameterValue(java.lang.String parameterName,
boolean defaultValue,
boolean mandatory)
A utility method to get the boolean parameter value.
|
java.lang.String |
getClassDescription(java.util.Locale locale)
Get the class description based on description annotations.
|
java.lang.Double |
getDoubleParameterValue(java.lang.String parameterName,
java.lang.Double defaultValue,
boolean mandatory)
A utility method to get the Double parameter value.
|
java.lang.Double[] |
getDoubleParameterValues(java.lang.String parameterName,
java.lang.Double[] defaultValues,
boolean mandatory)
A utility method that may be called by a sub-class to get the Double parameters
values from request.
|
java.lang.String |
getEnumeratedParameterValue(java.lang.String parameterName,
java.lang.String defaultValue,
boolean mandatory,
java.util.Collection<java.lang.String> validValues)
A utility method that may be called by a sub-class to get a String
parameter from the request using a set of valid values.
|
static java.lang.String |
getErrorCodeFromMessage(java.lang.String errorMessage)
get the unique error code from a message
|
java.lang.String |
getExternalResourceName()
Get the resource name to show externally.
|
static java.lang.String |
getFormattedMessage(java.lang.String errorKey,
java.lang.Object... parameters)
Returns the message in the REST properties file named by the given key,
and formatted with the given parameters.
|
static java.lang.String |
getFormattedMessageWithLocale(java.lang.String errorKey,
java.util.Locale locale,
java.lang.Object... parameters)
Returns the message in the REST properties file named by the given key,
and formatted with the given parameters.
|
java.lang.String |
getFormattingGroupName()
Returns the formatting group name for resolving the struts action of the
formatting JSP.
|
com.ibm.commerce.rest.utils.Instrumentor |
getInstrumentor()
Return the instrumentor associated with this handler instance.
|
int |
getIntegerParameterValue(java.lang.String parameterName,
int defaultValue,
boolean mandatory)
A utility method to get the integer parameter value.
|
java.lang.Integer[] |
getIntegerParameterValues(java.lang.String parameterName,
java.lang.Integer[] defaultValues,
boolean mandatory)
A utility method that may be called by a sub-class to get the Integer parameters
values from request.
|
java.lang.Long |
getLongParameterValue(java.lang.String parameterName,
java.lang.Long defaultValue,
boolean mandatory)
A utility method to get the Long parameter value.
|
java.lang.Long[] |
getLongParameterValues(java.lang.String parameterName,
java.lang.Long[] defaultValues,
boolean mandatory)
A utility method that may be called by a sub-class to get the Long parameters
values from request.
|
java.lang.String |
getParameterValue(java.lang.String parameterName,
java.lang.String defaultValue,
boolean mandatory)
A utility method that may be called by a sub-class to get the parameter
value from request.
|
java.lang.String |
getParameterValue(java.lang.String parameterName,
java.lang.String defaultValue,
boolean mandatory,
boolean allowEmptyValue)
A utility method that may be called by a sub-class to get the parameter
value from request.
|
java.lang.String[] |
getParameterValues(java.lang.String parameterName,
java.lang.String[] defaultValues,
boolean mandatory)
A utility method that may be called by a sub-class to get the parameter
values from request.
|
OperationRegistry |
getQueryRegistry()
Get the query registry for this handler.
|
javax.servlet.http.HttpServletRequest |
getRequest()
Provides access to the servlet request object.
|
javax.servlet.http.HttpServletResponse |
getResponse()
Provides access to the servlet response object.
|
javax.ws.rs.core.UriInfo |
getUriInfo()
Provides access to application and request URI information.
|
javax.ws.rs.core.Response |
handleException(java.lang.String responseFormat,
java.lang.Exception ex,
java.lang.String methodName)
This method generates a special response for
AbstractBusinessObjectDocumentException and re-throw the original
exception.
|
void |
initializeActionRegistry(OperationRegistry registry)
Initialize the action registry.
|
void |
initializeQueryRegistry(OperationRegistry registry)
Initialize the query registry.
|
abstract boolean |
isRequestInPreviewMode()
Test if the request is executed in preview mode.
|
javax.ws.rs.core.Response |
performAction(java.lang.String action,
java.lang.String responseFormat,
java.lang.Object... parameters)
Performs an action.
|
void |
postProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
Method to provide post process in out of box JSON/XML entity providers
after each DataObject has been converted to a Map and before constructing
the REST response.
|
void |
preProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
This method does the pre-processing of the response map before the entity
provider is invoked passing the response map.
|
void |
registerOperationWithMethodSignature(OperationRegistry registry,
java.lang.String operationName,
java.lang.String description,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Register an operation with a method signature.
|
javax.ws.rs.core.Response |
runQuery(java.lang.String queryName,
java.lang.String responseFormat,
java.lang.Object... parameters)
Run a query.
|
static java.lang.String |
staticConvertStreamToString(java.io.InputStream is)
Convert a stream to a string using UTF-8 encoding.
|
void |
throwInvalidQueryNameException(java.lang.String queryName)
Throw an error if the query name isn't valid.
|
void |
throwInvalidQueryNameException(java.lang.String queryName,
java.util.Collection<java.lang.String> validNames)
Throw an error if the query name isn't valid.
|
void |
throwRestException(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToThrow)
Throw an exception right away due to a detected error.
|
void |
throwRestExceptionIfErrorsAreDetected()
Throw a RestException only if errors were detected using the
addError(RestError) method. |
void |
validatePageNumberPageSize(int pageNumber,
int pageSize)
Validates the page number and page size parameters.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getResourceName
public static final java.lang.String COPYRIGHT
public static final java.lang.String APPLICATION_ATOM_XML
public static final java.lang.String APPLICATION_JSON
public static final java.lang.String APPLICATION_XHTML_XML
public static final java.lang.String APPLICATION_XML
public static final java.lang.String PARAMETER_LANG_ID
public static final java.lang.String PARAMETER_LANG_ID_DESCRIPTION
public static final java.lang.String PARAMETER_QUERY
public static final java.lang.String PARAMETER_QUERY_DESCRIPTION
public static final java.lang.String PARAMETER_PROFILE_NAME
public static final java.lang.String PARAMETER_PROFILE_NAME_DESCRIPTION
public static final java.lang.String PARAMETER_LOCALE
public static final java.lang.String PARAMETER_LOCALE_DESCRIPTION
public static final java.lang.String PARAMETER_CATALOG_ID
public static final java.lang.String PARAMETER_CATALOG_ID_DESCRIPTION
public static final java.lang.String PARAMETER_CURRENCY
public static final java.lang.String PARAMETER_CURRENCY_DESCRIPTION
public static final java.lang.String PARAMETER_STORE_ID
public static final java.lang.String PARAMETER_STORE_ID_DESCRIPTION
public static final java.lang.String PARAMETER_PAGE_SIZE
public static final java.lang.String PARAMETER_PAGE_SIZE_DESCRIPTION
public static final java.lang.String PARAMETER_PAGE_NUMBER
public static final java.lang.String PARAMETER_PAGE_NUMBER_DESCRIPTION
public static final java.lang.String PARAMETER_RESPONSE_FORMAT
public static final java.lang.String PARAMETER_RESPONSE_FORMAT_DESCRIPTION
public static final java.lang.String PARAMETER_FOR_USER
public static final java.lang.String PARAMETER_FOR_USER_DESCRIPTION
public static final java.lang.String PARAMETER_FOR_USER_ID
public static final java.lang.String PARAMETER_FOR_USER_ID_DESCRIPTION
public static final java.lang.String PARAMETER_WORKSPACE_IDENTIFIER
public static final java.lang.String PARAMETER_WORKSPACE_IDENTIFIER_DESCRIPTION
public static final java.lang.String PARAMETER_WORKSPACE_NAME
public static final java.lang.String PARAMETER_WORKSPACE_NAME_DESCRIPTION
public static final java.lang.String PARAMETER_WORKSPACE_TASKGROUP
public static final java.lang.String PARAMETER_WORKSPACE_TASKGROUP_DESCRIPTION
public static final java.lang.String PARAMETER_WORKSPACE_TASK
public static final java.lang.String PARAMETER_WORKSPACE_TASK_DESCRIPTION
public static final java.lang.String PARAMETER_ACTION
public static final java.lang.String PARAMETER_ACTION_DESCRIPTION
public static final java.lang.String PARAMETER_MODE
public static final java.lang.String PARAMETER_MODE_DESCRIPTION
public static final java.lang.String PARAMETER_RESET_PASSWORD_DESCRIPTION
public static final java.lang.String RESPONSE_200_DESCRIPTION
public static final java.lang.String RESPONSE_201_DESCRIPTION
public static final java.lang.String RESPONSE_204_DESCRIPTION
public static final java.lang.String RESPONSE_400_DESCRIPTION
public static final java.lang.String RESPONSE_401_DESCRIPTION
public static final java.lang.String RESPONSE_403_DESCRIPTION
public static final java.lang.String RESPONSE_404_DESCRIPTION
public static final java.lang.String RESPONSE_500_DESCRIPTION
public static final java.lang.String PROCESS_VERB
public static final java.lang.String CHANGE_VERB
public com.ibm.commerce.rest.utils.Instrumentor getInstrumentor()
public javax.ws.rs.core.Response handleException(java.lang.String responseFormat, java.lang.Exception ex, java.lang.String methodName)
responseFormat
- response formatex
- ExceptionmethodName
- method name that throws the exception ex
.public void addError(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToAdd)
errorToAdd
- the error to add.public javax.ws.rs.core.UriInfo getUriInfo()
public javax.servlet.http.HttpServletRequest getRequest()
public javax.servlet.http.HttpServletResponse getResponse()
public static java.lang.String getFormattedMessage(java.lang.String errorKey, java.lang.Object... parameters)
errorKey
- The key for the error message. This value cannot be null or
empty.parameters
- The parameters to insert into the error message. A null array
may not be specified, but no parameters need be given.public static java.lang.String getFormattedMessageWithLocale(java.lang.String errorKey, java.util.Locale locale, java.lang.Object... parameters)
errorKey
- The key for the error message. This value cannot be null or
empty.locale
- The request locale.parameters
- The parameters to insert into the error message. A null array
may not be specified, but no parameters need be given.public static java.lang.String getErrorCodeFromMessage(java.lang.String errorMessage)
errorMessage
- the error messagepublic void throwRestExceptionIfErrorsAreDetected() throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
addError(RestError)
method.RestException
- The RestException containing all the detected errors.public abstract boolean isRequestInPreviewMode()
public java.lang.String getParameterValue(java.lang.String parameterName, java.lang.String defaultValue, boolean mandatory)
parameterName
- The parameter name.defaultValue
- The parameter's default value.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.public java.lang.String getParameterValue(java.lang.String parameterName, java.lang.String defaultValue, boolean mandatory, boolean allowEmptyValue)
parameterName
- The parameter name.defaultValue
- The parameter's default value.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.allowEmptyValue
- Flag to indicate if empty value is allowed for the parameter.
If not but empty value is received, register an exception.public java.lang.String[] getParameterValues(java.lang.String parameterName, java.lang.String[] defaultValues, boolean mandatory)
parameterName
- The parameter name.defaultValues
- The parameter's default values.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.public java.lang.Integer[] getIntegerParameterValues(java.lang.String parameterName, java.lang.Integer[] defaultValues, boolean mandatory)
parameterName
- The parameter name.defaultValues
- The parameter's default values.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.public java.lang.Long[] getLongParameterValues(java.lang.String parameterName, java.lang.Long[] defaultValues, boolean mandatory)
parameterName
- The parameter name.defaultValues
- The parameter's default values.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.public java.lang.Double[] getDoubleParameterValues(java.lang.String parameterName, java.lang.Double[] defaultValues, boolean mandatory)
parameterName
- The parameter name.defaultValues
- The parameter's default values.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.public java.lang.String getEnumeratedParameterValue(java.lang.String parameterName, java.lang.String defaultValue, boolean mandatory, java.util.Collection<java.lang.String> validValues)
parameterName
- The parameter name.defaultValue
- The parameter's default value.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
exception.validValues
- the set of valid values.public boolean getBooleanParameterValue(java.lang.String parameterName, boolean defaultValue, boolean mandatory)
parameterName
- The parameter name.defaultValue
- The default value for the parameter.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
error.public int getIntegerParameterValue(java.lang.String parameterName, int defaultValue, boolean mandatory)
parameterName
- The parameter name.defaultValue
- The default value for parameter.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
error.public java.lang.Long getLongParameterValue(java.lang.String parameterName, java.lang.Long defaultValue, boolean mandatory)
parameterName
- The parameter name.defaultValue
- The default value for parameter.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
error.public java.lang.Double getDoubleParameterValue(java.lang.String parameterName, java.lang.Double defaultValue, boolean mandatory)
parameterName
- The parameter name.defaultValue
- The default value for parameter.mandatory
- Flag to indicate if the parameter is mandatory. If the value
is not provided for the mandatory parameter, register an
error.public void throwInvalidQueryNameException(java.lang.String queryName, java.util.Collection<java.lang.String> validNames) throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
queryName
- the query name.validNames
- the collection of valid query names.RestException
- the exception indicating that the query is invalid.public void throwInvalidQueryNameException(java.lang.String queryName) throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
queryName
- the query name.RestException
- the exception indicating that the query is invalid.public void throwRestException(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToThrow) throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
errorToThrow
- The detected error.RestException
- the RestException that will contain the specified error as
well as all the other errors detected so far.public java.util.Map<java.lang.String,java.lang.Object> createMapForProviderWithResultData(java.util.Map<java.lang.String,java.lang.Object> resultData, java.lang.String resourceName)
resultData
- Result map from REST resource handler.resourceName
- resource namepublic void preProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
Overwrite this method in your resource handler class to customize the response map.
preProcess
in interface IResourceHandler
responseMap
- the response map.public void postProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
postProcess
in interface IResourceHandler
responseMap
- The response Map after each DataObject has been converted to a
Map.public java.lang.String getFormattingGroupName()
getFormattingGroupName
in interface IResourceHandler
public javax.ws.rs.core.Response generateResponseFromHttpStatusCodeAndRespData(java.lang.String responseFormat, java.util.Map<java.lang.String,java.lang.Object> responseData, org.apache.wink.common.http.HttpStatus statusCode)
Use this method in your resource handler class when you want to pass name value pairs to the entity provider.
generateResponseFromHttpStatusCodeAndRespData
in interface IResourceHandler
responseFormat
- the response format shortcut. Response format is used to
resolve the media type for the REST response. If response
format is not provided, then Accept
header is
used to resolve the media type for the REST response. Refer to
MediaTypeHelper.getResponseMediaType(String, Request)
for more details on the response media type resolution.responseData
- the response map to pass to the entity provider.statusCode
- the HTTP status code to set in the REST response.public java.lang.String getExternalResourceName()
public org.apache.commons.json.JSONObject documentApi(java.lang.String urlContextRoot, AbstractBaseResourceHandler executionHandler, java.util.Map<java.lang.String,java.lang.String> bundle, java.util.Locale locale) throws java.lang.Exception
documentApi
in interface DocumentedResourceHandler
urlContextRoot
- the API URL context root.executionHandler
- the resource handler currently executing the request.bundle
- The resource bundle to generate.locale
- The locale to use.java.lang.Exception
- if anything goes wrong.#documentApi(java.lang.String,
com.ibm.commerce.foundation.rest.resourcehandler
.AbstractBaseResourceHandler, java.util.Map, java.util.Locale)
public java.lang.String getClassDescription(java.util.Locale locale)
DocumentedResourceHandler
getClassDescription
in interface DocumentedResourceHandler
locale
- The locale to use.public OperationRegistry getQueryRegistry()
public void initializeQueryRegistry(OperationRegistry registry)
registry
- The query registry to initialize.public OperationRegistry getActionRegistry()
public void initializeActionRegistry(OperationRegistry registry)
registry
- The query registry to initialize.public void registerOperationWithMethodSignature(OperationRegistry registry, java.lang.String operationName, java.lang.String description, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
registry
- The operation registry.operationName
- The operation name to register.description
- The operation description.methodName
- The method name to call.parameterTypes
- The parameters in the method to call.public javax.ws.rs.core.Response runQuery(java.lang.String queryName, java.lang.String responseFormat, java.lang.Object... parameters)
queryName
- Name of the query to execute.responseFormat
- The response format.parameters
- The parameters to use while running the query.public javax.ws.rs.core.Response performAction(java.lang.String action, java.lang.String responseFormat, java.lang.Object... parameters)
action
- Name of the action to perform.responseFormat
- The response format.parameters
- The parameters to use while performing the action.public static java.lang.String staticConvertStreamToString(java.io.InputStream is) throws java.io.IOException
is
- The input stream to convert.java.io.IOException
- If reading the stream fails.public void validatePageNumberPageSize(int pageNumber, int pageSize)
pageNumber
- The page number parameter.pageSize
- The page size parameter.