public abstract class Resource
extends java.lang.Object
Context
, a Request
and a Response
, corresponding to a
specific target resource.init(Context, Request, Response)
method is invoked. If you need to
do some additional initialization, you should just override 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(java.lang.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,
java.lang.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.
|
java.util.Set<Method> |
getAllowedMethods()
Returns the set of methods allowed for the current client by the
resource.
|
abstract java.lang.String |
getAttribute(java.lang.String name)
Returns the attribute value by looking up the given name in the request
or response attributes maps.
|
java.util.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.
|
Context |
getContext()
Returns the current context.
|
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.
|
java.util.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.
|
java.util.logging.Logger |
getLogger()
Returns the logger.
|
Form |
getMatrix()
Returns the resource reference's optional matrix.
|
java.lang.String |
getMatrixValue(java.lang.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.
|
java.util.List<ChallengeRequest> |
getProxyChallengeRequests()
Returns the list of proxy authentication requests sent by an origin
server to a client.
|
Form |
getQuery()
Returns the resource reference's optional query.
|
java.lang.String |
getQueryValue(java.lang.String name)
Returns the first value of the query parameter given its name if
existing, or null.
|
java.util.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.
|
java.util.Map<java.lang.String,java.lang.Object> |
getRequestAttributes()
Returns the request attributes.
|
java.util.List<CacheDirective> |
getRequestCacheDirectives()
Returns the request cache directives.
|
Representation |
getRequestEntity()
Returns the request entity representation.
|
Response |
getResponse()
Returns the handled response.
|
java.util.Map<java.lang.String,java.lang.Object> |
getResponseAttributes()
Returns the response attributes.
|
java.util.List<CacheDirective> |
getResponseCacheDirectives()
Returns the response cache directives.
|
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.
|
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() . |
abstract void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets the request or response attribute value.
|
void |
setQueryValue(java.lang.String name,
java.lang.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.
|
static java.lang.Boolean |
toBoolean(java.lang.String value)
Converts the given
String value into a Boolean or null. |
static java.lang.Byte |
toByte(java.lang.String value)
Converts the given
String value into a Byte or null. |
static java.lang.Double |
toDouble(java.lang.String value)
Converts the given
String value into an Double or null. |
static java.lang.Float |
toFloat(java.lang.String value)
Converts the given
String value into a Float or null. |
static java.lang.Integer |
toInteger(java.lang.String value)
Converts the given
String value into an Integer or null. |
static java.lang.Long |
toLong(java.lang.String value)
Converts the given
String value into an Long or null. |
Representation |
toRepresentation(java.lang.Object source)
Converts an object into a representation based on the default converter
service variant.
|
Representation |
toRepresentation(java.lang.Object source,
MediaType target)
Converts an object into a representation based on a given media type.
|
Representation |
toRepresentation(java.lang.Object source,
Variant target)
Converts an object into a representation based on client preferences.
|
static java.lang.Short |
toShort(java.lang.String value)
Converts the given
String value into a Short or null. |
java.lang.String |
toString() |
public static java.lang.Boolean toBoolean(java.lang.String value)
String
value into a Boolean
or null.value
- The value to convert or null.Boolean
value or null.public static java.lang.Byte toByte(java.lang.String value)
String
value into a Byte
or null.value
- The value to convert or null.Byte
value or null.public static java.lang.Double toDouble(java.lang.String value)
String
value into an Double
or null.value
- The value to convert or null.Double
value or null.public static java.lang.Float toFloat(java.lang.String value)
String
value into a Float
or null.value
- The value to convert or null.Float
value or null.public static java.lang.Integer toInteger(java.lang.String value)
String
value into an Integer
or null.value
- The value to convert or null.Integer
value or null.public static java.lang.Long toLong(java.lang.String value)
String
value into an Long
or null.value
- The value to convert or null.Long
value or null.public static java.lang.Short toShort(java.lang.String value)
String
value into a Short
or null.value
- The value to convert or null.Short
value or null.protected void doCatch(java.lang.Throwable throwable)
Throwable
is caught during initialization,
handling or releasing.throwable
- The caught error or exception.protected void doError(Status errorStatus)
errorStatus
- The error status received.protected final void doError(Status errorStatus, java.lang.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 java.util.Set<Method> getAllowedMethods()
public abstract java.lang.String getAttribute(java.lang.String name)
name
- The attribute name.public java.util.List<ChallengeRequest> getChallengeRequests()
Response.getChallengeRequests()
public ChallengeResponse getChallengeResponse()
Request.getChallengeResponse()
public ClientInfo getClientInfo()
Request.getClientInfo()
public Conditions getConditions()
Request.getConditions()
public Context getContext()
public Series<Cookie> getCookies()
Request.getCookies()
public Series<CookieSetting> getCookieSettings()
Response.getCookieSettings()
public java.util.Set<Dimension> getDimensions()
Response.getDimensions()
public Reference getHostRef()
Request.getHostRef()
public Reference getLocationRef()
Response.getLocationRef()
public java.util.logging.Logger getLogger()
public Form getMatrix()
Reference.getMatrixAsForm()
public java.lang.String getMatrixValue(java.lang.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 java.util.List<ChallengeRequest> getProxyChallengeRequests()
Response.getProxyChallengeRequests()
public Form getQuery()
Form
object aren't reported to the underlying
reference.Reference.getQueryAsForm()
public java.lang.String getQueryValue(java.lang.String name)
name
- The query parameter name.public java.util.List<Range> getRanges()
Request.getRanges()
public Reference getReference()
public Reference getReferrerRef()
public Request getRequest()
public java.util.Map<java.lang.String,java.lang.Object> getRequestAttributes()
Message.getAttributes()
public java.util.List<CacheDirective> getRequestCacheDirectives()
public Representation getRequestEntity()
public Response getResponse()
public java.util.Map<java.lang.String,java.lang.Object> getResponseAttributes()
Message.getAttributes()
public java.util.List<CacheDirective> getResponseCacheDirectives()
public Representation getResponseEntity()
public Reference getRootRef()
Request.getRootRef()
public ServerInfo getServerInfo()
Response.getServerInfo()
public Status getStatus()
Response.getStatus()
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 abstract void setAttribute(java.lang.String name, java.lang.Object value)
name
- The attribute name.value
- The attribute to set.public void setQueryValue(java.lang.String name, java.lang.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 Representation toRepresentation(java.lang.Object source) throws java.io.IOException
source
- The object to convert.java.io.IOException
public Representation toRepresentation(java.lang.Object source, MediaType target) throws java.io.IOException
source
- The object to convert.target
- The target representation media type.java.io.IOException
public Representation toRepresentation(java.lang.Object source, Variant target) throws java.io.IOException
source
- The object to convert.target
- The target representation variant.java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2005-2024 Restlet.