Class ClientRequest
- java.lang.Object
-
- org.glassfish.jersey.message.internal.OutboundMessageContext
-
- org.glassfish.jersey.client.ClientRequest
-
- All Implemented Interfaces:
ClientRequestContext,HttpHeaders,org.glassfish.jersey.internal.inject.InjectionManagerSupplier,PropertiesResolver
public class ClientRequest extends OutboundMessageContext implements ClientRequestContext, HttpHeaders, org.glassfish.jersey.internal.inject.InjectionManagerSupplier, PropertiesResolver
Jersey client request context.- Author:
- Marek Potociar
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.glassfish.jersey.message.internal.OutboundMessageContext
OutboundMessageContext.StreamProvider
-
-
Field Summary
-
Fields inherited from interface jakarta.ws.rs.core.HttpHeaders
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_ID, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_TYPE, COOKIE, DATE, ETAG, EXPECT, EXPIRES, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_UNMODIFIED_SINCE, LAST_EVENT_ID_HEADER, LAST_MODIFIED, LINK, LOCATION, RETRY_AFTER, SET_COOKIE, USER_AGENT, VARY, WWW_AUTHENTICATE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedClientRequest(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 voidabortWith(Response response)Abort the filter chain with a response.voidaccept(MediaType... types)Add new accepted types to the message headers.voidaccept(String... types)Add new accepted types to the message headers.voidacceptLanguage(String... locales)Add new accepted languages to the message headers.voidacceptLanguage(Locale... locales)Add new accepted languages to the message headers.voidcacheControl(CacheControl cacheControl)Add new cache control entry to the message headers.voidcookie(Cookie cookie)Add new cookie to the message headers.voidenableBuffering()Enable a buffering of serialized entity.voidencoding(String encoding)Set message encoding.ResponsegetAbortResponse()Get the request filter chain aborting response if set, ornullotherwise.JerseyClientgetClient()Get the client instance associated with the request.ConfigurationgetConfiguration()The related client/server sideConfiguration.Map<String,Cookie>getCookies()Get any cookies that accompanied the request.org.glassfish.jersey.internal.inject.InjectionManagergetInjectionManager()Get injection manager.StringgetMethod()Get the request method.ObjectgetProperty(String name)Returns the property with the given name registered in the current request/response exchange context, ornullif there is no property by that name.Collection<String>getPropertyNames()Returns an immutablecollectioncontaining the property names available within the context of the current request/response exchange context.Iterable<ReaderInterceptor>getReaderInterceptors()Get reader interceptors of this request.List<String>getRequestHeader(String name)Get the values of an HTTP request header if the header exists on the current request.MultivaluedMap<String,String>getRequestHeaders()Get the values of HTTP request headers.URIgetUri()Get the request URI.MessageBodyWorkersgetWorkers()Get the message body workers associated with the request.Iterable<WriterInterceptor>getWriterInterceptors()Get writer interceptors of this request.booleanhasProperty(String name)Returnstrueif the property with the given name is registered in the current request/response exchange context, orfalseif there is no property by that name.booleanignoreUserAgent()Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.voidignoreUserAgent(boolean ignore)Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.booleanisAsynchronous()Returns true if the request is called asynchronously usingAsyncInvokervoidlanguage(String language)Set message language.voidlanguage(Locale language)Set message language.voidremoveProperty(String name)Removes a property with the given name from the current request/response exchange context.<T> TresolveProperty(String name, Class<T> type)Resolve a property value for the specified propertyname.<T> TresolveProperty(String name, T defaultValue)Resolve a property value for the specified propertyname.voidsetMethod(String method)Set the request method.voidsetProperty(String name, Object object)Binds an object to a given property name in the current request/response exchange context.voidsetUri(URI uri)Set a new request URI.voidsetWorkers(MessageBodyWorkers workers)Set the message body workers associated with the request.voidtype(MediaType type)Set message content type.voidtype(String type)Set message content type.voidvariant(Variant variant)Set message content variant (type, language and encoding).voidwriteEntity()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 jakarta.ws.rs.client.ClientRequestContext
getAcceptableLanguages, getAcceptableMediaTypes, getDate, getEntity, getEntityAnnotations, getEntityClass, getEntityStream, getEntityType, getHeaders, getHeaderString, getLanguage, getMediaType, getStringHeaders, hasEntity, setEntity, setEntity, setEntityStream
-
Methods inherited from interface jakarta.ws.rs.core.HttpHeaders
getAcceptableLanguages, getAcceptableMediaTypes, getDate, getHeaderString, getLanguage, getLength, getMediaType
-
-
-
-
Constructor Detail
-
ClientRequest
protected ClientRequest(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(String name, Class<T> type)
Description copied from interface:PropertiesResolverResolve 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 runtime configurationthis request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returnsnullif no such property is registered neither in the runtime nor in the request-specific property bag.- Specified by:
resolvePropertyin interfacePropertiesResolver- Type Parameters:
T- property Java type.- Parameters:
name- property name.type- expected property class type.- Returns:
- resolved property value or
nullif no such property is registered.
-
resolveProperty
public <T> T resolveProperty(String name, T defaultValue)
Description copied from interface:PropertiesResolverResolve 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 runtime configurationthis request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returnsdefaultValueif no such property is registered neither in the runtime nor in the request-specific property bag.- Specified by:
resolvePropertyin interfacePropertiesResolver- 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
defaultValueif no such property is registered.
-
hasProperty
public boolean hasProperty(String name)
Description copied from interface:ClientRequestContextReturnstrueif the property with the given name is registered in the current request/response exchange context, orfalseif there is no property by that name.Use the
ClientRequestContext.getProperty(java.lang.String)method with a property name to get the value of a property.- Specified by:
hasPropertyin interfaceClientRequestContext- Parameters:
name- aStringspecifying the name of the property.- Returns:
trueif this property is registered in the context, orfalseif no property exists matching the given name.- See Also:
ClientRequestContext.getPropertyNames()
-
getProperty
public Object getProperty(String name)
Description copied from interface:ClientRequestContextReturns the property with the given name registered in the current request/response exchange context, ornullif 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
ClientRequestContext.getPropertyNames(). Custom property names should follow the same convention as package names.- Specified by:
getPropertyin interfaceClientRequestContext- Parameters:
name- aStringspecifying the name of the property.- Returns:
- an
Objectcontaining the value of the property, ornullif no property exists matching the given name. - See Also:
ClientRequestContext.getPropertyNames()
-
getPropertyNames
public Collection<String> getPropertyNames()
Description copied from interface:ClientRequestContextReturns an immutablecollectioncontaining the property names available within the context of the current request/response exchange context.Use the
ClientRequestContext.getProperty(java.lang.String)method with a property name to get the value of a property.- Specified by:
getPropertyNamesin interfaceClientRequestContext- Returns:
- an immutable
collectionof property names. - See Also:
ClientRequestContext.getProperty(java.lang.String)
-
setProperty
public void setProperty(String name, Object object)
Description copied from interface:ClientRequestContextBinds 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
ClientRequestContext.getPropertyNames(). Custom property names should follow the same convention as package names.If a
nullvalue is passed, the effect is the same as calling theClientRequestContext.removeProperty(String)method.- Specified by:
setPropertyin interfaceClientRequestContext- Parameters:
name- aStringspecifying the name of the property.object- anObjectrepresenting the property to be bound.
-
removeProperty
public void removeProperty(String name)
Description copied from interface:ClientRequestContextRemoves a property with the given name from the current request/response exchange context. After removal, subsequent calls toClientRequestContext.getProperty(java.lang.String)to retrieve the property value will returnnull.- Specified by:
removePropertyin interfaceClientRequestContext- Parameters:
name- aStringspecifying the name of the property to be removed.
-
getUri
public URI getUri()
Description copied from interface:ClientRequestContextGet the request URI.- Specified by:
getUriin interfaceClientRequestContext- Returns:
- request URI.
-
setUri
public void setUri(URI uri)
Description copied from interface:ClientRequestContextSet a new request URI.- Specified by:
setUriin interfaceClientRequestContext- Parameters:
uri- new request URI.
-
getMethod
public String getMethod()
Description copied from interface:ClientRequestContextGet the request method.- Specified by:
getMethodin interfaceClientRequestContext- Returns:
- the request method.
- See Also:
HttpMethod
-
setMethod
public void setMethod(String method)
Description copied from interface:ClientRequestContextSet the request method.- Specified by:
setMethodin interfaceClientRequestContext- Parameters:
method- new request method.- See Also:
HttpMethod
-
getClient
public JerseyClient getClient()
Description copied from interface:ClientRequestContextGet the client instance associated with the request.- Specified by:
getClientin interfaceClientRequestContext- Returns:
- client instance associated with the request.
-
abortWith
public void abortWith(Response response)
Description copied from interface:ClientRequestContextAbort 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.- Specified by:
abortWithin interfaceClientRequestContext- Parameters:
response- response to be sent back to the client.
-
getAbortResponse
public Response getAbortResponse()
Get the request filter chain aborting response if set, ornullotherwise.- Returns:
- request filter chain aborting response if set, or
nullotherwise.
-
getConfiguration
public Configuration getConfiguration()
Description copied from class:OutboundMessageContextThe related client/server sideConfiguration. Can benull.- Specified by:
getConfigurationin interfaceClientRequestContext- Overrides:
getConfigurationin classOutboundMessageContext- Returns:
Configurationthe configuration
-
getRequestHeader
public List<String> getRequestHeader(String name)
Get the values of an HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists ornullif it does not. This is a shortcut forgetRequestHeaders().get(name).- Specified by:
getRequestHeaderin interfaceHttpHeaders- Parameters:
name- the header name, case insensitive.- Returns:
- a read-only list of header values if the specified header exists, otherwise
null. - Throws:
IllegalStateException- if called outside the scope of a request.
-
getRequestHeaders
public MultivaluedMap<String,String> getRequestHeaders()
Description copied from interface:HttpHeadersGet the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returnsnull.- Specified by:
getRequestHeadersin interfaceHttpHeaders- Returns:
- a read-only map of header names and values.
-
getCookies
public Map<String,Cookie> getCookies()
Description copied from interface:ClientRequestContextGet any cookies that accompanied the request.- Specified by:
getCookiesin interfaceClientRequestContext- Specified by:
getCookiesin interfaceHttpHeaders- Returns:
- a read-only map of cookie name (String) to
Cookie.
-
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(MediaType... types)
Add new accepted types to the message headers.- Parameters:
types- accepted types to be added.
-
accept
public void accept(String... types)
Add new accepted types to the message headers.- Parameters:
types- accepted types to be added.
-
acceptLanguage
public void acceptLanguage(Locale... locales)
Add new accepted languages to the message headers.- Parameters:
locales- accepted languages to be added.
-
acceptLanguage
public void acceptLanguage(String... locales)
Add new accepted languages to the message headers.- Parameters:
locales- accepted languages to be added.
-
cookie
public void cookie(Cookie cookie)
Add new cookie to the message headers.- Parameters:
cookie- cookie to be added.
-
cacheControl
public void cacheControl(CacheControl cacheControl)
Add new cache control entry to the message headers.- Parameters:
cacheControl- cache control entry to be added.
-
encoding
public void encoding(String encoding)
Set message encoding.- Parameters:
encoding- message encoding to be set.
-
language
public void language(String language)
Set message language.- Parameters:
language- message language to be set.
-
language
public void language(Locale language)
Set message language.- Parameters:
language- message language to be set.
-
type
public void type(MediaType type)
Set message content type.- Parameters:
type- message content type to be set.
-
type
public void type(String type)
Set message content type.- Parameters:
type- message content type to be set.
-
variant
public void variant(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.
-
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 IOExceptionWrite (serialize) the entity set in this request into theentity stream. The method usewriter interceptorsandmessage 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:
IOException- In the case of IO error.
-
getWriterInterceptors
public Iterable<WriterInterceptor> getWriterInterceptors()
Get writer interceptors of this request.- Returns:
- Writer interceptors in the interceptor execution order.
-
getReaderInterceptors
public Iterable<ReaderInterceptor> getReaderInterceptors()
Get reader interceptors of this request.- Returns:
- Reader interceptors in the interceptor execution order.
-
getInjectionManager
public org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager()
Description copied from interface:org.glassfish.jersey.internal.inject.InjectionManagerSupplierGet injection manager.- Specified by:
getInjectionManagerin interfaceorg.glassfish.jersey.internal.inject.InjectionManagerSupplier- 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:
trueif the header should be omitted,falseotherwise.
-
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-trueif the header should be omitted,falseotherwise.
-
-