Package org.restlet.resource
Class ClientResource
- java.lang.Object
-
- org.restlet.resource.Resource
-
- org.restlet.resource.ClientResource
-
public class ClientResource extends Resource
Client-side resource. Acts like a proxy of a target resource.
This class changes the semantics of theResource.getRequest()
andResource.getResponse()
methods. Since a clientResource may receive severals responses for a single request (in case of interim response), theResource.getResponse()
method returns the last received response object. The Request object returned by theResource.getRequest()
is actually a prototype which is cloned (except the representation) just before thehandle()
method is called.
Users must be aware that by most representations can only be read or written once. Some others, such asStringRepresentation
stored the entity in memory which can be read several times but has the drawback to consume memory.
Concurrency note: instances of the class are not designed to be shared among several threads. If thread-safety is necessary, consider using the lower-levelClient
class instead.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClientResource()
Empty constructor.ClientResource(java.lang.String uri)
Constructor.ClientResource(java.net.URI uri)
Constructor.ClientResource(Context context, java.lang.String uri)
Constructor.ClientResource(Context context, java.net.URI uri)
Constructor.ClientResource(Context context, Method method, java.lang.String uri)
Constructor.ClientResource(Context context, Method method, java.net.URI uri)
Constructor.ClientResource(Context context, Method method, Reference reference)
Constructor.ClientResource(Context context, Reference reference)
Constructor.ClientResource(Context context, Request request)
Constructor.ClientResource(Context context, Request request, Response response)
Constructor.ClientResource(Method method, java.lang.String uri)
Constructor.ClientResource(Method method, java.net.URI uri)
Constructor.ClientResource(Method method, Reference reference)
Constructor.ClientResource(Reference reference)
Constructor.ClientResource(Request request)
Constructor.ClientResource(Request request, Response response)
Constructor.ClientResource(ClientResource resource)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(Metadata... metadata)
Updates the client preferences to accept the given metadata (media types, character sets, etc.) with a 1.0 quality in addition to existing ones.void
accept(Metadata metadata, float quality)
Updates the client preferences to accept the given metadata (media types, character sets, etc.) with a given quality in addition to existing ones.Reference
addQueryParameter(java.lang.String name, java.lang.String value)
Adds a parameter to the query component.Reference
addQueryParameter(Parameter parameter)
Adds a parameter to the query component.Reference
addQueryParameters(java.lang.Iterable<Parameter> parameters)
Adds several parameters to the query component.Reference
addSegment(java.lang.String value)
Adds a segment at the end of the path.static <T> T
create(java.lang.String uri, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls.static <T> T
create(Context context, Reference reference, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls.static <T> T
create(Reference reference, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls.protected Uniform
createNext()
Creates a next Restlet is no one is set.Request
createRequest()
Creates a new request by cloning the one wrapped by this class.protected Response
createResponse(Request request)
Creates a new response for the given request.Representation
delete()
Deletes the target resource and all its representations.<T> T
delete(java.lang.Class<T> resultClass)
Deletes the target resource and all its representations.Representation
delete(MediaType mediaType)
Deletes the target resource and all its representations.void
doError(Status errorStatus)
By default, it throws a new resource exception.void
doError(Status errorStatus, Request request, Response response)
By default, it throws a new resource exception.void
doError(Request request, Response response)
By default, it throws a new resource exception.protected void
doRelease()
Releases the resource by stopping any connector automatically created and associated to the "next" property (seegetNext()
method.protected void
finalize()
Attempts toResource.release()
the resource.Representation
get()
Represents the resource using content negotiation to select the best variant based on the client preferences.<T> T
get(java.lang.Class<T> resultClass)
Represents the resource in the given object class.Representation
get(MediaType mediaType)
Represents the resource using a given media type.java.lang.String
getAttribute(java.lang.String name)
Returns the attribute value by looking up the given name in the response attributes maps.ClientResource
getChild(java.lang.String relativeUri)
Returns the child resource defined by its URI relatively to the current resource.<T> T
getChild(java.lang.String relativeUri, java.lang.Class<? extends T> resourceInterface)
Wraps the child client resource to proxy calls to the given Java interface into Restlet method calls.ClientResource
getChild(Reference relativeRef)
Returns the child resource defined by its URI relatively to the current resource.<T> T
getChild(Reference relativeRef, java.lang.Class<? extends T> resourceInterface)
Wraps the child client resource to proxy calls to the given Java interface into Restlet method calls.int
getMaxRedirects()
Returns the maximum number of redirections that can be automatically followed for a single call.Uniform
getNext()
Returns the next Restlet.Uniform
getOnResponse()
Returns the callback invoked on response reception.Uniform
getOnSent()
Returns the callback invoked after sending the request.ClientResource
getParent()
Returns the parent resource.<T> T
getParent(java.lang.Class<? extends T> resourceInterface)
Wraps the parent client resource to proxy calls to the given Java interface into Restlet method calls.int
getRetryAttempts()
Returns the number of retry attempts before reporting an error.long
getRetryDelay()
Returns the delay in milliseconds between two retry attempts.Representation
handle()
Handles the call by invoking the next handler.protected Representation
handle(Method method)
Handles the call by cloning the prototype request, setting the method and entity.protected <T> T
handle(Method method, java.lang.Class<T> resultClass)
Handles the call by cloning the prototype request, setting the method and entity.protected <T> T
handle(Method method, java.lang.Object entity, java.lang.Class<T> resultClass)
Handles an object entity.protected Representation
handle(Method method, MediaType mediaType)
Handles the call by cloning the prototype request, setting the method and entity.protected Representation
handle(Method method, Representation entity)
Handles the call by cloning the prototype request, setting the method and entity.protected Representation
handle(Method method, Representation entity, ClientInfo clientInfo)
Handles the call by cloning the prototype request, setting the method and entity.protected Representation
handle(Method method, Representation entity, MediaType mediaType)
Handles the call by cloning the prototype request, setting the method and entity.protected void
handle(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Handle the call and follow redirection for safe methods.Representation
handleInbound(Response response)
Handles the inbound call.Response
handleOutbound(Request request)
Handles the outbound call by invoking the next handler.boolean
hasNext()
Indicates if there is a next Restlet.Representation
head()
Represents the resource using content negotiation to select the best variant based on the client preferences.Representation
head(MediaType mediaType)
Represents the resource using a given media type.boolean
isFollowingRedirects()
Indicates if redirections are followed.boolean
isRequestEntityBuffering()
Indicates if transient or unknown size response entities should be buffered after being received.boolean
isResponseEntityBuffering()
Indicates if transient or unknown size response entities should be buffered after being received.boolean
isRetryOnError()
Indicates if idempotent requests should be retried on error.Representation
options()
Describes the resource using content negotiation to select the best variant based on the client preferences.<T> T
options(java.lang.Class<T> resultClass)
Describes the resource using a given media type.Representation
options(MediaType mediaType)
Describes the resource using a given media type.Representation
patch(java.lang.Object entity)
Patches a resource with the given object as delta state.<T> T
patch(java.lang.Object entity, java.lang.Class<T> resultClass)
Patches a resource with the given object as delta state.Representation
patch(java.lang.Object entity, MediaType mediaType)
Patches a resource with the given object as delta state.Representation
patch(Representation entity)
Patches a resource with the given representation as delta state.Representation
post(java.lang.Object entity)
Posts an object entity.<T> T
post(java.lang.Object entity, java.lang.Class<T> resultClass)
Posts an object entity.Representation
post(java.lang.Object entity, MediaType mediaType)
Posts an object entity.Representation
post(Representation entity)
Posts a representation.Representation
put(java.lang.Object entity)
Puts an object entity.<T> T
put(java.lang.Object entity, java.lang.Class<T> resultClass)
Puts an object entity.Representation
put(java.lang.Object entity, MediaType mediaType)
Puts an object entity.Representation
put(Representation entity)
Creates or updates a resource with the given representation as new state to be stored.protected void
redirect(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Effectively redirects a client call.protected void
retry(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Effectively retries a failed client call.void
setAttribute(java.lang.String name, java.lang.Object value)
Sets the request attribute value.void
setChallengeResponse(ChallengeResponse challengeResponse)
Sets the authentication response sent by a client to an origin server.void
setChallengeResponse(ChallengeScheme scheme, java.lang.String identifier, java.lang.String secret)
Sets the authentication response sent by a client to an origin server given a scheme, identifier and secret.void
setClientInfo(ClientInfo clientInfo)
Sets the client-specific information.void
setConditions(Conditions conditions)
Sets the conditions applying to this request.void
setCookies(Series<Cookie> cookies)
Sets the cookies provided by the client.void
setEntityBuffering(boolean entityBuffering)
Indicates if transient entities should be buffered after being received or before being sent.void
setFollowingRedirects(boolean followingRedirects)
Indicates if redirections are followed.void
setHostRef(java.lang.String hostUri)
Sets the host reference using an URI string.void
setHostRef(Reference hostRef)
Sets the host reference.void
setLoggable(boolean loggable)
Indicates if the call is loggablevoid
setMaxRedirects(int maxRedirects)
Sets the maximum number of redirections that can be automatically followed for a single call.void
setMethod(Method method)
Sets the method called.void
setNext(Uniform next)
Sets the next handler such as a Restlet or a Filter.void
setOnResponse(Uniform onResponseCallback)
Sets the callback invoked on response reception.void
setOnSent(Uniform onSentCallback)
Sets the callback invoked after sending the request.void
setOriginalRef(Reference originalRef)
Sets the original reference requested by the client.void
setProtocol(Protocol protocol)
Sets the protocol used or to be used.void
setProxyChallengeResponse(ChallengeResponse challengeResponse)
Sets the proxy authentication response sent by a client to an origin server.void
setProxyChallengeResponse(ChallengeScheme scheme, java.lang.String identifier, java.lang.String secret)
Sets the proxy authentication response sent by a client to an origin server given a scheme, identifier and secret.void
setRanges(java.util.List<Range> ranges)
Sets the ranges to return from the target resource's representation.void
setReference(java.lang.String uri)
Sets the resource's reference using an URI string.void
setReference(Reference reference)
Sets the resource's reference.void
setReferrerRef(java.lang.String referrerUri)
Sets the referrer reference if available using an URI string.void
setReferrerRef(Reference referrerRef)
Sets the referrer reference if available.void
setRequestEntityBuffering(boolean requestEntityBuffering)
Indicates if transient or unknown size response entities should be buffered after being received.void
setResponseEntityBuffering(boolean responseEntityBuffering)
Indicates if transient or unknown size response entities should be buffered after being received.void
setRetryAttempts(int retryAttempts)
Sets the number of retry attempts before reporting an error.void
setRetryDelay(long retryDelay)
Sets the delay in milliseconds between two retry attempts.void
setRetryOnError(boolean retryOnError)
Indicates if idempotent requests should be retried on error.<T> T
wrap(java.lang.Class<? extends T> resourceInterface)
Wraps the client resource to proxy calls to the given Java interface into Restlet method calls.<T> T
wrap(java.lang.Class<? extends T> resourceInterface, java.lang.ClassLoader classLoader)
Wraps the client resource to proxy calls to the given Java interface into Restlet method calls.-
Methods inherited from class org.restlet.resource.Resource
doCatch, doError, doInit, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getConnegService, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMatrixValue, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getProxyChallengeRequests, getProxyChallengeResponse, getQuery, getQueryValue, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestCacheDirectives, getRequestEntity, getResponse, getResponseAttributes, getResponseCacheDirectives, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, isLoggable, release, setApplication, setQueryValue, setRequest, setResponse, toBoolean, toByte, toDouble, toFloat, toInteger, toLong, toObject, toRepresentation, toRepresentation, toRepresentation, toShort, toString
-
-
-
-
Constructor Detail
-
ClientResource
protected ClientResource()
Empty constructor.
-
ClientResource
public ClientResource(ClientResource resource)
Constructor.- Parameters:
resource
- The client resource to copy.
-
ClientResource
public ClientResource(Context context, java.net.URI uri)
Constructor.- Parameters:
context
- The context.uri
- The target URI.
-
ClientResource
public ClientResource(Context context, Method method, java.net.URI uri)
Constructor.- Parameters:
context
- The context.method
- The method to call.uri
- The target URI.
-
ClientResource
public ClientResource(Context context, Method method, Reference reference)
Constructor.- Parameters:
context
- The context.method
- The method to call.reference
- The target reference.
-
ClientResource
public ClientResource(Context context, Method method, java.lang.String uri)
Constructor.- Parameters:
context
- The context.method
- The method to call.uri
- The target URI.
-
ClientResource
public ClientResource(Context context, Reference reference)
Constructor.- Parameters:
context
- The context.reference
- The target reference.
-
ClientResource
public ClientResource(Context context, Request request)
Constructor.- Parameters:
context
- The current context.request
- The handled request.
-
ClientResource
public ClientResource(Context context, Request request, Response response)
Constructor.- Parameters:
context
- The current context.request
- The handled request.response
- The handled response.
-
ClientResource
public ClientResource(Context context, java.lang.String uri)
Constructor.- Parameters:
context
- The context.uri
- The target URI.
-
ClientResource
public ClientResource(java.net.URI uri)
Constructor.- Parameters:
uri
- The target URI.
-
ClientResource
public ClientResource(Method method, java.net.URI uri)
Constructor.- Parameters:
method
- The method to call.uri
- The target URI.
-
ClientResource
public ClientResource(Method method, Reference reference)
Constructor.- Parameters:
method
- The method to call.reference
- The target reference.
-
ClientResource
public ClientResource(Method method, java.lang.String uri)
Constructor.- Parameters:
method
- The method to call.uri
- The target URI.
-
ClientResource
public ClientResource(Reference reference)
Constructor.- Parameters:
reference
- The target reference.
-
ClientResource
public ClientResource(Request request)
Constructor.- Parameters:
request
- The handled request.
-
ClientResource
public ClientResource(Request request, Response response)
Constructor.- Parameters:
request
- The handled request.response
- The handled response.
-
ClientResource
public ClientResource(java.lang.String uri)
Constructor.- Parameters:
uri
- The target URI.
-
-
Method Detail
-
create
public static <T> T create(Context context, Reference reference, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls. It basically creates a new instance ofClientResource
and invokes thewrap(Class)
method.- Type Parameters:
T
- The proxified interface.- Parameters:
context
- The context.reference
- The target reference.resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
-
create
public static <T> T create(Reference reference, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls. It basically creates a new instance ofClientResource
and invokes thewrap(Class)
method.- Type Parameters:
T
- The proxified interface.- Parameters:
reference
- The target reference.resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
-
create
public static <T> T create(java.lang.String uri, java.lang.Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface into Restlet method calls. It basically creates a new instance ofClientResource
and invokes thewrap(Class)
method.- Type Parameters:
T
- The proxified interface.- Parameters:
uri
- The target URI.resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
-
accept
public void accept(Metadata... metadata)
Updates the client preferences to accept the given metadata (media types, character sets, etc.) with a 1.0 quality in addition to existing ones.- Parameters:
metadata
- The metadata to accept.- See Also:
ClientInfo.accept(Metadata...)
-
accept
public void accept(Metadata metadata, float quality)
Updates the client preferences to accept the given metadata (media types, character sets, etc.) with a given quality in addition to existing ones.- Parameters:
metadata
- The metadata to accept.quality
- The quality to set.- See Also:
ClientInfo.accept(Metadata, float)
-
addQueryParameter
public Reference addQueryParameter(Parameter parameter)
Adds a parameter to the query component. The name and value are automatically encoded if necessary.- Parameters:
parameter
- The parameter to add.- Returns:
- The updated reference.
- See Also:
Reference.addQueryParameter(Parameter)
-
addQueryParameter
public Reference addQueryParameter(java.lang.String name, java.lang.String value)
Adds a parameter to the query component. The name and value are automatically encoded if necessary.- Parameters:
name
- The parameter name.value
- The optional parameter value.- Returns:
- The updated reference.
- See Also:
Reference.addQueryParameter(String, String)
-
addQueryParameters
public Reference addQueryParameters(java.lang.Iterable<Parameter> parameters)
Adds several parameters to the query component. The name and value are automatically encoded if necessary.- Parameters:
parameters
- The parameters to add.- Returns:
- The updated reference.
- See Also:
Reference.addQueryParameters(Iterable)
-
addSegment
public Reference addSegment(java.lang.String value)
Adds a segment at the end of the path. If the current path doesn't end with a slash character, one is inserted before the new segment value. The value is automatically encoded if necessary.- Parameters:
value
- The segment value to add.- Returns:
- The updated reference.
- See Also:
Reference.addSegment(String)
-
createNext
protected Uniform createNext()
Creates a next Restlet is no one is set. By default, it creates a newClient
based on the protocol of the resource's URI reference.- Returns:
- The created next Restlet or null.
-
createRequest
public Request createRequest()
Creates a new request by cloning the one wrapped by this class.- Returns:
- The new response.
- See Also:
Resource.getRequest()
-
createResponse
protected Response createResponse(Request request)
Creates a new response for the given request.- Parameters:
request
- The associated request.- Returns:
- The new response.
-
delete
public Representation delete() throws ResourceException
Deletes the target resource and all its representations. If a success status is not returned, then a resource exception is thrown.- Returns:
- The optional response entity.
- Throws:
ResourceException
- See Also:
- HTTP DELETE method
-
delete
public <T> T delete(java.lang.Class<T> resultClass) throws ResourceException
Deletes the target resource and all its representations. If a success status is not returned, then a resource exception is thrown.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
resultClass
- The expected class for the response entity object.- Returns:
- The response entity object.
- Throws:
ResourceException
- See Also:
- HTTP DELETE method
-
delete
public Representation delete(MediaType mediaType) throws ResourceException
Deletes the target resource and all its representations. If a success status is not returned, then a resource exception is thrown.- Parameters:
mediaType
- The media type of the representation to retrieve.- Returns:
- The representation matching the given media type.
- Throws:
ResourceException
- See Also:
- HTTP DELETE method
-
doError
public void doError(Request request, Response response)
By default, it throws a new resource exception. CalldoError(org.restlet.data.Status, org.restlet.Request, org.restlet.Response)
.- Parameters:
request
- The associated request.response
- The associated response.
-
doError
public void doError(Status errorStatus)
By default, it throws a new resource exception. CalldoError(org.restlet.data.Status, org.restlet.Request, org.restlet.Response)
.
-
doError
public void doError(Status errorStatus, Request request, Response response)
By default, it throws a new resource exception. This can be overridden to provide a different behavior.- Parameters:
errorStatus
- The error status received.request
- The associated request.response
- The associated response.
-
doRelease
protected void doRelease() throws ResourceException
Releases the resource by stopping any connector automatically created and associated to the "next" property (seegetNext()
method.- Overrides:
doRelease
in classResource
- Throws:
ResourceException
- See Also:
Resource.release()
-
finalize
protected void finalize() throws java.lang.Throwable
Attempts toResource.release()
the resource.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
get
public Representation get() throws ResourceException
Represents the resource using content negotiation to select the best variant based on the client preferences. Note that the client preferences will be automatically adjusted, but only for this request. If you want to change them once for all, you can use theResource.getClientInfo()
method.
If a success status is not returned, then a resource exception is thrown.- Returns:
- The best representation.
- Throws:
ResourceException
- See Also:
- HTTP GET method
-
get
public <T> T get(java.lang.Class<T> resultClass) throws ResourceException
Represents the resource in the given object class. Note that the client preferences will be automatically adjusted, but only for this request. If you want to change them once for all, you can use theResource.getClientInfo()
method.
If a success status is not returned, then a resource exception is thrown.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
resultClass
- The expected class for the response entity object.- Returns:
- The response entity object.
- Throws:
ResourceException
- See Also:
- HTTP GET method
-
get
public Representation get(MediaType mediaType) throws ResourceException
Represents the resource using a given media type. Note that the client preferences will be automatically adjusted, but only for this request. If you want to change them once for all, you can use theResource.getClientInfo()
method.
If a success status is not returned, then a resource exception is thrown.- Parameters:
mediaType
- The media type of the representation to retrieve.- Returns:
- The representation matching the given media type.
- Throws:
ResourceException
- See Also:
- HTTP GET method
-
getAttribute
public java.lang.String getAttribute(java.lang.String name)
Returns the attribute value by looking up the given name in the response attributes maps. The toString() method is then invoked on the attribute value.- Specified by:
getAttribute
in classResource
- Parameters:
name
- The attribute name.- Returns:
- The response attribute value.
-
getChild
public ClientResource getChild(Reference relativeRef) throws ResourceException
Returns the child resource defined by its URI relatively to the current resource. The child resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Parameters:
relativeRef
- The URI reference of the child resource relatively to the current resource seen as the parent resource.- Returns:
- The child resource.
- Throws:
ResourceException
-
getChild
public <T> T getChild(Reference relativeRef, java.lang.Class<? extends T> resourceInterface) throws ResourceException
Wraps the child client resource to proxy calls to the given Java interface into Restlet method calls. The child resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Type Parameters:
T
- The proxified interface.- Parameters:
relativeRef
- The URI reference of the child resource relatively to the current resource seen as the parent resource.resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
- Throws:
ResourceException
-
getChild
public ClientResource getChild(java.lang.String relativeUri) throws ResourceException
Returns the child resource defined by its URI relatively to the current resource. The child resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Parameters:
relativeUri
- The URI of the child resource relatively to the current resource seen as the parent resource.- Returns:
- The child resource.
- Throws:
ResourceException
-
getChild
public <T> T getChild(java.lang.String relativeUri, java.lang.Class<? extends T> resourceInterface) throws ResourceException
Wraps the child client resource to proxy calls to the given Java interface into Restlet method calls. The child resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Type Parameters:
T
- The proxified interface.- Parameters:
relativeUri
- The URI of the child resource relatively to the current resource seen as the parent resource.resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
- Throws:
ResourceException
-
getMaxRedirects
public int getMaxRedirects()
Returns the maximum number of redirections that can be automatically followed for a single call. Default value is 10.- Returns:
- The maximum number of redirections that can be automatically followed for a single call.
-
getNext
public Uniform getNext()
Returns the next Restlet. By default, it is the client dispatcher if a context is available.- Returns:
- The next Restlet or null.
-
getOnResponse
public Uniform getOnResponse()
Returns the callback invoked on response reception. If the value is not null, then the associated request will be executed asynchronously.- Returns:
- The callback invoked on response reception.
-
getOnSent
public Uniform getOnSent()
Returns the callback invoked after sending the request.- Returns:
- The callback invoked after sending the request.
-
getParent
public ClientResource getParent() throws ResourceException
Returns the parent resource. The parent resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Returns:
- The parent resource.
- Throws:
ResourceException
-
getParent
public <T> T getParent(java.lang.Class<? extends T> resourceInterface) throws ResourceException
Wraps the parent client resource to proxy calls to the given Java interface into Restlet method calls. The parent resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, then an exception is thrown.- Type Parameters:
T
- The proxified interface.- Parameters:
resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
- Throws:
ResourceException
-
getRetryAttempts
public int getRetryAttempts()
Returns the number of retry attempts before reporting an error. Default value is 2.- Returns:
- The number of retry attempts before reporting an error.
-
getRetryDelay
public long getRetryDelay()
Returns the delay in milliseconds between two retry attempts. Default value is 2 seconds.- Returns:
- The delay in milliseconds between two retry attempts.
-
handle
public Representation handle()
Handles the call by invoking the next handler. The prototype request is retrieved viaResource.getRequest()
and cloned and the response is set as the latest withResource.setResponse(Response)
. If necessary thesetNext(Uniform)
method is called as well with aClient
instance matching the request protocol.
-
handle
protected Representation handle(Method method)
Handles the call by cloning the prototype request, setting the method and entity.- Parameters:
method
- The request method to use.- Returns:
- The optional response entity.
-
handle
protected <T> T handle(Method method, java.lang.Class<T> resultClass) throws ResourceException
Handles the call by cloning the prototype request, setting the method and entity.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
method
- The request method to use.resultClass
- The expected class for the response entity object.- Returns:
- The response entity object.
- Throws:
ResourceException
-
handle
protected Representation handle(Method method, MediaType mediaType)
Handles the call by cloning the prototype request, setting the method and entity.- Parameters:
method
- The request method to use.mediaType
- The preferred result media type.- Returns:
- The optional response entity.
-
handle
protected <T> T handle(Method method, java.lang.Object entity, java.lang.Class<T> resultClass) throws ResourceException
Handles an object entity. Automatically serializes the object using theConverterService
.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
method
- The request method to use.entity
- The object entity to post.resultClass
- The class of the response entity.- Returns:
- The response object entity.
- Throws:
ResourceException
-
handle
protected Representation handle(Method method, Representation entity)
Handles the call by cloning the prototype request, setting the method and entity.- Parameters:
method
- The request method to use.entity
- The request entity to set.- Returns:
- The optional response entity.
-
handle
protected Representation handle(Method method, Representation entity, ClientInfo clientInfo)
Handles the call by cloning the prototype request, setting the method and entity.- Parameters:
method
- The request method to use.entity
- The request entity to set.clientInfo
- The client preferences.- Returns:
- The optional response entity.
-
handle
protected Representation handle(Method method, Representation entity, MediaType mediaType)
Handles the call by cloning the prototype request, setting the method and entity.- Parameters:
method
- The request method to use.entity
- The request entity to set.mediaType
- The preferred result media type.- Returns:
- The optional response entity.
-
handle
protected void handle(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Handle the call and follow redirection for safe methods.- Parameters:
request
- The request to send.response
- The response to update.references
- The references that caused a redirection to prevent infinite loops.retryAttempt
- The number of remaining attempts.next
- The next handler handling the call.
-
handleInbound
public Representation handleInbound(Response response)
Handles the inbound call. Note that only synchronous calls are processed.- Parameters:
response
-- Returns:
- The response's entity, if any.
-
handleOutbound
public Response handleOutbound(Request request)
Handles the outbound call by invoking the next handler.- Parameters:
request
- The request to handle.- Returns:
- The response created.
- See Also:
getNext()
-
hasNext
public boolean hasNext()
Indicates if there is a next Restlet.- Returns:
- True if there is a next Restlet.
-
head
public Representation head() throws ResourceException
Represents the resource using content negotiation to select the best variant based on the client preferences. This method is identical toget()
but doesn't return the actual content of the representation, only its metadata.
Note that the client preferences will be automatically adjusted, but only for this request. If you want to change them once for all, you can use theResource.getClientInfo()
method.
If a success status is not returned, then a resource exception is thrown.- Returns:
- The best representation.
- Throws:
ResourceException
- See Also:
- HTTP HEAD method
-
head
public Representation head(MediaType mediaType) throws ResourceException
Represents the resource using a given media type. This method is identical toget(MediaType)
but doesn't return the actual content of the representation, only its metadata.
Note that the client preferences will be automatically adjusted, but only for this request. If you want to change them once for all, you can use theResource.getClientInfo()
method.
If a success status is not returned, then a resource exception is thrown.- Parameters:
mediaType
- The media type of the representation to retrieve.- Returns:
- The representation matching the given media type.
- Throws:
ResourceException
- See Also:
- HTTP HEAD method
-
isFollowingRedirects
public boolean isFollowingRedirects()
Indicates if redirections are followed.- Returns:
- True if redirections are followed.
-
isRequestEntityBuffering
public boolean isRequestEntityBuffering()
Indicates if transient or unknown size response entities should be buffered after being received. This is useful to increase the chance of being able to resubmit a failed request due to network error, or to prevent chunked encoding from being used an HTTP connector.- Returns:
- True if transient response entities should be buffered after being received.
-
isResponseEntityBuffering
public boolean isResponseEntityBuffering()
Indicates if transient or unknown size response entities should be buffered after being received. This is useful to be able to systematically reuse and process a response entity several times after retrieval.- Returns:
- True if transient response entities should be buffered after being received.
-
isRetryOnError
public boolean isRetryOnError()
Indicates if idempotent requests should be retried on error. Default value is true.- Returns:
- True if idempotent requests should be retried on error.
-
options
public Representation options() throws ResourceException
Describes the resource using content negotiation to select the best variant based on the client preferences. If a success status is not returned, then a resource exception is thrown.- Returns:
- The best description.
- Throws:
ResourceException
- See Also:
- HTTP OPTIONS method
-
options
public <T> T options(java.lang.Class<T> resultClass) throws ResourceException
Describes the resource using a given media type. If a success status is not returned, then a resource exception is thrown.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
resultClass
- The expected class for the response entity object.- Returns:
- The response entity object.
- Throws:
ResourceException
- See Also:
- HTTP OPTIONS method
-
options
public Representation options(MediaType mediaType) throws ResourceException
Describes the resource using a given media type. If a success status is not returned, then a resource exception is thrown.- Parameters:
mediaType
- The media type of the representation to retrieve.- Returns:
- The matched description or null.
- Throws:
ResourceException
- See Also:
- HTTP OPTIONS method
-
patch
public Representation patch(java.lang.Object entity) throws ResourceException
Patches a resource with the given object as delta state. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity containing the patch.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP PATCH method
-
patch
public <T> T patch(java.lang.Object entity, java.lang.Class<T> resultClass) throws ResourceException
Patches a resource with the given object as delta state. Automatically serializes the object using theConverterService
.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
entity
- The object entity containing the patch.resultClass
- The class of the response entity.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP PATCH method
-
patch
public Representation patch(java.lang.Object entity, MediaType mediaType) throws ResourceException
Patches a resource with the given object as delta state. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity containing the patch.mediaType
- The media type of the representation to retrieve.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP PATCH method
-
patch
public Representation patch(Representation entity) throws ResourceException
Patches a resource with the given representation as delta state. If a success status is not returned, then a resource exception is thrown.- Parameters:
entity
- The request entity containing the patch.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP PATCH method
-
post
public Representation post(java.lang.Object entity) throws ResourceException
Posts an object entity. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity to post.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP POST method
-
post
public <T> T post(java.lang.Object entity, java.lang.Class<T> resultClass) throws ResourceException
Posts an object entity. Automatically serializes the object using theConverterService
.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
entity
- The object entity to post.resultClass
- The class of the response entity.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP POST method
-
post
public Representation post(java.lang.Object entity, MediaType mediaType) throws ResourceException
Posts an object entity. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity to post.mediaType
- The media type of the representation to retrieve.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP POST method
-
post
public Representation post(Representation entity) throws ResourceException
Posts a representation. If a success status is not returned, then a resource exception is thrown.- Parameters:
entity
- The posted entity.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP POST method
-
put
public Representation put(java.lang.Object entity) throws ResourceException
Puts an object entity. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity to put.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP PUT method
-
put
public <T> T put(java.lang.Object entity, java.lang.Class<T> resultClass) throws ResourceException
Puts an object entity. Automatically serializes the object using theConverterService
.- Type Parameters:
T
- The expected type for the response entity.- Parameters:
entity
- The object entity to put.resultClass
- The class of the response entity.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP PUT method
-
put
public Representation put(java.lang.Object entity, MediaType mediaType) throws ResourceException
Puts an object entity. Automatically serializes the object using theConverterService
.- Parameters:
entity
- The object entity to post.mediaType
- The media type of the representation to retrieve.- Returns:
- The response object entity.
- Throws:
ResourceException
- See Also:
- HTTP PUT method
-
put
public Representation put(Representation entity) throws ResourceException
Creates or updates a resource with the given representation as new state to be stored. If a success status is not returned, then a resource exception is thrown.- Parameters:
entity
- The request entity to store.- Returns:
- The optional result entity.
- Throws:
ResourceException
- See Also:
- HTTP PUT method
-
redirect
protected void redirect(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Effectively redirects a client call. By default, it checks for infinite loops and unavailable entities, the references list is updated and thehandle(Request, Response, List, int, Uniform)
method invoked.- Parameters:
request
- The request to send.response
- The response to update.references
- The references that caused a redirection to prevent infinite loops.retryAttempt
- The number of remaining attempts.next
- The next handler handling the call.
-
retry
protected void retry(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
Effectively retries a failed client call. By default, it sleeps before the retry attempt and increments the number of retries.- Parameters:
request
- The request to send.response
- The response to update.references
- The references that caused a redirection to prevent infinite loops.retryAttempt
- The number of remaining attempts.next
- The next handler handling the call.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Sets the request attribute value.- Specified by:
setAttribute
in classResource
- Parameters:
name
- The attribute name.value
- The attribute to set.
-
setChallengeResponse
public void setChallengeResponse(ChallengeResponse challengeResponse)
Sets the authentication response sent by a client to an origin server.- Parameters:
challengeResponse
- The authentication response sent by a client to an origin server.- See Also:
Request.setChallengeResponse(ChallengeResponse)
-
setChallengeResponse
public void setChallengeResponse(ChallengeScheme scheme, java.lang.String identifier, java.lang.String secret)
Sets the authentication response sent by a client to an origin server given a scheme, identifier and secret.- Parameters:
scheme
- The challenge scheme.identifier
- The user identifier, such as a login name or an access key.secret
- The user secret, such as a password or a secret key.
-
setClientInfo
public void setClientInfo(ClientInfo clientInfo)
Sets the client-specific information.- Parameters:
clientInfo
- The client-specific information.- See Also:
Request.setClientInfo(ClientInfo)
-
setConditions
public void setConditions(Conditions conditions)
Sets the conditions applying to this request.- Parameters:
conditions
- The conditions applying to this request.- See Also:
Request.setConditions(Conditions)
-
setCookies
public void setCookies(Series<Cookie> cookies)
Sets the cookies provided by the client.- Parameters:
cookies
- The cookies provided by the client.- See Also:
Request.setCookies(Series)
-
setEntityBuffering
public void setEntityBuffering(boolean entityBuffering)
Indicates if transient entities should be buffered after being received or before being sent.- Parameters:
entityBuffering
- True if transient entities should be buffered.- See Also:
setRequestEntityBuffering(boolean)
,setResponseEntityBuffering(boolean)
-
setFollowingRedirects
public void setFollowingRedirects(boolean followingRedirects)
Indicates if redirections are followed.- Parameters:
followingRedirects
- True if redirections are followed.
-
setHostRef
public void setHostRef(Reference hostRef)
Sets the host reference.- Parameters:
hostRef
- The host reference.- See Also:
Request.setHostRef(Reference)
-
setHostRef
public void setHostRef(java.lang.String hostUri)
Sets the host reference using an URI string.- Parameters:
hostUri
- The host URI.- See Also:
Request.setHostRef(String)
-
setLoggable
public void setLoggable(boolean loggable)
Indicates if the call is loggable- Parameters:
loggable
- True if the call is loggable
-
setMaxRedirects
public void setMaxRedirects(int maxRedirects)
Sets the maximum number of redirections that can be automatically followed for a single call.- Parameters:
maxRedirects
- The maximum number of redirections that can be automatically followed for a single call.
-
setMethod
public void setMethod(Method method)
Sets the method called.- Parameters:
method
- The method called.- See Also:
Request.setMethod(Method)
-
setNext
public void setNext(Uniform next)
Sets the next handler such as a Restlet or a Filter. In addition, this method will set the context of the next Restlet if it is null by passing a reference to its own context.- Parameters:
next
- The next handler.
-
setOnResponse
public void setOnResponse(Uniform onResponseCallback)
Sets the callback invoked on response reception. If the value is not null, then the associated request will be executed asynchronously.- Parameters:
onResponseCallback
- The callback invoked on response reception.
-
setOnSent
public void setOnSent(Uniform onSentCallback)
Sets the callback invoked after sending the request.- Parameters:
onSentCallback
- The callback invoked after sending the request.
-
setOriginalRef
public void setOriginalRef(Reference originalRef)
Sets the original reference requested by the client.- Parameters:
originalRef
- The original reference.- See Also:
Request.setOriginalRef(Reference)
-
setProtocol
public void setProtocol(Protocol protocol)
Sets the protocol used or to be used.- Parameters:
protocol
- The protocol used or to be used.
-
setProxyChallengeResponse
public void setProxyChallengeResponse(ChallengeResponse challengeResponse)
Sets the proxy authentication response sent by a client to an origin server.- Parameters:
challengeResponse
- The proxy authentication response sent by a client to an origin server.- See Also:
Request.setProxyChallengeResponse(ChallengeResponse)
-
setProxyChallengeResponse
public void setProxyChallengeResponse(ChallengeScheme scheme, java.lang.String identifier, java.lang.String secret)
Sets the proxy authentication response sent by a client to an origin server given a scheme, identifier and secret.- Parameters:
scheme
- The challenge scheme.identifier
- The user identifier, such as a login name or an access key.secret
- The user secret, such as a password or a secret key.
-
setRanges
public void setRanges(java.util.List<Range> ranges)
Sets the ranges to return from the target resource's representation.- Parameters:
ranges
- The ranges.- See Also:
Request.setRanges(List)
-
setReference
public void setReference(Reference reference)
Sets the resource's reference. If the reference is relative, it will be resolved as an absolute reference. Also, the context's base reference will be reset. Finally, the reference will be normalized to ensure a consistent handling of the call.- Parameters:
reference
- The resource reference.- See Also:
Request.setResourceRef(Reference)
-
setReference
public void setReference(java.lang.String uri)
Sets the resource's reference using an URI string. Note that the URI can be either absolute or relative to the context's base reference.- Parameters:
uri
- The resource URI.- See Also:
Request.setResourceRef(String)
-
setReferrerRef
public void setReferrerRef(Reference referrerRef)
Sets the referrer reference if available.- Parameters:
referrerRef
- The referrer reference.- See Also:
Request.setReferrerRef(Reference)
-
setReferrerRef
public void setReferrerRef(java.lang.String referrerUri)
Sets the referrer reference if available using an URI string.- Parameters:
referrerUri
- The referrer URI.- See Also:
Request.setReferrerRef(String)
-
setRequestEntityBuffering
public void setRequestEntityBuffering(boolean requestEntityBuffering)
Indicates if transient or unknown size response entities should be buffered after being received. This is useful to increase the chance of being able to resubmit a failed request due to network error, or to prevent chunked encoding from being used an HTTP connector.- Parameters:
requestEntityBuffering
- True if transient request entities should be buffered after being received.
-
setResponseEntityBuffering
public void setResponseEntityBuffering(boolean responseEntityBuffering)
Indicates if transient or unknown size response entities should be buffered after being received. This is useful to be able to systematically reuse and process a response entity several times after retrieval.- Parameters:
responseEntityBuffering
- True if transient response entities should be buffered after being received.
-
setRetryAttempts
public void setRetryAttempts(int retryAttempts)
Sets the number of retry attempts before reporting an error.- Parameters:
retryAttempts
- The number of retry attempts before reporting an error.
-
setRetryDelay
public void setRetryDelay(long retryDelay)
Sets the delay in milliseconds between two retry attempts. The default value is two seconds.- Parameters:
retryDelay
- The delay in milliseconds between two retry attempts.
-
setRetryOnError
public void setRetryOnError(boolean retryOnError)
Indicates if idempotent requests should be retried on error.- Parameters:
retryOnError
- True if idempotent requests should be retried on error.
-
wrap
public <T> T wrap(java.lang.Class<? extends T> resourceInterface)
Wraps the client resource to proxy calls to the given Java interface into Restlet method calls. Use theEngine
classloader in order to generate the proxy.- Type Parameters:
T
-- Parameters:
resourceInterface
- The annotated resource interface class to proxy.- Returns:
- The proxy instance.
-
wrap
public <T> T wrap(java.lang.Class<? extends T> resourceInterface, java.lang.ClassLoader classLoader)
Wraps the client resource to proxy calls to the given Java interface into Restlet method calls.- Type Parameters:
T
-- Parameters:
resourceInterface
- The annotated resource interface class to proxy.classLoader
- The classloader used to instantiate the dynamic proxy.- Returns:
- The proxy instance.
-
-