Class ClientRequest
- java.lang.Object
-
- org.glassfish.jersey.message.internal.OutboundMessageContext
-
- org.glassfish.jersey.client.ClientRequest
-
- All Implemented Interfaces:
javax.ws.rs.client.ClientRequestContext
,InjectionManagerSupplier
public class ClientRequest extends OutboundMessageContext implements javax.ws.rs.client.ClientRequestContext, InjectionManagerSupplier
Jersey client request context.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.glassfish.jersey.message.internal.OutboundMessageContext
OutboundMessageContext.StreamProvider
-
-
Field Summary
Fields Modifier and Type Field 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
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClientRequest(java.net.URI requestUri, ClientConfig clientConfig, PropertiesDelegate propertiesDelegate)
Create new Jersey client request context.ClientRequest(ClientRequest original)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortWith(javax.ws.rs.core.Response response)
void
accept(java.lang.String... types)
Add new accepted types to the message headers.void
accept(javax.ws.rs.core.MediaType... types)
Add new accepted types to the message headers.void
acceptLanguage(java.lang.String... locales)
Add new accepted languages to the message headers.void
acceptLanguage(java.util.Locale... 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, ornull
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 usingAsyncInvoker
void
language(java.lang.String language)
Set message language.void
language(java.util.Locale 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 propertyname
.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 propertyname
.(package private) void
setAsynchronous(boolean async)
Sets the flag indicating whether the request is called asynchronously usingAsyncInvoker
.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(java.lang.String type)
Set message content type.void
type(javax.ws.rs.core.MediaType 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 theentity stream
.-
Methods inherited from class org.glassfish.jersey.message.internal.OutboundMessageContext
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.ws.rs.client.ClientRequestContext
getAcceptableLanguages, getAcceptableMediaTypes, getDate, getEntity, getEntityAnnotations, getEntityClass, getEntityStream, getEntityType, getHeaders, getHeaderString, getLanguage, getMediaType, getStringHeaders, hasEntity, setEntity, setEntity, setEntityStream
-
-
-
-
Field Detail
-
clientConfig
private final ClientConfig clientConfig
-
propertiesDelegate
private final PropertiesDelegate propertiesDelegate
-
requestUri
private java.net.URI requestUri
-
httpMethod
private java.lang.String httpMethod
-
abortResponse
private javax.ws.rs.core.Response abortResponse
-
workers
private MessageBodyWorkers workers
-
asynchronous
private boolean asynchronous
-
entityWritten
private boolean entityWritten
-
writerInterceptors
private java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors
-
readerInterceptors
private java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors
-
ignoreUserAgent
private boolean ignoreUserAgent
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
-
Constructor Detail
-
ClientRequest
protected ClientRequest(java.net.URI requestUri, ClientConfig clientConfig, PropertiesDelegate propertiesDelegate)
Create new Jersey client request context.- Parameters:
requestUri
- request Uri.clientConfig
- request configuration.propertiesDelegate
- properties delegate.
-
ClientRequest
public ClientRequest(ClientRequest original)
Copy constructor.- Parameters:
original
- original instance.
-
-
Method Detail
-
resolveProperty
public <T> T resolveProperty(java.lang.String name, java.lang.Class<T> type)
Resolve a property value for the specified propertyname
.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 returnsnull
if no such property is registered neither in the client runtime nor in the request-specific property bag.- Type Parameters:
T
- property Java type.- Parameters:
name
- property name.type
- expected property class type.- Returns:
- resolved property value or
null
if no such property is registered.
-
resolveProperty
public <T> T resolveProperty(java.lang.String name, T defaultValue)
Resolve a property value for the specified propertyname
.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 returnsdefaultValue
if no such property is registered neither in the client runtime nor in the request-specific property bag.- Type Parameters:
T
- property Java type.- Parameters:
name
- property name.defaultValue
- default value to return if the property is not registered.- Returns:
- resolved property value or
defaultValue
if no such property is registered.
-
resolveProperty
private <T> T resolveProperty(java.lang.String name, java.lang.Object defaultValue, java.lang.Class<T> type)
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
- Specified by:
getProperty
in interfacejavax.ws.rs.client.ClientRequestContext
-
getPropertyNames
public java.util.Collection<java.lang.String> getPropertyNames()
- Specified by:
getPropertyNames
in interfacejavax.ws.rs.client.ClientRequestContext
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object object)
- Specified by:
setProperty
in interfacejavax.ws.rs.client.ClientRequestContext
-
removeProperty
public void removeProperty(java.lang.String name)
- Specified by:
removeProperty
in interfacejavax.ws.rs.client.ClientRequestContext
-
getPropertiesDelegate
PropertiesDelegate getPropertiesDelegate()
Get the underlying properties delegate.- Returns:
- underlying properties delegate.
-
getClientRuntime
ClientRuntime getClientRuntime()
Get the underlying client runtime.- Returns:
- underlying client runtime.
-
getUri
public java.net.URI getUri()
- Specified by:
getUri
in interfacejavax.ws.rs.client.ClientRequestContext
-
setUri
public void setUri(java.net.URI uri)
- Specified by:
setUri
in interfacejavax.ws.rs.client.ClientRequestContext
-
getMethod
public java.lang.String getMethod()
- Specified by:
getMethod
in interfacejavax.ws.rs.client.ClientRequestContext
-
setMethod
public void setMethod(java.lang.String method)
- Specified by:
setMethod
in interfacejavax.ws.rs.client.ClientRequestContext
-
getClient
public JerseyClient getClient()
- Specified by:
getClient
in interfacejavax.ws.rs.client.ClientRequestContext
-
abortWith
public void abortWith(javax.ws.rs.core.Response response)
- Specified by:
abortWith
in interfacejavax.ws.rs.client.ClientRequestContext
-
getAbortResponse
public javax.ws.rs.core.Response getAbortResponse()
Get the request filter chain aborting response if set, ornull
otherwise.- Returns:
- request filter chain aborting response if set, or
null
otherwise.
-
getConfiguration
public javax.ws.rs.core.Configuration getConfiguration()
- Specified by:
getConfiguration
in interfacejavax.ws.rs.client.ClientRequestContext
-
getClientConfig
ClientConfig getClientConfig()
Get internal client configuration state.- Returns:
- internal client configuration state.
-
getCookies
public java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> getCookies()
- Specified by:
getCookies
in interfacejavax.ws.rs.client.ClientRequestContext
-
getWorkers
public MessageBodyWorkers getWorkers()
Get the message body workers associated with the request.- Returns:
- message body workers.
-
setWorkers
public void setWorkers(MessageBodyWorkers workers)
Set the message body workers associated with the request.- Parameters:
workers
- message body workers.
-
accept
public void accept(javax.ws.rs.core.MediaType... types)
Add new accepted types to the message headers.- Parameters:
types
- accepted types to be added.
-
accept
public void accept(java.lang.String... types)
Add new accepted types to the message headers.- Parameters:
types
- accepted types to be added.
-
acceptLanguage
public void acceptLanguage(java.util.Locale... locales)
Add new accepted languages to the message headers.- Parameters:
locales
- accepted languages to be added.
-
acceptLanguage
public void acceptLanguage(java.lang.String... locales)
Add new accepted languages to the message headers.- Parameters:
locales
- accepted languages to be added.
-
cookie
public void cookie(javax.ws.rs.core.Cookie cookie)
Add new cookie to the message headers.- Parameters:
cookie
- cookie to be added.
-
cacheControl
public void cacheControl(javax.ws.rs.core.CacheControl cacheControl)
Add new cache control entry to the message headers.- Parameters:
cacheControl
- cache control entry to be added.
-
encoding
public void encoding(java.lang.String encoding)
Set message encoding.- Parameters:
encoding
- message encoding to be set.
-
language
public void language(java.lang.String language)
Set message language.- Parameters:
language
- message language to be set.
-
language
public void language(java.util.Locale language)
Set message language.- Parameters:
language
- message language to be set.
-
type
public void type(javax.ws.rs.core.MediaType type)
Set message content type.- Parameters:
type
- message content type to be set.
-
type
public void type(java.lang.String type)
Set message content type.- Parameters:
type
- message content type to be set.
-
variant
public void variant(javax.ws.rs.core.Variant variant)
Set message content variant (type, language and encoding).- Parameters:
variant
- message content content variant (type, language and encoding) to be set.
-
isAsynchronous
public boolean isAsynchronous()
Returns true if the request is called asynchronously usingAsyncInvoker
- Returns:
- True if the request is asynchronous; false otherwise.
-
setAsynchronous
void setAsynchronous(boolean async)
Sets the flag indicating whether the request is called asynchronously usingAsyncInvoker
.- Parameters:
async
- True if the request is asynchronous; false otherwise.
-
enableBuffering
public void enableBuffering()
Enable a buffering of serialized entity. The buffering will be configured from runtime configuration associated with this request. The property determining the size of the buffer isCommonProperties.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 theentity stream
.
-
writeEntity
public void writeEntity() throws java.io.IOException
Write (serialize) the entity set in this request into theentity stream
. The method usewriter interceptors
andmessage 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 thatOutboundMessageContext.setStreamProvider(org.glassfish.jersey.message.internal.OutboundMessageContext.StreamProvider)
and optionallyenableBuffering()
must be called before calling this method.- Throws:
java.io.IOException
- In the case of IO error.
-
doWriteEntity
void doWriteEntity(MessageBodyWorkers writeWorkers, javax.ws.rs.core.GenericType<?> entityType) throws java.io.IOException
Added only to make the code testable.- Parameters:
writeWorkers
- Message body workers instance used to write the entity.entityType
- entity type.- Throws:
java.io.IOException
- whenMessageBodyWorkers.writeTo(Object, Class, Type, Annotation[], MediaType, MultivaluedMap, PropertiesDelegate, OutputStream, Iterable)
throws anIOException
. This state is always regarded as connection failure.
-
ensureMediaType
private void ensureMediaType()
-
getMediaType
private javax.ws.rs.core.MediaType getMediaType(java.util.List<javax.ws.rs.core.MediaType> mediaTypes)
-
setWriterInterceptors
void setWriterInterceptors(java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
Set writer interceptors for this request.- Parameters:
writerInterceptors
- Writer interceptors in the interceptor execution order.
-
getWriterInterceptors
public java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> getWriterInterceptors()
Get writer interceptors of this request.- Returns:
- Writer interceptors in the interceptor execution order.
-
getReaderInterceptors
public java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> getReaderInterceptors()
Get reader interceptors of this request.- Returns:
- Reader interceptors in the interceptor execution order.
-
setReaderInterceptors
void setReaderInterceptors(java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors)
Set reader interceptors for this request.- Parameters:
readerInterceptors
- Reader interceptors in the interceptor execution order.
-
getInjectionManager
public InjectionManager getInjectionManager()
Description copied from interface:InjectionManagerSupplier
Get injection manager.- Specified by:
getInjectionManager
in interfaceInjectionManagerSupplier
- Returns:
- injection manager.
-
ignoreUserAgent
public boolean ignoreUserAgent()
Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.- Returns:
true
if the header should be omitted,false
otherwise.
-
ignoreUserAgent
public void ignoreUserAgent(boolean ignore)
Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.- Parameters:
ignore
-true
if the header should be omitted,false
otherwise.
-
-