public class ClientResource extends Resource
Resource.getRequest()
and
Resource.getResponse()
methods. Since a clientResource may receive
severals responses for a single request (in case of interim response), the
Resource.getResponse()
method returns the last received response object. The
Request object returned by the Resource.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,
java.lang.String uri)
Constructor.
|
|
ClientResource(Context context,
Reference reference)
Constructor.
|
|
ClientResource(Context context,
Request request)
Constructor.
|
|
ClientResource(Context context,
Request request,
Response response)
Constructor.
|
|
ClientResource(Context context,
java.lang.String uri)
Constructor.
|
|
ClientResource(Method method,
Reference reference)
Constructor.
|
|
ClientResource(Method method,
java.lang.String uri)
Constructor.
|
|
ClientResource(Reference reference)
Constructor.
|
|
ClientResource(Request request)
Constructor.
|
|
ClientResource(Request request,
Response response)
Constructor.
|
|
ClientResource(java.lang.String uri)
Constructor.
|
Modifier and Type | Method and 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(Parameter parameter)
Adds a parameter to the query component.
|
Reference |
addQueryParameter(java.lang.String name,
java.lang.String value)
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.
|
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.
|
Representation |
delete(MediaType mediaType)
Deletes the target resource and all its representations.
|
void |
doError(Request request,
Response response)
By default, it throws a new resource exception.
|
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.
|
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
Resource.release() the resource. |
Representation |
get()
Represents the resource using content negotiation to select the best
variant based on the client preferences.
|
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(Reference relativeRef)
Returns the child resource defined by its URI relatively to the current
resource.
|
ClientResource |
getChild(java.lang.String relativeUri)
Returns the child resource defined by its URI relatively to the current
resource.
|
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.
|
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 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 |
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.
|
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.
|
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.
|
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.
|
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 |
setHostRef(Reference hostRef)
Sets the host reference.
|
void |
setHostRef(java.lang.String hostUri)
Sets the host reference using an URI string.
|
void |
setLoggable(boolean loggable)
Indicates if the call is loggable
|
void |
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 |
setRanges(java.util.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(java.lang.String uri)
Sets the resource's reference using an URI string.
|
void |
setReferrerRef(Reference referrerRef)
Sets the referrer reference if available.
|
void |
setReferrerRef(java.lang.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.
|
doCatch, doError, doInit, getAllowedMethods, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getContext, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMatrixValue, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getProxyChallengeRequests, getQuery, getQueryValue, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestCacheDirectives, getRequestEntity, getResponse, getResponseAttributes, getResponseCacheDirectives, getResponseEntity, getRootRef, getServerInfo, getStatus, init, isConfidential, isLoggable, release, setQueryValue, setRequest, setResponse, toBoolean, toByte, toDouble, toFloat, toInteger, toLong, toRepresentation, toRepresentation, toRepresentation, toShort, toString
protected ClientResource()
public ClientResource(ClientResource resource)
resource
- The client resource to copy.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, java.lang.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)
context
- The current context.request
- The handled request.public ClientResource(Context context, Request request, Response response)
context
- The current context.request
- The handled request.response
- The handled response.public ClientResource(Context context, java.lang.String uri)
context
- The context.uri
- The target URI.public ClientResource(Method method, Reference reference)
method
- The method to call.reference
- The target reference.public ClientResource(Method method, java.lang.String uri)
method
- The method to call.uri
- The target URI.public ClientResource(Reference reference)
reference
- The target reference.public ClientResource(Request request)
request
- The handled request.public ClientResource(Request request, Response response)
request
- The handled request.response
- The handled response.public ClientResource(java.lang.String uri)
uri
- The target URI.public void accept(Metadata... metadata)
metadata
- The metadata to accept.ClientInfo.accept(Metadata...)
public void accept(Metadata metadata, float quality)
metadata
- The metadata to accept.quality
- The quality to set.ClientInfo.accept(Metadata, float)
public Reference addQueryParameter(Parameter parameter)
parameter
- The parameter to add.Reference.addQueryParameter(Parameter)
public Reference addQueryParameter(java.lang.String name, java.lang.String value)
name
- The parameter name.value
- The optional parameter value.Reference.addQueryParameter(String, String)
public Reference addQueryParameters(java.lang.Iterable<Parameter> parameters)
parameters
- The parameters to add.Reference.addQueryParameters(Iterable)
public Reference addSegment(java.lang.String value)
value
- The segment value to add.Reference.addSegment(String)
protected Uniform createNext()
Client
based on the protocol of the resource's URI reference.public Request createRequest()
Resource.getRequest()
protected Response createResponse(Request request)
request
- The associated request.public Representation delete() throws ResourceException
ResourceException
public Representation delete(MediaType mediaType) throws ResourceException
mediaType
- The media type of the representation to retrieve.ResourceException
public void doError(Request request, Response response)
doError(org.restlet.client.data.Status, org.restlet.client.Request, org.restlet.client.Response)
.request
- The associated request.response
- The associated response.public void doError(Status errorStatus)
doError(org.restlet.client.data.Status, org.restlet.client.Request, org.restlet.client.Response)
.public void doError(Status errorStatus, Request request, Response response)
errorStatus
- The error status received.request
- The associated request.response
- The associated response.protected void doRelease() throws ResourceException
getNext()
method.doRelease
in class Resource
ResourceException
Resource.release()
protected void finalize() throws java.lang.Throwable
Resource.release()
the resource.finalize
in class java.lang.Object
java.lang.Throwable
public Representation get() throws ResourceException
Resource.getClientInfo()
method.ResourceException
public Representation get(MediaType mediaType) throws ResourceException
Resource.getClientInfo()
method.mediaType
- The media type of the representation to retrieve.ResourceException
public java.lang.String getAttribute(java.lang.String name)
getAttribute
in class Resource
name
- The attribute name.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 ClientResource getChild(java.lang.String relativeUri) throws ResourceException
relativeUri
- The URI of the child resource relatively to the current
resource seen as the parent resource.ResourceException
public int getMaxRedirects()
public Uniform getNext()
public Uniform getOnResponse()
public Uniform getOnSent()
public ClientResource getParent() throws ResourceException
ResourceException
public int getRetryAttempts()
public long getRetryDelay()
public Representation handle()
Resource.getRequest()
and cloned and the response is set as
the latest with Resource.setResponse(Response)
. If necessary the
setNext(Uniform)
method is called as well with a Client
instance matching the request protocol.protected Representation handle(Method method)
method
- The request method to use.protected Representation handle(Method method, MediaType mediaType)
method
- The request method to use.mediaType
- The preferred result media type.protected Representation handle(Method method, Representation entity)
method
- The request method to use.entity
- The request entity to set.protected Representation handle(Method method, Representation entity, ClientInfo clientInfo)
method
- The request method to use.entity
- The request entity to set.clientInfo
- The client preferences.protected Representation handle(Method method, Representation entity, MediaType mediaType)
method
- The request method to use.entity
- The request entity to set.mediaType
- The preferred result media type.protected void handle(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
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.public Representation handleInbound(Response response)
response
- public Response handleOutbound(Request request)
request
- The request to handle.getNext()
public boolean hasNext()
public Representation head() throws ResourceException
get()
but doesn't return the actual content of the
representation, only its metadata.Resource.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.Resource.getClientInfo()
method.mediaType
- The media type of the representation to retrieve.ResourceException
public boolean isRetryOnError()
public Representation options() throws ResourceException
ResourceException
public Representation options(MediaType mediaType) throws ResourceException
mediaType
- The media type of the representation to retrieve.ResourceException
public Representation patch(java.lang.Object entity) throws ResourceException
org.restlet.client.service.ConverterService
.entity
- The object entity containing the patch.ResourceException
public Representation patch(java.lang.Object entity, MediaType mediaType) throws ResourceException
org.restlet.client.service.ConverterService
.entity
- The object entity containing the patch.mediaType
- The media type of the representation to retrieve.ResourceException
public Representation patch(Representation entity) throws ResourceException
entity
- The request entity containing the patch.ResourceException
public Representation post(java.lang.Object entity) throws ResourceException
org.restlet.client.service.ConverterService
.entity
- The object entity to post.ResourceException
public Representation post(java.lang.Object entity, MediaType mediaType) throws ResourceException
org.restlet.client.service.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(java.lang.Object entity) throws ResourceException
org.restlet.client.service.ConverterService
.entity
- The object entity to put.ResourceException
public Representation put(java.lang.Object entity, MediaType mediaType) throws ResourceException
org.restlet.client.service.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
protected void redirect(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
handle(Request, Response, List, int, Uniform)
method invoked.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.protected void retry(Request request, Response response, java.util.List<Reference> references, int retryAttempt, Uniform next)
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.public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in class Resource
name
- The attribute name.value
- The attribute to set.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, java.lang.String identifier, java.lang.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 setHostRef(Reference hostRef)
hostRef
- The host reference.Request.setHostRef(Reference)
public void setHostRef(java.lang.String hostUri)
hostUri
- The host URI.Request.setHostRef(String)
public void setLoggable(boolean loggable)
loggable
- True if the call is loggablepublic void setMaxRedirects(int maxRedirects)
maxRedirects
- The maximum number of redirections that can be automatically
followed for a single call.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(java.util.List<Range> ranges)
ranges
- The ranges.Request.setRanges(List)
public void setReference(Reference reference)
reference
- The resource reference.Request.setResourceRef(Reference)
public void setReference(java.lang.String uri)
uri
- The resource URI.Request.setResourceRef(String)
public void setReferrerRef(Reference referrerRef)
referrerRef
- The referrer reference.Request.setReferrerRef(Reference)
public void setReferrerRef(java.lang.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.Copyright © 2005-2024 Restlet.