Top Description Inners Methods
javax.ws.rs.client

public Interface Invocation

Imports
java.util.Locale, java.util.concurrent.Future, javax.ws.rs.ProcessingException, .WebApplicationException, javax.ws.rs.core.CacheControl, .Cookie, .GenericType, .MediaType, .MultivaluedMap, .Response

A client request invocation. An invocation is a request that has been prepared and is ready for execution. Invocations provide a generic (command) interface that enables a separation of concerns between the creator and the submitter. In particular, the submitter does not need to know how the invocation was prepared, but only how it should be executed (synchronously or asynchronously) and when.
Authors
Marek Potociar, Santiago Pericas-Geertsen
See Also
Invocation.Builder

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Invocation.Builder

A client request invocation builder.

Method Summary

Modifier and TypeMethod and Description
public Response

Returns:

response object as a result of the request invocation.
invoke
()

Synchronously invoke the request and receive a response back.

public <
response type
T
>
T

Returns:

response object of the specified type as a result of the request invocation.
invoke
(Class<T>
Java type the response should be converted into.
responseType
)

Synchronously invoke the request and receive a response of the specified type back.

public <
generic response type
T
>
T

Returns:

response object of the specified generic type as a result of the request invocation.
invoke
(GenericType<T>
type literal representing a generic Java type the response should be converted into.
responseType
)

Synchronously invoke the request and receive a response of the specified generic type back.

public Invocation

Returns:

the updated invocation.
property
(String
property name.
name
,
Object
(new) property value. null value removes the property with the given name.
value
)

Set a new property in the context of a request represented by this invocation.

public Future<Response>

Returns:

future response object as a result of the request invocation.
submit
()

Submit the request for an asynchronous invocation and receive a future response back.

public <
response type
T
>
Future<T>

Returns:

future response object of the specified type as a result of the request invocation.
submit
(Class<T>
Java type the response should be converted into.
responseType
)

Submit the request for an asynchronous invocation and receive a future response of the specified type back.

public <
generic response type
T
>
Future<T>

Returns:

future response object of the specified generic type as a result of the request invocation.
submit
(GenericType<T>
type literal representing a generic Java type the response should be converted into.
responseType
)

Submit the request for an asynchronous invocation and receive a future response of the specified generic type back.

public <
response type
T
>
Future<T>

Returns:

future response object of the specified type as a result of the request invocation.
submit
(InvocationCallback<T>
invocation callback for asynchronous processing of the request invocation result.
callback
)

Submit the request for an asynchronous invocation and register an InvocationCallback to process the future result of the invocation.

Method Detail

invokeback to summary
public Response invoke()

Synchronously invoke the request and receive a response back.

Returns:Response

response object as a result of the request invocation.

Exceptions
ResponseProcessingException:
in case processing of a received HTTP response fails (e.g. in a filter or during conversion of the response entity data to an instance of a particular Java type).
ProcessingException:
in case the request processing or subsequent I/O operation fails.
invokeback to summary
public <T> T invoke(Class<T> responseType)

Synchronously invoke the request and receive a response of the specified type back.

Parameters
<T>
response type
responseType:Class<T>

Java type the response should be converted into.

Returns:T

response object of the specified type as a result of the request invocation.

Exceptions
ResponseProcessingException:
in case processing of a received HTTP response fails (e.g. in a filter or during conversion of the response entity data to an instance of a particular Java type).
ProcessingException:
in case the request processing or subsequent I/O operation fails.
WebApplicationException:
in case the response status code of the response returned by the server is not successful and the specified response type is not javax.ws.rs.core.Response.
invokeback to summary
public <T> T invoke(GenericType<T> responseType)

Synchronously invoke the request and receive a response of the specified generic type back.

Parameters
<T>
generic response type
responseType:GenericType<T>

type literal representing a generic Java type the response should be converted into.

Returns:T

response object of the specified generic type as a result of the request invocation.

Exceptions
ResponseProcessingException:
in case processing of a received HTTP response fails (e.g. in a filter or during conversion of the response entity data to an instance of a particular Java type).
ProcessingException:
in case the request processing or subsequent I/O operation fails.
WebApplicationException:
in case the response status code of the response returned by the server is not successful.
propertyback to summary
public Invocation property(String name, Object value)

