Package org.glassfish.jersey.client
Class ClientRequest
- java.lang.Object
-
- org.glassfish.jersey.message.internal.MessageHeaderMethods
-
- org.glassfish.jersey.message.internal.OutboundMessageContext
-
- org.glassfish.jersey.client.ClientRequest
-
- All Implemented Interfaces:
ClientRequestContext,HttpHeaders,HttpHeaders,InjectionManagerSupplier,PropertiesResolver
public class ClientRequest extends OutboundMessageContext implements ClientRequestContext, HttpHeaders, 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 class org.glassfish.jersey.message.internal.MessageHeaderMethods
runtimeDelegateDecorator
-
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, EXPIRES, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_UNMODIFIED_SINCE, LAST_EVENT_ID_HEADER, LAST_MODIFIED, LOCATION, RETRY_AFTER, SET_COOKIE, USER_AGENT, VARY, WWW_AUTHENTICATE
-
Fields inherited from interface org.glassfish.jersey.http.HttpHeaders
ACCEPT_PATCH, ACCEPT_RANGES, AGE, CONNECTION, CONTENT_RANGE, EXPECT, FORWARDED, FROM, IF_RANGE, LINK, MAX_FORWARDS, MIME_VERSION, ORIGIN, PROXY_AUTHENTICATE, PROXY_AUTHENTICATION_INFO, PROXY_AUTHORIZATION, PROXY_CONNECTION, RANGE, REFERER, SERVER, TE, TRAILER, TRANSFER_ENCODING, UPGRADE, VIA
-
-
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)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.voidcancel(boolean mayInterruptIfRunning)Cancels thisClientRequest.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()ConfigurationgetConfiguration()Map<String,Cookie>getCookies()InjectionManagergetInjectionManager()StringgetMethod()ObjectgetProperty(String name)Collection<String>getPropertyNames()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()URIgetUri()MessageBodyWorkersgetWorkers()Get the message body workers associated with the request.Iterable<WriterInterceptor>getWriterInterceptors()Get writer interceptors of this request.booleanhasProperty(String 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 usingAsyncInvokerbooleanisCancelled()Returnstrueif thisClientRequestwas cancelled before it completed normally.voidlanguage(String language)Set message language.voidlanguage(Locale language)Set message language.voidremoveProperty(String name)<T> TresolveProperty(String name, Class<T> type)<T> TresolveProperty(String name, T defaultValue)voidsetMethod(String method)voidsetProperty(String name, Object object)voidsetUri(URI 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, getEntity, getEntityAnnotations, getEntityClass, getEntityStream, getEntityType, getHeaders, getHeaderString, getHeaderValueExceptionContext, getLinks, getMediaType, getStringHeaders, hasEntity, isCommitted, replaceHeaders, setEntity, setEntity, setEntity, setEntity, setEntityAnnotations, setEntityStream, setEntityType, setMediaType, setStreamProvider
-
Methods inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
containsHeaderString, containsHeaderString, exception, getAllowedMethods, getDate, getEntityTag, getLanguage, getLastModified, getLength, getLengthLong, getLink, getLinkBuilder, getLocation, getRequestCookies, getResponseCookies, hasLink, singleHeader, singleHeader
-
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)
- Specified by:
resolvePropertyin interfacePropertiesResolver
-
resolveProperty
public <T> T resolveProperty(String name, T defaultValue)
- Specified by:
resolvePropertyin interfacePropertiesResolver
-
hasProperty
public boolean hasProperty(String name)
- Specified by:
hasPropertyin interfaceClientRequestContext
-
getProperty
public Object getProperty(String name)
- Specified by:
getPropertyin interfaceClientRequestContext
-
getPropertyNames
public Collection<String> getPropertyNames()
- Specified by:
getPropertyNamesin interfaceClientRequestContext
-
setProperty
public void setProperty(String name, Object object)
- Specified by:
setPropertyin interfaceClientRequestContext
-
removeProperty
public void removeProperty(String name)
- Specified by:
removePropertyin interfaceClientRequestContext
-
getUri
public URI getUri()
- Specified by:
getUriin interfaceClientRequestContext
-
setUri
public void setUri(URI uri)
- Specified by:
setUriin interfaceClientRequestContext
-
getMethod
public String getMethod()
- Specified by:
getMethodin interfaceClientRequestContext
-
setMethod
public void setMethod(String method)
- Specified by:
setMethodin interfaceClientRequestContext
-
getClient
public JerseyClient getClient()
- Specified by:
getClientin interfaceClientRequestContext
-
abortWith
public void abortWith(Response response)
- Specified by:
abortWithin interfaceClientRequestContext
-
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()
- Specified by:
getConfigurationin interfaceClientRequestContext- Overrides:
getConfigurationin classOutboundMessageContext
-
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()
- Specified by:
getRequestHeadersin interfaceHttpHeaders
-
getCookies
public Map<String,Cookie> getCookies()
- Specified by:
getCookiesin interfaceClientRequestContext- Specified by:
getCookiesin interfaceHttpHeaders
-
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 InjectionManager getInjectionManager()
- Specified by:
getInjectionManagerin interfaceInjectionManagerSupplier
-
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.
-
cancel
public void cancel(boolean mayInterruptIfRunning)
Cancels thisClientRequest. May result inCancellationExceptionlater in this request processing if thisClientRequestis backed by aFutureprovided toJerseyInvocation.Builder.setCancellable(Future).- Parameters:
mayInterruptIfRunning- may have no effect ortrueif the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
-
isCancelled
public boolean isCancelled()
Returnstrueif thisClientRequestwas cancelled before it completed normally.- Returns:
trueif thisClientRequestwas cancelled before it completed normally
-
-