java.lang.AutoCloseablepublic class SocketHttpClient
extends java.lang.Object
implements java.lang.AutoCloseable
| Constructor | Description |
|---|---|
SocketHttpClient(WebServer webServer) |
Creates the instance linked with the provided webserver.
|
| Modifier and Type | Method | Description |
|---|---|---|
static void |
assertConnectionIsClosed(SocketHttpClient s) |
Assert that the socket associated with the provided client is closed.
|
static void |
assertConnectionIsOpen(SocketHttpClient s) |
Assert that the socket associated with the provided client is working and open.
|
void |
close() |
|
static java.lang.StringBuilder |
longData(int bytes) |
Generates at least
bytes number of bytes as a sequence of decimal numbers delimited
by newlines. |
java.lang.String |
receive() |
Read the data from the socket.
|
void |
request(io.helidon.common.http.Http.Method method) |
Sends a request to the webserver.
|
void |
request(io.helidon.common.http.Http.Method method,
java.lang.String payload) |
Sends a request to the webserver.
|
void |
request(io.helidon.common.http.Http.Method method,
java.lang.String path,
java.lang.String payload) |
Sends a request to the webserver.
|
void |
request(io.helidon.common.http.Http.Method method,
java.lang.String path,
java.lang.String payload,
java.lang.Iterable<java.lang.String> headers) |
Sends a request to the webserver.
|
static java.lang.String |
sendAndReceive(io.helidon.common.http.Http.Method method,
java.lang.String payload,
WebServer webServer) |
A helper method that sends the given payload with the provided method to the webserver.
|
static java.lang.String |
sendAndReceive(java.lang.String path,
io.helidon.common.http.Http.Method method,
java.lang.String payload,
WebServer webServer) |
A helper method that sends the given payload at the given path with the provided method and headers to the webserver.
|
static java.lang.String |
sendAndReceive(java.lang.String path,
io.helidon.common.http.Http.Method method,
java.lang.String payload,
java.lang.Iterable<java.lang.String> headers,
WebServer webServer) |
A helper method that sends the given payload at the given path with the provided method to the webserver.
|
protected void |
sendPayload(java.io.PrintWriter pw,
java.lang.String payload) |
Override this to send a specific payload.
|
public SocketHttpClient(WebServer webServer) throws java.io.IOException
webServer - the webserver to link this client withjava.io.IOException - in case of an errorpublic static java.lang.String sendAndReceive(io.helidon.common.http.Http.Method method,
java.lang.String payload,
WebServer webServer)
throws java.lang.Exception
method - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)webServer - the webserver where to send the payloadHTTP/1.1 200 OK line for instance)java.lang.Exception - in case of an errorpublic static java.lang.String sendAndReceive(java.lang.String path,
io.helidon.common.http.Http.Method method,
java.lang.String payload,
WebServer webServer)
throws java.lang.Exception
path - the path to accessmethod - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)webServer - the webserver where to send the payloadHTTP/1.1 200 OK line for instance)java.lang.Exception - in case of an errorpublic static java.lang.String sendAndReceive(java.lang.String path,
io.helidon.common.http.Http.Method method,
java.lang.String payload,
java.lang.Iterable<java.lang.String> headers,
WebServer webServer)
throws java.lang.Exception
path - the path to accessmethod - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)headers - HTTP request headerswebServer - the webserver where to send the payloadHTTP/1.1 200 OK line for instance)java.lang.Exception - in case of an errorpublic static void assertConnectionIsOpen(SocketHttpClient s) throws java.io.IOException
s - the socket clientjava.io.IOException - in case of an IO errorpublic static void assertConnectionIsClosed(SocketHttpClient s) throws java.io.IOException
s - the socket clientjava.io.IOException - in case of an IO errorpublic static java.lang.StringBuilder longData(int bytes)
bytes number of bytes as a sequence of decimal numbers delimited
by newlines.bytes - the amount of bytes to generate (might get little bit more than that)public java.lang.String receive()
throws java.io.IOException
java.io.IOException - in case of an IO errorpublic void request(io.helidon.common.http.Http.Method method)
throws java.io.IOException
method - the http methodjava.io.IOException - in case of an IO errorpublic void request(io.helidon.common.http.Http.Method method,
java.lang.String payload)
throws java.io.IOException
method - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)java.io.IOException - in case of an IO errorpublic void request(io.helidon.common.http.Http.Method method,
java.lang.String path,
java.lang.String payload)
throws java.io.IOException
path - the path to accessmethod - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)java.io.IOException - in case of an IO errorpublic void request(io.helidon.common.http.Http.Method method,
java.lang.String path,
java.lang.String payload,
java.lang.Iterable<java.lang.String> headers)
throws java.io.IOException
path - the path to accessmethod - the http methodpayload - the payload to send (must be without the newlines;
otherwise it's not a valid payload)headers - the headers (e.g., Content-Type: application/json)java.io.IOException - in case of an IO errorprotected void sendPayload(java.io.PrintWriter pw,
java.lang.String payload)
pw - the print writer where to write the payloadpayload - the payload as provided in the receive() methods.public void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.ExceptionCopyright © 2018 Oracle Corporation. All rights reserved.