public abstract class Resource extends Object
Context
, a Request
and a Response
, corresponding to a
specific target resource.init(Context, Request, Response)
method is invoked, with a
chance for the developer to do some additional initialization by overriding
the doInit()
method.handle()
method can be invoked. For concrete
behavior, see the ClientResource
and ServerResource
subclasses. Note that the state of the resource can be changed several times
and the handle()
method called more than once, but always by the
same thread.release()
method can be called to clean-up the
resource, with a chance for the developer to do some additional clean-up by
overriding the doRelease()
method.Error
and Exception
can be caught in a single point by overriding the doCatch(Throwable)
method.Uniform
class and its
main Restlet
subclass where a single instance can handle several
calls concurrently, one instance of Resource
is created for each call
handled and accessed by only one thread at a time.Constructor and Description |
---|
Resource() |
Modifier and Type | Method and Description |
---|---|
protected void |
doCatch(Throwable throwable)
Invoked when a
Throwable is caught during initialization,
handling or releasing. |
protected void |
doError(Status errorStatus)
Invoked when an error response status is received.
|
protected void |
doError(Status errorStatus,
String errorMessage)
Invoked when an error response status is received.
|
protected void |
doInit()
Set-up method that can be overridden in order to initialize the state of
the resource.
|
protected void |
doRelease()
Clean-up method that can be overridden in order to release the state of
the resource.
|
Set<Method> |
getAllowedMethods()
Returns the set of methods allowed for the current client by the
resource.
|
Application |
getApplication()
Returns the parent application.
|
abstract String |
getAttribute(String name)
Returns the attribute value by looking up the given name in the request
or response attributes maps.
|
List<ChallengeRequest> |
getChallengeRequests()
Returns the list of authentication requests sent by an origin server to a
client.
|
ChallengeResponse |
getChallengeResponse()
Returns the authentication response sent by a client to an origin server.
|
ClientInfo |
getClientInfo()
Returns the client-specific information.
|
Conditions |
getConditions()
Returns the modifiable conditions applying to this request.
|
ConnegService |
getConnegService()
Returns the application's content negotiation service or create a new
one.
|
Context |
getContext()
Returns the current context.
|
ConverterService |
getConverterService()
Returns the application's converter service or create a new one.
|
Series<Cookie> |
getCookies()
Returns the modifiable series of cookies provided by the client.
|
Series<CookieSetting> |
getCookieSettings()
Returns the modifiable series of cookie settings provided by the server.
|
Set<Dimension> |
getDimensions()
Returns the modifiable set of selecting dimensions on which the response
entity may vary.
|
Reference |
getHostRef()
Returns the host reference.
|
Reference |
getLocationRef()
Returns the reference that the client should follow for redirections or
resource creations.
|
Logger |
getLogger()
Returns the logger.
|
Form |
getMatrix()
Returns the resource reference's optional matrix.
|
String |
getMatrixValue(String name)
Returns the first value of the matrix parameter given its name if
existing, or null.
|
int |
getMaxForwards()
Returns the maximum number of intermediaries.
|
MetadataService |
getMetadataService()
Returns the application's metadata service or create a new one.
|
Method |
getMethod()
Returns the method.
|
Reference |
getOriginalRef()
Returns the original reference as requested by the client.
|
Protocol |
getProtocol()
Returns the protocol by first returning the resourceRef.schemeProtocol
property if it is set, or the baseRef.schemeProtocol property otherwise.
|
List<ChallengeRequest> |
getProxyChallengeRequests()
Returns the list of proxy authentication requests sent by an origin
server to a client.
|
ChallengeResponse |
getProxyChallengeResponse()
Returns the proxy authentication response sent by a client to an origin
server.
|
Form |
getQuery()
Returns the resource reference's optional query.
|
String |
getQueryValue(String name)
Returns the first value of the query parameter given its name if
existing, or null.
|
List<Range> |
getRanges()
Returns the ranges to return from the target resource's representation.
|
Reference |
getReference()
Returns the URI reference.
|
Reference |
getReferrerRef()
Returns the referrer reference if available.
|
Request |
getRequest()
Returns the handled request.
|
Map<String,Object> |
getRequestAttributes()
Returns the request attributes.
|
List<CacheDirective> |
getRequestCacheDirectives()
Returns the request cache directives.
Note that when used with HTTP connectors, this property maps to the "Cache-Control" header. |
Representation |
getRequestEntity()
Returns the request entity representation.
|
Response |
getResponse()
Returns the handled response.
|
Map<String,Object> |
getResponseAttributes()
Returns the response attributes.
|
List<CacheDirective> |
getResponseCacheDirectives()
Returns the response cache directives.
Note that when used with HTTP connectors, this property maps to the "Cache-Control" header. |
Representation |
getResponseEntity()
Returns the response entity representation.
|
Reference |
getRootRef()
Returns the application root reference.
|
ServerInfo |
getServerInfo()
Returns the server-specific information.
|
Status |
getStatus()
Returns the status.
|
StatusService |
getStatusService()
Returns the application's status service or create a new one.
|
abstract Representation |
handle()
Handles the call composed of the current context, request and response.
|
void |
init(Context context,
Request request,
Response response)
Initialization method setting the environment of the current resource
instance.
|
boolean |
isConfidential()
Indicates if the message was or will be exchanged confidentially, for
example via a SSL-secured connection.
|
boolean |
isLoggable()
Indicates if the call is loggable
|
void |
release()
Releases the resource by calling
doRelease() . |
void |
setApplication(Application application)
Sets the parent application.
|
abstract void |
setAttribute(String name,
Object value)
Sets the request or response attribute value.
|
void |
setQueryValue(String name,
String value)
Sets the query value for the named parameter.
|
void |
setRequest(Request request)
Sets the handled request.
|
void |
setResponse(Response response)
Sets the handled response.
|
<T> T |
toObject(Representation source,
Class<T> target)
Converts a representation into a Java object.
|
Representation |
toRepresentation(Object source,
Variant target)
Converts an object into a representation based on client preferences.
|
String |
toString() |
protected void doCatch(Throwable throwable)
Throwable
is caught during initialization,
handling or releasing. By default, updates the responses's status with
the result of
StatusService.getStatus(Throwable, Resource)
.throwable
- The caught error or exception.protected void doError(Status errorStatus)
errorStatus
- The error status received.protected final void doError(Status errorStatus, String errorMessage)
errorStatus
- The error status received.errorMessage
- The custom error message.protected void doInit() throws ResourceException
ResourceException
init(Context, Request, Response)
protected void doRelease() throws ResourceException
ResourceException
release()
public Set<Method> getAllowedMethods()
public Application getApplication()
Application.getCurrent()
if it
exists, or instantiates a new one as a last resort.public abstract String getAttribute(String name)
name
- The attribute name.public List<ChallengeRequest> getChallengeRequests()
Response.getChallengeRequests()
public ChallengeResponse getChallengeResponse()
Request.getChallengeResponse()
public ClientInfo getClientInfo()
Request.getClientInfo()
public Conditions getConditions()
Request.getConditions()
public ConnegService getConnegService()
public Context getContext()
public ConverterService getConverterService()
public Series<Cookie> getCookies()
Request.getCookies()
public Series<CookieSetting> getCookieSettings()
Response.getCookieSettings()
public Set<Dimension> getDimensions()
Response.getDimensions()
public Reference getHostRef()
Request.getHostRef()
public Reference getLocationRef()
Response.getLocationRef()
public Logger getLogger()
public Form getMatrix()
Reference.getMatrixAsForm()
public String getMatrixValue(String name)
name
- The matrix parameter name.public int getMaxForwards()
public MetadataService getMetadataService()
public Method getMethod()
Request.getMethod()
public Reference getOriginalRef()
Request.getOriginalRef()
public Protocol getProtocol()
Request.getProtocol()
public List<ChallengeRequest> getProxyChallengeRequests()
Response.getProxyChallengeRequests()
public ChallengeResponse getProxyChallengeResponse()
Request.getProxyChallengeResponse()
public Form getQuery()
Form
object aren't reported to the underlying
reference.Reference.getQueryAsForm()
public String getQueryValue(String name)
name
- The query parameter name.public List<Range> getRanges()
Request.getRanges()
public Reference getReference()
public Reference getReferrerRef()
public Request getRequest()
public Map<String,Object> getRequestAttributes()
Message.getAttributes()
public List<CacheDirective> getRequestCacheDirectives()
public Representation getRequestEntity()
public Response getResponse()
public Map<String,Object> getResponseAttributes()
Message.getAttributes()
public List<CacheDirective> getResponseCacheDirectives()
public Representation getResponseEntity()
public Reference getRootRef()
Request.getRootRef()
public ServerInfo getServerInfo()
Response.getServerInfo()
public Status getStatus()
Response.getStatus()
public StatusService getStatusService()
public abstract Representation handle()
public void init(Context context, Request request, Response response)
doInit()
method that can be
overridden.context
- The current context.request
- The handled request.response
- The handled response.public boolean isConfidential()
Request.isConfidential()
public boolean isLoggable()
public final void release()
doRelease()
.public void setApplication(Application application)
application
- The parent application.public abstract void setAttribute(String name, Object value)
name
- The attribute name.value
- The attribute to set.public void setQueryValue(String name, String value)
name
- The query parameter name.value
- The query parameter value.public void setRequest(Request request)
request
- The handled request.public void setResponse(Response response)
response
- The handled response.public <T> T toObject(Representation source, Class<T> target) throws ResourceException
ConverterService
.T
- The expected class of the Java object.source
- The source representation to convert.target
- The target class of the Java object.ResourceException
public Representation toRepresentation(Object source, Variant target)
source
- The object to convert.target
- The target representation variant.Copyright © 2005–2014. All rights reserved.