Package org.restlet.util
Class WrapperRequest
- java.lang.Object
-
- org.restlet.Message
-
- org.restlet.Request
-
- org.restlet.util.WrapperRequest
-
public class WrapperRequest extends Request
Request wrapper. Useful for application developer who need to enrich the request with application related properties and behavior.- Author:
- Jerome Louvel
- See Also:
- The decorator (aka wrapper) pattern
-
-
Constructor Summary
Constructors Constructor Description WrapperRequest(Request wrappedRequest)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
abort()
Ask the connector to attempt to abort the related network connection, for example immediately closing the socket.void
commit(Response response)
Asks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client.java.util.Set<java.lang.String>
getAccessControlRequestHeaders()
Returns the access control request headers of the target resource.Method
getAccessControlRequestMethod()
Returns the access control request method of the target resource.java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>
getAttributes()
Returns a modifiable attributes map that can be used by developers to save information relative to the message.ChallengeResponse
getChallengeResponse()
Returns the authentication response sent by a client to an origin server.ClientInfo
getClientInfo()
Returns the client-specific information.Conditions
getConditions()
Returns the conditions applying to this call.Series<Cookie>
getCookies()
Returns the cookies provided by the client.Representation
getEntity()
Returns the entity representation.Reference
getHostRef()
Returns the host reference.int
getMaxForwards()
Returns the maximum number of intermediaries.Method
getMethod()
Returns the method.Uniform
getOnResponse()
Returns the callback invoked on response reception.Reference
getOriginalRef()
Returns the original reference as requested by the client.Protocol
getProtocol()
Returns the protocol by first returning the baseRef.schemeProtocol property if it is set, or the resourceRef.schemeProtocol property otherwise.ChallengeResponse
getProxyChallengeResponse()
Returns the authentication response sent by a client to a proxy.java.util.List<Range>
getRanges()
Returns the ranges to return from the target resource's representation.Reference
getReferrerRef()
Returns the referrer reference if available.Reference
getResourceRef()
Returns the reference of the target resource.Reference
getRootRef()
Returns the application root reference.protected Request
getWrappedRequest()
Returns the wrapped request.boolean
isAsynchronous()
Indicates if the request is asynchronous.boolean
isConfidential()
Indicates if the call came over a confidential channel such as an SSL-secured connection.boolean
isEntityAvailable()
Indicates if a content is available and can be sent.boolean
isExpectingResponse()
Indicates if an associated response is expected.boolean
isSynchronous()
Indicates if the request is synchronous.void
setAccessControlRequestHeaders(java.util.Set<java.lang.String> accessControlRequestHeaders)
Sets the access control request headers of the target resource.void
setAccessControlRequestMethod(Method accessControlRequestMethod)
Sets the access control request method of the target resource.void
setChallengeResponse(ChallengeResponse response)
Sets the authentication response sent by a client to an origin server.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 modifiable series of cookies provided by the client.void
setEntity(java.lang.String value, MediaType mediaType)
Sets a textual entity.void
setEntity(Representation entity)
Sets the entity representation.void
setHostRef(java.lang.String hostUri)
Sets the host reference using an URI string.void
setHostRef(Reference hostRef)
Sets the host reference.void
setMaxForwards(int maxForwards)
Sets the maximum number of intermediaries.void
setMethod(Method method)
Sets the method called.void
setOnResponse(Uniform onResponseCallback)
Sets the callback invoked on response reception.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 response)
Sets the authentication response sent by a client to a proxy.void
setRanges(java.util.List<Range> ranges)
Sets the modifiable list of ranges to return from the target resource's representation.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
setResourceRef(java.lang.String resourceUri)
Sets the target resource reference using an URI string.void
setResourceRef(Reference resourceRef)
Sets the target resource reference.void
setRootRef(Reference rootRef)
Sets the application root reference.java.lang.String
toString()
Displays a synthesis of the request like an HTTP request line.-
Methods inherited from class org.restlet.Request
getCurrent, isLoggable, setLoggable
-
Methods inherited from class org.restlet.Message
bufferEntity, flushBuffers, getCacheDirectives, getDate, getEntityAsText, getHeaders, getOnError, getOnSent, getRecipientsInfo, getWarnings, release, setAttributes, setCacheDirectives, setDate, setOnError, setOnSent, setRecipientsInfo, setWarnings
-
-
-
-
Constructor Detail
-
WrapperRequest
public WrapperRequest(Request wrappedRequest)
Constructor.- Parameters:
wrappedRequest
- The wrapped request.
-
-
Method Detail
-
abort
public boolean abort()
Description copied from class:Request
Ask the connector to attempt to abort the related network connection, for example immediately closing the socket.
-
commit
public void commit(Response response)
Description copied from class:Request
Asks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client. Note that all server connectors don't necessarily support this feature.
-
getAttributes
public java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> getAttributes()
Returns a modifiable attributes map that can be used by developers to save information relative to the message. This is an easier alternative to the creation of a wrapper instance around the whole message.
In addition, this map is a shared space between the developer and the connectors. In this case, it is used to exchange information that is not uniform across all protocols and couldn't therefore be directly included in the API. For this purpose, all attribute names starting with "org.restlet" are reserved. Currently the following attributes are used:list of supported attributes Attribute name Class name Description org.restlet.http.headers org.restlet.data.Form Server HTTP connectors must provide all request headers and client HTTP connectors must provide all response headers, exactly as they were received. In addition, developers can also use this attribute to specify non-standard headers that should be added to the request or to the response. - Overrides:
getAttributes
in classMessage
- Returns:
- The modifiable attributes map.
-
getChallengeResponse
public ChallengeResponse getChallengeResponse()
Returns the authentication response sent by a client to an origin server.- Overrides:
getChallengeResponse
in classRequest
- Returns:
- The authentication response sent by a client to an origin server.
-
getClientInfo
public ClientInfo getClientInfo()
Returns the client-specific information.- Overrides:
getClientInfo
in classRequest
- Returns:
- The client-specific information.
-
getConditions
public Conditions getConditions()
Returns the conditions applying to this call.- Overrides:
getConditions
in classRequest
- Returns:
- The conditions applying to this call.
-
getCookies
public Series<Cookie> getCookies()
Returns the cookies provided by the client.- Overrides:
getCookies
in classRequest
- Returns:
- The cookies provided by the client.
-
getEntity
public Representation getEntity()
Returns the entity representation.
-
getHostRef
public Reference getHostRef()
Returns the host reference. This may be different from the resourceRef's host, for example for URNs and other URIs that don't contain host information.- Overrides:
getHostRef
in classRequest
- Returns:
- The host reference.
-
getMaxForwards
public int getMaxForwards()
Description copied from class:Request
Returns the maximum number of intermediaries.- Overrides:
getMaxForwards
in classRequest
- Returns:
- The maximum number of intermediaries.
-
getMethod
public Method getMethod()
Returns the method.
-
getOnResponse
public Uniform getOnResponse()
Description copied from class:Request
Returns the callback invoked on response reception. If the value is not null, then the associated request will be executed asynchronously.- Overrides:
getOnResponse
in classRequest
- Returns:
- The callback invoked on response reception.
-
getOriginalRef
public Reference getOriginalRef()
Description copied from class:Request
Returns the original reference as requested by the client. Note that this property is not used during request routing. See theRequest.getResourceRef()
method for details.- Overrides:
getOriginalRef
in classRequest
- Returns:
- The original reference.
- See Also:
Request.getResourceRef()
-
getProtocol
public Protocol getProtocol()
Returns the protocol by first returning the baseRef.schemeProtocol property if it is set, or the resourceRef.schemeProtocol property otherwise.- Overrides:
getProtocol
in classRequest
- Returns:
- The protocol or null if not available.
-
getProxyChallengeResponse
public ChallengeResponse getProxyChallengeResponse()
Returns the authentication response sent by a client to a proxy.- Overrides:
getProxyChallengeResponse
in classRequest
- Returns:
- The authentication response sent by a client to a proxy.
-
getRanges
public java.util.List<Range> getRanges()
Description copied from class:Request
Returns the ranges to return from the target resource's representation. Note that when used with HTTP connectors, this property maps to the "Range" header.
-
getReferrerRef
public Reference getReferrerRef()
Returns the referrer reference if available.- Overrides:
getReferrerRef
in classRequest
- Returns:
- The referrer reference.
-
getResourceRef
public Reference getResourceRef()
Returns the reference of the target resource.- Overrides:
getResourceRef
in classRequest
- Returns:
- The reference of the target resource.
- See Also:
Request.getOriginalRef()
,Request.getHostRef()
-
getRootRef
public Reference getRootRef()
Returns the application root reference.- Overrides:
getRootRef
in classRequest
- Returns:
- The application root reference.
-
getWrappedRequest
protected Request getWrappedRequest()
Returns the wrapped request.- Returns:
- The wrapped request.
-
getAccessControlRequestHeaders
public java.util.Set<java.lang.String> getAccessControlRequestHeaders()
Returns the access control request headers of the target resource.- Overrides:
getAccessControlRequestHeaders
in classRequest
- Returns:
- The access control request headers of the target resource.
-
getAccessControlRequestMethod
public Method getAccessControlRequestMethod()
Returns the access control request method of the target resource.- Overrides:
getAccessControlRequestMethod
in classRequest
- Returns:
- The access control request method of the target resource.
-
isAsynchronous
public boolean isAsynchronous()
Description copied from class:Request
Indicates if the request is asynchronous. The test consist in verifying that theRequest.getOnResponse()
method returns a callback object.- Overrides:
isAsynchronous
in classRequest
- Returns:
- True if the request is synchronous.
-
isConfidential
public boolean isConfidential()
Indicates if the call came over a confidential channel such as an SSL-secured connection.- Overrides:
isConfidential
in classRequest
- Returns:
- True if the call came over a confidential channel.
-
isEntityAvailable
public boolean isEntityAvailable()
Indicates if a content is available and can be sent. Several conditions must be met: the method must allow the sending of content, the content must exists and have some available data.- Overrides:
isEntityAvailable
in classRequest
- Returns:
- True if a content is available and can be sent.
-
isExpectingResponse
public boolean isExpectingResponse()
Description copied from class:Request
Indicates if an associated response is expected.- Overrides:
isExpectingResponse
in classRequest
- Returns:
- True if an associated response is expected.
-
isSynchronous
public boolean isSynchronous()
Description copied from class:Request
Indicates if the request is synchronous. The test consist in verifying that theRequest.getOnResponse()
method returns null.- Overrides:
isSynchronous
in classRequest
- Returns:
- True if the request is synchronous.
-
setChallengeResponse
public void setChallengeResponse(ChallengeResponse response)
Sets the authentication response sent by a client to an origin server.- Overrides:
setChallengeResponse
in classRequest
- Parameters:
response
- The authentication response sent by a client to an origin server.
-
setClientInfo
public void setClientInfo(ClientInfo clientInfo)
Description copied from class:Request
Sets the client-specific information.- Overrides:
setClientInfo
in classRequest
- Parameters:
clientInfo
- The client-specific information.
-
setConditions
public void setConditions(Conditions conditions)
Description copied from class:Request
Sets the conditions applying to this request.- Overrides:
setConditions
in classRequest
- Parameters:
conditions
- The conditions applying to this request.
-
setCookies
public void setCookies(Series<Cookie> cookies)
Description copied from class:Request
Sets the modifiable series of cookies provided by the client. Note that when used with HTTP connectors, this property maps to the "Cookie" header. This method clears the current series and adds all entries in the parameter series.- Overrides:
setCookies
in classRequest
- Parameters:
cookies
- A series of cookies provided by the client.
-
setEntity
public void setEntity(Representation entity)
Sets the entity representation.
-
setEntity
public void setEntity(java.lang.String value, MediaType mediaType)
Sets a textual entity.
-
setHostRef
public void setHostRef(Reference hostRef)
Sets the host reference.- Overrides:
setHostRef
in classRequest
- Parameters:
hostRef
- The host reference.
-
setHostRef
public void setHostRef(java.lang.String hostUri)
Sets the host reference using an URI string.- Overrides:
setHostRef
in classRequest
- Parameters:
hostUri
- The host URI.
-
setMaxForwards
public void setMaxForwards(int maxForwards)
Description copied from class:Request
Sets the maximum number of intermediaries.- Overrides:
setMaxForwards
in classRequest
- Parameters:
maxForwards
- The maximum number of intermediaries.
-
setMethod
public void setMethod(Method method)
Sets the method called.
-
setOnResponse
public void setOnResponse(Uniform onResponseCallback)
Description copied from class:Request
Sets the callback invoked on response reception. If the value is not null, then the associated request will be executed asynchronously.- Overrides:
setOnResponse
in classRequest
- Parameters:
onResponseCallback
- The callback invoked on response reception.
-
setOriginalRef
public void setOriginalRef(Reference originalRef)
Description copied from class:Request
Sets the original reference requested by the client.- Overrides:
setOriginalRef
in classRequest
- Parameters:
originalRef
- The original reference.- See Also:
Request.getOriginalRef()
-
setProtocol
public void setProtocol(Protocol protocol)
Description copied from class:Request
Sets the protocol used or to be used.- Overrides:
setProtocol
in classRequest
- Parameters:
protocol
- The protocol used or to be used.
-
setProxyChallengeResponse
public void setProxyChallengeResponse(ChallengeResponse response)
Sets the authentication response sent by a client to a proxy.- Overrides:
setProxyChallengeResponse
in classRequest
- Parameters:
response
- The authentication response sent by a client to a proxy.
-
setRanges
public void setRanges(java.util.List<Range> ranges)
Description copied from class:Request
Sets the modifiable list of ranges to return from the target resource's representation. Note that when used with HTTP connectors, this property maps to the "Range" header. This method clears the current list and adds all entries in the parameter list.
-
setReferrerRef
public void setReferrerRef(Reference referrerRef)
Sets the referrer reference if available.- Overrides:
setReferrerRef
in classRequest
- Parameters:
referrerRef
- The referrer reference.
-
setReferrerRef
public void setReferrerRef(java.lang.String referrerUri)
Sets the referrer reference if available using an URI string.- Overrides:
setReferrerRef
in classRequest
- Parameters:
referrerUri
- The referrer URI.- See Also:
Request.setReferrerRef(Reference)
-
setResourceRef
public void setResourceRef(Reference resourceRef)
Sets the target resource 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.- Overrides:
setResourceRef
in classRequest
- Parameters:
resourceRef
- The resource reference.- See Also:
Request.getResourceRef()
-
setResourceRef
public void setResourceRef(java.lang.String resourceUri)
Sets the target resource reference using an URI string. Note that the URI can be either absolute or relative to the context's base reference.- Overrides:
setResourceRef
in classRequest
- Parameters:
resourceUri
- The resource URI.- See Also:
Request.setResourceRef(Reference)
-
setRootRef
public void setRootRef(Reference rootRef)
Sets the application root reference.- Overrides:
setRootRef
in classRequest
- Parameters:
rootRef
- The application root reference.
-
setAccessControlRequestHeaders
public void setAccessControlRequestHeaders(java.util.Set<java.lang.String> accessControlRequestHeaders)
Sets the access control request headers of the target resource.- Overrides:
setAccessControlRequestHeaders
in classRequest
- Parameters:
accessControlRequestHeaders
- The access control request headers of the target resource.
-
setAccessControlRequestMethod
public void setAccessControlRequestMethod(Method accessControlRequestMethod)
Sets the access control request method of the target resource.- Overrides:
setAccessControlRequestMethod
in classRequest
- Parameters:
accessControlRequestMethod
- The access control request method of the target resource.
-
-