Package org.restlet
Class Request
java.lang.Object
org.restlet.Message
org.restlet.Request
- Direct Known Subclasses:
HttpRequest,WrapperRequest
Generic request sent by client connectors. It is then received by server
connectors and processed by
Restlets. This request can also be
processed by a chain of Restlets, on both client and server sides. Requests
are uniform across all types of connectors, protocols and components.-
Constructor Summary
ConstructorsConstructorDescriptionRequest()Constructor.Constructor.Request(Method method, String resourceUri, Representation entity) Constructor.Constructor.Request(Method method, Reference resourceRef, Representation entity) Constructor.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanabort()Ask the connector to attempt to abort the related network connection, for example immediately closing the socket.voidAsks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client.Returns the modifiable set of headers the client is willing to send in future request to this resource.Returns the method the client is willing to use in future request to this resource.Returns the authentication response sent by a client to an origin server.Returns the client-specific information.Returns the modifiable conditions applying to this request.Returns the modifiable series of cookies provided by the client.static RequestReturns the request associated to the current thread.Returns the host reference.intReturns the maximum number of intermediaries.Returns the method.Returns the callback invoked on response reception.Returns the original reference as requested by the client.Returns the protocol used or to be used, if known.Returns the authentication response sent by a client to a proxy.Returns the ranges to return from the target resource's representation.Returns the referrer reference if available.Returns the reference of the target resource.Returns the application root reference.booleanIndicates if the request is asynchronous.booleanImplemented based on theProtocol.isConfidential()method for the request's protocol returned bygetProtocol();booleanIndicates if a content is available and can be sent.booleanIndicates if an associated response is expected.booleanIndicates if the call is loggablebooleanIndicates if the request is synchronous.voidsetAccessControlRequestHeaders(Set<String> accessControlRequestHeaders) Sets the set of headers the client is willing to use in future request to this resource.voidsetAccessControlRequestMethod(Method accessControlRequestMethod) Sets the method the client is willing to use in future request to this resource.voidsetChallengeResponse(ChallengeResponse challengeResponse) Sets the authentication response sent by a client to an origin server.voidsetClientInfo(ClientInfo clientInfo) Sets the client-specific information.voidsetConditions(Conditions conditions) Sets the conditions applying to this request.voidsetCookies(Series<Cookie> cookies) Sets the modifiable series of cookies provided by the client.voidsetHostRef(String hostUri) Sets the host reference using a URI string.voidsetHostRef(Reference hostRef) Sets the host reference.voidsetLoggable(boolean loggable) Indicates if the call is loggablevoidsetMaxForwards(int maxForwards) Sets the maximum number of intermediaries.voidSets the method called.voidsetOnResponse(Uniform onResponseCallback) Sets the callback invoked on response reception.voidsetOriginalRef(Reference originalRef) Sets the original reference requested by the client.voidsetProtocol(Protocol protocol) Sets the protocol used or to be used.voidsetProxyChallengeResponse(ChallengeResponse challengeResponse) Sets the authentication response sent by a client to a proxy.voidSets the modifiable list of ranges to return from the target resource's representation.voidsetReferrerRef(String referrerUri) Sets the referrer reference if available using an URI string.voidsetReferrerRef(Reference referrerRef) Sets the referrer reference if available.voidsetResourceRef(String resourceUri) Sets the target resource reference using an URI string.voidsetResourceRef(Reference resourceRef) Sets the target resource reference.voidsetRootRef(Reference rootRef) Sets the application root reference.toString()Displays a synthesis of the request like an HTTP request line.Methods inherited from class org.restlet.Message
bufferEntity, flushBuffers, getAttributes, getCacheDirectives, getDate, getEntity, getEntityAsText, getHeaders, getOnError, getOnSent, getRecipientsInfo, getWarnings, release, setAttributes, setCacheDirectives, setDate, setEntity, setEntity, setOnError, setOnSent, setRecipientsInfo, setWarnings
-
Constructor Details
-
Request
public Request()Constructor. -
Request
Constructor.- Parameters:
method- The call's method.resourceRef- The resource reference.
-
Request
Constructor.- Parameters:
method- The call's method.resourceRef- The resource reference.entity- The entity.
-
Request
Constructor.- Parameters:
method- The call's method.resourceUri- The resource URI.
-
Request
Constructor.- Parameters:
method- The call's method.resourceUri- The resource URI.entity- The entity.
-
Request
Copy constructor.- Parameters:
request- The request to copy.
-
-
Method Details
-
getCurrent
Returns the request associated to the current thread. This is reusing theResponse.getCurrent()method.
Warning: this method should only be used under duress. You should by default prefer obtaining the current context using methods such asResource.getRequest().- Returns:
- The thread's request.
-
abort
public boolean abort()Ask the connector to attempt to abort the related network connection, for example immediately closing the socket.- Returns:
- True if the request was aborted.
-
commit
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.- Parameters:
response- The response to commit.
-
getAccessControlRequestHeaders
Returns the modifiable set of headers the client is willing to send in future request to this resource. Used when issuing a preflight CORS request to let the origin server knows what headers will be sent later.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header.- Returns:
- The headers the client is willing to send in future request to this resource. Useful for CORS support.
-
getAccessControlRequestMethod
Returns the method the client is willing to use in future request to this resource. Used when issuing a preflight CORS request to let the origin server knows what method will be sent later.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Request-Method" header.- Returns:
- The method the client is willing to send in future request to this resource. Useful for CORS support.
-
getChallengeResponse
Returns the authentication response sent by a client to an origin server. Note that when used with HTTP connectors, this property maps to the "Authorization" header.- Returns:
- The authentication response sent by a client to an origin server.
-
getClientInfo
Returns the client-specific information. Creates a new instance if no one has been set.- Returns:
- The client-specific information.
-
getConditions
Returns the modifiable conditions applying to this request. Creates a new instance if no one has been set.- Returns:
- The conditions applying to this call.
-
getCookies
Returns the modifiable series of cookies provided by the client. Creates a new instance if no one has been set.
Note that when used with HTTP connectors, this property maps to the "Cookie" header.- Returns:
- The cookies provided by the client.
-
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.
Note that when used with HTTP connectors, this property maps to the "Host" header.- Returns:
- The host reference.
-
getMaxForwards
public int getMaxForwards()Returns the maximum number of intermediaries.- Returns:
- The maximum number of intermediaries.
-
getMethod
Returns the method.- Returns:
- The method.
-
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.
-
getOriginalRef
Returns the original reference as requested by the client. Note that this property is not used during request routing. See thegetResourceRef()method for details.- Returns:
- The original reference.
- See Also:
-
getProtocol
Returns the protocol used or to be used, if known.- Returns:
- The protocol used or to be used.
-
getProxyChallengeResponse
Returns the authentication response sent by a client to a proxy. Note that when used with HTTP connectors, this property maps to the "Proxy-Authorization" header.- Returns:
- The authentication response sent by a client to a proxy.
-
getRanges
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.- Returns:
- The ranges to return.
-
getReferrerRef
Returns the referrer reference if available. Note that when used with HTTP connectors, this property maps to the "Referer" header.- Returns:
- The referrer reference.
-
getResourceRef
Returns the reference of the target resource. This reference is especially important during routing, dispatching and resource finding. During such processing, its base reference is constantly updated to reflect the reference of the parent Restlet or resource and the remaining part of the URI that must be routed or analyzed. If you need to get the URI reference originally requested by the client, then you should use thegetOriginalRef()method instead. Also, note that beside the update of its base property, the resource reference can be modified during the request processing. For example, theTunnelServiceassociated to an application can extract some special extensions or query parameters and replace them by semantically equivalent properties on the request object. Therefore, the resource reference can become different from the original reference. Finally, when sending out requests via a dispatcher such asContext.getClientDispatcher()orContext.getServerDispatcher(), if the reference contains URI template variables, those variables are automatically resolved using the request's attributes.- Returns:
- The reference of the target resource.
- See Also:
-
getRootRef
Returns the application root reference.- Returns:
- The application root reference.
-
isAsynchronous
public boolean isAsynchronous()Indicates if the request is asynchronous. The test consist in verifying that thegetOnResponse()method returns a callback object.- Returns:
- True if the request is synchronous.
-
isConfidential
public boolean isConfidential()Implemented based on theProtocol.isConfidential()method for the request's protocol returned bygetProtocol();- Specified by:
isConfidentialin classMessage- Returns:
- True if the message is confidential.
-
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:
isEntityAvailablein classMessage- Returns:
- True if a content is available and can be sent.
-
isExpectingResponse
public boolean isExpectingResponse()Indicates if an associated response is expected.- Returns:
- True if an associated response is expected.
-
isLoggable
public boolean isLoggable()Indicates if the call is loggable- Returns:
- True if the call is loggable
-
isSynchronous
public boolean isSynchronous()Indicates if the request is synchronous. The test consist in verifying that thegetOnResponse()method returns null.- Returns:
- True if the request is synchronous.
-
setAccessControlRequestHeaders
Sets the set of headers the client is willing to use in future request to this resource. Used when issuing a preflight CORS request to let the origin server knows what headers will be sent later.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Request-Method" header.- Parameters:
accessControlRequestHeaders- The set of headers the client is willing to send in future request to this resource. Useful for CORS support.
-
setAccessControlRequestMethod
Sets the method the client is willing to use in future request to this resource. Used when issuing a preflight CORS request to let the origin server knows what method will be sent later.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Request-Method" header.- Parameters:
accessControlRequestMethod- The method the client is willing to send in future request to this resource. Useful for CORS support.
-
setChallengeResponse
Sets the authentication response sent by a client to an origin server. Note that when used with HTTP connectors, this property maps to the "Authorization" header.- Parameters:
challengeResponse- The authentication response sent by a client to an origin server.
-
setClientInfo
Sets the client-specific information.- Parameters:
clientInfo- The client-specific information.
-
setConditions
Sets the conditions applying to this request.- Parameters:
conditions- The conditions applying to this request.
-
setCookies
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.- Parameters:
cookies- A series of cookies provided by the client.
-
setHostRef
Sets the host reference. Note that when used with HTTP connectors, this property maps to the "Host" header.- Parameters:
hostRef- The host reference.
-
setHostRef
Sets the host reference using a URI string. Note that when used with HTTP connectors, this property maps to the "Host" header.- Parameters:
hostUri- The host URI.
-
setLoggable
public void setLoggable(boolean loggable) Indicates if the call is loggable- Parameters:
loggable- True if the call is loggable
-
setMaxForwards
public void setMaxForwards(int maxForwards) Sets the maximum number of intermediaries.- Parameters:
maxForwards- The maximum number of intermediaries.
-
setMethod
Sets the method called.- Parameters:
method- The method called.
-
setOnResponse
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.
-
setOriginalRef
Sets the original reference requested by the client.- Parameters:
originalRef- The original reference.- See Also:
-
setProtocol
Sets the protocol used or to be used.- Parameters:
protocol- The protocol used or to be used.
-
setProxyChallengeResponse
Sets the authentication response sent by a client to a proxy. Note that when used with HTTP connectors, this property maps to the "Proxy-Authorization" header.- Parameters:
challengeResponse- The authentication response sent by a client to a proxy.
-
setRanges
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.- Parameters:
ranges- A list of ranges.
-
setReferrerRef
Sets the referrer reference if available. Note that when used with HTTP connectors, this property maps to the "Referer" header.- Parameters:
referrerRef- The referrer reference.
-
setReferrerRef
Sets the referrer reference if available using an URI string. Note that when used with HTTP connectors, this property maps to the "Referer" header.- Parameters:
referrerUri- The referrer URI.- See Also:
-
setResourceRef
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.- Parameters:
resourceRef- The resource reference.- See Also:
-
setResourceRef
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.- Parameters:
resourceUri- The resource URI.- See Also:
-
setRootRef
Sets the application root reference.- Parameters:
rootRef- The application root reference.
-
toString
Displays a synthesis of the request like an HTTP request line.
-