Package org.apache.http.protocol
Class HttpRequestExecutor
java.lang.Object
org.apache.http.protocol.HttpRequestExecutor
public class HttpRequestExecutor extends Object
Sends HTTP requests and receives the responses.
Takes care of request preprocessing and response postprocessing
by the respective interceptors.
- Since:
- 4.0
- Version:
- $Revision: 576073 $
- Author:
- Oleg Kalnichevski
-
Constructor Summary
Constructors Constructor Description HttpRequestExecutor()Create a new request executor. -
Method Summary
Modifier and Type Method Description protected booleancanResponseHaveBody(HttpRequest request, HttpResponse response)Decide whether a response comes with an entity.protected HttpResponsedoReceiveResponse(HttpRequest request, HttpClientConnection conn, HttpContext context)Wait for and receive a response.protected HttpResponsedoSendRequest(HttpRequest request, HttpClientConnection conn, HttpContext context)Send a request over a connection.HttpResponseexecute(HttpRequest request, HttpClientConnection conn, HttpContext context)Synchronously send a request and obtain the response.voidpostProcess(HttpResponse response, HttpProcessor processor, HttpContext context)Finish a response.voidpreProcess(HttpRequest request, HttpProcessor processor, HttpContext context)Prepare a request for sending.
-
Constructor Details
-
HttpRequestExecutor
public HttpRequestExecutor()Create a new request executor.
-
-
Method Details
-
canResponseHaveBody
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 methodresponse- the response, to obtain the status code
-
execute
public HttpResponse execute(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpExceptionSynchronously send a request and obtain the response.- Parameters:
request- the request to send. It will be preprocessed.conn- the open connection over which to send- Returns:
- the response to the request, postprocessed
- Throws:
HttpException- in case of a protocol or processing problemIOException- in case of an I/O problem
-
preProcess
public void preProcess(HttpRequest request, HttpProcessor processor, HttpContext context) throws HttpException, IOExceptionPrepare a request for sending.- Parameters:
request- the request to prepareprocessor- the processor to usecontext- the context for sending the request- Throws:
HttpException- in case of a protocol or processing problemIOException- in case of an I/O problem
-
doSendRequest
protected HttpResponse doSendRequest(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpExceptionSend 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, alreadypreprocessedconn- the connection over which to send the request, already establishedcontext- the context for sending the request- Returns:
- a terminal response received as part of an expect-continue
handshake, or
nullif the expect-continue handshake is not used - Throws:
HttpException- in case of a protocol or processing problemIOException- in case of an I/O problem
-
doReceiveResponse
protected HttpResponse doReceiveResponse(HttpRequest request, HttpClientConnection conn, HttpContext context) throws HttpException, IOExceptionWait 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 responseconn- the connection over which the request was sentcontext- the context for receiving the response- Returns:
- the final response, not yet post-processed
- Throws:
HttpException- in case of a protocol or processing problemIOException- in case of an I/O problem
-
postProcess
public void postProcess(HttpResponse response, HttpProcessor processor, HttpContext context) throws HttpException, IOExceptionFinish 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 finishprocessor- the processor to usecontext- the context for post-processing the response- Throws:
HttpException- in case of a protocol or processing problemIOException- in case of an I/O problem
-