Package io.vertx.core.http
Class WebSocketConnectOptions
- java.lang.Object
-
- io.vertx.core.http.HttpConnectOptions
-
- io.vertx.core.http.RequestOptions
-
- io.vertx.core.http.WebSocketConnectOptions
-
public class WebSocketConnectOptions extends RequestOptions
Options describing how anHttpClientconnect aWebSocket.- Author:
- Julien Viet
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_ALLOW_ORIGIN_HEADERThe default WebSocket allow origin header =truestatic ProxyOptionsDEFAULT_PROXY_OPTIONSThe default value for proxy options =nullstatic booleanDEFAULT_REGISTER_WRITE_HANDLERSWhether write-handlers should be registered by default = false.static List<String>DEFAULT_SUB_PROTOCOLSThe default WebSocket sub protocols =nullstatic WebSocketVersionDEFAULT_VERSIONThe default WebSocket version =WebSocketVersion.V13-
Fields inherited from class io.vertx.core.http.RequestOptions
DEFAULT_CONNECT_TIMEOUT, DEFAULT_FOLLOW_REDIRECTS, DEFAULT_HOST, DEFAULT_HTTP_METHOD, DEFAULT_IDLE_TIMEOUT, DEFAULT_PORT, DEFAULT_SERVER, DEFAULT_SSL, DEFAULT_TIMEOUT, DEFAULT_URI
-
-
Constructor Summary
Constructors Constructor Description WebSocketConnectOptions()WebSocketConnectOptions(WebSocketConnectOptions other)WebSocketConnectOptions(JsonObject json)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebSocketConnectOptionsaddHeader(CharSequence key, CharSequence value)Add a request header.WebSocketConnectOptionsaddHeader(CharSequence key, Iterable<CharSequence> values)WebSocketConnectOptionsaddHeader(String key, String value)Add a request header.WebSocketConnectOptionsaddSubProtocol(String subprotocol)Add a WebSocket sub protocol to use.booleangetAllowOriginHeader()ProxyOptionsgetProxyOptions()Get the proxy options override for connectionsList<String>getSubProtocols()WebSocketVersiongetVersion()booleanisRegisterWriteHandlers()WebSocketConnectOptionsputHeader(CharSequence key, CharSequence value)Set a request header.WebSocketConnectOptionsputHeader(CharSequence key, Iterable<CharSequence> values)WebSocketConnectOptionsputHeader(String key, String value)Set a request header.WebSocketConnectOptionssetAbsoluteURI(String absoluteURI)Parse an absolute URI to use, this will update thessl,host,portandurifields.WebSocketConnectOptionssetAbsoluteURI(URL url)LikeRequestOptions.setAbsoluteURI(String)but using anURLparameter.WebSocketConnectOptionssetAllowOriginHeader(boolean allowOriginHeader)Set whether to add theoriginheader to the WebSocket handshake request, enabled by default.WebSocketConnectOptionssetConnectTimeout(long timeout)Sets the amount of time after which, if the request is not obtained from the client within the timeout period, theFuture<HttpClientRequest>obtained from the client is failed with aTimeoutException.WebSocketConnectOptionssetFollowRedirects(Boolean followRedirects)Set whether to follow HTTP redirectWebSocketConnectOptionssetHeaders(MultiMap headers)Set request headers from a multi-map.WebSocketConnectOptionssetHost(String host)Set the host name to be used by the client request.WebSocketConnectOptionssetIdleTimeout(long timeout)Sets the amount of time after which, if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with aTimeoutException, e.g.WebSocketConnectOptionssetMethod(HttpMethod method)Set the HTTP method to be used by the client request.WebSocketConnectOptionssetPort(Integer port)Set the port to be used by the client request.RequestOptionssetProxyOptions(ProxyOptions proxyOptions)Override theHttpClientOptions.setProxyOptions(ProxyOptions)proxy options for connections.WebSocketConnectOptionssetRegisterWriteHandlers(boolean registerWriteHandlers)Whether write-handlers should be registered on theEventBus.WebSocketConnectOptionssetServer(Address server)Set the server address to be used by the client request.WebSocketConnectOptionssetSsl(Boolean ssl)Set whether SSL/TLS is enabled.WebSocketConnectOptionssetSslOptions(ClientSSLOptions sslOptions)Set the SSL options to use.WebSocketConnectOptionssetSubProtocols(List<String> subProtocols)Set the WebSocket sub protocols to use.WebSocketConnectOptionssetTimeout(long timeout)Sets the amount of time after which if the WebSocket handshake does not happen within the timeout period anWebSocketHandshakeExceptionwill be passed to the exception handler and the connection will be closed.WebSocketConnectOptionssetTraceOperation(String op)Override the operation the tracer use for this request.WebSocketConnectOptionssetURI(String uri)Set the request relative URI.WebSocketConnectOptionssetVersion(WebSocketVersion version)Set the WebSocket version.JsonObjecttoJson()-
Methods inherited from class io.vertx.core.http.RequestOptions
getFollowRedirects, getHeaders, getIdleTimeout, getMethod, getRoutingKey, getTimeout, getTraceOperation, getURI, init, removeHeader, removeHeader, setRoutingKey
-
Methods inherited from class io.vertx.core.http.HttpConnectOptions
getConnectTimeout, getHost, getPort, getServer, getSslOptions, isSsl
-
-
-
-
Field Detail
-
DEFAULT_PROXY_OPTIONS
public static final ProxyOptions DEFAULT_PROXY_OPTIONS
The default value for proxy options =null
-
DEFAULT_VERSION
public static final WebSocketVersion DEFAULT_VERSION
The default WebSocket version =WebSocketVersion.V13
-
DEFAULT_SUB_PROTOCOLS
public static final List<String> DEFAULT_SUB_PROTOCOLS
The default WebSocket sub protocols =null
-
DEFAULT_ALLOW_ORIGIN_HEADER
public static final boolean DEFAULT_ALLOW_ORIGIN_HEADER
The default WebSocket allow origin header =true- See Also:
- Constant Field Values
-
DEFAULT_REGISTER_WRITE_HANDLERS
public static final boolean DEFAULT_REGISTER_WRITE_HANDLERS
Whether write-handlers should be registered by default = false.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WebSocketConnectOptions
public WebSocketConnectOptions()
-
WebSocketConnectOptions
public WebSocketConnectOptions(WebSocketConnectOptions other)
-
WebSocketConnectOptions
public WebSocketConnectOptions(JsonObject json)
-
-
Method Detail
-
getVersion
public WebSocketVersion getVersion()
- Returns:
- the WebSocket version
-
setVersion
public WebSocketConnectOptions setVersion(WebSocketVersion version)
Set the WebSocket version.- Returns:
- a reference to this, so the API can be used fluently
-
getSubProtocols
public List<String> getSubProtocols()
- Returns:
- the list of WebSocket sub protocols or
nullif there are none
-
setSubProtocols
public WebSocketConnectOptions setSubProtocols(List<String> subProtocols)
Set the WebSocket sub protocols to use.- Returns:
- a reference to this, so the API can be used fluently
-
addSubProtocol
public WebSocketConnectOptions addSubProtocol(String subprotocol)
Add a WebSocket sub protocol to use.- Returns:
- a reference to this, so the API can be used fluently
-
getProxyOptions
public ProxyOptions getProxyOptions()
Get the proxy options override for connections- Overrides:
getProxyOptionsin classHttpConnectOptions- Returns:
- proxy options override
-
setProxyOptions
public RequestOptions setProxyOptions(ProxyOptions proxyOptions)
Override theHttpClientOptions.setProxyOptions(ProxyOptions)proxy options for connections.- Overrides:
setProxyOptionsin classRequestOptions- Parameters:
proxyOptions- proxy options override object- Returns:
- a reference to this, so the API can be used fluently
-
getAllowOriginHeader
public boolean getAllowOriginHeader()
- Returns:
- whether to add the
originheader to the WebSocket handshake request
-
setAllowOriginHeader
public WebSocketConnectOptions setAllowOriginHeader(boolean allowOriginHeader)
Set whether to add theoriginheader to the WebSocket handshake request, enabled by default.Set to
falsewhen a server does not accept WebSocket with an origin header.- Parameters:
allowOriginHeader- whether to add theoriginheader to the WebSocket handshake request- Returns:
- a reference to this, so the API can be used fluently
-
setHost
public WebSocketConnectOptions setHost(String host)
Description copied from class:HttpConnectOptionsSet the host name to be used by the client request.- Overrides:
setHostin classRequestOptions- Returns:
- a reference to this, so the API can be used fluently
-
setPort
public WebSocketConnectOptions setPort(Integer port)
Description copied from class:HttpConnectOptionsSet the port to be used by the client request.- Overrides:
setPortin classRequestOptions- Returns:
- a reference to this, so the API can be used fluently
-
setSsl
public WebSocketConnectOptions setSsl(Boolean ssl)
Description copied from class:HttpConnectOptionsSet whether SSL/TLS is enabled.- Overrides:
setSslin classRequestOptions- Parameters:
ssl- true if enabled- Returns:
- a reference to this, so the API can be used fluently
-
setSslOptions
public WebSocketConnectOptions setSslOptions(ClientSSLOptions sslOptions)
Description copied from class:HttpConnectOptionsSet the SSL options to use.When none is provided, the client SSL options will be used instead.
- Overrides:
setSslOptionsin classRequestOptions- Parameters:
sslOptions- the SSL options to use- Returns:
- a reference to this, so the API can be used fluently
-
setURI
public WebSocketConnectOptions setURI(String uri)
Description copied from class:RequestOptionsSet the request relative URI.- Overrides:
setURIin classRequestOptions- Parameters:
uri- the relative uri- Returns:
- a reference to this, so the API can be used fluently
-
setTimeout
public WebSocketConnectOptions setTimeout(long timeout)
Sets the amount of time after which if the WebSocket handshake does not happen within the timeout period anWebSocketHandshakeExceptionwill be passed to the exception handler and the connection will be closed.- Overrides:
setTimeoutin classRequestOptions- Parameters:
timeout- the amount of time in milliseconds.- Returns:
- a reference to this, so the API can be used fluently
-
setConnectTimeout
public WebSocketConnectOptions setConnectTimeout(long timeout)
Description copied from class:HttpConnectOptionsSets the amount of time after which, if the request is not obtained from the client within the timeout period, theFuture<HttpClientRequest>obtained from the client is failed with aTimeoutException. Note this is not related to the TCPHttpClientOptions.setConnectTimeout(int)option, when a request is made against a pooled HTTP client, the timeout applies to the duration to obtain a connection from the pool to serve the request, the timeout might fire because the server does not respond in time or the pool is too busy to serve a request.- Overrides:
setConnectTimeoutin classRequestOptions- Parameters:
timeout- the amount of time in milliseconds.- Returns:
- a reference to this, so the API can be used fluently
-
setIdleTimeout
public WebSocketConnectOptions setIdleTimeout(long timeout)
Description copied from class:RequestOptionsSets the amount of time after which, if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with aTimeoutException, e.g.Future<HttpClientResponse>orFuture<Buffer>response body. The timeout starts after a connection is obtained from the client, similar to callingHttpClientRequest.idleTimeout(long).- Overrides:
setIdleTimeoutin classRequestOptions- Parameters:
timeout- the amount of time in milliseconds.- Returns:
- a reference to this, so the API can be used fluently
-
addHeader
public WebSocketConnectOptions addHeader(String key, String value)
Description copied from class:RequestOptionsAdd a request header.- Overrides:
addHeaderin classRequestOptions- Parameters:
key- the header keyvalue- the header value- Returns:
- a reference to this, so the API can be used fluently
-
addHeader
public WebSocketConnectOptions addHeader(CharSequence key, CharSequence value)
Description copied from class:RequestOptionsAdd a request header.- Overrides:
addHeaderin classRequestOptions- Parameters:
key- the header keyvalue- the header value- Returns:
- a reference to this, so the API can be used fluently
-
addHeader
public WebSocketConnectOptions addHeader(CharSequence key, Iterable<CharSequence> values)
- Overrides:
addHeaderin classRequestOptions
-
putHeader
public WebSocketConnectOptions putHeader(String key, String value)
Description copied from class:RequestOptionsSet a request header.- Overrides:
putHeaderin classRequestOptions- Parameters:
key- the header keyvalue- the header value- Returns:
- a reference to this, so the API can be used fluently
-
putHeader
public WebSocketConnectOptions putHeader(CharSequence key, CharSequence value)
Description copied from class:RequestOptionsSet a request header.- Overrides:
putHeaderin classRequestOptions- Parameters:
key- the header keyvalue- the header value- Returns:
- a reference to this, so the API can be used fluently
-
putHeader
public WebSocketConnectOptions putHeader(CharSequence key, Iterable<CharSequence> values)
- Overrides:
putHeaderin classRequestOptions
-
setHeaders
public WebSocketConnectOptions setHeaders(MultiMap headers)
Description copied from class:RequestOptionsSet request headers from a multi-map.- Overrides:
setHeadersin classRequestOptions- Parameters:
headers- the headers- Returns:
- a reference to this, so the API can be used fluently
-
setServer
public WebSocketConnectOptions setServer(Address server)
Description copied from class:HttpConnectOptionsSet the server address to be used by the client request.When the server address is
null, the address will be resolved after thehostproperty by the Vert.x resolver.Use this when you want to connect to a specific server address without name resolution.
- Overrides:
setServerin classRequestOptions- Returns:
- a reference to this, so the API can be used fluently
-
setMethod
public WebSocketConnectOptions setMethod(HttpMethod method)
Description copied from class:RequestOptionsSet the HTTP method to be used by the client request.- Overrides:
setMethodin classRequestOptions- Returns:
- a reference to this, so the API can be used fluently
-
setFollowRedirects
public WebSocketConnectOptions setFollowRedirects(Boolean followRedirects)
Description copied from class:RequestOptionsSet whether to follow HTTP redirect- Overrides:
setFollowRedirectsin classRequestOptions- Parameters:
followRedirects- whether to follow redirect- Returns:
- a reference to this, so the API can be used fluently
-
setAbsoluteURI
public WebSocketConnectOptions setAbsoluteURI(String absoluteURI)
Description copied from class:RequestOptionsParse an absolute URI to use, this will update thessl,host,portandurifields.- Overrides:
setAbsoluteURIin classRequestOptions- Parameters:
absoluteURI- the uri to use- Returns:
- a reference to this, so the API can be used fluently
-
setAbsoluteURI
public WebSocketConnectOptions setAbsoluteURI(URL url)
Description copied from class:RequestOptionsLikeRequestOptions.setAbsoluteURI(String)but using anURLparameter.- Overrides:
setAbsoluteURIin classRequestOptions- Parameters:
url- the uri to use- Returns:
- a reference to this, so the API can be used fluently
-
setTraceOperation
public WebSocketConnectOptions setTraceOperation(String op)
Description copied from class:RequestOptionsOverride the operation the tracer use for this request. When no operation is set, the HTTP method is used instead.- Overrides:
setTraceOperationin classRequestOptions- Parameters:
op- the override- Returns:
- a reference to this, so the API can be used fluently
-
toJson
public JsonObject toJson()
- Overrides:
toJsonin classRequestOptions
-
isRegisterWriteHandlers
public boolean isRegisterWriteHandlers()
- Returns:
trueif write-handlers should be registered on theEventBus, otherwisefalse
-
setRegisterWriteHandlers
public WebSocketConnectOptions setRegisterWriteHandlers(boolean registerWriteHandlers)
Whether write-handlers should be registered on theEventBus.Defaults to
false.- Parameters:
registerWriteHandlers- true to register write-handlers- Returns:
- a reference to this, so the API can be used fluently
- See Also:
WebSocketBase.textHandlerID(),WebSocketBase.binaryHandlerID()
-
-