com.sun.ws.rest.api.client
Class Client

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

public class Client
extends Filterable
implements ClientHandler

The HTTP client class for handling requests and responses specified by ClientHandler or for creating WebResource instances.

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.

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


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 compoenent provider.
 
Method Summary
 void addInjectable(java.lang.reflect.Type fieldType, Injectable injectable)
          Add an injectable resource to the set maintained by 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.
 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.
 
Methods inherited from class com.sun.ws.rest.api.client.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 compoenent 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

addInjectable

public final void addInjectable(java.lang.reflect.Type fieldType,
                                Injectable injectable)
Add an injectable resource to the set maintained by the client. The fieldType is used as a unique key and therefore adding an injectable for a type already supported will override the existing one.

Parameters:
fieldType - the type of the field that will be injected.
injectable - the injectable for the field.

resource

public final 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 final WebResource resource(java.net.URI u)
Create a Web resource from the client.

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

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.