public class RestUtils extends GenericService
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string.
|
static java.lang.String |
DEFAULT_REST_UTILS_PATH
Default path to a configuration instance of this service
|
static java.lang.String |
ID_PROPERTY |
static java.lang.String |
REST_REQUEST_DATA_KEY_PREFIX
The prefix added to request data.
|
protected static RestUtils |
sDefaultRestUtils |
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
RestUtils() |
Modifier and Type | Method and Description |
---|---|
void |
addRestRequestData(java.lang.String pKey,
java.lang.Object pValue)
Store data for the rest request.
|
java.lang.String[] |
buildPageMembersUris(ListingResponse pListingResponse,
<any> pQueryParams,
java.lang.String pIdPropertyName)
Returns string uri(s) for member(s) based on the ListingResponse items.
|
RestException |
createException(int pStatus,
java.lang.String pMessage)
Set an error for this request.
|
RestException |
createException(int pStatus,
java.lang.String pMessage,
java.util.List<java.lang.Exception> pErrors)
Set an error containing multiple error messages.
|
RestException |
createException(int pStatus,
java.lang.String pErrorCode,
java.lang.String pMessage,
java.lang.String pDevMessage,
java.lang.String pMoreInfo,
java.lang.Throwable pRootCause,
java.util.List<java.lang.Exception> pAllErrors)
Set an error for this request.
|
RestException |
createException(java.lang.String pMessage)
Set an error for this request.
|
RestException |
createException(java.lang.String pErrorCode,
java.lang.String pMessage,
java.lang.String pDevMessage,
java.lang.String pMoreInfo)
Set an error for this request, default to using
status 500.
|
RestException |
createException(java.lang.String pMessage,
java.lang.Throwable pRootCause)
Set an error for this request, default to using
status 500.
|
RestException |
createException(java.lang.Throwable pException)
Handle an error during the doAction() method and build a jaxrs
exception.
|
int |
determineResourceVersion(java.lang.Object pVersionedObject)
Utility method an endpoint may use to invoke the ETag service to try and determine a version for the given
object.
|
RestResourceRegistry |
getCurrentRegistry()
Utility method to retrieve the current registry in context
|
java.lang.String |
getCurrentResourceId()
Gets the id of the current resource in context.
|
java.lang.String |
getDefaultCurie() |
java.util.Map<java.lang.String,java.lang.Object> |
getErrorAttributes(java.lang.Throwable pCurrentException,
java.util.Set<java.lang.Throwable> pProcessedExceptions) |
atg.service.jaxrs.RestExceptionRegistry |
getExceptionRegistry()
Return exceptionRegistry.
|
ListingRequest |
getListingRequest(int pDefaultLimit)
Utility method to build the listing request.
|
JAXRSApplication |
getMatchingApplication(java.lang.String pUriPath) |
RepresentationModel.Builder |
getModelBuilderWithPaging(int pDefResourcePageSize,
boolean pSortAllowed,
java.lang.String pIdPropertyName,
<any> pQueryParams,
java.util.Collection pMembers)
Build the model with the members set to a page of the given collection
(list/set) and the ListingResponse for pagination set.
|
RepresentationModel.Builder |
getModelBuilderWithPaging(int pDefaultResourcePageSize,
java.lang.String pIdPropertyName,
<any> pQueryParams,
java.lang.String... pMembersIds)
Build the model with the members set to a page of the given array and the
ListingResponse for pagination set.
|
RelationsRegistry |
getRelationsRegistry()
Reference to the relations registry that can be used to access curie details or other relation data.
|
Response |
getResource(java.lang.String pRelName,
java.lang.String pResourceURI,
java.lang.String pUseValidatorId,
int pFilterDepth,
boolean pCrossRegistryURI)
Uses the internal client to call into Jersey and retrieve a resource representation
for the given resource URI.
|
java.lang.Object |
getResourceReference(java.lang.String pResourceId)
Utility method to get a reference to a resource by its id.
|
atg.service.jaxrs.RestUpdateInfo.RestResourceUpdateInfo |
getResourceUpdateInfo()
Utility method to the ResourceUpdateInfo for the current request
|
java.lang.Object |
getRestRequestData(java.lang.String pKey)
Get rest request data.
|
static RestUtils |
getRestUtils()
//----------------------------------------
Static method to get an instance of this component.
|
java.lang.Object |
getRootResource()
Utility method to return the resource representation for the root resource of the request in context.
|
java.lang.String |
getRootResourcePath()
Utility method to get the string uri path for the singular root resource of the current request resource.
|
protected java.sql.SQLException |
getSQLException(java.lang.Throwable pException)
Recursively searches the exception for a SQLException.
|
boolean |
isTemplatedPath(java.lang.String pPath)
Utility method to determine if the given path string has any templated parts, e.g.
|
void |
setExceptionRegistry(atg.service.jaxrs.RestExceptionRegistry pExceptionRegistry)
Set exceptionRegistry.
|
void |
setRelationsRegistry(RelationsRegistry pRelationsRegistry)
Reference to the relations registry that can be used to access curie details or other relation data.
|
boolean |
shouldLogError(int pStatusCode)
Check to see if we should log the given error.
|
void |
sortListingResponse(ListingResponse pListingResponse)
Sort the ListingResponse collection if the orderBy or sortBy param was set.
|
void |
streamState(java.io.OutputStream pStream,
byte[] pStateBinary)
Write the state information passed in pState to the output stream passed in pStream.
|
void |
streamState(java.io.OutputStream pStream,
java.lang.String pState)
Write the state information passed in pState to the output stream passed in pStream.
|
RestException |
toRestException(java.lang.Throwable pOriginatingException) |
void |
validateInputObject(java.lang.Object pInputObject)
Utility method to invoke validation of an input object.
|
void |
validateInputObject(java.lang.Object pInputObject,
java.lang.String pValidatorId)
Utility method to invoke validation of an object using
the specified validator
|
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, toString
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
public static java.lang.String CLASS_VERSION
public static final java.lang.String REST_REQUEST_DATA_KEY_PREFIX
public static final java.lang.String DEFAULT_REST_UTILS_PATH
public static final java.lang.String ID_PROPERTY
protected static RestUtils sDefaultRestUtils
public static RestUtils getRestUtils()
public RelationsRegistry getRelationsRegistry()
public void setRelationsRegistry(RelationsRegistry pRelationsRegistry)
pRelationsRegistry
- RelationsRegistry referencepublic void setExceptionRegistry(atg.service.jaxrs.RestExceptionRegistry pExceptionRegistry)
pExceptionRegistry
- the exception registry property.RestExceptionRegistry
public atg.service.jaxrs.RestExceptionRegistry getExceptionRegistry()
public RestException createException(int pStatus, java.lang.String pErrorCode, java.lang.String pMessage, java.lang.String pDevMessage, java.lang.String pMoreInfo, java.lang.Throwable pRootCause, java.util.List<java.lang.Exception> pAllErrors)
pStatus
- the http response status code ie 404, 500 etc.pErrorCode
- an internal application-specific error codepMessage
- the error message, suitable for display in a UIpDevMessage
- an optional developer-oriented error message to give
more in-depth information about the error conditionpMoreInfo
- an optional url link for additional information about
the error conditionpRootCause
- the root cause of the exception. May be null.pAllErrors
- other exceptions that have occurred along with this errorpublic RestException createException(int pStatus, java.lang.String pMessage, java.util.List<java.lang.Exception> pErrors)
pStatus
- the http response status code ie 404, 500 etc.pMessage
- the optional general error messagepErrors
- errors that have occurred, possibly more than one.public RestException createException(java.lang.Throwable pException)
pException
- the exception to create jaxrs exception from.public RestException createException(java.lang.String pMessage, java.lang.Throwable pRootCause)
pMessage
- the error message, suitable for display in a UIpRootCause
- the root cause of the exception. May be null.public RestException toRestException(java.lang.Throwable pOriginatingException)
public java.util.Map<java.lang.String,java.lang.Object> getErrorAttributes(java.lang.Throwable pCurrentException, java.util.Set<java.lang.Throwable> pProcessedExceptions)
public RestException createException(int pStatus, java.lang.String pMessage)
pStatus
- the http response status code ie 404, 500 etc.pMessage
- the error message, suitable for display in a UIpublic RestException createException(java.lang.String pMessage)
pMessage
- the error message, suitable for display in a UIpublic RestException createException(java.lang.String pErrorCode, java.lang.String pMessage, java.lang.String pDevMessage, java.lang.String pMoreInfo)
pErrorCode
- an internal application-specific error codepMessage
- the error message, suitable for display in a UIpDevMessage
- an optional developer-oriented error message to give
more in-depth information about the error conditionpMoreInfo
- an optional url link for additional information about
the error conditionpublic boolean shouldLogError(int pStatusCode)
pStatusCode
- the http response status code ie 404, 500 etc.protected java.sql.SQLException getSQLException(java.lang.Throwable pException)
pException
- root cause to build sql exception from.public void streamState(java.io.OutputStream pStream, java.lang.String pState) throws java.io.IOException
pStream
- the output stream.pState
- the state information as a string.java.io.IOException
- is an error occurs communicating with the stream.public void streamState(java.io.OutputStream pStream, byte[] pStateBinary) throws java.io.IOException
pStream
- the output stream.pStateBinary
- the state information as an array of bytes.java.io.IOException
- is an error occurs communicating with the stream.public JAXRSApplication getMatchingApplication(java.lang.String pUriPath)
public Response getResource(java.lang.String pRelName, java.lang.String pResourceURI, java.lang.String pUseValidatorId, int pFilterDepth, boolean pCrossRegistryURI)
pRelName
- String rel name that this resource will be embedded withpResourceURI
- URI to the resource. If it doesn't start with the context root then it is prepended automatically.pUseValidatorId
- the validator id to use for the specified embedded resourcepFilterDepth
- the depth with which to filter the current resourcepCrossRegistryURI
- true if pResourceURI may belong to a registry not currently in contextpublic void addRestRequestData(java.lang.String pKey, java.lang.Object pValue)
pKey
- key to cache entrypValue
- object to cachepublic java.lang.Object getRestRequestData(java.lang.String pKey)
pKey
- key to cache entrypublic java.lang.String getCurrentResourceId()
public RestResourceRegistry getCurrentRegistry()
public java.lang.String getDefaultCurie()
public void validateInputObject(java.lang.Object pInputObject)
pInputObject
- the object to validatepublic void validateInputObject(java.lang.Object pInputObject, java.lang.String pValidatorId)
pInputObject
- the object to validatepValidatorId
- the id of the validator to usepublic java.lang.Object getResourceReference(java.lang.String pResourceId) throws RestException
pResourceId
- String id of the resource to get an reference toRestException
public ListingRequest getListingRequest(int pDefaultLimit) throws RestException
pDefaultLimit
- page size limit to use if none is setRestException
- the rest exceptionpublic RepresentationModel.Builder getModelBuilderWithPaging(int pDefaultResourcePageSize, java.lang.String pIdPropertyName, <any> pQueryParams, java.lang.String... pMembersIds) throws RestException
The array of string ids passed in are used to build the member uris.
Using the Listing classes this method supports the standard pagination limit & offset params. The orderBy param is not supported. The model's Listing Response is set so that the paging links will be shown correctly.
It also supports the getForUpdate param for PATCH merge - setting the ListingResponse items to the full collection, so ids can be output before and after the paged collection, thus not deleting unmodified items.
pDefaultResourcePageSize
- the default page size for the calling resourcepIdPropertyName
- identifies the collection item's property to use as
the member's idpQueryParams
- Optional map of query param key/value pairs to be added
to any built uris, null if nonepMembersIds
- One or more string member instance idsRestException
public RepresentationModel.Builder getModelBuilderWithPaging(int pDefResourcePageSize, boolean pSortAllowed, java.lang.String pIdPropertyName, <any> pQueryParams, java.util.Collection pMembers) throws RestException
To build the member uris the collection object's
Using the Listing classes this method supports the standard pagination limit
& offset params. It supports the standard orderBy param if pSortAllowed
is true. It also supports the getForUpdate param for PATCH merge - setting
the ListingResponse items to the full collection. So ids can be output
before and after the paged collection, thus not deleting unmodified items.
Pagination requires an ordered member collection to maintain consistency
across calls. If the collection is unordered using offset > 0 or
limit < collection size can produce a different collection of items for
the same request.
To guarantee the same result ensure the members collection passed in is a list.
The members collection still supports a Set but the paged result will only be
consistent if orderBy is also used. When orderBy is used the collection is
converted to a list for sorting, it takes longer as the collection gets bigger.
pDefResourcePageSize
- the default page size for the calling resourcepSortAllowed
- indicates if calling resource should honor the orderBy
param or ignore itpIdPropertyName
- identifies the collection item's property to use as
the member's idpQueryParams
- Optional map of query param key/value pairs to be added
to any built uris, null if nonepMembers
- a collection (list/set) of resource membersRestException
public void sortListingResponse(ListingResponse pListingResponse)
Supports sorting of List and Set collections by cloning the original collection. Collection is cloned as:
The sort will take longer as the collection gets bigger.
pListingResponse
- listing response used to build up the member URI
from the paginated set of itemspublic java.lang.String[] buildPageMembersUris(ListingResponse pListingResponse, <any> pQueryParams, java.lang.String pIdPropertyName)
If the collection is already paged then the ListingResponse collection will be used. If the collection is not paged then the ListingResponse pagination settings will be used to return only the paged uris. Supports the ListingResponse holding either a List or Set collection.
Optionally a map of query params can also be passed in which will then be appended to any built uris.
pListingResponse
- listing response used to build up the member URI
from the paginated set of itemspQueryParams
- Optional map of query param key/value pairs to be
added to any built uris, null if nonepublic atg.service.jaxrs.RestUpdateInfo.RestResourceUpdateInfo getResourceUpdateInfo() throws RestException
RestException
- the rest exceptionpublic int determineResourceVersion(java.lang.Object pVersionedObject)
pVersionedObject
- Object for the resource that may contain an inherent version.public java.lang.String getRootResourcePath()
public java.lang.Object getRootResource()
public boolean isTemplatedPath(java.lang.String pPath)
pPath
- String path that may or may not have template variable parts.