com.sun.jersey.api.client
Class Client

java.lang.Object
  extended by com.sun.jersey.api.client.filter.Filterable
      extended by com.sun.jersey.api.client.Client
All Implemented Interfaces:
ClientHandler

public final class Client
extends Filterable
implements ClientHandler

The main class for creating 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 construtor.

Methods to create instances of WebResource are thread-safe. Methods that modify configuration and or filters are not guaranteed to be thread-safe.

A client may integrate with an IoC framework by passing a ComponentProvider instance to the appropriate constructor.

Author:
Paul.Sandoz@Sun.Com

Constructor Summary
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, ComponentProvider provider)
          Create a new instance with a client configuration and a component provider.
 
Method Summary
 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.
static Client create()
          Create a default client.
static Client create(ClientConfig cc)
          Create a default client with client configuration.
static Client create(ClientConfig cc, ComponentProvider cp)
          Create a default client with client configuration and component provider.
 java.util.Map<java.lang.String,java.lang.Object> getProperties()
          Get the mutable property bag.
 ClientResponse handle(ClientRequest cr)
          Handle a HTTP request as a ClientRequest and return the HTTP response as a ClientResponse.
 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.
 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.
 
Methods inherited from class com.sun.jersey.api.client.filter.Filterable
addFilter, getHeadHandler, removeAllFilters, removeFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client(ClientHandler root)
Create a new client instance.

Parameters:
root - the root client handler for dispatching a request and returning a response.

Client

public Client(ClientHandler root,
              ClientConfig config)
Create a new client instance with a client configuration.

Parameters:
root - the root client handler for dispatching a request and returning a response.
config - the client configuration.

Client

public Client(ClientHandler root,
              ClientConfig config,
              ComponentProvider provider)
Create a new instance with a client configuration and a component provider.

Parameters:
root - the root client handler for dispatching a request and returning a response.
config - the client configuration.
provider - the component provider.
Method Detail

resource

public WebResource resource(java.lang.String u)
Create a Web resource from the client.

Parameters:
u - the URI of the resource.
Returns:
the Web resource.

resource

public WebResource resource(java.net.URI u)
Create a Web resource from the client.

Parameters:
u - the URI of the resource.
Returns:
the Web resource.

asyncResource

public AsyncWebResource asyncResource(java.lang.String u)
Create an asynchronous Web resource from the client.

Parameters:
u - the URI of the resource.
Returns:
the Web resource.

asyncResource

public AsyncWebResource asyncResource(java.net.URI u)
Create an asynchronous Web resource from the client.

Parameters:
u - the URI of the resource.
Returns:
the Web resource.

getProperties

public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Get the mutable property bag.

Returns:
the property bag.

setFollowRedirects

public void setFollowRedirects(java.lang.Boolean redirect)
Set if redirection should be performed or not. This method is the functional equivalent to setting the property ClientConfig.PROPERTY_FOLLOW_REDIRECTS on the property bag returned from getProperties()

Parameters:
redirect - if true then the client will automatically redirect to the URI declared in 3xx responses.

setReadTimeout

public void setReadTimeout(java.lang.Integer interval)
Set the read timeout interval. This method is the functional equivalent to setting the property ClientConfig.PROPERTY_READ_TIMEOUT on the property bag returned from getProperties()

Parameters:
interval - the read timeout interval. If null or 0 then an interval of infinity is declared.

setConnectTimeout

public void setConnectTimeout(java.lang.Integer interval)
Set the connect timeout interval. This method is the functional equivalent to setting the property ClientConfig.PROPERTY_CONNECT_TIMEOUT on the property bag returned from getProperties()

Parameters:
interval - the connect timeout interval. If null or 0 then an interval of infinity is declared.

setChunkedEncodingSize

public void setChunkedEncodingSize(java.lang.Integer chunkSize)
Set the client to send request entities using chunked encoding with a particular chunk size. This method is the functional equivalent to setting the property ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE on the property bag returned from getProperties()

Parameters:
chunkSize - the chunked encoding size. If <= 0 then the default size will be used. If null then chunked encoding will not be utilized.

handle

public ClientResponse handle(ClientRequest cr)
                      throws ClientHandlerException
Description copied from interface: ClientHandler
Handle a HTTP request as a ClientRequest and return the HTTP response as a ClientResponse.

Specified by:
handle in interface ClientHandler
Parameters:
cr - the HTTP request.
Returns:
the HTTP response.
Throws:
ClientHandlerException - if the client handler fails to process the request or response.

create

public static Client create()
Create a default client.

Returns:
a default client.

create

public static Client create(ClientConfig cc)
Create a default client with client configuration.

Parameters:
cc - the client configuration.
Returns:
a default client.

create

public static Client create(ClientConfig cc,
                            ComponentProvider cp)
Create a default client with client configuration and component provider.

Parameters:
cc - the client configuration.
cp - the component provider.
Returns:
a default client.


Copyright © 2008 Sun Microsystems, Inc. All Rights Reserved.