org.sonatype.spice.jersey.client.ahc
Class AhcClientHandler

java.lang.Object
  extended by org.sonatype.spice.jersey.client.ahc.AhcClientHandler
All Implemented Interfaces:
com.sun.jersey.api.client.ClientHandler

public final class AhcClientHandler
extends Object
implements com.sun.jersey.api.client.ClientHandler

A root handler with Sonatype AsyncHttpClient acting as a backend.

Client operations are thread safe, the HTTP connection may be shared between different threads.

If a response entity is obtained that is an instance of Closeable then the instance MUST be closed after processing the entity to release connection-based resources.

If a ClientResponse is obtained and an entity is not read from the response then ClientResponse.close() MUST be called after processing the response to release connection-based resources.

The following methods are currently supported: HEAD, GET, POST, PUT, DELETE, TRACE OPTIONS as well as custom methods.

Author:
Jeanfrancois Arcand

Constructor Summary
AhcClientHandler(com.ning.http.client.AsyncHttpClient client)
          Create a new root handler with an AsyncHttpClient.
AhcClientHandler(com.ning.http.client.AsyncHttpClient client, AhcConfig config)
          Create a new root handler with an AsyncHttpClient.
 
Method Summary
 AhcRequestWriter getAhcRequestWriter()
          Return the instance of RequestWriter.
 AhcConfig getConfig()
          Get the client config.
 com.ning.http.client.AsyncHttpClient getHttpClient()
          Get the AsyncHttpClient.
 com.sun.jersey.api.client.ClientResponse handle(com.sun.jersey.api.client.ClientRequest cr)
          Translate the ClientRequest into a AsyncHttpClient request, and execute it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AhcClientHandler

public AhcClientHandler(com.ning.http.client.AsyncHttpClient client)
Create a new root handler with an AsyncHttpClient.

Parameters:
client - the AsyncHttpClient.

AhcClientHandler

public AhcClientHandler(com.ning.http.client.AsyncHttpClient client,
                        AhcConfig config)
Create a new root handler with an AsyncHttpClient.

Parameters:
client - the AsyncHttpClient.
config - the client configuration.
Method Detail

getConfig

public AhcConfig getConfig()
Get the client config.

Returns:
the client config.

getHttpClient

public com.ning.http.client.AsyncHttpClient getHttpClient()
Get the AsyncHttpClient.

Returns:
the AsyncHttpClient.

handle

public com.sun.jersey.api.client.ClientResponse handle(com.sun.jersey.api.client.ClientRequest cr)
                                                throws com.sun.jersey.api.client.ClientHandlerException
Translate the ClientRequest into a AsyncHttpClient request, and execute it.

Specified by:
handle in interface com.sun.jersey.api.client.ClientHandler
Parameters:
cr - the HTTP request.
Returns:
the ClientResponse
Throws:
com.sun.jersey.api.client.ClientHandlerException

getAhcRequestWriter

public AhcRequestWriter getAhcRequestWriter()
Return the instance of RequestWriter. This instance will be injected within Jersey so it cannot be null.

Returns:
the instance of RequestWriter.


Copyright © 2012. All Rights Reserved.