org.restlet

## Class Client

- java.lang.Object
- - org.restlet.Restlet
  - - org.restlet.Connector
    - - org.restlet.Client

All Implemented Interfaces:
  Uniform

Direct Known Subclasses:
  TemplateDispatcher

    public class Client
    extends Connector

Connector acting as a generic client. It internally uses one of the available connector helpers registered with the Restlet engine.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`Client(Context context, java.util.List<Protocol> protocols)` Constructor.
`Client(Context context, java.util.List<Protocol> protocols, java.lang.String helperClass)` Constructor.
`Client(Context context, Protocol protocol)` Constructor.
`Client(java.util.List<Protocol> protocols)` Constructor.
`Client(Protocol protocol)` Constructor.
`Client(java.lang.String protocolName)` Constructor.

### Method Summary

Methods
`int` `getConnectTimeout()` Returns the connection timeout in milliseconds.
`Response` `handle(Request request)` Handles a call.
`void` `handle(Request request, Response response)` Handles a call.
`void` `handle(Request request, Response response, Uniform onResponseCallback)` Handles a call.
`void` `handle(Request request, Uniform onReceivedCallback)` Handles a call.
`boolean` `isAvailable()` Indicates the underlying connector helper is available.
`void` `setConnectTimeout(int connectTimeout)` Sets the connection timeout in milliseconds.
`void` `start()` Starts the Restlet.
`void` `stop()` Stops the Restlet.

### Methods inherited from class org.restlet.Connector

`getProtocols, setProtocols`

### Methods inherited from class org.restlet.Restlet

`finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner`

### Methods inherited from class java.lang.Object

`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Client

    public Client(Context context,
          java.util.List<Protocol> protocols)

Constructor.

Parameters:
  `context` - The context.
  `protocols` - The connector protocols.

#### Client

    public Client(Context context,
          java.util.List<Protocol> protocols,
          java.lang.String helperClass)

Constructor.

Parameters:
  `context` - The context.
  `protocols` - The connector protocols.
  `helperClass` - Optional helper class name.

#### Client

    public Client(Context context,
          Protocol protocol)

Constructor.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.

#### Client

    public Client(java.util.List<Protocol> protocols)

Constructor.

Parameters:
  `protocols` - The connector protocols.

#### Client

    public Client(Protocol protocol)

Constructor.

Parameters:
  `protocol` - The connector protocol.

#### Client

    public Client(java.lang.String protocolName)

Constructor.

Parameters:
  `protocolName` - The connector protocol.

### Method Detail

#### getConnectTimeout

    public int getConnectTimeout()

Returns the connection timeout in milliseconds. The default value is 0, meaning an infinite timeout.

Returns:
  The connection timeout.

#### handle

    public final Response handle(Request request)

Handles a call.

Parameters:
  `request` - The request to handle.
Returns:
  The returned response.

#### handle

    public void handle(Request request,
              Response response)

Description copied from class: `Restlet`
Handles a call. The default behavior is to initialize the Restlet by setting the current context using the `Context.setCurrent(Context)` method and by attempting to start it, unless it was already started. If an exception is thrown during the start action, then the response status is set to `Status.SERVER_ERROR_INTERNAL`.

Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.

Specified by:
  `handle` in interface `Uniform`
Overrides:
  `handle` in class `Restlet`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.

#### handle

    public void handle(Request request,
              Response response,
              Uniform onResponseCallback)

Handles a call.

Parameters:
  `request` - The request to handle.
  `response` - The response to update.
  `onResponseCallback` - The callback invoked upon response reception.

#### handle

    public final void handle(Request request,
              Uniform onReceivedCallback)

Handles a call.

Parameters:
  `request` - The request to handle.
  `onReceivedCallback` - The callback invoked upon request reception.

#### isAvailable

    public boolean isAvailable()

Indicates the underlying connector helper is available.

Specified by:
  `isAvailable` in class `Connector`
Returns:
  True if the underlying connector helper is available.

#### setConnectTimeout

    public void setConnectTimeout(int connectTimeout)

Sets the connection timeout in milliseconds. The default value is 0, meaning an infinite timeout.

Parameters:
  `connectTimeout` - The connection timeout.

#### start

    public void start()
               throws java.lang.Exception

Description copied from class: `Restlet`
Starts the Restlet.

Overrides:
  `start` in class `Restlet`
Throws:
  `java.lang.Exception`

#### stop

    public void stop()
              throws java.lang.Exception

Description copied from class: `Restlet`
Stops the Restlet.

Overrides:
  `stop` in class `Restlet`
Throws:
  `java.lang.Exception`