Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.vertx.groovy.core.http
[Groovy] Class HttpClient

    java.lang.Object
      org.vertx.groovy.core.http.HttpClient

    abstract class HttpClient

An HTTP client that maintains a pool of connections to a specific host, at a specific port. The client supports pipelining of requests.

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 then and event loop will be assigned to the instance and used when any of its handlers are called.

Instances cannot be used from worker verticles

Authors:
  Tim Fox

Field Summary
`protected HttpClient` | `jClient`

Method Summary
`void` | `close()` Close the HTTP client.
`HttpClientRequest` | `connect(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP CONNECT request with the specified `uri`.
`void` | `connectWebsocket(java.lang.String uri, groovy.lang.Closure handler)` Attempt to connect an HTML5 websocket to the specified URI
`void` | `connectWebsocket(java.lang.String uri, WebSocketVersion version, groovy.lang.Closure handler)` Attempt to connect an HTML5 websocket to the specified URI
`HttpClientRequest` | `delete(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP DELETE request with the specified `uri`.
`void` | `exceptionHandler(groovy.lang.Closure handler)` Set an exception handler
`HttpClientRequest` | `get(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP GET request with the specified `uri`.
`java.lang.Integer` | `getBossThreads()` @return The number of boss threads
`java.lang.Long` | `getConnectTimeout()` @return The connect timeout
`java.lang.String` | `getKeyStorePassword()` @return The keystore password
`java.lang.String` | `getKeyStorePath()` @return The path to the key store
`int` | `getMaxPoolSize()` Returns the maximum number of connections in the pool
`void` | `getNow(java.lang.String uri, groovy.lang.Closure responseHandler)` This is a quick version of the get(String, Closure) method where you do not want to do anything with the request before sending.
`void` | `getNow(java.lang.String uri, java.util.Map headers, groovy.lang.Closure responseHandler)` This method works in the same manner as getNow(String,Closure), except that it allows you specify a set of `headers` that will be sent with the request.
`java.lang.Integer` | `getReceiveBufferSize()` @return The TCP receive buffer size
`java.lang.Integer` | `getSendBufferSize()` @return The TCP send buffer size
`java.lang.Integer` | `getTrafficClass()` @return the value of TCP traffic class
`java.lang.String` | `getTrustStorePassword()` @return The trust store password
`java.lang.String` | `getTrustStorePath()` @return The trust store path
`HttpClientRequest` | `head(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP HEAD request with the specified `uri`.
`java.lang.Boolean` | `isReuseAddress()` @return The value of TCP reuse address
`boolean` | `isSSL()` @return true if this client will make SSL connections
`java.lang.Boolean` | `isSoLinger()` @return the value of TCP so linger
`java.lang.Boolean` | `isTCPKeepAlive()` @return true if TCP keep alive is enabled
`java.lang.Boolean` | `isTCPNoDelay()` @return true if Nagle's algorithm is disabled.
`boolean` | `isTrustAll()` @return true if this client will trust all server certificates.
`HttpClientRequest` | `options(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP OPTIONS request with the specified `uri`.
`HttpClientRequest` | `patch(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP PATCH request with the specified `uri`.
`HttpClientRequest` | `post(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP POST request with the specified `uri`.
`HttpClientRequest` | `put(java.lang.String uri, groovy.lang.Closure 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, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP request with the specified `uri`.
`HttpClient` | `setBossThreads(long threads)` Set the number of boss threads to use.
`HttpClient` | `setConnectTimeout(long 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` | `setKeyStorePassword(java.lang.String pwd)` Set the password for the SSL key store.
`HttpClient` | `setKeyStorePath(java.lang.String path)` Set the path to the SSL key store.
`HttpClient` | `setMaxPoolSize(int maxConnections)` Set the maximum pool size
`HttpClient` | `setPort(int port)` Set the port that the client will attempt to connect to the server on to `port`.
`HttpClient` | `setReceiveBufferSize(int size)` Set the TCP receive buffer size for connections created by this instance to `size` in bytes.
`HttpClient` | `setReuseAddress(boolean reuse)` Set the TCP reuseAddress setting for connections created by this instance to `reuse`.
`HttpClient` | `setSSL(boolean ssl)` If `ssl` is `true`, this signifies that any connections will be SSL connections.
`HttpClient` | `setSendBufferSize(int size)` Set the TCP send buffer size for connections created by this instance to `size` in bytes.
`HttpClient` | `setSoLinger(boolean linger)` Set the TCP soLinger setting for connections created by this instance to `linger`.
`HttpClient` | `setTCPKeepAlive(boolean keepAlive)` Set the TCP keepAlive setting for connections created by this instance to `keepAlive`.
`HttpClient` | `setTCPNoDelay(boolean tcpNoDelay)` If `tcpNoDelay` is set to `true` then Nagle's algorithm will turned off for the TCP connections created by this instance.
`HttpClient` | `setTrafficClass(int trafficClass)` Set the TCP trafficClass setting for connections created by this instance to `trafficClass`.
`HttpClient` | `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.
`HttpClient` | `setTrustStorePassword(java.lang.String pwd)` Set the password for the SSL trust store.
`HttpClient` | `setTrustStorePath(java.lang.String path)` Set the path to the SSL trust store.
`HttpClientRequest` | `trace(java.lang.String uri, groovy.lang.Closure responseHandler)` This method returns an HttpClientRequest instance which represents an HTTP TRACE request with the specified `uri`.

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### jClient

    protected HttpClient jClient

Method Detail

### close

    void close()

  Close the HTTP client. This will cause any pooled HTTP connections to be closed.

### connect

    HttpClientRequest connect(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### connectWebsocket

    void connectWebsocket(java.lang.String uri, groovy.lang.Closure handler)

  Attempt to connect an HTML5 websocket to the specified URI

  The connect is done asynchronously and `wsConnect` is called back with the websocket

### connectWebsocket

    void connectWebsocket(java.lang.String uri, WebSocketVersion version, groovy.lang.Closure handler)

  Attempt to connect an HTML5 websocket to the specified URI

  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

### delete

    HttpClientRequest delete(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### exceptionHandler

    void exceptionHandler(groovy.lang.Closure handler)

  Set an exception handler

### get

    HttpClientRequest get(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### getBossThreads

    java.lang.Integer getBossThreads()

  Returns:
    The number of boss threads

### getConnectTimeout

    java.lang.Long getConnectTimeout()

  Returns:
    The connect timeout

### getKeyStorePassword

    java.lang.String getKeyStorePassword()

  Returns:
    The keystore password

### getKeyStorePath

    java.lang.String getKeyStorePath()

  Returns:
    The path to the key store

### getMaxPoolSize

    int getMaxPoolSize()

  Returns the maximum number of connections in the pool

### getNow

    void getNow(java.lang.String uri, groovy.lang.Closure responseHandler)

  This is a quick version of the get(String, Closure) 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()#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

    void getNow(java.lang.String uri, java.util.Map headers, groovy.lang.Closure responseHandler)

  This method works in the same manner as getNow(String,Closure), except that it allows you specify a set of `headers` that will be sent with the request.

### getReceiveBufferSize

    java.lang.Integer getReceiveBufferSize()

  Returns:
    The TCP receive buffer size

### getSendBufferSize

    java.lang.Integer getSendBufferSize()

  Returns:
    The TCP send buffer size

### getTrafficClass

    java.lang.Integer getTrafficClass()

  Returns:
    the value of TCP traffic class

### getTrustStorePassword

    java.lang.String getTrustStorePassword()

  Returns:
    The trust store password

### getTrustStorePath

    java.lang.String getTrustStorePath()

  Returns:
    The trust store path

### head

    HttpClientRequest head(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### isReuseAddress

    java.lang.Boolean isReuseAddress()

  Returns:
    The value of TCP reuse address

### isSSL

    boolean isSSL()

  Returns:
    true if this client will make SSL connections

### isSoLinger

    java.lang.Boolean isSoLinger()

  Returns:
    the value of TCP so linger

### isTCPKeepAlive

    java.lang.Boolean isTCPKeepAlive()

  Returns:
    true if TCP keep alive is enabled

### isTCPNoDelay

    java.lang.Boolean isTCPNoDelay()

  Returns:
    true if Nagle's algorithm is disabled.

### isTrustAll

    boolean isTrustAll()

  Returns:
    true if this client will trust all server certificates.

### options

    HttpClientRequest options(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### patch

    HttpClientRequest patch(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### post

    HttpClientRequest post(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### put

    HttpClientRequest put(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### request

    HttpClientRequest request(java.lang.String method, java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

### setBossThreads

    HttpClient setBossThreads(long threads)

  Set the number of boss threads to use. Boss threads are used to make connections.
  Returns:
    a reference to this so multiple method calls can be chained together

### setConnectTimeout

    HttpClient setConnectTimeout(long timeout)

  Set the connect timeout in milliseconds
  Returns:
    a reference to this so multiple method calls can be chained together

### setHost

    HttpClient setHost(java.lang.String host)

  Set the host that the client will attempt to connect to the server on to `host`. The default value is `localhost`
  Returns:
    A reference to this, so multiple invocations can be chained together.

### setKeepAlive

    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. In this manner, many HTTP requests can be pipe-lined over an HTTP connection. Keep alive connections will not be closed until the close() 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.

  Returns:
    A reference to this, so multiple invocations can be chained together.

### setKeyStorePassword

    HttpClient setKeyStorePassword(java.lang.String pwd)

  Set the password for the SSL key store. This method should only be used in SSL mode, i.e. after setSSL(boolean) has been set to `true`.

  Returns:
    A reference to this, so multiple invocations can be chained together.

### setKeyStorePath

    HttpClient setKeyStorePath(java.lang.String path)

  Set the path to the SSL key store. This method should only be used in SSL mode, i.e. after 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.

  Returns:
    A reference to this, so multiple invocations can be chained together.

### setMaxPoolSize

    HttpClient setMaxPoolSize(int maxConnections)

  Set the maximum pool size

  The client will maintain up to `maxConnections` HTTP connections in an internal pool

  Returns:
    A reference to this, so multiple invocations can be chained together.

### setPort

    HttpClient setPort(int port)

  Set the port that the client will attempt to connect to the server on to `port`. The default value is `80`
  Returns:
    A reference to this, so multiple invocations can be chained together.

### setReceiveBufferSize

    HttpClient setReceiveBufferSize(int size)

  Set the TCP receive buffer size for connections created by this instance to `size` in bytes.
  Returns:
    a reference to this so multiple method calls can be chained together

### setReuseAddress

    HttpClient setReuseAddress(boolean reuse)

  Set the TCP reuseAddress setting for connections created by this instance to `reuse`.
  Returns:
    a reference to this so multiple method calls can be chained together

### setSSL

    HttpClient setSSL(boolean ssl)

  If `ssl` is `true`, this signifies that any connections will be SSL connections.
  Returns:
    A reference to this, so multiple invocations can be chained together.

### setSendBufferSize

    HttpClient setSendBufferSize(int size)

  Set the TCP send buffer size for connections created by this instance to `size` in bytes.
  Returns:
    a reference to this so multiple method calls can be chained together

### setSoLinger

    HttpClient setSoLinger(boolean linger)

  Set the TCP soLinger setting for connections created by this instance to `linger`.
  Returns:
    a reference to this so multiple method calls can be chained together

### setTCPKeepAlive

    HttpClient setTCPKeepAlive(boolean keepAlive)

  Set the TCP keepAlive setting for connections created by this instance to `keepAlive`.
  Returns:
    a reference to this so multiple method calls can be chained together

### setTCPNoDelay

    HttpClient setTCPNoDelay(boolean tcpNoDelay)

  If `tcpNoDelay` is set to `true` then Nagle's algorithm will turned off for the TCP connections created by this instance.
  Returns:
    a reference to this so multiple method calls can be chained together

### setTrafficClass

    HttpClient setTrafficClass(int trafficClass)

  Set the TCP trafficClass setting for connections created by this instance to `trafficClass`.
  Returns:
    a reference to this so multiple method calls can be chained together

### setTrustAll

    HttpClient 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.

  Use this with caution as you may be exposed to "main in the middle" attacks

  Parameters:
    `trustAll` - Set to true if you want to trust all server certificates

### setTrustStorePassword

    HttpClient setTrustStorePassword(java.lang.String pwd)

  Set the password for the SSL trust store. This method should only be used in SSL mode, i.e. after setSSL(boolean) has been set to `true`.

  Returns:
    A reference to this, so multiple invocations can be chained together.

### setTrustStorePath

    HttpClient setTrustStorePath(java.lang.String path)

  Set the path to the SSL trust store. This method should only be used in SSL mode, i.e. after 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. If you wish the client to trust all server certificates you can use the setTrustAll(boolean) method.

  Returns:
    A reference to this, so multiple invocations can be chained together.

### trace

    HttpClientRequest trace(java.lang.String uri, groovy.lang.Closure responseHandler)

  This method returns an 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.

Groovy Documentation