public interface HttpClient extends ClientSSLSupport<HttpClient>, TCPSupport<HttpClient>
As well as HTTP requests, the client can act as a factory for WebSocket websockets
.
If an instance is instantiated from an event loop then the handlers of the instance will always be called on that same event loop. If an instance is instantiated from some other arbitrary Java thread (i.e. when running embedded) then and event loop will be assigned to the instance and used when any of its handlers are called.
Instances of HttpClient are thread-safe.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the HTTP client.
|
HttpClientRequest |
connect(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP CONNECT request with the specified uri . |
HttpClient |
connectWebsocket(java.lang.String uri,
Handler<WebSocket> wsConnect)
Attempt to connect an HTML5 websocket to the specified URI
|
HttpClient |
connectWebsocket(java.lang.String uri,
WebSocketVersion wsVersion,
Handler<WebSocket> wsConnect)
Attempt to connect an HTML5 websocket to the specified URI
|
HttpClient |
connectWebsocket(java.lang.String uri,
WebSocketVersion wsVersion,
MultiMap headers,
Handler<WebSocket> wsConnect)
Attempt to connect an HTML5 websocket to the specified URI
|
HttpClientRequest |
delete(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP DELETE request with the specified uri . |
HttpClient |
exceptionHandler(Handler<java.lang.Throwable> handler)
Set an exception handler
|
HttpClientRequest |
get(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP GET request with the specified uri . |
int |
getConnectTimeout() |
java.lang.String |
getHost() |
int |
getMaxPoolSize()
Returns the maximum number of connections in the pool
|
int |
getMaxWebSocketFrameSize()
Get the maximum websocket frame size in bytes.
|
HttpClient |
getNow(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This is a quick version of the
get(String, org.vertx.java.core.Handler)
method where you do not want to do anything with the request before sending. |
HttpClient |
getNow(java.lang.String uri,
MultiMap headers,
Handler<HttpClientResponse> responseHandler)
This method works in the same manner as
getNow(String, org.vertx.java.core.Handler) ,
except that it allows you specify a set of headers that will be sent with the request. |
int |
getPort() |
boolean |
getTryUseCompression()
Returns
true if the HttpClient should try to use compression. |
HttpClientRequest |
head(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP HEAD request with the specified uri . |
boolean |
isKeepAlive() |
boolean |
isVerifyHost() |
HttpClientRequest |
options(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP OPTIONS request with the specified uri . |
HttpClientRequest |
patch(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP PATCH request with the specified uri . |
HttpClientRequest |
post(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP POST request with the specified uri . |
HttpClientRequest |
put(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP PUT request with the specified uri . |
HttpClientRequest |
request(java.lang.String method,
java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP request with the specified uri . |
HttpClient |
setConnectTimeout(int timeout)
Set the connect timeout in milliseconds.
|
HttpClient |
setHost(java.lang.String host)
Set the host that the client will attempt to connect to the server on to
host . |
HttpClient |
setKeepAlive(boolean keepAlive)
If
keepAlive is true then, after the request has ended the connection will be returned to the pool
where it can be used by another request. |
HttpClient |
setMaxPoolSize(int maxConnections)
Set the maximum pool size
|
HttpClient |
setMaxWebSocketFrameSize(int maxSize)
Sets the maximum websocket frame size in bytes.
|
HttpClient |
setPort(int port)
Set the port that the client will attempt to connect to the server on to
port . |
HttpClient |
setTryUseCompression(boolean tryUseCompression)
Set if the
HttpClient should try to use compression. |
HttpClient |
setVerifyHost(boolean verifyHost)
If
verifyHost is true , then the client will try to validate the remote server's certificate
hostname against the requested host. |
HttpClientRequest |
trace(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This method returns an
HttpClientRequest instance which represents an HTTP TRACE request with the specified uri . |
isTrustAll, setTrustAll
getKeyStorePassword, getKeyStorePath, getTrustStorePassword, getTrustStorePath, isSSL, setKeyStorePassword, setKeyStorePath, setSSL, setTrustStorePassword, setTrustStorePath
getSoLinger, isTCPKeepAlive, isTCPNoDelay, isUsePooledBuffers, setSoLinger, setTCPKeepAlive, setTCPNoDelay, setUsePooledBuffers
getReceiveBufferSize, getSendBufferSize, getTrafficClass, isReuseAddress, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setTrafficClass
HttpClient exceptionHandler(Handler<java.lang.Throwable> handler)
HttpClient setMaxPoolSize(int maxConnections)
The client will maintain up to maxConnections
HTTP connections in an internal pool
int getMaxPoolSize()
HttpClient setKeepAlive(boolean keepAlive)
keepAlive
is true
then, after the request has ended the connection will be returned to the pool
where it can be used by another request. In this manner, many HTTP requests can be pipe-lined over an HTTP connection.
Keep alive connections will not be closed until the close()
method is invoked.
If keepAlive
is false
then a new connection will be created for each request and it won't ever go in the pool,
the connection will closed after the response has been received. Even with no keep alive,
the client will not allow more than getMaxPoolSize()
connections to be created at any one time.
boolean isKeepAlive()
HttpClient setPort(int port)
port
. The default value is
80
int getPort()
HttpClient setHost(java.lang.String host)
host
. The default value is
localhost
java.lang.String getHost()
HttpClient connectWebsocket(java.lang.String uri, Handler<WebSocket> wsConnect)
The connect is done asynchronously and wsConnect
is called back with the websocket
HttpClient connectWebsocket(java.lang.String uri, WebSocketVersion wsVersion, Handler<WebSocket> wsConnect)
This version of the method allows you to specify the websockets version using the wsVersion parameter
The connect is done asynchronously and wsConnect
is called back with the websocket
HttpClient connectWebsocket(java.lang.String uri, WebSocketVersion wsVersion, MultiMap headers, Handler<WebSocket> wsConnect)
This version of the method allows you to specify the websockets version using the wsVersion parameter
You can also specify a set of headers to append to the upgrade request
The connect is done asynchronously and wsConnect
is called back with the websocket
HttpClient getNow(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
get(String, org.vertx.java.core.Handler)
method where you do not want to do anything with the request before sending.
Normally with any of the HTTP methods you create the request then when you are ready to send it you call
HttpClientRequest.end()
on it. With this method the request is immediately sent.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClient getNow(java.lang.String uri, MultiMap headers, Handler<HttpClientResponse> responseHandler)
getNow(String, org.vertx.java.core.Handler)
,
except that it allows you specify a set of headers
that will be sent with the request.HttpClientRequest options(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP OPTIONS request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest get(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP GET request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest head(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP HEAD request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest post(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP POST request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest put(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP PUT request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest delete(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP DELETE request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest trace(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP TRACE request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest connect(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP CONNECT request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
Because of the nature of CONNECT the connection is automatically upgraded to raw TCP if a response code of 200 is received from the
remote peer. In this case you are able to get hold of the raw TCP socket via calling HttpClientResponse.netSocket()
.
HttpClientRequest patch(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP PATCH request with the specified uri
.
When an HTTP response is received from the server the responseHandler
is called passing in the response.
HttpClientRequest request(java.lang.String method, java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientRequest
instance which represents an HTTP request with the specified uri
.
The specific HTTP method (e.g. GET, POST, PUT etc) is specified using the parameter method
When an HTTP response is received from the server the responseHandler
is called passing in the response.
void close()
HttpClient setVerifyHost(boolean verifyHost)
verifyHost
is true
, then the client will try to validate the remote server's certificate
hostname against the requested host. Should default to 'true'.
This method should only be used in SSL mode, i.e. after SSLSupport.setSSL(boolean)
has been set to true
.boolean isVerifyHost()
HttpClient setConnectTimeout(int timeout)
int getConnectTimeout()
HttpClient setTryUseCompression(boolean tryUseCompression)
HttpClient
should try to use compression.boolean getTryUseCompression()
true
if the HttpClient
should try to use compression.HttpClient setMaxWebSocketFrameSize(int maxSize)
maxSize
- The size in bytesint getMaxWebSocketFrameSize()