Set a new property in the context of a request represented by this invocation.

The property is available for a later retrieval via ClientRequestContext#getProperty(String) or javax.ws.rs.ext.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.

Parameters
name:String

property name.

value:Object

(new) property value. null value removes the property with the given name.

Returns:Invocation

the updated invocation.

See Also
Invocation.Builder#property(String, Object)
submitback to summary
public Future<Response> submit()

Submit the request for an asynchronous invocation and receive a future response back.

Note that calling the java.util.concurrent.Future#get() method on the returned Future instance may throw an java.util.concurrent.ExecutionException that wraps a ProcessingException thrown in case of an invocation processing failure. In case a processing of a properly received response fails, the wrapped processing exception will be of ResponseProcessingException type and will contain the Response instance whose processing has failed.

Returns:Future<Response>

future response object as a result of the request invocation.

submitback to summary
public <T> Future<T> submit(Class<T> responseType)

Submit the request for an asynchronous invocation and receive a future response of the specified type back.

Note that calling the java.util.concurrent.Future#get() method on the returned Future instance may throw an java.util.concurrent.ExecutionException that wraps either a ProcessingException thrown in case of an invocation processing failure or a WebApplicationException or one of its subclasses thrown in case the received response status code is not successful and the specified response type is not javax.ws.rs.core.Response. In case a processing of a properly received response fails, the wrapped processing exception will be of ResponseProcessingException type and will contain the Response instance whose processing has failed.

Parameters
<T>
response type
responseType:Class<T>

Java type the response should be converted into.

Returns:Future<T>

future response object of the specified type as a result of the request invocation.

submitback to summary
public <T> Future<T> submit(GenericType<T> responseType)

Submit the request for an asynchronous invocation and receive a future response of the specified generic type back.

Note that calling the java.util.concurrent.Future#get() method on the returned Future instance may throw an java.util.concurrent.ExecutionException that wraps either a ProcessingException thrown in case of an invocation processing failure or a WebApplicationException or one of its subclasses thrown in case the received response status code is not successful and the specified response type is not javax.ws.rs.core.Response. In case a processing of a properly received response fails, the wrapped processing exception will be of ResponseProcessingException type and will contain the Response instance whose processing has failed.

Parameters
<T>
generic response type
responseType:GenericType<T>

type literal representing a generic Java type the response should be converted into.

Returns:Future<T>

future response object of the specified generic type as a result of the request invocation.

submitback to summary
public <T> Future<T> submit(InvocationCallback<T> callback)

Submit the request for an asynchronous invocation and register an InvocationCallback to process the future result of the invocation.

Note that calling the java.util.concurrent.Future#get() method on the returned Future instance may throw an java.util.concurrent.ExecutionException that wraps either a ProcessingException thrown in case of an invocation processing failure or a WebApplicationException or one of its subclasses thrown in case the received response status code is not successful and the generic type of the supplied response callback is not javax.ws.rs.core.Response. In case a processing of a properly received response fails, the wrapped processing exception will be of ResponseProcessingException type and will contain the Response instance whose processing has failed.

Parameters
<T>
response type
callback:InvocationCallback<T>

invocation callback for asynchronous processing of the request invocation result.

Returns:Future<T>

future response object of the specified type as a result of the request invocation.

javax.ws.rs.client back to summary

public Interface Invocation.Builder

extends SyncInvoker

A client request invocation builder. The builder, obtained via a call to one of the 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);

Method Summary

Modifier and TypeMethod and Description
public Invocation.Builder

Returns:

the updated builder.
accept
(String...
accepted response media types.
mediaTypes
)

Add the accepted response media types.

public Invocation.Builder

Returns:

the updated builder.
accept
(MediaType...
accepted response media types.
mediaTypes
)

Add the accepted response media types.

public Invocation.Builder

Returns:

the updated builder.
acceptEncoding
(String...
an array of the acceptable encodings.
encodings
)

Add acceptable encodings.

