public class ClientRequest extends OutboundMessageContext implements javax.ws.rs.client.ClientRequestContext, InjectionManagerSupplier
OutboundMessageContext.StreamProvider
Modifier and Type | Field and Description |
---|---|
private javax.ws.rs.core.Response |
abortResponse |
private boolean |
asynchronous |
private ClientConfig |
clientConfig |
private boolean |
entityWritten |
private java.lang.String |
httpMethod |
private boolean |
ignoreUserAgent |
private static java.util.logging.Logger |
LOGGER |
private PropertiesDelegate |
propertiesDelegate |
private java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> |
readerInterceptors |
private java.net.URI |
requestUri |
private MessageBodyWorkers |
workers |
private java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> |
writerInterceptors |
Modifier | Constructor and Description |
---|---|
|
ClientRequest(ClientRequest original)
Copy constructor.
|
protected |
ClientRequest(java.net.URI requestUri,
ClientConfig clientConfig,
PropertiesDelegate propertiesDelegate)
Create new Jersey client request context.
|
Modifier and Type | Method and Description |
---|---|
void |
abortWith(javax.ws.rs.core.Response response) |
void |
accept(javax.ws.rs.core.MediaType... types)
Add new accepted types to the message headers.
|
void |
accept(java.lang.String... types)
Add new accepted types to the message headers.
|
void |
acceptLanguage(java.util.Locale... locales)
Add new accepted languages to the message headers.
|
void |
acceptLanguage(java.lang.String... locales)
Add new accepted languages to the message headers.
|
void |
cacheControl(javax.ws.rs.core.CacheControl cacheControl)
Add new cache control entry to the message headers.
|
void |
cookie(javax.ws.rs.core.Cookie cookie)
Add new cookie to the message headers.
|
(package private) void |
doWriteEntity(MessageBodyWorkers writeWorkers,
javax.ws.rs.core.GenericType<?> entityType)
Added only to make the code testable.
|
void |
enableBuffering()
Enable a buffering of serialized entity.
|
void |
encoding(java.lang.String encoding)
Set message encoding.
|
private void |
ensureMediaType() |
javax.ws.rs.core.Response |
getAbortResponse()
Get the request filter chain aborting response if set, or
null otherwise. |
JerseyClient |
getClient() |
(package private) ClientConfig |
getClientConfig()
Get internal client configuration state.
|
(package private) ClientRuntime |
getClientRuntime()
Get the underlying client runtime.
|
javax.ws.rs.core.Configuration |
getConfiguration() |
java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> |
getCookies() |
InjectionManager |
getInjectionManager()
Get injection manager.
|
private javax.ws.rs.core.MediaType |
getMediaType(java.util.List<javax.ws.rs.core.MediaType> mediaTypes) |
java.lang.String |
getMethod() |
(package private) PropertiesDelegate |
getPropertiesDelegate()
Get the underlying properties delegate.
|
java.lang.Object |
getProperty(java.lang.String name) |
java.util.Collection<java.lang.String> |
getPropertyNames() |
java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> |
getReaderInterceptors()
Get reader interceptors of this request.
|
java.net.URI |
getUri() |
MessageBodyWorkers |
getWorkers()
Get the message body workers associated with the request.
|
java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> |
getWriterInterceptors()
Get writer interceptors of this request.
|
boolean |
ignoreUserAgent()
Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.
|
void |
ignoreUserAgent(boolean ignore)
Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.
|
boolean |
isAsynchronous()
Returns true if the request is called asynchronously using
AsyncInvoker |
void |
language(java.util.Locale language)
Set message language.
|
void |
language(java.lang.String language)
Set message language.
|
void |
removeProperty(java.lang.String name) |
<T> T |
resolveProperty(java.lang.String name,
java.lang.Class<T> type)
Resolve a property value for the specified property
name . |
private <T> T |
resolveProperty(java.lang.String name,
java.lang.Object defaultValue,
java.lang.Class<T> type) |
<T> T |
resolveProperty(java.lang.String name,
T defaultValue)
Resolve a property value for the specified property
name . |
(package private) void |
setAsynchronous(boolean async)
Sets the flag indicating whether the request is called asynchronously using
AsyncInvoker . |
void |
setMethod(java.lang.String method) |
void |
setProperty(java.lang.String name,
java.lang.Object object) |
(package private) void |
setReaderInterceptors(java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors)
Set reader interceptors for this request.
|
void |
setUri(java.net.URI uri) |
void |
setWorkers(MessageBodyWorkers workers)
Set the message body workers associated with the request.
|
(package private) void |
setWriterInterceptors(java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
Set writer interceptors for this request.
|
void |
type(javax.ws.rs.core.MediaType type)
Set message content type.
|
void |
type(java.lang.String type)
Set message content type.
|
void |
variant(javax.ws.rs.core.Variant variant)
Set message content variant (type, language and encoding).
|
void |
writeEntity()
Write (serialize) the entity set in this request into the
entity stream . |
close, commitStream, enableBuffering, getAcceptableLanguages, getAcceptableMediaTypes, getAllowedMethods, getDate, getEntity, getEntityAnnotations, getEntityClass, getEntityStream, getEntityTag, getEntityType, getHeaders, getHeaderString, getLanguage, getLastModified, getLength, getLengthLong, getLink, getLinkBuilder, getLinks, getLocation, getMediaType, getRequestCookies, getResponseCookies, getStringHeaders, hasEntity, hasLink, isCommitted, replaceHeaders, setEntity, setEntity, setEntity, setEntity, setEntityAnnotations, setEntityStream, setEntityType, setMediaType, setStreamProvider
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAcceptableLanguages, getAcceptableMediaTypes, getDate, getEntity, getEntityAnnotations, getEntityClass, getEntityStream, getEntityType, getHeaders, getHeaderString, getLanguage, getMediaType, getStringHeaders, hasEntity, setEntity, setEntity, setEntityStream
private final ClientConfig clientConfig
private final PropertiesDelegate propertiesDelegate
private java.net.URI requestUri
private java.lang.String httpMethod
private javax.ws.rs.core.Response abortResponse
private MessageBodyWorkers workers
private boolean asynchronous
private boolean entityWritten
private java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors
private java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors
private boolean ignoreUserAgent
private static final java.util.logging.Logger LOGGER
protected ClientRequest(java.net.URI requestUri, ClientConfig clientConfig, PropertiesDelegate propertiesDelegate)
requestUri
- request Uri.clientConfig
- request configuration.propertiesDelegate
- properties delegate.public ClientRequest(ClientRequest original)
original
- original instance.public <T> T resolveProperty(java.lang.String name, java.lang.Class<T> type)
name
.
The method returns the value of the property registered in the request-specific
property bag, if available. If no property for the given property name is found
in the request-specific property bag, the method looks at the properties stored
in the global client-runtime configuration
this request
belongs to. If there is a value defined in the client-runtime configuration,
it is returned, otherwise the method returns null
if no such property is
registered neither in the client runtime nor in the request-specific property bag.
T
- property Java type.name
- property name.type
- expected property class type.null
if no such property is registered.public <T> T resolveProperty(java.lang.String name, T defaultValue)
name
.
The method returns the value of the property registered in the request-specific
property bag, if available. If no property for the given property name is found
in the request-specific property bag, the method looks at the properties stored
in the global client-runtime configuration
this request
belongs to. If there is a value defined in the client-runtime configuration,
it is returned, otherwise the method returns defaultValue
if no such property is
registered neither in the client runtime nor in the request-specific property bag.
T
- property Java type.name
- property name.defaultValue
- default value to return if the property is not registered.defaultValue
if no such property is registered.private <T> T resolveProperty(java.lang.String name, java.lang.Object defaultValue, java.lang.Class<T> type)
public java.lang.Object getProperty(java.lang.String name)
getProperty
in interface javax.ws.rs.client.ClientRequestContext
public java.util.Collection<java.lang.String> getPropertyNames()
getPropertyNames
in interface javax.ws.rs.client.ClientRequestContext
public void setProperty(java.lang.String name, java.lang.Object object)
setProperty
in interface javax.ws.rs.client.ClientRequestContext
public void removeProperty(java.lang.String name)
removeProperty
in interface javax.ws.rs.client.ClientRequestContext
PropertiesDelegate getPropertiesDelegate()
ClientRuntime getClientRuntime()
public java.net.URI getUri()
getUri
in interface javax.ws.rs.client.ClientRequestContext
public void setUri(java.net.URI uri)
setUri
in interface javax.ws.rs.client.ClientRequestContext
public java.lang.String getMethod()
getMethod
in interface javax.ws.rs.client.ClientRequestContext
public void setMethod(java.lang.String method)
setMethod
in interface javax.ws.rs.client.ClientRequestContext
public JerseyClient getClient()
getClient
in interface javax.ws.rs.client.ClientRequestContext
public void abortWith(javax.ws.rs.core.Response response)
abortWith
in interface javax.ws.rs.client.ClientRequestContext
public javax.ws.rs.core.Response getAbortResponse()
null
otherwise.null
otherwise.public javax.ws.rs.core.Configuration getConfiguration()
getConfiguration
in interface javax.ws.rs.client.ClientRequestContext
ClientConfig getClientConfig()
public java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> getCookies()
getCookies
in interface javax.ws.rs.client.ClientRequestContext
public MessageBodyWorkers getWorkers()
public void setWorkers(MessageBodyWorkers workers)
workers
- message body workers.public void accept(javax.ws.rs.core.MediaType... types)
types
- accepted types to be added.public void accept(java.lang.String... types)
types
- accepted types to be added.public void acceptLanguage(java.util.Locale... locales)
locales
- accepted languages to be added.public void acceptLanguage(java.lang.String... locales)
locales
- accepted languages to be added.public void cookie(javax.ws.rs.core.Cookie cookie)
cookie
- cookie to be added.public void cacheControl(javax.ws.rs.core.CacheControl cacheControl)
cacheControl
- cache control entry to be added.public void encoding(java.lang.String encoding)
encoding
- message encoding to be set.public void language(java.lang.String language)
language
- message language to be set.public void language(java.util.Locale language)
language
- message language to be set.public void type(javax.ws.rs.core.MediaType type)
type
- message content type to be set.public void type(java.lang.String type)
type
- message content type to be set.public void variant(javax.ws.rs.core.Variant variant)
variant
- message content content variant (type, language and encoding)
to be set.public boolean isAsynchronous()
AsyncInvoker
void setAsynchronous(boolean async)
AsyncInvoker
.async
- True if the request is asynchronous; false otherwise.public void enableBuffering()
CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER
.
The buffering functionality is by default disabled and could be enabled by calling this method. In this case
this method must be called before first bytes are written to the entity stream
.public void writeEntity() throws java.io.IOException
entity stream
. The method
use writer interceptors
and message body writer
.
This method modifies the state of this request and therefore it can be called only once per request life cycle otherwise
IllegalStateException is thrown.
Note that OutboundMessageContext.setStreamProvider(org.glassfish.jersey.message.internal.OutboundMessageContext.StreamProvider)
and optionally enableBuffering()
must be called before calling this method.java.io.IOException
- In the case of IO error.void doWriteEntity(MessageBodyWorkers writeWorkers, javax.ws.rs.core.GenericType<?> entityType) throws java.io.IOException
writeWorkers
- Message body workers instance used to write the entity.entityType
- entity type.java.io.IOException
- when MessageBodyWorkers.writeTo(Object, Class, Type, Annotation[], MediaType,
MultivaluedMap, PropertiesDelegate, OutputStream, Iterable)
throws an IOException
.
This state is always regarded as connection failure.private void ensureMediaType()
private javax.ws.rs.core.MediaType getMediaType(java.util.List<javax.ws.rs.core.MediaType> mediaTypes)
void setWriterInterceptors(java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
writerInterceptors
- Writer interceptors in the interceptor execution order.public java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> getWriterInterceptors()
public java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> getReaderInterceptors()
void setReaderInterceptors(java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors)
readerInterceptors
- Reader interceptors in the interceptor execution order.public InjectionManager getInjectionManager()
InjectionManagerSupplier
getInjectionManager
in interface InjectionManagerSupplier
public boolean ignoreUserAgent()
true
if the header should be omitted, false
otherwise.public void ignoreUserAgent(boolean ignore)
ignore
- true
if the header should be omitted, false
otherwise.