Top Description Fields Constructors Methods
org.apache.http.protocol

public Class HttpRequestExecutor

extends Object
Class Inheritance
Annotations
@Contract
threading:IMMUTABLE
Imports
java.io.IOException, org.apache.http.HttpClientConnection, .HttpEntityEnclosingRequest, .HttpException, .HttpRequest, .HttpResponse, .HttpStatus, .HttpVersion, .ProtocolException, .ProtocolVersion, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.util.Args

HttpRequestExecutor is a client side HTTP protocol handler based on the blocking (classic) I/O model.

HttpRequestExecutor relies on HttpProcessor to generate mandatory protocol headers for all outgoing messages and apply common, cross-cutting message transformations to all incoming and outgoing messages. Application specific processing can be implemented outside HttpRequestExecutor once the request has been executed and a response has been received.

Since
4.0

Field Summary

Modifier and TypeField and Description
public static final int
private final int

Constructor Summary

AccessConstructor and Description
public
HttpRequestExecutor(final int waitForContinue)

Creates new instance of HttpRequestExecutor.

public

Method Summary

Modifier and TypeMethod and Description
protected boolean
canResponseHaveBody(final HttpRequest
the request, to obtain the executed method
request
,
final HttpResponse
the response, to obtain the status code
response
)

Decide whether a response comes with an entity.

private static void
protected HttpResponse

Returns:

the terminal response, not yet post-processed
doReceiveResponse
(final HttpRequest
the request for which to obtain the response
request
,
final HttpClientConnection
the connection over which the request was sent
conn
,
final HttpContext
the context for receiving the response
context
)

Waits for and receives a response.

protected HttpResponse

Returns:

a terminal response received as part of an expect-continue handshake, or null if the expect-continue handshake is not used
doSendRequest
(final HttpRequest
the request to send, already preprocessed
request
,
final HttpClientConnection
the connection over which to send the request, already established
conn
,
final HttpContext
the context for sending the request
context
)

Send the given request over the given connection.

public HttpResponse

Returns:

the response to the request.
execute
(final HttpRequest
the request to execute.
request
,
final HttpClientConnection
the connection over which to execute the request.
conn
,
final HttpContext context)

Sends the request and obtain a response.

public void
postProcess(final HttpResponse
the response object to post-process
response
,
final HttpProcessor
the processor to use
processor
,
final HttpContext
the context for post-processing the response
context
)

Post-processes the given response using the given protocol processor and completes the process of request execution.

public void
preProcess(final HttpRequest
the request to prepare
request
,
final HttpProcessor
the processor to use
processor
,
final HttpContext
the context for sending the request
context
)

Pre-process the given request using the given protocol processor and initiates the process of request execution.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_WAIT_FOR_CONTINUEback to summary
public static final int DEFAULT_WAIT_FOR_CONTINUE
waitForContinueback to summary
private final int waitForContinue

Constructor Detail

HttpRequestExecutorback to summary
public HttpRequestExecutor(final int waitForContinue)

Creates new instance of HttpRequestExecutor.

Since
4.3
HttpRequestExecutorback to summary
public HttpRequestExecutor()

Method Detail

canResponseHaveBodyback to summary
protected boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response)

Decide whether a response comes with an entity. The implementation in this class is based on RFC 2616.

Derived executors can override this method to handle methods and response codes not specified in RFC 2616.

Parameters
request:HttpRequest

the request, to obtain the executed method

response:HttpResponse

the response, to obtain the status code

closeConnectionback to summary
private static void closeConnection(final HttpClientConnection conn)
doReceiveResponseback to summary
protected HttpResponse doReceiveResponse(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws HttpException, IOException

Waits for and receives a response. This method will automatically ignore intermediate responses with status code 1xx.

Parameters
request:HttpRequest

the request for which to obtain the response

conn:HttpClientConnection

the connection over which the request was sent

context:HttpContext

the context for receiving the response

Returns:HttpResponse

the terminal response, not yet post-processed

Exceptions
HttpException:
in case of HTTP protocol violation or a processing problem.
IOException:
in case of an I/O error.
doSendRequestback to summary
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException

Send the given request over the given 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:HttpRequest

the request to send, already preprocessed

conn:HttpClientConnection

the connection over which to send the request, already established

context:HttpContext

the context for sending the request

Returns:HttpResponse

a terminal response received as part of an expect-continue handshake, or null if the expect-continue handshake is not used

Exceptions
IOException:
in case of an I/O error.
HttpException:
in case of HTTP protocol violation or a processing problem.
executeback to summary
public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException

Sends the request and obtain a response.

Parameters
request:HttpRequest

the request to execute.

conn:HttpClientConnection

the connection over which to execute the request.

Returns:HttpResponse

the response to the request.

Exceptions
IOException:
in case of an I/O error.
HttpException:
in case of HTTP protocol violation or a processing problem.
postProcessback to summary
public void postProcess(final HttpResponse response, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException

Post-processes the given response using the given protocol processor and completes the process of request execution.

This method does not read the response entity, if any. The connection over which content of the response entity is being streamed from cannot be reused until org.apache.http.util.EntityUtils#consume(org.apache.http.HttpEntity) has been invoked.

Parameters
response:HttpResponse

the response object to post-process

processor:HttpProcessor

the processor to use

context:HttpContext

the context for post-processing the response

Exceptions
HttpException:
in case of HTTP protocol violation or a processing problem.
IOException:
in case of an I/O error.
preProcessback to summary
public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException

Pre-process the given request using the given protocol processor and initiates the process of request execution.

Parameters
request:HttpRequest

the request to prepare

processor:HttpProcessor

the processor to use

context:HttpContext

the context for sending the request

Exceptions
HttpException:
in case of HTTP protocol violation or a processing problem.
IOException:
in case of an I/O error.