public class HTTPClient
extends org.threadly.util.AbstractService
This is a HTTPClient for doing many simple HTTPRequests. Every request will be make a new connection and requests
can be done in parallel. This is mainly used for doing many smaller Request and Response messages as the full Request/Response
is kept in memory and are not handled as streams. See HTTPStreamClient
for use with large HTTP data sets.
Modifier and Type | Class | Description |
---|---|---|
static class |
HTTPClient.HTTPResponseData |
This is a simple, full HttpResponse with data.
|
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_CONCURRENT |
|
static int |
DEFAULT_MAX_IDLE |
|
static int |
DEFAULT_TIMEOUT |
|
static int |
MAX_HTTP_RESPONSE |
Constructor | Description |
---|---|
HTTPClient() |
|
HTTPClient(int maxConcurrent,
int maxResponseSize) |
This constructor will let you set the max Concurrent Requests and max Response Size but will still
create its own
SingleThreadScheduler to use as a threadpool. |
HTTPClient(int maxConcurrent,
int maxResponseSize,
org.threadly.litesockets.SocketExecuter sei) |
This constructor will let you set the max Concurrent Requests and max Response Size
as well as your own
SocketExecuter as the thread pool to use. |
Modifier and Type | Method | Description |
---|---|---|
void |
closeAllClients() |
This forces closed all client connections on this HTTPClient.
|
int |
getInProgressSize() |
Number of HTTPRequests pending on the HTTPClient.
|
long |
getMaxIdleTimeout() |
Checks the configured maximum connection idle time.
|
int |
getOpenConnections() |
Returns the total number of open Client Connections on this HTTPClient.
|
int |
getRequestQueueSize() |
Number of HTTPRequests pending on the HTTPClient.
|
HTTPClient.HTTPResponseData |
request(java.net.URL url) |
Sends a blocking HTTP request.
|
HTTPClient.HTTPResponseData |
request(java.net.URL url,
org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod rm,
java.nio.ByteBuffer bb) |
Sends a blocking HTTP request.
|
HTTPClient.HTTPResponseData |
request(org.threadly.litesockets.protocols.http.request.ClientHTTPRequest request) |
Sends a blocking HTTP request.
|
org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> |
requestAsync(java.net.URL url) |
Sends an asynchronous HTTP request.
|
org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> |
requestAsync(java.net.URL url,
org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod rm,
java.nio.ByteBuffer bb) |
Sends an asynchronous HTTP request.
|
org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> |
requestAsync(org.threadly.litesockets.protocols.http.request.ClientHTTPRequest request) |
Sends an asynchronous HTTP request.
|
void |
setMaxIdleTimeout(long idleTimeout,
java.util.concurrent.TimeUnit unit) |
Sets the max amount of time we will hold onto idle connections.
|
void |
setSSLContext(javax.net.ssl.SSLContext sslctx) |
Sets the
SSLContext to be used for connection using ssl on this client. |
void |
setTimeout(long timeout,
java.util.concurrent.TimeUnit unit) |
Sets the default timeout in milliseconds to wait for HTTPRequest responses from the server.
|
public static final int DEFAULT_CONCURRENT
public static final int DEFAULT_TIMEOUT
public static final int DEFAULT_MAX_IDLE
public static final int MAX_HTTP_RESPONSE
public HTTPClient()
public HTTPClient(int maxConcurrent, int maxResponseSize)
This constructor will let you set the max Concurrent Requests and max Response Size but will still
create its own SingleThreadScheduler
to use as a threadpool.
maxConcurrent
- maximum number of requests to run simultaneously.maxResponseSize
- the maximum responseSize clients are allowed to send.public HTTPClient(int maxConcurrent, int maxResponseSize, org.threadly.litesockets.SocketExecuter sei)
This constructor will let you set the max Concurrent Requests and max Response Size
as well as your own SocketExecuter
as the thread pool to use.
maxConcurrent
- maximum number of requests to run simultaneously.maxResponseSize
- the maximum responseSize clients are allowed to send.sei
- the SocketExecuter to use with these HTTPClients.public int getRequestQueueSize()
public int getInProgressSize()
public int getOpenConnections()
public void setSSLContext(javax.net.ssl.SSLContext sslctx)
SSLContext
to be used for connection using ssl on this client.
If nothing is set a completely open SSLContext
is used providing no cert validation.sslctx
- the SSLContext
to use for ssl connections.public void closeAllClients()
public void setTimeout(long timeout, java.util.concurrent.TimeUnit unit)
timeout
- time in milliseconds to wait for HTTPRequests to finish.unit
- The unit the timeout
value is represented inpublic long getMaxIdleTimeout()
public void setMaxIdleTimeout(long idleTimeout, java.util.concurrent.TimeUnit unit)
idleTimeout
- the time in milliseconds to wait before timing out a connection.unit
- The unit the idleTimeout
value is represented inpublic HTTPClient.HTTPResponseData request(java.net.URL url) throws org.threadly.litesockets.protocols.http.shared.HTTPParsingException
url
- the url to send the request too.HTTPClient.HTTPResponseData
object containing the headers and content of the response.org.threadly.litesockets.protocols.http.shared.HTTPParsingException
- is thrown if the server sends back protocol or a response that is larger then allowed.public HTTPClient.HTTPResponseData request(java.net.URL url, org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod rm, java.nio.ByteBuffer bb) throws org.threadly.litesockets.protocols.http.shared.HTTPParsingException
url
- the url to send the request too.rm
- the HTTPRequestMethod
to use on the request.bb
- the data to put in the body for this request.HTTPClient.HTTPResponseData
object containing the headers and content of the response.org.threadly.litesockets.protocols.http.shared.HTTPParsingException
- is thrown if the server sends back protocol or a response that is larger then allowed.public HTTPClient.HTTPResponseData request(org.threadly.litesockets.protocols.http.request.ClientHTTPRequest request) throws org.threadly.litesockets.protocols.http.shared.HTTPParsingException
request
- the HTTPRequest
to send the server once connected.HTTPClient.HTTPResponseData
object containing the headers and content of the response.org.threadly.litesockets.protocols.http.shared.HTTPParsingException
- is thrown if the server sends back protocol or a response that is larger then allowed.public org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> requestAsync(java.net.URL url)
url
- the URL
to send the request too.ListenableFuture
containing a HTTPClient.HTTPResponseData
object that will be completed when the request is finished,
successfully or with errors.public org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> requestAsync(java.net.URL url, org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod rm, java.nio.ByteBuffer bb)
url
- the URL
to send the request too.rm
- the HTTPRequestMethod
to use on the request.bb
- the data to put in the body for this request.ListenableFuture
containing a HTTPClient.HTTPResponseData
object that will be completed when the request is finished,
successfully or with errors.public org.threadly.concurrent.future.ListenableFuture<HTTPClient.HTTPResponseData> requestAsync(org.threadly.litesockets.protocols.http.request.ClientHTTPRequest request)
request
- the HTTPRequest
to send the server once connected.ListenableFuture
containing a HTTPClient.HTTPResponseData
object that will be completed when the request is finished,
successfully or with errors.