javax.ws.rs.client
Interface ClientRequestContext


public interface ClientRequestContext

Client request filter context. A mutable class that provides request-specific information for the filter, such as request URI, message headers, message entity or request-scoped properties. The exposed setters allow modification of the exposed request-specific information.

Since:
2.0
Author:
Marek Potociar (marek.potociar at oracle.com)

Method Summary
 void abortWith(Response response)
          Abort the filter chain with a response.
 java.util.List<java.util.Locale> getAcceptableLanguages()
          Get a list of languages that are acceptable for the response.
 java.util.List<MediaType> getAcceptableMediaTypes()
          Get a list of media types that are acceptable for the response.
 Client getClient()
          Get the client instance associated with the request.
 Configuration getConfiguration()
          Get the configuration of the request.
 java.util.Map<java.lang.String,Cookie> getCookies()
          Get any cookies that accompanied the request.
 java.util.Date getDate()
          Get message date.
 GenericType<?> getDeclaredEntityType()
          Get the declared generic message entity type information.
 java.lang.Object getEntity()
          Get the message entity Java instance.
 java.lang.annotation.Annotation[] getEntityAnnotations()
          Get the annotations attached to the entity.
 java.io.OutputStream getEntityStream()
          Get the entity output stream.
 MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
          Get the mutable request headers multivalued map.
 java.util.Locale getLanguage()
          Get the language of the entity.
 MediaType getMediaType()
          Get the media type of the entity.
 java.lang.String getMethod()
          Get the request method.
 java.lang.Object getProperty(java.lang.String name)
          Returns the property with the given name registered in the current request/response exchange context, or null if there is no property by that name.
 java.util.Enumeration<java.lang.String> getPropertyNames()
          Returns an enumeration containing the property names available within the context of the current request/response exchange context.
 java.net.URI getUri()
          Get the request URI.
 boolean hasEntity()
          Check if there is an entity available in the request.
 void removeProperty(java.lang.String name)
          Removes a property with the given name from the current request/response exchange context.
<T> void
setEntity(java.lang.Class<T> type, java.lang.annotation.Annotation[] annotations, MediaType mediaType, T entity)
          Set a new response message entity.
<T> void
setEntity(GenericType<T> type, java.lang.annotation.Annotation[] annotations, MediaType mediaType, T entity)
          Set a new response message entity.
 void setEntityStream(java.io.OutputStream input)
          Set a new entity output stream.
 void setMethod(java.lang.String method)
          Set the request method.
 void setProperty(java.lang.String name, java.lang.Object object)
          Binds an object to a given property name in the current request/response exchange context.
 void setUri(java.net.URI uri)
          Set a new request URI.
 

Method Detail

getProperty

java.lang.Object getProperty(java.lang.String name)
Returns the property with the given name registered in the current request/response exchange context, or null if there is no property by that name.

A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

A list of supported properties can be retrieved using getPropertyNames(). Custom property names should follow the same convention as package names.

Parameters:
name - a String specifying the name of the property.
Returns:
an Object containing the value of the property, or null if no property exists matching the given name.
See Also:
getPropertyNames()

getPropertyNames

java.util.Enumeration<java.lang.String> getPropertyNames()
Returns an enumeration containing the property names available within the context of the current request/response exchange context.

Use the getProperty(java.lang.String) method with a property name to get the value of a property.

Returns:
an enumeration of property names.
See Also:
getProperty(java.lang.String)

setProperty

void setProperty(java.lang.String name,
                 java.lang.Object object)
Binds an object to a given property name in the current request/response exchange context. If the name specified is already used for a property, this method will replace the value of the property with the new value.

A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

A list of supported properties can be retrieved using getPropertyNames(). Custom property names should follow the same convention as package names.

If a null value is passed, the effect is the same as calling the removeProperty(String) method.

Parameters:
name - a String specifying the name of the property.
object - an Object representing the property to be bound.

removeProperty

