Class JdkHttpClient
- java.lang.Object
-
- com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient
-
- All Implemented Interfaces:
HttpClient
public class JdkHttpClient extends Object implements HttpClient
AHttpClientimplementation based onHttpURLConnection.- Since:
- 4.0.0
- Author:
- Dmytro Nosan
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.github.nosan.embedded.cassandra.commons.web.HttpClient
HttpClient.BodySuppliers
-
-
Constructor Summary
Constructors Constructor Description JdkHttpClient()Creates aJdkHttpClientwith no connection or read timeouts and no proxy.JdkHttpClient(Proxy proxy)Creates aJdkHttpClientwith no connection or read timeouts and a specific proxy.JdkHttpClient(Duration connectTimeout, Duration readTimeout)Creates aJdkHttpClientwith specified connection and read timeouts, but no proxy.JdkHttpClient(Duration connectTimeout, Duration readTimeout, Proxy proxy)Creates aJdkHttpClientwith specified connection and read timeouts and a proxy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpResponsesend(HttpRequest httpRequest, IOSupplier<? extends InputStream> bodySupplier)Sends an HTTP request using theHttpURLConnectionAPI.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.nosan.embedded.cassandra.commons.web.HttpClient
send
-
-
-
-
Constructor Detail
-
JdkHttpClient
public JdkHttpClient()
Creates aJdkHttpClientwith no connection or read timeouts and no proxy.
-
JdkHttpClient
public JdkHttpClient(Proxy proxy)
Creates aJdkHttpClientwith no connection or read timeouts and a specific proxy.- Parameters:
proxy- the proxy to use for HTTP requests (can benull)
-
JdkHttpClient
public JdkHttpClient(Duration connectTimeout, Duration readTimeout)
Creates aJdkHttpClientwith specified connection and read timeouts, but no proxy.- Parameters:
connectTimeout- the duration to wait for establishing a connection (can benull)readTimeout- the duration to wait for reading data (can benull)
-
JdkHttpClient
public JdkHttpClient(Duration connectTimeout, Duration readTimeout, Proxy proxy)
Creates aJdkHttpClientwith specified connection and read timeouts and a proxy.- Parameters:
connectTimeout- the duration to wait for establishing a connection (can benull)readTimeout- the duration to wait for reading data (can benull)proxy- the proxy to use for HTTP requests (can benull)
-
-
Method Detail
-
send
public final HttpResponse send(HttpRequest httpRequest, IOSupplier<? extends InputStream> bodySupplier) throws IOException
Sends an HTTP request using theHttpURLConnectionAPI.- Specified by:
sendin interfaceHttpClient- Parameters:
httpRequest- the HTTP request to send (must not benull)bodySupplier- an optional supplier for the request body (can benull)- Returns:
- the HTTP response representing the server's reply (never
null) - Throws:
IOException- if an I/O error occurs while sending the request or reading the responseIllegalStateException- if the connection cannot be established correctly- See Also:
HttpClient.BodySuppliers
-
-