public Invocation.Builder

Returns:

the updated builder.
acceptLanguage
(Locale...
an array of the acceptable languages.
locales
)

Add acceptable languages.

public Invocation.Builder

Returns:

the updated builder.
acceptLanguage
(String...
an array of the acceptable languages.
locales
)

Add acceptable languages.

public AsyncInvoker

Returns:

asynchronous uniform request invocation interface.
async
()

Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.

public Invocation

Returns:

invocation encapsulating the built request.
build
(String
request method name.
method
)

Build a request invocation using an arbitrary request method name.

public Invocation

Returns:

invocation encapsulating the built request.
build
(String
request method name.
method
,
Entity<?>
request entity, including it's full javax.ws.rs.core.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.
entity
)

Build a request invocation using an arbitrary request method name and request entity.

public Invocation

Returns:

invocation encapsulating the built DELETE request.
buildDelete
()

Build a DELETE request invocation.

public Invocation

Returns:

invocation encapsulating the built GET request.
buildGet
()

Build a GET request invocation.

public Invocation

Returns:

invocation encapsulating the built POST request.
buildPost
(Entity<?>
request entity, including it's full javax.ws.rs.core.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.
entity
)

Build a POST request invocation.

public Invocation

Returns:

invocation encapsulating the built PUT request.
buildPut
(Entity<?>
request entity, including it's full javax.ws.rs.core.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.
entity
)

Build a PUT request invocation.

public Invocation.Builder

Returns:

the updated builder.
cacheControl
(CacheControl
the cache control directives, if null any existing cache control directives will be removed.
cacheControl
)

Set the cache control data of the message.

public Invocation.Builder

Returns:

the updated builder.
cookie
(Cookie
to be set.
cookie
)

Add a cookie to be set.

public Invocation.Builder

Returns:

the updated builder.
cookie
(String
the name of the cookie.
name
,
String
the value of the cookie.
value
)

Add a cookie to be set.

public Invocation.Builder

Returns:

the updated builder.
header
(String
the name of the header
name
,
Object
the value of the header, the header will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.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.
value
)

Add an arbitrary header.

public Invocation.Builder

Returns:

the updated builder.
headers
(MultivaluedMap<String, Object>
new headers to be set, if null all existing headers will be removed.
headers
)

Replaces all existing headers with the newly supplied headers.

public Invocation.Builder

Returns:

the updated builder.
property
(String
property name.
name
,
Object
(new) property value. null value removes the property with the given name.
value
)

Set a new property in the context of a request represented by this invocation builder.

public CompletionStageRxInvoker

Returns:

default reactive invoker instance.
rx
()

Access the default reactive invoker based on java.util.concurrent.CompletionStage.

public <T extends RxInvoker> T

Returns:

reactive invoker instance.
rx
(Class<T>
RxInvoker subclass.
clazz
)

Access a reactive invoker based on a RxInvoker subclass provider.

Inherited from javax.ws.rs.client.SyncInvoker:
deletedeletedeletegetgetgetheadmethodmethodmethodmethodmethodmethodoptionsoptionsoptionspostpostpostputputputtracetracetrace

Method Detail

acceptback to summary
public Invocation.Builder accept(String... mediaTypes)

Add the accepted response media types.

Parameters
mediaTypes:String[]

accepted response media types.

Returns:Invocation.Builder

the updated builder.

acceptback to summary
public Invocation.Builder accept(MediaType... mediaTypes)

Add the accepted response media types.

Parameters
mediaTypes:MediaType[]

accepted response media types.

Returns:Invocation.Builder

the updated builder.

acceptEncodingback to summary
public Invocation.Builder acceptEncoding(String... encodings)

Add acceptable encodings.

Parameters
encodings:String[]

an array of the acceptable encodings.

Returns:Invocation.Builder

the updated builder.

acceptLanguageback to summary
public Invocation.Builder acceptLanguage(Locale... locales)

Add acceptable languages.

Parameters
locales:Locale[]

an array of the acceptable languages.

Returns:Invocation.Builder

the updated builder.

acceptLanguageback to summary
public Invocation.Builder acceptLanguage(String... locales)

