public class Client extends Filterable implements ClientHandler
WebResource
instances and configuring
the properties of connections and requests.
ClientFilter
instances may be added to the client for filtering
requests and responses, including those of WebResource
instances
created from the client.
A client may be configured by passing a ClientConfig
instance to
the appropriate constructor.
Methods to create instances of WebResource
are thread-safe. Methods
that modify configuration and or filters are not guaranteed to be
thread-safe.
The creation of a Client
instance is an expensive operation and
the instance may make use of and retain many resources. It is therefore
recommended that a Client
instance is reused for the creation of
WebResource
instances that require the same configuration settings.
A client may integrate with an IoC framework by passing a
IoCComponentProviderFactory
instance to the appropriate constructor.
Constructor and Description |
---|
Client()
Create a new client instance.
|
Client(ClientHandler root)
Create a new client instance.
|
Client(ClientHandler root,
ClientConfig config)
Create a new client instance with a client configuration.
|
Client(ClientHandler root,
ClientConfig config,
IoCComponentProviderFactory provider)
Create a new instance with a client configuration and a
component provider.
|
Modifier and Type | Method and Description |
---|---|
AsyncWebResource |
asyncResource(java.lang.String u)
Create an asynchronous Web resource from the client.
|
AsyncWebResource |
asyncResource(java.net.URI u)
Create an asynchronous Web resource from the client.
|
<T> java.util.concurrent.Future<T> |
asyncView(java.lang.String u,
java.lang.Class<T> type) |
<T> java.util.concurrent.Future<T> |
asyncView(java.lang.String u,
T t) |
<T> java.util.concurrent.Future<T> |
asyncView(java.net.URI uri,
java.lang.Class<T> type) |
<T> java.util.concurrent.Future<T> |
asyncView(java.net.URI uri,
T t) |
AsyncViewResource |
asyncViewResource(java.lang.String u) |
AsyncViewResource |
asyncViewResource(java.net.URI u) |
static Client |
create()
Create a default client.
|
static Client |
create(ClientConfig cc)
Create a default client with client configuration.
|
static Client |
create(ClientConfig cc,
IoCComponentProviderFactory provider)
Create a default client with client configuration and component provider.
|
void |
destroy()
Destroy the client.
|
protected void |
finalize()
Defer to
destroy() |
java.util.concurrent.ExecutorService |
getExecutorService()
Get the
ExecutorService for sending asynchronous
HTTP requests when no underlying asynchronous HTTP implementation is
utilized. |
MessageBodyWorkers |
getMessageBodyWorkers()
Get the
MessageBodyWorkers utilized by the client. |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Get the mutable property bag.
|
Providers |
getProviders()
Get the
Providers utilized by the client. |
<T> ViewProxy<T> |
getViewProxy(java.lang.Class<T> c) |
ClientResponse |
handle(ClientRequest request)
Handle a HTTP request as a
ClientRequest and return the HTTP
response as a ClientResponse . |
void |
inject(java.lang.Object o)
Inject client-side bindings on an instance.
|
WebResource |
resource(java.lang.String u)
Create a Web resource from the client.
|
WebResource |
resource(java.net.URI u)
Create a Web resource from the client.
|
void |
setChunkedEncodingSize(java.lang.Integer chunkSize)
Set the client to send request entities using chunked encoding
with a particular chunk size.
|
void |
setConnectTimeout(java.lang.Integer interval)
Set the connect timeout interval, in milliseconds.
|
void |
setExecutorService(java.util.concurrent.ExecutorService es)
Set the
ExecutorService for sending asynchronous
HTTP requests when no underlying asynchronous HTTP implementation is
utilized. |
void |
setFollowRedirects(java.lang.Boolean redirect)
Set if redirection should be performed or not.
|
void |
setReadTimeout(java.lang.Integer interval)
Set the read timeout interval, in milliseconds.
|
<T> T |
view(java.lang.Class<T> c,
ClientResponse response) |
<T> T |
view(java.lang.String u,
java.lang.Class<T> type) |
<T> T |
view(java.lang.String u,
T t) |
<T> T |
view(T t,
ClientResponse response) |
<T> T |
view(java.net.URI uri,
java.lang.Class<T> type) |
<T> T |
view(java.net.URI uri,
T t) |
ViewResource |
viewResource(java.lang.String u) |
ViewResource |
viewResource(java.net.URI u) |
addFilter, getHeadHandler, isFilterPresent, isFilterPreset, removeAllFilters, removeFilter
public Client()
public Client(ClientHandler root)
root
- the root client handler for dispatching a request and
returning a response.public Client(ClientHandler root, ClientConfig config)
root
- the root client handler for dispatching a request and
returning a response.config
- the client configuration.public Client(ClientHandler root, ClientConfig config, IoCComponentProviderFactory provider)
root
- the root client handler for dispatching a request and
returning a response.config
- the client configuration.provider
- the IoC component provider factory.public void destroy()
This method must be called when there are not responses pending otherwise undefined behavior will occur.
The client must not be reused after this method is called otherwise undefined behavior will occur.
protected void finalize() throws java.lang.Throwable
destroy()
finalize
in class java.lang.Object
java.lang.Throwable
public Providers getProviders()
Providers
utilized by the client.Providers
utilized by the client.public MessageBodyWorkers getMessageBodyWorkers()
MessageBodyWorkers
utilized by the client.MessageBodyWorkers
utilized by the client.public WebResource resource(java.lang.String u)
u
- the URI of the resource.public WebResource resource(java.net.URI u)
u
- the URI of the resource.public AsyncWebResource asyncResource(java.lang.String u)
u
- the URI of the resource.public AsyncWebResource asyncResource(java.net.URI u)
u
- the URI of the resource.public ViewResource viewResource(java.lang.String u)
public ViewResource viewResource(java.net.URI u)
public AsyncViewResource asyncViewResource(java.lang.String u)
public AsyncViewResource asyncViewResource(java.net.URI u)
public <T> T view(java.lang.String u, java.lang.Class<T> type)
public <T> T view(java.net.URI uri, java.lang.Class<T> type)
public <T> T view(java.lang.String u, T t)
public <T> T view(java.net.URI uri, T t)
public <T> java.util.concurrent.Future<T> asyncView(java.lang.String u, java.lang.Class<T> type)
public <T> java.util.concurrent.Future<T> asyncView(java.net.URI uri, java.lang.Class<T> type)
public <T> java.util.concurrent.Future<T> asyncView(java.lang.String u, T t)
public <T> java.util.concurrent.Future<T> asyncView(java.net.URI uri, T t)
public <T> T view(java.lang.Class<T> c, ClientResponse response)
public <T> T view(T t, ClientResponse response)
public <T> ViewProxy<T> getViewProxy(java.lang.Class<T> c)
public void setExecutorService(java.util.concurrent.ExecutorService es)
ExecutorService
for sending asynchronous
HTTP requests when no underlying asynchronous HTTP implementation is
utilized.es
- the ExecutorService
.public java.util.concurrent.ExecutorService getExecutorService()
ExecutorService
for sending asynchronous
HTTP requests when no underlying asynchronous HTTP implementation is
utilized.
By default the implementation returned
from Executors.newCachedThreadPool()
is utilized.
ExecutorService
.public java.util.Map<java.lang.String,java.lang.Object> getProperties()
public void setFollowRedirects(java.lang.Boolean redirect)
ClientConfig.PROPERTY_FOLLOW_REDIRECTS
on the property bag
returned from getProperties()
redirect
- if true then the client will automatically redirect
to the URI declared in 3xx responses.public void setReadTimeout(java.lang.Integer interval)
ClientConfig.PROPERTY_READ_TIMEOUT
on the property bag
returned from getProperties()
interval
- the read timeout interval. If null or 0 then
an interval of infinity is declared.public void setConnectTimeout(java.lang.Integer interval)
ClientConfig.PROPERTY_CONNECT_TIMEOUT
on the property bag
returned from getProperties()
interval
- the connect timeout interval. If null or 0 then
an interval of infinity is declared.public void setChunkedEncodingSize(java.lang.Integer chunkSize)
ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE
on the property bag
returned from getProperties()
chunkSize
- the chunked encoding size. If <= 0 then the default
size will be used. If null then chunked encoding will not be
utilized.public ClientResponse handle(ClientRequest request) throws ClientHandlerException
ClientHandler
ClientRequest
and return the HTTP
response as a ClientResponse
.handle
in interface ClientHandler
request
- the HTTP request.ClientHandlerException
- if the client
handler fails to process the request or response.public void inject(java.lang.Object o)
o
- the instance to inject on.public static Client create()
public static Client create(ClientConfig cc)
cc
- the client configuration.public static Client create(ClientConfig cc, IoCComponentProviderFactory provider)
cc
- the client configuration.provider
- the IoC component provider factory.Copyright © 2016 Oracle Corporation. All Rights Reserved.