public class HTTPClient extends TimedEntry
This client allows the asynchronous communication over HTTP.
HTTPClient client = HTTPClient.create("http://127.0.0.1:8080/hello");
// access http://127.0.0.1:8080/hello
client.exchange();
// access http://127.0.0.1:8080/test
client.exchange("/test");
// access http://127.0.0.1:8080/test with a user defined HTTP GET request
HTTPRequest request = new DefaultHTTPGetRequest(); client.exchange(request);
// Close the communication
client.close();
HTTPRequest| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_CLIENT_CONNECTIONS |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection with the server.
|
static void |
closeAllClients()
Close all existing and provided HTTP clients with the
close() method. |
static void |
exchange(HTTPClientDestination dest,
boolean secure)
Sends a simple HTTP GET request to the host, defined by the
create method. |
static void |
exchange(HTTPClientDestination dest,
HTTPRequest request)
Sends a HTTP request (with the path defined in the HTTP header inside the request) to the host, defined by the
create method. |
static void |
exchange(HTTPClientDestination dest,
java.lang.String request,
boolean secure)
Sends a simple HTTP GET request with given request path to the host, defined by the
create method. |
java.lang.String |
getPresetRequest()
Returns the preset HTTP path for the request.
|
TCPConnection |
getTCPConnection()
Returns the TCP connection for this HTTP client.
|
boolean |
isClosed()
Returns
true if the client is closed and cannot be used for a request or false if the
client can still be used. |
void |
kill()
Closes the connection with the server immediately!!!
|
static void |
killAllClients()
Kill all existing and provided HTTP clients with the
kill() method. |
void |
register(ContentType type,
HTTPResponseHandler handler)
Registers a handler with given Internet media type which will handle incoming HTTP responses.
|
protected void |
timedOut()
Runs what should be done at time out.
|
isDisabled, toStringpublic static void killAllClients()
kill() method.public static void closeAllClients()
close() method.public static void exchange(HTTPClientDestination dest, boolean secure)
create method.
The request is not actually sent instantaneously to the host. It is put into a request queue and will be started as soon as possible. The speed depends on the thread scheduler and the Object.notifiy() method.
public static void exchange(HTTPClientDestination dest, java.lang.String request, boolean secure)
create method.
The request is not actually sent instantaneously to the host. It is put into a request queue and will be started as soon as possible. The speed depends on the thread scheduler and the Object.notifiy() method.
request - the HTTP request path.public static void exchange(HTTPClientDestination dest, HTTPRequest request)
create method.
The request is not actually sent instantaneously to the host. It is put into a request queue and will be started as soon as possible. The speed depends on the thread scheduler and the Object.notifiy() method..
request - the HTTP request.public void register(ContentType type, HTTPResponseHandler handler)
This HTTPResponseHandler will ONLY BE USED if NO handler is returned by the HTTPRequest.getResponseHandler(ContentType) method.
type - the Internet media type.handler - the handler which will handle the HTTP response.HTTPRequestpublic java.lang.String getPresetRequest()
public TCPConnection getTCPConnection()
public void close()
This will stop the response and request threads before the connection is closed. The client will try to send the queued requests and handle the incoming responses before the client is closed.
If the client should be closed immediately use the kill() method.
public void kill()
Existing connections will be closed regardless of which thread wants to read the streams. This will stop the response and request threads before the connection is closed.
If the connection should be closed without killing the connections the close()
method should be used.
public boolean isClosed()
true if the client is closed and cannot be used for a request or false if the
client can still be used.true if the client is closed and cannot be used for a request or false if the
client can still be used.protected void timedOut()
TimedEntrytimedOut in class TimedEntry