void removeProperty(java.lang.String name)
Removes a property with the given name from the current request/response exchange context. After removal, subsequent calls to getProperty(java.lang.String) to retrieve the property value will return null.

Parameters:
name - a String specifying the name of the property to be removed.

getUri

java.net.URI getUri()
Get the request URI.

Returns:
request URI.

setUri

void setUri(java.net.URI uri)
Set a new request URI.

Parameters:
uri - new request URI.

getMethod

java.lang.String getMethod()
Get the request method.

Returns:
the request method.
See Also:
HttpMethod

setMethod

void setMethod(java.lang.String method)
Set the request method.

Parameters:
method - new request method.
See Also:
HttpMethod

getHeaders

MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
Get the mutable request headers multivalued map.

Returns:
mutable multivalued map of request headers.

getDate

java.util.Date getDate()
Get message date.

Returns:
the message date, otherwise null if not present.

getLanguage

java.util.Locale getLanguage()
Get the language of the entity.

Returns:
the language of the entity or null if not specified

getMediaType

MediaType getMediaType()
Get the media type of the entity.

Returns:
the media type or null if not specified (e.g. there's no request entity).

getAcceptableMediaTypes

java.util.List<MediaType> getAcceptableMediaTypes()
Get a list of media types that are acceptable for the response.

Returns:
a read-only list of requested response media types sorted according to their q-value, with highest preference first.

getAcceptableLanguages

java.util.List<java.util.Locale> getAcceptableLanguages()
Get a list of languages that are acceptable for the response.

Returns:
a read-only list of acceptable languages sorted according to their q-value, with highest preference first.

getCookies

java.util.Map<java.lang.String,Cookie> getCookies()
Get any cookies that accompanied the request.

Returns:
a read-only map of cookie name (String) to Cookie.

hasEntity

boolean hasEntity()
Check if there is an entity available in the request. The method returns true if the entity is present, returns false otherwise.

Returns:
true if there is an entity present in the message, false otherwise.

getEntity

java.lang.Object getEntity()
Get the message entity Java instance. Returns null if the message does not contain an entity.

Returns:
the message entity or null if message does not contain an entity body.

setEntity

<T> void setEntity(java.lang.Class<T> type,
                   java.lang.annotation.Annotation[] annotations,
                   MediaType mediaType,
                   T entity)
Set a new response message entity.

Type Parameters:
T - entity Java type.
Parameters:
type - declared entity class.
annotations - annotations attached to the entity.
mediaType - entity media type.
entity - entity object.
See Also:
MessageBodyWriter

setEntity

<T> void setEntity(GenericType<T> type,
                   java.lang.annotation.Annotation[] annotations,
                   MediaType mediaType,
                   T entity)
Set a new response message entity.

Type Parameters:
T - entity Java type.
Parameters:
type - declared generic entity type.
annotations - annotations attached to the entity.
mediaType - entity media type.
entity - entity object.
See Also:
MessageBodyWriter

getDeclaredEntityType

GenericType<?> getDeclaredEntityType()
Get the declared generic message entity type information.

Returns:
declared generic message entity type.

getEntityAnnotations

java.lang.annotation.Annotation[] getEntityAnnotations()
Get the annotations attached to the entity.

Returns:
entity annotations.

getEntityStream

java.io.OutputStream getEntityStream()
Get the entity output stream.

Returns:
entity output stream.

setEntityStream

void setEntityStream(java.io.OutputStream input)
Set a new entity output stream.

Parameters:
input - new entity output stream.

getClient

Client getClient()
Get the client instance associated with the request.

Returns:
client instance associated with the request.

getConfiguration

Configuration getConfiguration()
Get the configuration of the request.

Returns:
request configuration.

abortWith

void abortWith(Response response)
Abort the filter chain with a response. This method breaks the filter chain processing and returns the provided response back to the client. The provided response goes through the chain of applicable response filters.

Parameters:
response - response to be sent back to the client.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.