Add acceptable languages.

Parameters
locales:String[]

an array of the acceptable languages.

Returns:Invocation.Builder

the updated builder.

asyncback to summary
public AsyncInvoker async()

Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.

Returns:AsyncInvoker

asynchronous uniform request invocation interface.

buildback to summary
public Invocation build(String method)

Build a request invocation using an arbitrary request method name.

Parameters
method:String

request method name.

Returns:Invocation

invocation encapsulating the built request.

buildback to summary
public Invocation build(String method, Entity<?> entity)

Build a request invocation using an arbitrary request method name and request entity.

Parameters
method:String

request method name.

entity:Entity<?>

request entity, including it's full javax.ws.rs.core.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.

Returns:Invocation

invocation encapsulating the built request.

buildDeleteback to summary
public Invocation buildDelete()

Build a DELETE request invocation.

Returns:Invocation

invocation encapsulating the built DELETE request.

buildGetback to summary
public Invocation buildGet()

Build a GET request invocation.

Returns:Invocation

invocation encapsulating the built GET request.

buildPostback to summary
public Invocation buildPost(Entity<?> entity)

Build a POST request invocation.

Parameters
entity:Entity<?>

request entity, including it's full javax.ws.rs.core.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.

Returns:Invocation

invocation encapsulating the built POST request.

buildPutback to summary
public Invocation buildPut(Entity<?> entity)

Build a PUT request invocation.

Parameters
entity:Entity<?>

request entity, including it's full javax.ws.rs.core.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.

Returns:Invocation

invocation encapsulating the built PUT request.

cacheControlback to summary
public Invocation.Builder cacheControl(CacheControl cacheControl)

Set the cache control data of the message.

Parameters
cacheControl:CacheControl

the cache control directives, if null any existing cache control directives will be removed.

Returns:Invocation.Builder

the updated builder.

cookieback to summary
public Invocation.Builder cookie(Cookie cookie)

Add a cookie to be set.

Parameters
cookie:Cookie

to be set.

Returns:Invocation.Builder

the updated builder.

cookieback to summary
public Invocation.Builder cookie(String name, String value)

Add a cookie to be set.

Parameters
name:String

the name of the cookie.

value:String

the value of the cookie.

Returns:Invocation.Builder

the updated builder.

headerback to summary
public Invocation.Builder header(String name, Object value)

Add an arbitrary header.

Parameters
name:String

the name of the header

value:Object

the value of the header, the header will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.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.

Returns:Invocation.Builder

the updated builder.

headersback to summary
public Invocation.Builder headers(MultivaluedMap<String, Object> headers)

Replaces all existing headers with the newly supplied headers.

Parameters
headers:MultivaluedMap<String, Object>

new headers to be set, if null all existing headers will be removed.

Returns:Invocation.Builder

the updated builder.

propertyback to summary
public Invocation.Builder property(String name, Object value)

Set a new property in the context of a request represented by this invocation builder.

The property is available for a later retrieval via ClientRequestContext#getProperty(String) or javax.ws.rs.ext.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.

Parameters
name:String

property name.

value:Object

(new) property value. null value removes the property with the given name.

Returns:Invocation.Builder

the updated builder.

See Also
Invocation#property(String, Object)
rxback to summary
public CompletionStageRxInvoker rx()

Access the default reactive invoker based on java.util.concurrent.CompletionStage.

Returns:CompletionStageRxInvoker

default reactive invoker instance.

Since
2.1
See Also
javax.ws.rs.client.Invocation.Builder#rx(Class)
rxback to summary
public <T extends RxInvoker> T rx(Class<T> clazz)

Access a reactive invoker based on a RxInvoker subclass provider. Note that corresponding RxInvokerProvider must be registered in the client runtime.

This method is an extension point for JAX-RS implementations to support other types representing asynchronous computations.

Parameters
clazz:Class<T>

RxInvoker subclass.

Returns:T

reactive invoker instance.

Exceptions
IllegalStateException:
when provider for given class is not registered.
Since
2.1
See Also
javax.ws.rs.client.Client#register(Class)