public static interface Invocation.Builder extends SyncInvoker
request(...)
methods on a resource target, provides methods for
preparing a client request invocation. Once the request is prepared
the invocation builder can be either used to build an Invocation
with a generic execution interface:
Client client = ClientBuilder.newClient();
WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");
// Build a HTTP GET request that accepts "text/plain" response type
// and contains a custom HTTP header entry "Foo: bar".
Invocation invocation = resourceTarget.request("text/plain")
.header("Foo", "bar").buildGet();
// Invoke the request using generic interface
String response = invocation.invoke(String.class);
Alternatively, one of the inherited synchronous invocation
methods can be used to invoke the prepared request and return the server
response in a single step, e.g.:
Client client = ClientBuilder.newClient();
WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");
// Build and invoke the get request in a single step
String response = resourceTarget.request("text/plain")
.header("Foo", "bar").get(String.class);
Once the request is fully prepared for invoking, switching to an
asynchronous invocation mode is possible by
calling the async() method on the builder, e.g.:
Client client = ClientBuilder.newClient();
WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");
// Build and invoke the get request asynchronously in a single step
Future response = resourceTarget.request("text/plain")
.header("Foo", "bar").async().get(String.class);
| Modifier and Type | Method and Description |
|---|---|
Invocation.Builder |
accept(MediaType... mediaTypes)
Add the accepted response media types.
|
Invocation.Builder |
accept(String... mediaTypes)
Add the accepted response media types.
|
Invocation.Builder |
acceptEncoding(String... encodings)
Add acceptable encodings.
|
Invocation.Builder |
acceptLanguage(Locale... locales)
Add acceptable languages.
|
Invocation.Builder |
acceptLanguage(String... locales)
Add acceptable languages.
|
AsyncInvoker |
async()
Access the asynchronous uniform request invocation interface to
asynchronously invoke the built request.
|
Invocation |
build(String method)
Build a request invocation using an arbitrary request method name.
|
Invocation |
build(String method,
Entity<?> entity)
Build a request invocation using an arbitrary request method name and
request entity.
|
Invocation |
buildDelete()
Build a DELETE request invocation.
|
Invocation |
buildGet()
Build a GET request invocation.
|
Invocation |
buildPost(Entity<?> entity)
Build a POST request invocation.
|
Invocation |
buildPut(Entity<?> entity)
Build a PUT request invocation.
|
Invocation.Builder |
cacheControl(CacheControl cacheControl)
Set the cache control data of the message.
|
Invocation.Builder |
cookie(Cookie cookie)
Add a cookie to be set.
|
Invocation.Builder |
cookie(String name,
String value)
Add a cookie to be set.
|
Invocation.Builder |
header(String name,
Object value)
Add an arbitrary header.
|
Invocation.Builder |
headers(MultivaluedMap<String,Object> headers)
Replaces all existing headers with the newly supplied headers.
|
NioInvoker |
nio()
Access the NIO uniform request invocation interface to use non-blocking I/O
to read/write entities.
|
Invocation.Builder |
property(String name,
Object value)
Set a new property in the context of a request represented by this invocation builder.
|
CompletionStageRxInvoker |
rx()
Access the default reactive invoker based on
CompletionStage. |
<T extends RxInvoker> |
rx(Class<T> clazz)
Access a reactive invoker based on an implementation of
RxInvoker
provided. |
<T extends RxInvoker> |
rx(Class<T> clazz,
ExecutorService executorService)
Access a reactive invoker based on an implementation of
RxInvoker
and the executor service provided. |
CompletionStageRxInvoker |
rx(ExecutorService executorService)
Access the default reactive invoker based on
CompletionStage
and provide an ExecutorService for it. |
Invocation build(String method)
method - request method name.Invocation build(String method, Entity<?> entity)
method - request method name.entity - request entity, including it's full Variant information.
Any variant-related HTTP headers previously set (namely Content-Type,
Content-Language and Content-Encoding) will be overwritten using
the entity variant information.Invocation buildGet()
Invocation buildDelete()
Invocation buildPost(Entity<?> entity)
entity - request entity, including it's full Variant information.
Any variant-related HTTP headers previously set (namely Content-Type,
Content-Language and Content-Encoding) will be overwritten using
the entity variant information.Invocation buildPut(Entity<?> entity)
entity - request entity, including it's full Variant information.
Any variant-related HTTP headers previously set (namely Content-Type,
Content-Language and Content-Encoding) will be overwritten using
the entity variant information.AsyncInvoker async()
Invocation.Builder accept(String... mediaTypes)
mediaTypes - accepted response media types.Invocation.Builder accept(MediaType... mediaTypes)
mediaTypes - accepted response media types.Invocation.Builder acceptLanguage(Locale... locales)
locales - an array of the acceptable languages.Invocation.Builder acceptLanguage(String... locales)
locales - an array of the acceptable languages.Invocation.Builder acceptEncoding(String... encodings)
encodings - an array of the acceptable encodings.Invocation.Builder cookie(Cookie cookie)
cookie - to be set.Invocation.Builder cookie(String name, String value)
name - the name of the cookie.value - the value of the cookie.Invocation.Builder cacheControl(CacheControl cacheControl)
cacheControl - the cache control directives, if null
any existing cache control directives will be removed.Invocation.Builder header(String name, Object value)
name - the name of the headervalue - the value of the header, the header will be serialized
using a RuntimeDelegate.HeaderDelegate if
one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the class of value or using its toString method
if a header delegate is not available. If value is null
then all current headers of the same name will be removed.Invocation.Builder headers(MultivaluedMap<String,Object> headers)
headers - new headers to be set, if null all existing
headers will be removed.Invocation.Builder property(String name, Object value)
The property is available for a later retrieval via ClientRequestContext.getProperty(String)
or InterceptorContext.getProperty(String).
If a property with a given name is already set in the request context,
the existing value of the property will be updated.
Setting a null value into a property effectively removes the property
from the request property bag.
name - property name.value - (new) property value. null value removes the property
with the given name.Invocation.property(String, Object)CompletionStageRxInvoker rx()
CompletionStage.
Equivalent to calling rx(CompletionStageRxInvoker.class).rx(Class)CompletionStageRxInvoker rx(ExecutorService executorService)
CompletionStage
and provide an ExecutorService for it. Note that not
all executor services are supported in all runtime environments. For example, only
executor services provided by JSR 236 should be supported in a Java EE environment.executorService - executor service to use.IllegalArgumentException - if the executor service provided is not
supported by the runtime environment.rx()<T extends RxInvoker> T rx(Class<T> clazz)
RxInvoker
provided. This method is an extension point for JAX-RS implementations to support other types
representing asynchronous computations.clazz - implementation of reactive invoker.rx(Class, ExecutorService)<T extends RxInvoker> T rx(Class<T> clazz, ExecutorService executorService)
RxInvoker
and the executor service provided. This method is an extension point for JAX-RS implementations
to support other types representing asynchronous computations. Note that not
all executor services are supported in all runtime environments. For example, only
executor services provided by JSR 236 should be supported in a Java EE environment.clazz - implementation of reactive invoker.executorService - executor service to use.IllegalArgumentException - if the executor service provided is not
supported by the runtime environment.rx()NioInvoker nio()
Copyright © 1996-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.