public class DefaultHttpClient extends java.lang.Object implements HttpClient
| Constructor and Description |
|---|
DefaultHttpClient(VertxInternal vertx) |
| 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. |
DefaultHttpClient |
exceptionHandler(Handler<java.lang.Throwable> handler)
Set an exception handler
|
protected void |
finalize() |
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() |
java.lang.String |
getKeyStorePassword() |
java.lang.String |
getKeyStorePath() |
int |
getMaxPoolSize()
Returns the maximum number of connections in the pool
|
HttpClient |
getNow(java.lang.String uri,
Handler<HttpClientResponse> responseHandler)
This is a quick version of the
HttpClient.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
HttpClient.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() |
int |
getReceiveBufferSize() |
int |
getSendBufferSize() |
int |
getSoLinger() |
int |
getTrafficClass() |
java.lang.String |
getTrustStorePassword() |
java.lang.String |
getTrustStorePath() |
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 |
isReuseAddress() |
boolean |
isSSL() |
boolean |
isTCPKeepAlive() |
boolean |
isTCPNoDelay() |
boolean |
isTrustAll() |
boolean |
isUsePooledBuffers() |
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. |
DefaultHttpClient |
setConnectTimeout(int timeout)
Set the connect timeout in milliseconds.
|
DefaultHttpClient |
setHost(java.lang.String host)
Set the host that the client will attempt to connect to the server on to
host. |
DefaultHttpClient |
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. |
DefaultHttpClient |
setKeyStorePassword(java.lang.String pwd)
Set the password for the SSL key store.
|
DefaultHttpClient |
setKeyStorePath(java.lang.String path)
Set the path to the SSL key store.
|
DefaultHttpClient |
setMaxPoolSize(int maxConnections)
Set the maximum pool size
|
DefaultHttpClient |
setPort(int port)
Set the port that the client will attempt to connect to the server on to
port. |
DefaultHttpClient |
setReceiveBufferSize(int size)
Set the TCP receive buffer size for connections created by this instance to
size in bytes. |
DefaultHttpClient |
setReuseAddress(boolean reuse)
Set the TCP reuseAddress setting for connections created by this instance to
reuse. |
DefaultHttpClient |
setSendBufferSize(int size)
Set the TCP send buffer size for connections created by this instance to
size in bytes. |
DefaultHttpClient |
setSoLinger(int linger)
Set the TCP soLinger setting for connections created by this instance to
linger. |
DefaultHttpClient |
setSSL(boolean ssl)
If
ssl is true, this signifies that any connections will be SSL connections. |
DefaultHttpClient |
setTCPKeepAlive(boolean keepAlive)
Set the TCP keepAlive setting for connections created by this instance to
keepAlive. |
DefaultHttpClient |
setTCPNoDelay(boolean tcpNoDelay)
If
tcpNoDelay is set to true then Nagle's algorithm
will turned off for the TCP connections created by this instance. |
DefaultHttpClient |
setTrafficClass(int trafficClass)
Set the TCP trafficClass setting for connections created by this instance to
trafficClass. |
DefaultHttpClient |
setTrustAll(boolean trustAll)
If you want an SSL client to trust *all* server certificates rather than match them
against those in its trust store, you can set this to true.
|
DefaultHttpClient |
setTrustStorePassword(java.lang.String pwd)
Set the password for the SSL trust store.
|
DefaultHttpClient |
setTrustStorePath(java.lang.String path)
Set the path to the SSL trust store.
|
HttpClient |
setUsePooledBuffers(boolean pooledBuffers)
Set if vertx should use pooled buffers for performance reasons.
|
DefaultHttpClient |
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. |
public DefaultHttpClient(VertxInternal vertx)
public DefaultHttpClient exceptionHandler(Handler<java.lang.Throwable> handler)
HttpClientexceptionHandler in interface HttpClientpublic DefaultHttpClient setMaxPoolSize(int maxConnections)
HttpClient
The client will maintain up to maxConnections HTTP connections in an internal pool
setMaxPoolSize in interface HttpClientpublic int getMaxPoolSize()
HttpClientgetMaxPoolSize in interface HttpClientpublic DefaultHttpClient setKeepAlive(boolean keepAlive)
HttpClientkeepAlive 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 HttpClient.getMaxPoolSize() connections to be created at any one time.
setKeepAlive in interface HttpClientpublic boolean isKeepAlive()
isKeepAlive in interface HttpClientpublic DefaultHttpClient setPort(int port)
HttpClientport. The default value is
80setPort in interface HttpClientpublic int getPort()
getPort in interface HttpClientpublic DefaultHttpClient setHost(java.lang.String host)
HttpClienthost. The default value is
localhostsetHost in interface HttpClientpublic java.lang.String getHost()
getHost in interface HttpClientpublic HttpClient connectWebsocket(java.lang.String uri, Handler<WebSocket> wsConnect)
HttpClient
The connect is done asynchronously and wsConnect is called back with the websocket
connectWebsocket in interface HttpClientpublic HttpClient connectWebsocket(java.lang.String uri, WebSocketVersion wsVersion, Handler<WebSocket> wsConnect)
HttpClient
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
connectWebsocket in interface HttpClientpublic HttpClient connectWebsocket(java.lang.String uri, WebSocketVersion wsVersion, MultiMap headers, Handler<WebSocket> wsConnect)
HttpClient
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
connectWebsocket in interface HttpClientpublic HttpClient getNow(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClient.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.
getNow in interface HttpClientpublic HttpClient getNow(java.lang.String uri, MultiMap headers, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClient.getNow(String, org.vertx.java.core.Handler),
except that it allows you specify a set of headers that will be sent with the request.getNow in interface HttpClientpublic HttpClientRequest options(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
options in interface HttpClientpublic HttpClientRequest get(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
get in interface HttpClientpublic HttpClientRequest head(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
head in interface HttpClientpublic HttpClientRequest post(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
post in interface HttpClientpublic HttpClientRequest put(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
put in interface HttpClientpublic HttpClientRequest delete(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
delete in interface HttpClientpublic HttpClientRequest trace(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
trace in interface HttpClientpublic HttpClientRequest connect(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
connect in interface HttpClientpublic HttpClientRequest patch(java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
patch in interface HttpClientpublic HttpClientRequest request(java.lang.String method, java.lang.String uri, Handler<HttpClientResponse> responseHandler)
HttpClientHttpClientRequest 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.
request in interface HttpClientpublic void close()
HttpClientclose in interface HttpClientpublic DefaultHttpClient setSSL(boolean ssl)
SSLSupportssl is true, this signifies that any connections will be SSL connections.setSSL in interface SSLSupport<HttpClient>public DefaultHttpClient setVerifyHost(boolean verifyHost)
HttpClientverifyHost 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.setVerifyHost in interface HttpClientpublic DefaultHttpClient setKeyStorePath(java.lang.String path)
SSLSupportSSLSupport.setSSL(boolean)
has been set to true.The SSL key store is a standard Java Key Store, and will contain the client certificate. Client certificates are only required if the server requests client authentication.
setKeyStorePath in interface SSLSupport<HttpClient>public DefaultHttpClient setKeyStorePassword(java.lang.String pwd)
SSLSupportSSLSupport.setSSL(boolean)
has been set to true.setKeyStorePassword in interface SSLSupport<HttpClient>public DefaultHttpClient setTrustStorePath(java.lang.String path)
SSLSupportSSLSupport.setSSL(boolean)
has been set to true.The trust store is a standard Java Key Store, and should contain the certificates of any servers that the client trusts.
setTrustStorePath in interface SSLSupport<HttpClient>public DefaultHttpClient setTrustStorePassword(java.lang.String pwd)
SSLSupportSSLSupport.setSSL(boolean)
has been set to true.setTrustStorePassword in interface SSLSupport<HttpClient>public DefaultHttpClient setTrustAll(boolean trustAll)
ClientSSLSupportUse this with caution as you may be exposed to "main in the middle" attacks
setTrustAll in interface ClientSSLSupport<HttpClient>trustAll - Set to true if you want to trust all server certificatespublic DefaultHttpClient setTCPNoDelay(boolean tcpNoDelay)
TCPSupporttcpNoDelay is set to true then Nagle's algorithm
will turned off for the TCP connections created by this instance.setTCPNoDelay in interface TCPSupport<HttpClient>public DefaultHttpClient setSendBufferSize(int size)
TCPSupportsize in bytes.setSendBufferSize in interface TCPSupport<HttpClient>public DefaultHttpClient setReceiveBufferSize(int size)
TCPSupportsize in bytes.setReceiveBufferSize in interface TCPSupport<HttpClient>public DefaultHttpClient setTCPKeepAlive(boolean keepAlive)
TCPSupportkeepAlive.setTCPKeepAlive in interface TCPSupport<HttpClient>public DefaultHttpClient setReuseAddress(boolean reuse)
TCPSupportreuse.setReuseAddress in interface TCPSupport<HttpClient>public DefaultHttpClient setSoLinger(int linger)
TCPSupportlinger.
Using a negative value will disable soLinger.setSoLinger in interface TCPSupport<HttpClient>public DefaultHttpClient setTrafficClass(int trafficClass)
TCPSupporttrafficClass.setTrafficClass in interface TCPSupport<HttpClient>public DefaultHttpClient setConnectTimeout(int timeout)
HttpClientsetConnectTimeout in interface HttpClientpublic boolean isTCPNoDelay()
isTCPNoDelay in interface TCPSupport<HttpClient>public int getSendBufferSize()
getSendBufferSize in interface TCPSupport<HttpClient>public int getReceiveBufferSize()
getReceiveBufferSize in interface TCPSupport<HttpClient>public boolean isTCPKeepAlive()
isTCPKeepAlive in interface TCPSupport<HttpClient>public boolean isReuseAddress()
isReuseAddress in interface TCPSupport<HttpClient>public int getSoLinger()
getSoLinger in interface TCPSupport<HttpClient>public int getTrafficClass()
getTrafficClass in interface TCPSupport<HttpClient>public int getConnectTimeout()
getConnectTimeout in interface HttpClientpublic boolean isSSL()
isSSL in interface SSLSupport<HttpClient>public boolean isVerifyHost()
isVerifyHost in interface HttpClientpublic boolean isTrustAll()
isTrustAll in interface ClientSSLSupport<HttpClient>public java.lang.String getKeyStorePath()
getKeyStorePath in interface SSLSupport<HttpClient>public java.lang.String getKeyStorePassword()
getKeyStorePassword in interface SSLSupport<HttpClient>public java.lang.String getTrustStorePath()
getTrustStorePath in interface SSLSupport<HttpClient>public java.lang.String getTrustStorePassword()
getTrustStorePassword in interface SSLSupport<HttpClient>public HttpClient setUsePooledBuffers(boolean pooledBuffers)
TCPSupportsetUsePooledBuffers in interface TCPSupport<HttpClient>public boolean isUsePooledBuffers()
isUsePooledBuffers in interface TCPSupport<HttpClient>true if pooled buffers are usedprotected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable