javax.ws.rs.client
Interface Invocation.Builder

All Superinterfaces:
SyncInvoker
Enclosing interface:
Invocation

public static 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 = ClientFactory.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 = ClientFactory.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 = ClientFactory.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
 Invocation.Builder acceptLanguage(java.util.Locale... locales)
          Add acceptable languages.
 Invocation.Builder acceptLanguage(java.lang.String... locales)
          Add acceptable languages.
 AsyncInvoker async()
          Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.
 Invocation build(java.lang.String method)
          Build a request invocation using an arbitrary request method name.
 Invocation build(java.lang.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.
 Configuration configuration()
          Get access to the underlying configuration.
 Invocation.Builder cookie(Cookie cookie)
          Add a cookie to be set.
 Invocation.Builder cookie(java.lang.String name, java.lang.String value)
          Add a cookie to be set.
 Invocation.Builder header(java.lang.String name, java.lang.Object value)
          Add an arbitrary header.
 Invocation.Builder headers(MultivaluedMap<java.lang.String,java.lang.Object> headers)
          Replaces all existing headers with the newly supplied headers.
 
Methods inherited from interface javax.ws.rs.client.SyncInvoker
delete, delete, delete, get, get, get, head, method, method, method, method, method, method, options, options, options, post, post, post, put, put, put, trace, trace, trace
 

Method Detail

build

Invocation build(java.lang.String method)
Build a request invocation using an arbitrary request method name.

Parameters:
method - request method name.
Returns:
invocation encapsulating the built request.

build

Invocation build(java.lang.String method,
                 Entity<?> entity)
Build a request invocation using an arbitrary request method name and request entity.

Parameters:
method - request method name.
entity - request entity.
Returns:
invocation encapsulating the built request.

buildGet

Invocation buildGet()
Build a GET request invocation.

Returns:
invocation encapsulating the built GET request.

buildDelete

Invocation buildDelete()
Build a DELETE request invocation.

Returns:
invocation encapsulating the built DELETE request.

buildPost

Invocation buildPost(Entity<?> entity)
Build a POST request invocation.

Parameters:
entity - request entity
Returns:
invocation encapsulating the built POST request.

buildPut

Invocation buildPut(Entity<?> entity)
Build a PUT request invocation.

Parameters:
entity - request entity
Returns:
invocation encapsulating the built PUT request.

async

AsyncInvoker async()
Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.

Returns:
asynchronous uniform request invocation interface.

acceptLanguage

Invocation.Builder acceptLanguage(java.util.Locale... locales)
Add acceptable languages.

Parameters:
locales - an array of the acceptable languages
Returns:
the updated builder.

acceptLanguage

Invocation.Builder acceptLanguage(java.lang.String... locales)
Add acceptable languages.

Parameters:
locales - an array of the acceptable languages
Returns:
the updated builder.

cookie

Invocation.Builder cookie(Cookie cookie)
Add a cookie to be set.

Parameters:
cookie - to be set.
Returns:
the updated builder.

cookie

Invocation.Builder cookie(java.lang.String name,
                          java.lang.String value)
Add a cookie to be set.

Parameters:
name - the name of the cookie.
value - the value of the cookie.
Returns:
the updated builder.

cacheControl

Invocation.Builder cacheControl(CacheControl cacheControl)
Set the cache control data of the message.

Parameters:
cacheControl - the cache control directives, if null any existing cache control directives will be removed.
Returns:
the updated builder.

header

Invocation.Builder header(java.lang.String name,
                          java.lang.Object value)
Add an arbitrary header.

Parameters:
name - the name of the header
value - 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.
Returns:
the updated builder.

headers

Invocation.Builder headers(MultivaluedMap<java.lang.String,java.lang.Object> headers)
Replaces all existing headers with the newly supplied headers.

Parameters:
headers - new headers to be set, if null all existing headers will be removed.
Returns:
the updated builder.

configuration

Configuration configuration()
Get access to the underlying configuration.

Returns:
a mutable configuration bound to the instance.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.