org.apache.http.impl.client
Class DefaultClientRequestDirector

java.lang.Object
  extended by org.apache.http.impl.client.DefaultClientRequestDirector
All Implemented Interfaces:
ClientRequestDirector

public class DefaultClientRequestDirector
extends java.lang.Object
implements ClientRequestDirector

Default implementation of a client-side request director.
This class replaces the HttpMethodDirector in HttpClient 3.

Since:
4.0
Version:
$Revision: 586567 $
Author:
Roland Weber, Oleg Kalnichevski

Field Summary
protected  ClientConnectionManager connManager
          The connection manager.
protected  org.apache.http.protocol.HttpProcessor httpProcessor
          The HTTP protocol processor.
protected  ManagedClientConnection managedConn
          The currently allocated connection.
protected  org.apache.http.params.HttpParams params
          The HTTP parameters.
protected  RedirectHandler redirectHandler
          The redirect handler.
protected  org.apache.http.protocol.HttpRequestExecutor requestExec
          The request executor.
protected  HttpRequestRetryHandler retryHandler
          The request retry handler.
protected  org.apache.http.ConnectionReuseStrategy reuseStrategy
          The connection re-use strategy.
 
Constructor Summary
DefaultClientRequestDirector(ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, org.apache.http.params.HttpParams params)
           
 
Method Summary
protected  ManagedClientConnection allocateConnection(HttpRoute route, long timeout)
          Obtains a connection for the target route.
protected  org.apache.http.HttpRequest createConnectRequest(HttpRoute route, org.apache.http.protocol.HttpContext context)
          Creates the CONNECT request for tunnelling.
protected  boolean createTunnelToProxy(HttpRoute route, int hop, org.apache.http.protocol.HttpContext context)
          Creates a tunnel to an intermediate proxy.
protected  boolean createTunnelToTarget(HttpRoute route, org.apache.http.protocol.HttpContext context)
          Creates a tunnel to the target server.
protected  void establishRoute(HttpRoute route, org.apache.http.protocol.HttpContext context)
          Establishes the target route.
 org.apache.http.HttpResponse execute(RoutedRequest roureq, org.apache.http.protocol.HttpContext context)
          Executes a request.
 ManagedClientConnection getConnection()
          Obtains the connection to which the response is tied.
protected  RoutedRequest handleResponse(RoutedRequest roureq, org.apache.http.HttpRequest request, org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)
          Analyzes a response to check need for a followup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connManager

protected final ClientConnectionManager connManager
The connection manager.


reuseStrategy

protected final org.apache.http.ConnectionReuseStrategy reuseStrategy
The connection re-use strategy.


requestExec

protected final org.apache.http.protocol.HttpRequestExecutor requestExec
The request executor.


httpProcessor

protected final org.apache.http.protocol.HttpProcessor httpProcessor
The HTTP protocol processor.


retryHandler

protected final HttpRequestRetryHandler retryHandler
The request retry handler.


redirectHandler

protected final RedirectHandler redirectHandler
The redirect handler.


params

protected final org.apache.http.params.HttpParams params
The HTTP parameters.


managedConn

protected ManagedClientConnection managedConn
The currently allocated connection.

Constructor Detail

DefaultClientRequestDirector

public DefaultClientRequestDirector(ClientConnectionManager conman,
                                    org.apache.http.ConnectionReuseStrategy reustrat,
                                    org.apache.http.protocol.HttpProcessor httpProcessor,
                                    HttpRequestRetryHandler retryHandler,
                                    RedirectHandler redirectHandler,
                                    AuthenticationHandler targetAuthHandler,
                                    AuthenticationHandler proxyAuthHandler,
                                    org.apache.http.params.HttpParams params)
Method Detail

getConnection

public ManagedClientConnection getConnection()
Description copied from interface: ClientRequestDirector
Obtains the connection to which the response is tied. Responses with a non-buffered response entity are tied to their connection until the entity is consumed or discarded. Until then, the connection must not be released. Afterwards, it must be released.

Specified by:
getConnection in interface ClientRequestDirector
Returns:
the connection to which the response from execute is tied, or null if there is none

execute

public org.apache.http.HttpResponse execute(RoutedRequest roureq,
                                            org.apache.http.protocol.HttpContext context)
                                     throws org.apache.http.HttpException,
                                            java.io.IOException,
                                            java.lang.InterruptedException
Description copied from interface: ClientRequestDirector
Executes a request.
Note: For the time being, a new director is instantiated for each request. This is the same behavior as for HttpMethodDirector in HttpClient 3.

Specified by:
execute in interface ClientRequestDirector
Parameters:
roureq - the route and request to execute
context - the context for executing the request
Returns:
the final response to the request. This is never an intermediate response with status code 1xx.
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem
java.lang.InterruptedException - in case of an interrupt

allocateConnection

protected ManagedClientConnection allocateConnection(HttpRoute route,
                                                     long timeout)
                                              throws org.apache.http.HttpException,
                                                     ConnectionPoolTimeoutException,
                                                     java.lang.InterruptedException
Obtains a connection for the target route.

Parameters:
route - the route for which to allocate a connection
Throws:
org.apache.http.HttpException - in case of a (protocol) problem
ConnectionPoolTimeoutException - in case of a timeout
java.lang.InterruptedException - in case of an interrupt

establishRoute

protected void establishRoute(HttpRoute route,
                              org.apache.http.protocol.HttpContext context)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Establishes the target route.

Parameters:
route - the route to establish
context - the context for the request execution
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem

createTunnelToTarget

protected boolean createTunnelToTarget(HttpRoute route,
                                       org.apache.http.protocol.HttpContext context)
                                throws org.apache.http.HttpException,
                                       java.io.IOException
Creates a tunnel to the target server. The connection must be established to the (last) proxy. A CONNECT request for tunnelling through the proxy will be created and sent, the response received and checked. This method does not update the connection with information about the tunnel, that is left to the caller.

Parameters:
route - the route to establish
context - the context for request execution
Returns:
true if the tunnelled route is secure, false otherwise. The implementation here always returns false, but derived classes may override.
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem

createTunnelToProxy

protected boolean createTunnelToProxy(HttpRoute route,
                                      int hop,
                                      org.apache.http.protocol.HttpContext context)
                               throws org.apache.http.HttpException,
                                      java.io.IOException
Creates a tunnel to an intermediate proxy. This method is not implemented in this class. It just throws an exception here.

Parameters:
route - the route to establish
hop - the hop in the route to establish now. route.getHopTarget(hop) will return the proxy to tunnel to.
context - the context for request execution
Returns:
true if the partially tunnelled connection is secure, false otherwise.
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem

createConnectRequest

protected org.apache.http.HttpRequest createConnectRequest(HttpRoute route,
                                                           org.apache.http.protocol.HttpContext context)
Creates the CONNECT request for tunnelling. Called by createTunnelToTarget.

Parameters:
route - the route to establish
context - the context for request execution
Returns:
the CONNECT request for tunnelling

handleResponse

protected RoutedRequest handleResponse(RoutedRequest roureq,
                                       org.apache.http.HttpRequest request,
                                       org.apache.http.HttpResponse response,
                                       org.apache.http.protocol.HttpContext context)
                                throws org.apache.http.HttpException,
                                       java.io.IOException
Analyzes a response to check need for a followup.

Parameters:
roureq - the request and route. This is the same object as was passed to wrapRequest(HttpRequest).
request - the request that was actually sent. This is the object returned by wrapRequest(HttpRequest).
response - the response to analayze
context - the context used for the current request execution
Returns:
the followup request and route if there is a followup, or null if the response should be returned as is
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.