Class AbstractResource
- Direct Known Subclasses:
AbstractImageResource
,ConfigurationResource
,FileResource
,HealthResource
,LandingResource
,StatusResource
,TaskResource
,TasksResource
,TrailingSlashResource
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
authenticateUsingBasic
(String realm, CredentialStore credentialStore) Checks theAuthorization
header for credentials that exist in the givenCredentialStore
.protected static String
decodePathComponent
(String pathComponent) URL-decodes and un-slashes the given path component.void
destroy()
Called at the end of the instance's lifecycle.void
doDELETE()
Must be overridden by implementations that supportDELETE
.void
doGET()
Must be overridden by implementations that supportGET
.void
doHEAD()
This implementation simply callsdoGET()
.void
doInit()
Initialization method, called after all necessary setters have been called but before any request handler method (likedoGET()
etc.)final void
If the implementationsupports any methods
other thanOPTIONS
, this method sends a correct response to anOPTIONS
request.void
doPATCH()
Must be overridden by implementations that supportPATCH
.void
doPOST()
Must be overridden by implementations that supportPOST
.void
doPUT()
Must be overridden by implementations that supportPUT
.protected String
Returns the user agent's IP address, respecting theX-Forwarded-For
request header, if present.Returns a map of template variables common to most or all templates.protected final Delegate
Returns theDelegate
instance for the current request.protected String
protected abstract org.slf4j.Logger
Returns a list of client-preferred media types as expressed in theAccept
request header.protected Reference
Therequest URI
is not necessarily the URI that the client has supplied, or sees, or should see, as it may have come from a reverse proxy server.protected Reference
Returns a reference to the base URI of the application.protected String
getRepresentationDisposition
(String identifierStr, Format outputFormat) Returns a sanitized value for aContent-Disposition
header based on the value of theRESPONSE_CONTENT_DISPOSITION_QUERY_ARG
query argument.final Request
Returns the request being handled.protected final RequestContext
final Response
Returns the response to be sent.Part of theResource
contract.protected final String
negotiateContentType
(List<String> limitToTypes) Negotiates a content/media type according to client preferences as expressed in anAccept
header.final void
setRequest
(Request request) Sets the request being handled.final void
setResponse
(Response response) Sets the response to send.
-
Field Details
-
PUBLIC_IDENTIFIER_HEADER
- See Also:
-
-
Constructor Details
-
AbstractResource
public AbstractResource()
-
-
Method Details
-
decodePathComponent
-
doInit
Initialization method, called after all necessary setters have been called but before any request handler method (like
doGET()
etc.)If an implementation class has anything to do with
image identifiers
, it should add the request identifier to therequest context
.Overrides must call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
destroy
public void destroy()Called at the end of the instance's lifecycle.
Overrides must call
super
. -
doDELETE
Must be overridden by implementations that support
DELETE
.Overrides must not call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
doGET
Must be overridden by implementations that support
GET
.Overrides must not call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
doHEAD
This implementation simply callsdoGET()
. When that is overridden, this may also be overridden in order to set headers only and not compute a response body.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
doOPTIONS
public final void doOPTIONS()If the implementationsupports any methods
other thanOPTIONS
, this method sends a correct response to anOPTIONS
request. Otherwise, it returns HTTP 405 (Method Not Allowed). -
doPATCH
Must be overridden by implementations that support
PATCH
.Overrides must not call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
doPOST
Must be overridden by implementations that support
POST
.Overrides must not call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
doPUT
Must be overridden by implementations that support
PUT
.Overrides must not call
super
.- Throws:
Exception
- upon any error. This may be aResourceException
to enable a custom status.
-
authenticateUsingBasic
Checks theAuthorization
header for credentials that exist in the givenCredentialStore
. If not found, sends aWWW-Authenticate
header and throws an exception.- Parameters:
realm
- Basic realm.credentialStore
- Credential store.- Throws:
ResourceException
- if authentication failed.
-
getCanonicalClientIPAddress
Returns the user agent's IP address, respecting theX-Forwarded-For
request header, if present.- Returns:
- User agent's IP address.
-
getRoutes
-
getCommonTemplateVars
-
getDelegate
-
getLocalBasePath
-
getLogger
protected abstract org.slf4j.Logger getLogger() -
getPreferredMediaTypes
-
getPublicReference
The
request URI
is not necessarily the URI that the client has supplied, or sees, or should see, as it may have come from a reverse proxy server. This method generates a new instance based on therequest URI
and either theKey.BASE_URI
configuration key orX-Forwarded-*
request headers, resulting in something that is more appropriate to expose to a client. For example, when generating URIs of application resources to include in a response, it would be appropriate to generate them using this method.Note that the return value may not be appropriate for exposure to a client in all cases—for example, any identifier present in the URI path is not translated (slashes substituted, etc.). In those cases it will be necessary to use adjust the path manually.
- Returns:
- New instance.
- See Also:
-
getPublicRootReference
Returns a reference to the base URI of the application.
Key.BASE_URI
is respected, if set. Otherwise, theX-Forwarded-*
request headers are respected, if available.- Returns:
- New instance.
- See Also:
-
getRepresentationDisposition
Returns a sanitized value for a
Content-Disposition
header based on the value of theRESPONSE_CONTENT_DISPOSITION_QUERY_ARG
query argument.If the disposition is
attachment
and the filename is not set, it will be set to a reasonable value based on the given identifier and output format.- Parameters:
identifierStr
- URI identifier.outputFormat
- Requested image format.- Returns:
- Value for a
Content-Disposition
header, which may benull
.
-
getRequest
Returns the request being handled.- Returns:
- The request being handled.
-
getRequestContext
- Returns:
- Instance corresponding to the request. Its properties are gradually filled in as they become available.
-
getResponse
Returns the response to be sent.- Returns:
- The response to be sent.
-
negotiateContentType
Negotiates a content/media type according to client preferences as expressed in anAccept
header.- Parameters:
limitToTypes
- Media types to limit the result to, in order of most to least preferred by the application.- Returns:
- Negotiated media type, or
null
if negotiation failed.
-
setRequest
Sets the request being handled.- Parameters:
request
- Request being handled.
-
setResponse
Sets the response to send.- Parameters:
response
- Response that will be sent.
-