org.apache.http.protocol
Class HttpRequestExecutor

java.lang.Object
  extended by org.apache.http.protocol.AbstractHttpProcessor
      extended by org.apache.http.protocol.HttpRequestExecutor

public class HttpRequestExecutor
extends AbstractHttpProcessor

Sends HTTP requests and receives the responses. Takes care of request preprocessing and response postprocessing by the respective interceptors.

Since:
4.0
Version:
$Revision: 385867 $
Author:
Oleg Kalnichevski

Field Summary
protected  HttpContext defaultContext
          The context holding the default context information.
protected static int WAIT_FOR_CONTINUE_MS
           
 
Constructor Summary
HttpRequestExecutor()
          Create a new request executor.
HttpRequestExecutor(HttpContext parentContext)
          Create a new request executor with default context information.
 
Method Summary
protected  boolean canResponseHaveBody(HttpRequest request, HttpResponse response)
          Decide whether a response comes with an entity.
protected  void doEstablishConnection(HttpClientConnection conn, HttpHost target, HttpParams params)
          Establish a connection with the target host.
protected  void doFinishResponse(HttpResponse response, HttpContext context)
          Finish a response.
protected  void doPrepareRequest(HttpRequest request, HttpContext context)
          Prepare a request for sending.
protected  HttpResponse doReceiveResponse(HttpRequest request, HttpClientConnection conn, HttpContext context)
          Wait for and receive a response.
protected  HttpResponse doSendRequest(HttpRequest request, HttpClientConnection conn, HttpContext context)
          Send a request over a connection.
 HttpResponse execute(HttpRequest request, HttpClientConnection conn)
          Synchronously send a request and obtain the response.
 HttpContext getContext()
          Obtain the default context information.
 HttpParams getParams()
          Obtain the parameters for executing requests.
 HttpRequestRetryHandler getRetryHandler()
          Obtain the retry handler.
 void setParams(HttpParams params)
          Set new parameters for executing requests.
 void setRetryHandler(HttpRequestRetryHandler retryhandler)
          Set the retry handler.
 
Methods inherited from class org.apache.http.protocol.AbstractHttpProcessor
addInterceptor, addInterceptor, clearInterceptors, postprocessResponse, preprocessRequest, removeInterceptor, removeInterceptor, removeInterceptors, setInterceptors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WAIT_FOR_CONTINUE_MS

protected static final int WAIT_FOR_CONTINUE_MS
See Also:
Constant Field Values

defaultContext

protected final HttpContext defaultContext
The context holding the default context information.

Constructor Detail

HttpRequestExecutor

public HttpRequestExecutor(HttpContext parentContext)
Create a new request executor with default context information. The attributes in the argument context will be made available in the context used for executing a request.

Parameters:
parentContext - the default context information, or null

HttpRequestExecutor

public HttpRequestExecutor()
Create a new request executor.

Method Detail

getContext

public final HttpContext getContext()
Obtain the default context information. This is not necessarily the same object passed to the constructor, but the default context information will be available here.

Returns:
the context holding the default context information

getParams

public final HttpParams getParams()
Obtain the parameters for executing requests.

Returns:
the currently installed parameters

setParams

public final void setParams(HttpParams params)
Set new parameters for executing requests.

Parameters:
params - the new parameters to use from now on

getRetryHandler

public final HttpRequestRetryHandler getRetryHandler()
Obtain the retry handler.

Returns:
the handler deciding whether a request should be retried

setRetryHandler

public final void setRetryHandler(HttpRequestRetryHandler retryhandler)
Set the retry handler.

Parameters:
retryhandler - the handler to decide whether a request should be retried

canResponseHaveBody

protected boolean canResponseHaveBody(HttpRequest request,
                                      HttpResponse response)
Decide whether a response comes with an entity. The implementation in this class is based on RFC 2616. Unknown methods and response codes are supposed to indicate responses with an entity.
Derived executors can override this method to handle methods and response codes not specified in RFC 2616.

Parameters:
request - the request, to obtain the executed method
response - the response, to obtain the status code

execute

public HttpResponse execute(HttpRequest request,
                            HttpClientConnection conn)
                     throws java.io.IOException,
                            HttpException
Synchronously send a request and obtain the response.

Parameters:
request - the request to send. It will be preprocessed.
conn - the connection over which to send. The target host has to be set before calling this method.
Returns:
the response to the request, postprocessed
Throws:
HttpException - in case of a protocol or processing problem
java.io.IOException - in case of an I/O problem

doPrepareRequest

protected void doPrepareRequest(HttpRequest request,
                                HttpContext context)
                         throws HttpException,
                                java.io.IOException
Prepare a request for sending.

Parameters:
request - the request to prepare
context - the context for sending the request
Throws:
HttpException - in case of a protocol or processing problem
java.io.IOException - in case of an I/O problem

doEstablishConnection

protected void doEstablishConnection(HttpClientConnection conn,
                                     HttpHost target,
                                     HttpParams params)
                              throws HttpException,
                                     java.io.IOException
Establish a connection with the target host.

Parameters:
conn - the HTTP connection
target - the target host for the request, or null to send to the host already set as the connection target
Throws:
HttpException - in case of a problem
java.io.IOException - in case of an IO problem

doSendRequest

protected HttpResponse doSendRequest(HttpRequest request,
                                     HttpClientConnection conn,
                                     HttpContext context)
                              throws java.io.IOException,
                                     HttpException
Send a request over a connection. This method also handles the expect-continue handshake if necessary. If it does not have to handle an expect-continue handshake, it will not use the connection for reading or anything else that depends on data coming in over the connection.

Parameters:
request - the request to send, already prepared
conn - the connection over which to send the request, already established
context - the context for sending the request
Returns:
a terminal response received as part of an expect-continue handshake, or null if the expect-continue handshake is not used
Throws:
HttpException - in case of a protocol or processing problem
java.io.IOException - in case of an I/O problem

doReceiveResponse

protected HttpResponse doReceiveResponse(HttpRequest request,
                                         HttpClientConnection conn,
                                         HttpContext context)
                                  throws HttpException,
                                         java.io.IOException
Wait for and receive a response. This method will automatically ignore intermediate responses with status code 1xx.

Parameters:
request - the request for which to obtain the response
conn - the connection over which the request was sent
context - the context for receiving the response
Returns:
the final response, not yet post-processed
Throws:
HttpException - in case of a protocol or processing problem
java.io.IOException - in case of an I/O problem

doFinishResponse

protected void doFinishResponse(HttpResponse response,
                                HttpContext context)
                         throws HttpException,
                                java.io.IOException
Finish a response. This includes post-processing of the response object. It does not read the response entity, if any. It does not allow for immediate re-use of the connection over which the response is coming in.

Parameters:
response - the response object to finish
context - the context for post-processing the response
Throws:
HttpException - in case of a protocol or processing problem
java.io.IOException - in case of an I/O problem


Copyright 2005-2005-2006 Apache Software Foundation. All Rights Reserved.