public class ClientResource extends UniformResource
UniformResource.getRequest()
and UniformResource.getResponse()
methods. Since a clientResource may
receive severals responses for a single request (in case of interim
response), the UniformResource.getResponse()
method returns the last received
response object. The Request object returned by the UniformResource.getRequest()
is
actually a prototype which is cloned (except the representation) just before
the handle()
method is called.StringRepresentation
stored the entity in
memory which can be read several times but has the drawback to consume
memory.Client
class instead.Modifier | Constructor and Description |
---|---|
protected |
ClientResource()
Empty constructor.
|
|
ClientResource(ClientResource resource)
Constructor.
|
|
ClientResource(Context context,
Method method,
Reference reference)
Constructor.
|
|
ClientResource(Context context,
Method method,
String uri)
Constructor.
|
|
ClientResource(Context context,
Method method,
URI uri)
Constructor.
|
|
ClientResource(Context context,
Reference reference)
Constructor.
|
|
ClientResource(Context context,
Request request,
Response response)
Constructor.
|
|
ClientResource(Context context,
String uri)
Constructor.
|
|
ClientResource(Context context,
URI uri)
Constructor.
|
|
ClientResource(Method method,
Reference reference)
Constructor.
|
|
ClientResource(Method method,
String uri)
Constructor.
|
|
ClientResource(Method method,
URI uri)
Constructor.
|
|
ClientResource(Reference reference)
Constructor.
|
|
ClientResource(Request request,
Response response)
Constructor.
|
|
ClientResource(String uri)
Constructor.
|
|
ClientResource(URI uri)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
create(Context context,
Reference reference,
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,
Class<? extends T> resourceInterface)
Creates a client resource that proxy calls to the given Java interface
into Restlet method calls.
|
static <T> T |
create(String uri,
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.
|
protected Request |
createRequest(Request prototype)
Creates a new request by cloning the given one.
|
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(Class<T> resultClass)
Deletes the target resource and all its representations.
|
Representation |
delete(MediaType mediaType)
Deletes the target resource and all its representations.
|
protected void |
doRelease()
Releases the resource by stopping any connector automatically created and
associated to the "next" property (see
getNext() method. |
protected void |
finalize()
Attempts to
UniformResource.release() the resource. |
Representation |
get()
Represents the resource using content negotiation to select the best
variant based on the client preferences.
|
<T> T |
get(Class<T> resultClass)
Represents the resource in the given object class.
|
Representation |
get(MediaType mediaType)
Represents the resource using a given media type.
|
ClientResource |
getChild(Reference relativeRef)
Returns the child resource defined by its URI relatively to the current
resource.
|
<T> T |
getChild(Reference relativeRef,
Class<? extends T> resourceInterface)
Wraps the child client resource to proxy calls to the given Java
interface into Restlet method calls.
|
ClientResource |
getChild(String relativeUri)
Returns the child resource defined by its URI relatively to the current
resource.
|
<T> T |
getChild(String relativeUri,
Class<? extends T> resourceInterface)
Wraps the child client resource to proxy calls to the given Java
interface into Restlet method calls.
|
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(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.
|
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 |
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(Class<T> resultClass)
Describes the resource using a given media type.
|
Representation |
options(MediaType mediaType)
Describes the resource using a given media type.
|
Representation |
post(Object entity)
Posts an object entity.
|
<T> T |
post(Object entity,
Class<T> resultClass)
Posts an object entity.
|
Representation |
post(Object entity,
MediaType mediaType)
Posts an object entity.
|
Representation |
post(Representation entity)
Posts a representation.
|
Representation |
put(Object entity)
Puts an object entity.
|
<T> T |
put(Object entity,
Class<T> resultClass)
Puts an object entity.
|
Representation |
put(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.
|
void |
setChallengeResponse(ChallengeResponse challengeResponse)
Sets the authentication response sent by a client to an origin server.
|
void |
setChallengeResponse(ChallengeScheme scheme,
String identifier,
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 |
setFollowingRedirects(boolean followingRedirects)
Indicates if redirections are followed.
|
void |
setHostRef(Reference hostRef)
Sets the host reference.
|
void |
setHostRef(String hostUri)
Sets the host reference using an URI string.
|
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 |
setRanges(List<Range> ranges)
Sets the ranges to return from the target resource's representation.
|
void |
setReference(Reference reference)
Sets the resource's reference.
|
void |
setReference(String uri)
Sets the resource's reference using an URI string.
|
void |
setReferrerRef(Reference referrerRef)
Sets the referrer reference if available.
|
void |
setReferrerRef(String referrerUri)
Sets the referrer reference if available using an URI string.
|
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(Class<? extends T> resourceInterface)
Wraps the client resource to proxy calls to the given Java interface into
Restlet method calls.
|
doCatch, doInit, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getQuery, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestEntity, getResponse, getResponseAttributes, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, release, setRequest, setResponse, toObject, toRepresentation
protected ClientResource()
public ClientResource(ClientResource resource)
resource
- The client resource to copy.public ClientResource(Context context, URI uri)
context
- The context.uri
- The target URI.public ClientResource(Context context, Method method, URI uri)
context
- The context.method
- The method to call.uri
- The target URI.public ClientResource(Context context, Method method, Reference reference)
context
- The context.method
- The method to call.reference
- The target reference.public ClientResource(Context context, Method method, String uri)
context
- The context.method
- The method to call.uri
- The target URI.public ClientResource(Context context, Reference reference)
context
- The context.reference
- The target reference.public ClientResource(Context context, Request request, Response response)
context
- The current context.request
- The handled request.response
- The handled response.public ClientResource(Context context, String uri)
context
- The context.uri
- The target URI.public ClientResource(URI uri)
uri
- The target URI.public ClientResource(Method method, URI uri)
method
- The method to call.uri
- The target URI.public ClientResource(Method method, Reference reference)
method
- The method to call.reference
- The target reference.public ClientResource(Method method, String uri)
method
- The method to call.uri
- The target URI.public ClientResource(Reference reference)
reference
- The target reference.public ClientResource(Request request, Response response)
request
- The handled request.response
- The handled response.public ClientResource(String uri)
uri
- The target URI.public static <T> T create(Context context, Reference reference, Class<? extends T> resourceInterface)
ClientResource
and invokes the wrap(Class)
method.T
- context
- The context.reference
- The target reference.resourceInterface
- The annotated resource interface class to proxy.public static <T> T create(Reference reference, Class<? extends T> resourceInterface)
ClientResource
and invokes the wrap(Class)
method.T
- resourceInterface
- The annotated resource interface class to proxy.public static <T> T create(String uri, Class<? extends T> resourceInterface)
ClientResource
and invokes the wrap(Class)
method.T
- uri
- The target URI.resourceInterface
- The annotated resource interface class to proxy.protected Uniform createNext()
Client
based on the protocol of the resource's URI reference.protected Request createRequest(Request prototype)
prototype
- The prototype request.protected Response createResponse(Request request)
request
- The associated request.public Representation delete() throws ResourceException
ResourceException
public <T> T delete(Class<T> resultClass) throws ResourceException
T
- The expected type for the response entity.resultClass
- The expected class for the response entity object.ResourceException
public Representation delete(MediaType mediaType) throws ResourceException
mediaType
- The media type of the representation to retrieve.ResourceException
protected void doRelease() throws ResourceException
getNext()
method.doRelease
in class UniformResource
ResourceException
UniformResource.release()
protected void finalize() throws Throwable
UniformResource.release()
the resource.public Representation get() throws ResourceException
UniformResource.getClientInfo()
method.ResourceException
public <T> T get(Class<T> resultClass) throws ResourceException
UniformResource.getClientInfo()
method.T
- The expected type for the response entity.resultClass
- The expected class for the response entity object.ResourceException
public Representation get(MediaType mediaType) throws ResourceException
UniformResource.getClientInfo()
method.mediaType
- The media type of the representation to retrieve.ResourceException
public ClientResource getChild(Reference relativeRef) throws ResourceException
relativeRef
- The URI reference of the child resource relatively to the
current resource seen as the parent resource.ResourceException
public <T> T getChild(Reference relativeRef, Class<? extends T> resourceInterface) throws ResourceException
T
- 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.ResourceException
public ClientResource getChild(String relativeUri) throws ResourceException
relativeUri
- The URI of the child resource relatively to the current
resource seen as the parent resource.ResourceException
public <T> T getChild(String relativeUri, Class<? extends T> resourceInterface) throws ResourceException
T
- 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.ResourceException
public Uniform getNext()
public Uniform getOnResponse()
public Uniform getOnSent()
public ClientResource getParent() throws ResourceException
ResourceException
public <T> T getParent(Class<? extends T> resourceInterface) throws ResourceException
T
- resourceInterface
- The annotated resource interface class to proxy.ResourceException
public int getRetryAttempts()
public long getRetryDelay()
public Representation handle()
UniformResource.getRequest()
and cloned and the response is set as
the latest with UniformResource.setResponse(Response)
. If necessary the
setNext(Uniform)
method is called as well with a Client
instance matching the request protocol.handle
in class UniformResource
getNext()
public boolean hasNext()
public Representation head() throws ResourceException
get()
but doesn't return the actual content of the
representation, only its metadata.UniformResource.getClientInfo()
method.ResourceException
public Representation head(MediaType mediaType) throws ResourceException
get(MediaType)
but doesn't return the actual
content of the representation, only its metadata.UniformResource.getClientInfo()
method.mediaType
- The media type of the representation to retrieve.ResourceException
public boolean isFollowingRedirects()
public boolean isRetryOnError()
public Representation options() throws ResourceException
ResourceException
public <T> T options(Class<T> resultClass) throws ResourceException
T
- The expected type for the response entity.resultClass
- The expected class for the response entity object.ResourceException
public Representation options(MediaType mediaType) throws ResourceException
mediaType
- The media type of the representation to retrieve.ResourceException
public Representation post(Object entity) throws ResourceException
ConverterService
.entity
- The object entity to post.ResourceException
public <T> T post(Object entity, Class<T> resultClass) throws ResourceException
ConverterService
.entity
- The object entity to post.resultClass
- The class of the response entity.ResourceException
public Representation post(Object entity, MediaType mediaType) throws ResourceException
ConverterService
.entity
- The object entity to post.mediaType
- The media type of the representation to retrieve.ResourceException
public Representation post(Representation entity) throws ResourceException
entity
- The posted entity.ResourceException
public Representation put(Object entity) throws ResourceException
ConverterService
.entity
- The object entity to put.ResourceException
public <T> T put(Object entity, Class<T> resultClass) throws ResourceException
ConverterService
.entity
- The object entity to put.resultClass
- The class of the response entity.ResourceException
public Representation put(Object entity, MediaType mediaType) throws ResourceException
ConverterService
.entity
- The object entity to post.mediaType
- The media type of the representation to retrieve.ResourceException
public Representation put(Representation entity) throws ResourceException
entity
- The request entity to store.ResourceException
public void setChallengeResponse(ChallengeResponse challengeResponse)
challengeResponse
- The authentication response sent by a client to an origin
server.Request.setChallengeResponse(ChallengeResponse)
public void setChallengeResponse(ChallengeScheme scheme, String identifier, String secret)
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.public void setClientInfo(ClientInfo clientInfo)
clientInfo
- The client-specific information.Request.setClientInfo(ClientInfo)
public void setConditions(Conditions conditions)
conditions
- The conditions applying to this request.Request.setConditions(Conditions)
public void setCookies(Series<Cookie> cookies)
cookies
- The cookies provided by the client.Request.setCookies(Series)
public void setFollowingRedirects(boolean followingRedirects)
followingRedirects
- True if redirections are followed.public void setHostRef(Reference hostRef)
hostRef
- The host reference.Request.setHostRef(Reference)
public void setHostRef(String hostUri)
hostUri
- The host URI.Request.setHostRef(String)
public void setMethod(Method method)
method
- The method called.Request.setMethod(Method)
public void setNext(Uniform next)
next
- The next handler.public void setOnResponse(Uniform onResponseCallback)
onResponseCallback
- The callback invoked on response reception.public void setOnSent(Uniform onSentCallback)
onSentCallback
- The callback invoked after sending the request.public void setOriginalRef(Reference originalRef)
originalRef
- The original reference.Request.setOriginalRef(Reference)
public void setProtocol(Protocol protocol)
protocol
- The protocol used or to be used.public void setRanges(List<Range> ranges)
ranges
- The ranges.Request.setRanges(List)
public void setReference(Reference reference)
reference
- The resource reference.Request.setResourceRef(Reference)
public void setReference(String uri)
uri
- The resource URI.Request.setResourceRef(String)
public void setReferrerRef(Reference referrerRef)
referrerRef
- The referrer reference.Request.setReferrerRef(Reference)
public void setReferrerRef(String referrerUri)
referrerUri
- The referrer URI.Request.setReferrerRef(String)
public void setRetryAttempts(int retryAttempts)
retryAttempts
- The number of retry attempts before reporting an error.public void setRetryDelay(long retryDelay)
retryDelay
- The delay in milliseconds between two retry attempts.public void setRetryOnError(boolean retryOnError)
retryOnError
- True if idempotent requests should be retried on error.public <T> T wrap(Class<? extends T> resourceInterface)
T
- resourceInterface
- The annotated resource interface class to proxy.Copyright © 2005–2016. All rights reserved.