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 voidauthenticateUsingBasic(String realm, CredentialStore credentialStore) Checks theAuthorizationheader for credentials that exist in the givenCredentialStore.protected static StringdecodePathComponent(String pathComponent) URL-decodes and un-slashes the given path component.voiddestroy()Called at the end of the instance's lifecycle.voiddoDELETE()Must be overridden by implementations that supportDELETE.voiddoGET()Must be overridden by implementations that supportGET.voiddoHEAD()This implementation simply callsdoGET().voiddoInit()Initialization method, called after all necessary setters have been called but before any request handler method (likedoGET()etc.)final voidIf the implementationsupports any methodsother thanOPTIONS, this method sends a correct response to anOPTIONSrequest.voiddoPATCH()Must be overridden by implementations that supportPATCH.voiddoPOST()Must be overridden by implementations that supportPOST.voiddoPUT()Must be overridden by implementations that supportPUT.protected StringReturns the user agent's IP address, respecting theX-Forwarded-Forrequest header, if present.Returns a map of template variables common to most or all templates.protected final DelegateReturns theDelegateinstance for the current request.protected Stringprotected abstract org.slf4j.LoggerReturns a list of client-preferred media types as expressed in theAcceptrequest header.protected ReferenceTherequest URIis 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 ReferenceReturns a reference to the base URI of the application.protected StringgetRepresentationDisposition(String identifierStr, Format outputFormat) Returns a sanitized value for aContent-Dispositionheader based on the value of theRESPONSE_CONTENT_DISPOSITION_QUERY_ARGquery argument.final RequestReturns the request being handled.protected final RequestContextfinal ResponseReturns the response to be sent.Part of theResourcecontract.protected final StringnegotiateContentType(List<String> limitToTypes) Negotiates a content/media type according to client preferences as expressed in anAcceptheader.final voidsetRequest(Request request) Sets the request being handled.final voidsetResponse(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 aResourceExceptionto 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 aResourceExceptionto 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 aResourceExceptionto 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 aResourceExceptionto enable a custom status.
-
doOPTIONS
public final void doOPTIONS()If the implementationsupports any methodsother thanOPTIONS, this method sends a correct response to anOPTIONSrequest. 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 aResourceExceptionto 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 aResourceExceptionto 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 aResourceExceptionto enable a custom status.
-
authenticateUsingBasic
Checks theAuthorizationheader for credentials that exist in the givenCredentialStore. If not found, sends aWWW-Authenticateheader 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-Forrequest header, if present.- Returns:
- User agent's IP address.
-
getRoutes
-
getCommonTemplateVars
-
getDelegate
-
getLocalBasePath
-
getLogger
protected abstract org.slf4j.Logger getLogger() -
getPreferredMediaTypes
-
getPublicReference
The
request URIis 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 URIand either theKey.BASE_URIconfiguration 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_URIis 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-Dispositionheader based on the value of theRESPONSE_CONTENT_DISPOSITION_QUERY_ARGquery argument.If the disposition is
attachmentand 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-Dispositionheader, 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 anAcceptheader.- Parameters:
limitToTypes- Media types to limit the result to, in order of most to least preferred by the application.- Returns:
- Negotiated media type, or
nullif 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.
-