Package org.apache.cxf.jaxrs.client
Class WebClient
java.lang.Object
org.apache.cxf.jaxrs.client.AbstractClient
org.apache.cxf.jaxrs.client.WebClient
- All Implemented Interfaces:
Client
Http-centric web client
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cxf.jaxrs.client.AbstractClient
AbstractClient.AbstractBodyWriter, AbstractClient.AbstractClientAsyncResponseInterceptor
-
Field Summary
Fields inherited from class org.apache.cxf.jaxrs.client.AbstractClient
cfg, EXECUTOR_SERVICE_PROPERTY, HTTP_SCHEME, KEEP_CONDUIT_ALIVE, REQUEST_CONTEXT, RESPONSE_CONTEXT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccept
(jakarta.ws.rs.core.MediaType... types) Set HTTP Accept headerSet HTTP Accept headeracceptEncoding
(String... encodings) Set HTTP Accept-Encoding headeracceptLanguage
(String... languages) Set HTTP Accept-Language headerjakarta.ws.rs.client.AsyncInvoker
async()
authorization
(Object auth) Set HTTP Authorization headerback
(boolean fast) Goes backstatic Client
Converts object to Clientcookie
(jakarta.ws.rs.core.Cookie cookie) Set HTTP Cookie headerstatic WebClient
Creates WebClientstatic WebClient
Creates WebClientstatic WebClient
Creates WebClientstatic WebClient
Creates WebClient which will do basic authenticationstatic WebClient
Creates WebClientstatic WebClient
Creates WebClientstatic WebClient
Creates a thread safe WebClientstatic WebClient
Creates WebClientstatic WebClient
create
(String baseAddress, List<?> providers, String username, String password, String configLocation) Creates WebClient which will do basic authenticationstatic WebClient
create
(String baseAddress, List<?> providers, List<? extends org.apache.cxf.feature.Feature> features, String configLocation) Creates WebClient with a list of custom featuresstatic WebClient
Creates WebClientstatic WebClient
Creates WebClientstatic WebClient
Creates WebClientjakarta.ws.rs.core.Response
delete()
Does HTTP DELETE invocationprotected jakarta.ws.rs.core.Response
doChainedInvocation
(String httpMethod, jakarta.ws.rs.core.MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inType, Annotation[] inAnns, Class<?> respClass, Type outType, org.apache.cxf.message.Exchange exchange, Map<String, Object> invContext) protected jakarta.ws.rs.core.Response
doInvoke
(String httpMethod, Object body, Class<?> requestClass, Type inGenericType, Class<?> responseClass, Type outGenericType) protected jakarta.ws.rs.core.Response
doInvoke
(String httpMethod, Object body, Type inGenericType, Class<?> responseClass, Type outGenericType) protected <T> Future<T>
doInvokeAsync
(String httpMethod, Object body, Class<?> requestClass, Type inType, Class<?> respClass, Type outType, jakarta.ws.rs.client.InvocationCallback<T> callback) protected <T> Future<T>
doInvokeAsyncCallback
(String httpMethod, Object body, Class<?> requestClass, Type inType, jakarta.ws.rs.client.InvocationCallback<T> callback) protected jakarta.ws.rs.core.Response
doResponse
(org.apache.cxf.message.Message m, Class<?> responseClass, Type outGenericType) Set HTTP Content-Encoding headerjakarta.ws.rs.core.Response
form
(jakarta.ws.rs.core.Form form) Posts form datajakarta.ws.rs.core.Response
Posts form dataUpdates the current URI fragmentstatic WebClient
fromClient
(Client client) Creates WebClient, baseURI will be set to Client currentURIstatic WebClient
fromClient
(Client client, boolean inheritHeaders) Creates WebClient, baseURI will be set to Client currentURIstatic WebClient
fromClientObject
(Object object) Creates WebClient, baseURI will be set to Client currentURIjakarta.ws.rs.core.Response
get()
Does HTTP GET invocation<T> Future<T>
get
(jakarta.ws.rs.client.InvocationCallback<T> callback) Does HTTP Async GET invocation and returns Future.<T> T
get
(jakarta.ws.rs.core.GenericType<T> responseType) Does HTTP GET invocation and returns typed response object<T> T
Does HTTP GET invocation and returns typed response object<T> Collection<? extends T>
getCollection
(Class<T> memberClass) Does HTTP GET invocation and returns a collection of typed objectsstatic ClientConfiguration
Retrieves ClientConfigurationprotected jakarta.ws.rs.core.Response
handleResponse
(org.apache.cxf.message.Message outMessage, Class<?> responseClass, Type genericType) jakarta.ws.rs.core.Response
head()
Does HTTP HEAD invocationSet arbitrary HTTP HeaderSet HTTP Headersjakarta.ws.rs.core.Response
Does HTTP invocation<T> T
Does HTTP invocation and returns types response object<T> T
Does HTTP invocation and returns types response object<T> T
Does HTTP invocation and returns types response object<T> Collection<? extends T>
invokeAndGetCollection
(String httpMethod, Object body, Class<T> memberClass) Does HTTP invocation and returns a collection of typed objectsSet HTTP Content-Language headermatch
(jakarta.ws.rs.core.EntityTag tag, boolean ifNot) Set HTTP If-Match or If-None-Match headerUpdates the current URI matrix parametersSet HTTP If-Modified-Since or If-Unmodified-Since headerjakarta.ws.rs.core.Response
options()
Does HTTP OPTIONS invocationUpdates the current URI pathUpdates the current URI path with path segment which may contain template variablesjakarta.ws.rs.core.Response
Does HTTP POST invocation<T> Future<T>
Does HTTP Async POST invocation and returns Future.<T> T
Does HTTP POST invocation and returns typed response object<T> T
Does HTTP POST invocation and returns typed response object<T> Collection<? extends T>
postAndGetCollection
(Object body, Class<T> memberClass) Posts request body and returns a collection of typed objects<T1,
T2> Collection<? extends T2> postAndGetCollection
(Object collection, Class<T1> memberClass, Class<T2> responseClass) Posts collection of typed objects and returns a collection of typed objects<T> jakarta.ws.rs.core.Response
postCollection
(Object collection, Class<T> memberClass) Posts a collection of typed objects<T1,
T2> T2 postCollection
(Object collection, Class<T1> memberClass, Class<T2> responseClass) Posts a collection of typed objects<T> Collection<? extends T>
postObjectGetCollection
(Object body, Class<T> responseClass) Posts the object and returns a collection of typed objectsprotected void
prepareAsyncClient
(String httpMethod, Object body, Class<?> requestClass, Type inType, Class<?> respClass, Type outType, JaxrsClientCallback<?> cb) jakarta.ws.rs.core.Response
Does HTTP PUT invocation<T> Future<T>
Does HTTP Async PUT invocation and returns Future.<T> T
Does HTTP PUT invocation and returns typed response object<T> T
Does HTTP PUT invocation and returns typed response objectUpdate the current URI query parametersreplaceHeader
(String headerName, Object value) Replaces the header value with the new values.replacePath
(String path) Replaces the current path with the new value.replaceQuery
(String queryString) Replaces the current query with the new value.replaceQueryParam
(String queryParam, Object... value) Replaces the current query with the new value.reset()
Reset the headers and response state if anyResets the current queryprotected Object
retryInvoke
(URI newRequestURI, jakarta.ws.rs.core.MultivaluedMap<String, String> headers, Object body, org.apache.cxf.message.Exchange exchange, Map<String, Object> invContext) jakarta.ws.rs.client.CompletionStageRxInvoker
rx()
<T extends jakarta.ws.rs.client.RxInvoker>
T<T extends jakarta.ws.rs.client.RxInvoker>
Trx
(Class<T> rxCls, ExecutorService executorService) jakarta.ws.rs.client.CompletionStageRxInvoker
rx
(ExecutorService ex) jakarta.ws.rs.client.SyncInvoker
sync()
Moves WebClient to a new baseURI or forwards to new currentURItype
(jakarta.ws.rs.core.MediaType ct) Set HTTP Content-Type headerSet HTTP Content-Type headerMethods inherited from class org.apache.cxf.jaxrs.client.AbstractClient
addMatrixQueryParamsToBuilder, calculateNewRequestURI, checkClientException, checkClosed, checkIfBodyEmpty, close, completeExchange, convertParamValue, convertParamValue, convertToWebApplicationException, createExchange, createMessage, doRunInterceptorChain, findCallbackType, getBaseURI, getCallbackClass, getCallbackType, getConfiguration, getContentsList, getCurrentBuilder, getCurrentURI, getHeaders, getRequestContext, getResponse, getState, getTemplateParametersMap, parseQuotedHeaderValue, prepareConduitSelector, preProcessResult, readBody, removeAllHeaders, reportMessageHandlerProblem, resetBaseAddress, resetCurrentBuilder, resetResponse, resetResponseStateImmediatelyIfNeeded, responseStreamCanBeClosed, retryInvoke, setAsyncMessageObserverIfNeeded, setConfiguration, setContexts, setEmptyRequestPropertyIfNeeded, setPlainOperationNameProperty, setResponseBuilder, setSupportOnewayResponseProperty, setupInFaultObserver, setupInInterceptorChain, setupOutInterceptorChain, waitForResponseCode, writeBody
-
Constructor Details
-
WebClient
-
WebClient
-
WebClient
-
WebClient
-
WebClient
-
-
Method Details
-
create
Creates WebClient- Parameters:
baseAddress
- baseAddress
-
create
Creates WebClient- Parameters:
baseAddress
- baseAddress
-
create
Creates WebClient- Parameters:
baseURI
- baseURI
-
create
Creates WebClient- Parameters:
baseURI
- baseURI
-
create
Creates WebClient- Parameters:
baseAddress
- baseURIproviders
- list of providers
-
create
Creates WebClient- Parameters:
baseAddress
- baseURIproviders
- list of providersthreadSafe
- if true ThreadLocalClientState is used
-
create
public static WebClient create(String baseAddress, List<?> providers, Map<String, Object> properties, boolean threadSafe) Creates WebClient- Parameters:
baseAddress
- baseURIproviders
- list of providersthreadSafe
- if true ThreadLocalClientState is usedproperties
- additional properties
-
create
Creates a thread safe WebClient- Parameters:
baseAddress
- baseURIproviders
- list of providerstimeToKeepState
- time to keep this thread safe state.
-
create
Creates WebClient- Parameters:
baseAddress
- baseAddressproviders
- list of providersconfigLocation
- classpath location of the configuration resource, can be null- Returns:
- WebClient instance
-
create
public static WebClient create(String baseAddress, List<?> providers, List<? extends org.apache.cxf.feature.Feature> features, String configLocation) Creates WebClient with a list of custom features- Parameters:
baseAddress
- baseAddressproviders
- list of providersfeatures
- the features which will be applied to the clientconfigLocation
- classpath location of the configuration resource, can be null- Returns:
- WebClient instance
-
create
Creates WebClient- Parameters:
baseAddress
- baseAddressconfigLocation
- classpath location of the configuration resource, can be null- Returns:
- WebClient instance
-
create
public static WebClient create(String baseAddress, String username, String password, String configLocation) Creates WebClient which will do basic authentication- Parameters:
baseAddress
- baseAddressusername
- usernamepassword
- passwordconfigLocation
- classpath location of the configuration resource, can be null- Returns:
- WebClient instance
-
create
public static WebClient create(String baseAddress, List<?> providers, String username, String password, String configLocation) Creates WebClient which will do basic authentication- Parameters:
baseAddress
- baseAddressproviders
- list of providersusername
- usernamepassword
- passwordconfigLocation
- classpath location of the configuration resource, can be null- Returns:
- WebClient instance
-
fromClientObject
Creates WebClient, baseURI will be set to Client currentURI- Parameters:
object
- existing client object
-
fromClient
Creates WebClient, baseURI will be set to Client currentURI- Parameters:
client
- existing client
-
fromClient
Creates WebClient, baseURI will be set to Client currentURI- Parameters:
client
- existing clientinheritHeaders
- if existing Client headers can be inherited by new client
-
client
Converts object to Client- Parameters:
object
- the object- Returns:
- Client object converted to Client
-
getConfig
Retrieves ClientConfiguration- Parameters:
client
- proxy or http-centric Client- Returns:
- underlying ClientConfiguration instance
-
invoke
Does HTTP invocation- Parameters:
httpMethod
- HTTP methodbody
- request body, can be null- Returns:
- JAXRS Response, entity may hold a string representaion of error message if client or server error occured
-
post
Does HTTP POST invocation- Parameters:
body
- request body, can be null- Returns:
- JAXRS Response
-
put
Does HTTP PUT invocation- Parameters:
body
- request body, can be null- Returns:
- JAXRS Response
-
get
public jakarta.ws.rs.core.Response get()Does HTTP GET invocation- Returns:
- JAXRS Response
-
head
public jakarta.ws.rs.core.Response head()Does HTTP HEAD invocation- Returns:
- JAXRS Response
-
options
public jakarta.ws.rs.core.Response options()Does HTTP OPTIONS invocation- Returns:
- JAXRS Response
-
delete
public jakarta.ws.rs.core.Response delete()Does HTTP DELETE invocation- Returns:
- JAXRS Response
-
form
Posts form data- Parameters:
values
- form values- Returns:
- JAXRS Response
-
form
public jakarta.ws.rs.core.Response form(jakarta.ws.rs.core.Form form) Posts form data- Parameters:
form
- form values- Returns:
- JAXRS Response
-
invoke
Does HTTP invocation and returns types response object- Parameters:
httpMethod
- HTTP methodbody
- request body, can be nullresponseType
- generic response type- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
invoke
Does HTTP invocation and returns types response object- Parameters:
httpMethod
- HTTP methodbody
- request body, can be nullresponseClass
- expected type of response object- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
invoke
Does HTTP invocation and returns types response object- Parameters:
httpMethod
- HTTP methodbody
- request body, can be nullrequestClass
- request body classresponseClass
- expected type of response object- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
post
Does HTTP POST invocation and returns typed response object- Parameters:
body
- request body, can be nullresponseClass
- expected type of response object- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
post
Does HTTP POST invocation and returns typed response object- Parameters:
body
- request body, can be nullresponseType
- generic response type- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
post
Does HTTP Async POST invocation and returns Future. Shortcut for async().post(Entity, InvocationCallback)- Parameters:
callback
- invocation callback- Returns:
- the future
-
put
Does HTTP PUT invocation and returns typed response object- Parameters:
body
- request body, can be nullresponseClass
- expected type of response object- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
put
Does HTTP PUT invocation and returns typed response object- Parameters:
body
- request body, can be nullresponseType
- generic response type- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
put
Does HTTP Async PUT invocation and returns Future. Shortcut for async().put(Entity, InvocationCallback)- Parameters:
callback
- invocation callback- Returns:
- the future
-
invokeAndGetCollection
public <T> Collection<? extends T> invokeAndGetCollection(String httpMethod, Object body, Class<T> memberClass) Does HTTP invocation and returns a collection of typed objects- Parameters:
httpMethod
- HTTP methodbody
- request body, can be nullmemberClass
- expected type of collection member class- Returns:
- typed collection
-
postCollection
Posts a collection of typed objects- Parameters:
collection
- request bodymemberClass
- type of collection member class- Returns:
- JAX-RS Response
-
postCollection
public <T1,T2> T2 postCollection(Object collection, Class<T1> memberClass, Class<T2> responseClass) Posts a collection of typed objects- Parameters:
collection
- request bodymemberClass
- type of collection member classresponseClass
- expected type of response object- Returns:
- JAX-RS Response
-
postAndGetCollection
public <T1,T2> Collection<? extends T2> postAndGetCollection(Object collection, Class<T1> memberClass, Class<T2> responseClass) Posts collection of typed objects and returns a collection of typed objects- Parameters:
collection
- request bodymemberClass
- type of collection member classresponseClass
- expected type of response object- Returns:
- JAX-RS Response
-
postObjectGetCollection
Posts the object and returns a collection of typed objects- Parameters:
body
- request bodyresponseClass
- expected type of response object- Returns:
- JAX-RS Response
-
postAndGetCollection
Posts request body and returns a collection of typed objects- Parameters:
body
- request body, can be nullmemberClass
- expected type of collection member class- Returns:
- typed collection
-
getCollection
Does HTTP GET invocation and returns a collection of typed objects- Parameters:
memberClass
- expected type of collection member class- Returns:
- typed collection
-
get
Does HTTP GET invocation and returns typed response object- Parameters:
responseClass
- expected type of response object- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
get
public <T> T get(jakarta.ws.rs.core.GenericType<T> responseType) Does HTTP GET invocation and returns typed response object- Parameters:
responseType
- generic response type- Returns:
- typed object, can be null. Response status code and headers can be obtained too, see Client.getResponse()
-
get
Does HTTP Async GET invocation and returns Future. Shortcut for async().get(InvocationCallback)- Parameters:
callback
- invocation callback- Returns:
- the future
-
path
Updates the current URI path- Parameters:
path
- new relative path segment- Returns:
- updated WebClient
-
path
Updates the current URI path with path segment which may contain template variables- Parameters:
path
- new relative path segmentvalues
- template variable values- Returns:
- updated WebClient
-
query
Description copied from class:AbstractClient
Update the current URI query parameters- Specified by:
query
in interfaceClient
- Overrides:
query
in classAbstractClient
- Parameters:
name
- query namevalues
- query values- Returns:
- updated WebClient
-
matrix
Updates the current URI matrix parameters- Parameters:
name
- matrix namevalues
- matrix values- Returns:
- updated WebClient
-
fragment
Updates the current URI fragment- Parameters:
name
- fragment name- Returns:
- updated WebClient
-
to
Moves WebClient to a new baseURI or forwards to new currentURI- Parameters:
newAddress
- new URIforward
- if true then currentURI will be based on baseURI- Returns:
- updated WebClient
-
back
Goes back- Parameters:
fast
- if true then goes back to baseURI otherwise to a previous path segment- Returns:
- updated WebClient
-
replacePath
Replaces the current path with the new value.- Parameters:
path
- new path value. If it starts from "/" then all the current path starting from the base URI will be replaced, otherwise only the last path segment will be replaced. Providing a null value is equivalent to calling back(true)- Returns:
- updated WebClient
-
resetQuery
Resets the current query- Returns:
- updated WebClient
-
replaceQuery
Replaces the current query with the new value.- Parameters:
queryString
- the new value, providing a null is equivalent to calling resetQuery().- Returns:
- updated WebClient
-
replaceHeader
Replaces the header value with the new values.- Parameters:
headerName
- headerValuesvalue
- new values, null is equivalent to removing the header- Returns:
- updated WebClient
-
replaceQueryParam
Replaces the current query with the new value.- Parameters:
queryParam
- query param namevalue
- the new value, providing a null is equivalent to calling resetQuery().- Returns:
- updated WebClient
-
type
Description copied from class:AbstractClient
Set HTTP Content-Type header- Specified by:
type
in interfaceClient
- Overrides:
type
in classAbstractClient
- Parameters:
ct
- JAXRS MediaType representing Content-Type value- Returns:
- the updated Client
-
type
Description copied from class:AbstractClient
Set HTTP Content-Type header- Specified by:
type
in interfaceClient
- Overrides:
type
in classAbstractClient
- Parameters:
type
- Content-Type value- Returns:
- the updated Client
-
accept
Description copied from class:AbstractClient
Set HTTP Accept header- Specified by:
accept
in interfaceClient
- Overrides:
accept
in classAbstractClient
- Parameters:
types
- list of JAXRS MediaTypes representing Accept header values- Returns:
- the updated Client
-
accept
Description copied from class:AbstractClient
Set HTTP Accept header- Specified by:
accept
in interfaceClient
- Overrides:
accept
in classAbstractClient
- Parameters:
types
- list of Accept header values- Returns:
- the updated Client
-
language
Description copied from class:AbstractClient
Set HTTP Content-Language header- Specified by:
language
in interfaceClient
- Overrides:
language
in classAbstractClient
- Parameters:
language
- Content-Language header value- Returns:
- the updated Client
-
acceptLanguage
Description copied from class:AbstractClient
Set HTTP Accept-Language header- Specified by:
acceptLanguage
in interfaceClient
- Overrides:
acceptLanguage
in classAbstractClient
- Parameters:
languages
- list of Accept-Language header values- Returns:
- the updated Client
-
encoding
Description copied from class:AbstractClient
Set HTTP Content-Encoding header- Specified by:
encoding
in interfaceClient
- Overrides:
encoding
in classAbstractClient
- Parameters:
encoding
- Content-Encoding header value- Returns:
- the updated Client
-
acceptEncoding
Description copied from class:AbstractClient
Set HTTP Accept-Encoding header- Specified by:
acceptEncoding
in interfaceClient
- Overrides:
acceptEncoding
in classAbstractClient
- Parameters:
encodings
- list of Accept-Encoding header value- Returns:
- the updated Client
-
match
Description copied from class:AbstractClient
Set HTTP If-Match or If-None-Match header- Specified by:
match
in interfaceClient
- Overrides:
match
in classAbstractClient
- Parameters:
tag
- ETag valueifNot
- if true then If-None-Match is set, If-Match otherwise- Returns:
- the updated Client
-
modified
Description copied from class:AbstractClient
Set HTTP If-Modified-Since or If-Unmodified-Since header- Specified by:
modified
in interfaceClient
- Overrides:
modified
in classAbstractClient
- Parameters:
date
- Date value, will be formated as "EEE, dd MMM yyyy HH:mm:ss zzz"ifNot
- if true then If-Unmodified-Since is set, If-Modified-Since otherwise- Returns:
- the updated Client
-
cookie
Description copied from class:AbstractClient
Set HTTP Cookie header- Specified by:
cookie
in interfaceClient
- Overrides:
cookie
in classAbstractClient
- Parameters:
cookie
- Cookie value- Returns:
- the updated Client
-
authorization
Description copied from class:AbstractClient
Set HTTP Authorization header- Specified by:
authorization
in interfaceClient
- Overrides:
authorization
in classAbstractClient
- Parameters:
auth
- Authorization value- Returns:
- the updated Client
-
header
Description copied from class:AbstractClient
Set arbitrary HTTP Header- Specified by:
header
in interfaceClient
- Overrides:
header
in classAbstractClient
- Parameters:
name
- header namevalues
- list of header values- Returns:
- the updated Client
-
headers
Description copied from class:AbstractClient
Set HTTP Headers- Specified by:
headers
in interfaceClient
- Overrides:
headers
in classAbstractClient
- Parameters:
map
- headers- Returns:
- the updated Client
-
reset
Description copied from class:AbstractClient
Reset the headers and response state if any- Specified by:
reset
in interfaceClient
- Overrides:
reset
in classAbstractClient
- Returns:
- the updated Client
-
doInvoke
-
doInvoke
-
doInvokeAsyncCallback
-
doInvokeAsync
-
prepareAsyncClient
-
retryInvoke
protected Object retryInvoke(URI newRequestURI, jakarta.ws.rs.core.MultivaluedMap<String, String> headers, Object body, org.apache.cxf.message.Exchange exchange, Map<String, throws ThrowableObject> invContext) - Specified by:
retryInvoke
in classAbstractClient
- Throws:
Throwable
-
doChainedInvocation
protected jakarta.ws.rs.core.Response doChainedInvocation(String httpMethod, jakarta.ws.rs.core.MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inType, Annotation[] inAnns, Class<?> respClass, Type outType, org.apache.cxf.message.Exchange exchange, Map<String, Object> invContext) -
doResponse
-
handleResponse
-
async
public jakarta.ws.rs.client.AsyncInvoker async() -
sync
public jakarta.ws.rs.client.SyncInvoker sync() -
rx
public jakarta.ws.rs.client.CompletionStageRxInvoker rx() -
rx
-
rx
-
rx
public <T extends jakarta.ws.rs.client.RxInvoker> T rx(Class<T> rxCls, ExecutorService executorService)
-