Class WebsocketRequestBuilderDefault
java.lang.Object
org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase<WebsocketRequestBuilder>
org.spincast.plugins.httpclient.websocket.builders.WebsocketRequestBuilderDefault
- All Implemented Interfaces:
HttpRequestBuilder<WebsocketRequestBuilder>
,WebsocketRequestBuilder
public class WebsocketRequestBuilderDefault
extends HttpRequestBuilderBase<WebsocketRequestBuilder>
implements WebsocketRequestBuilder
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWebsocketRequestBuilderDefault
(String url, CookieFactory cookieFactory, HttpResponseFactory spincastHttpResponseFactory, SpincastHttpClientWithWebsocketUtils spincastHttpClientWithWebsocketUtils, SpincastHttpClientWithWebsocketConfig spincastHttpClientWithWebsocketConfig) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCustomCookies
(Map<String, List<String>> headers) protected void
addCustomHeaders
(Map<String, List<String>> headers) protected void
addHttpAuthHeaders
(Map<String, List<String>> headers) protected void
addSslContext
(io.undertow.websockets.client.WebSocketClient.ConnectionBuilder connectionBuilder) protected void
connect
(WebsocketClientHandler websocketClientHandler) Sends the request and establish the WebSocket connection.protected io.undertow.server.DefaultByteBufferPool
protected io.undertow.websockets.client.WebSocketClient.ConnectionBuilder
createConnectionBuilder
(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url) protected org.spincast.shaded.org.apache.http.client.methods.HttpRequestBase
Creates the HttpRequestBase depending on the HTTP method.protected List<io.undertow.websockets.WebSocketExtension>
protected io.undertow.websockets.core.WebSocketChannel
protected io.undertow.websockets.core.WebSocketChannel
createWebSocketChannel
(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url, int redirectionNbr) protected URI
createWebsocketUri
(String url) protected org.xnio.XnioWorker
protected int
protected SpincastHttpClientWithWebsocketConfig
protected SpincastHttpClientWithWebsocketUtils
protected SSLContext
protected ExecutorService
The ExecutorService to use to send events to the client.protected int
The maximum number of concurrent threads used when sending events to the application.protected ThreadFactory
The ThreadFactory to use for the Executor that sends events to the client.protected int
The timeout amount before cancelling a task when sending events to the application.protected TimeUnit
The timeout asdasd before cancelling a task when sending events to the application.protected WebsocketClientHandler
protected io.undertow.websockets.core.WebSocketCallback<Void>
protected org.xnio.Xnio
getXnio()
ping
(int seconds) You can use this to configure the pings that are automatically sent to the Websocket endpoint every X seconds.send()
Sends the request and gets the HTTP response.protected void
sendClientEventInNewThread
(Runnable runnable) Sends an event to the client in a separated thread.protected void
protected void
sendOnBytesMessageClientEvent
(byte[] message) Sends a "Bytes message" event to the app.protected void
sendOnConnectionClosedMessageClientEvent
(int code, String reason) Sends a "Connection closed message" event to the app.protected void
sendOnStringMessageClientEvent
(String message) Sends a "String message" event to the app.protected void
Methods inherited from class org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase
addHeaderValue, addHeaderValues, addHTMLAcceptHeader, addJsonAcceptHeader, addPlainTextAcceptHeader, addXMLAcceptHeader, convertToApacheCookie, convertToApacheCookieTweakName, convertToApacheCookieTweakValue, createHttpClient, createHttpClientBuilder, disableRedirectHandling, disableSslCertificateErrors, getCookieEncoding, getCookieFactory, getCookieStore, getHeaders, getHttpAuthPassword, getHttpAuthUsername, getHttpClient, getHttpClientBuilder, getHttpRequestExecutor, getRequestConfig, getSpincastHttpClientConfig, getSpincastHttpClientUtils, getSpincastHttpResponseFactory, getUrl, isDisableRedirectHandling, isDisableSslCertificateErrors, sendGetRawResponse, setCookie, setCookie, setCookie, setCookies, setCookieStore, setHeaders, setHeaderValues, setHttpAuthCredentials, setHttpClientBuilder, setRequestConfig
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.spincast.plugins.httpclient.HttpRequestBuilder
addHeaderValue, addHeaderValues, addHTMLAcceptHeader, addJsonAcceptHeader, addPlainTextAcceptHeader, addXMLAcceptHeader, disableRedirectHandling, disableSslCertificateErrors, setCookie, setCookie, setCookie, setCookies, setHeaders, setHeaderValues, setHttpAuthCredentials, setHttpClientBuilder, setRequestConfig
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
WebsocketRequestBuilderDefault
public WebsocketRequestBuilderDefault(String url, CookieFactory cookieFactory, HttpResponseFactory spincastHttpResponseFactory, SpincastHttpClientWithWebsocketUtils spincastHttpClientWithWebsocketUtils, SpincastHttpClientWithWebsocketConfig spincastHttpClientWithWebsocketConfig) Constructor
-
-
Method Details
-
getSpincastHttpClientWithWebsocketConfig
-
getSpincastHttpClientWithWebsocketUtils
-
createMethodSpecificHttpRequest
protected org.spincast.shaded.org.apache.http.client.methods.HttpRequestBase createMethodSpecificHttpRequest(String url) Description copied from class:HttpRequestBuilderBase
Creates the HttpRequestBase depending on the HTTP method.- Specified by:
createMethodSpecificHttpRequest
in classHttpRequestBuilderBase<WebsocketRequestBuilder>
-
getPingsIntervalSeconds
protected int getPingsIntervalSeconds() -
getWebsocketClientReader
-
ping
Description copied from interface:WebsocketRequestBuilder
You can use this to configure the pings that are automatically sent to the Websocket endpoint every X seconds.WebsocketClientHandler#onConnectionClosed()
will be called if the connection is closed.Use a value
<= 0
to disable the pings.The automatic pings and their default interval are also configurable using:
SpincastHttpClientWithWebsocketConfig#isWebsocketAutomaticPingEnabled()
and
SpincastHttpClientWithWebsocketConfig#getWebsocketAutomaticPingIntervalSeconds()
Pings are enabled by default.
- Specified by:
ping
in interfaceWebsocketRequestBuilder
- Parameters:
seconds
- the interval in seconds or <= 0 to disable the pings.
-
send
Description copied from interface:HttpRequestBuilder
Sends the request and gets the HTTP response.- Specified by:
send
in interfaceHttpRequestBuilder<WebsocketRequestBuilder>
- Specified by:
send
in interfaceWebsocketRequestBuilder
- Overrides:
send
in classHttpRequestBuilderBase<WebsocketRequestBuilder>
- Returns:
- A object containg the parsed information of the response.
-
addWebsocketRequestHeaders
protected void addWebsocketRequestHeaders() -
connect
Description copied from interface:WebsocketRequestBuilder
Sends the request and establish the WebSocket connection.- Specified by:
connect
in interfaceWebsocketRequestBuilder
- Parameters:
websocketClientHandler
- The handler that is responsible to handle the various WebSocket events.- Returns:
- a writer to send WebSocket messages to the connected endpoint.
-
getWebsocketWriteCallback
protected io.undertow.websockets.core.WebSocketCallback<Void> getWebsocketWriteCallback(WebsocketClientHandler reader) -
startSendingPings
-
getXnio
protected org.xnio.Xnio getXnio() -
createXnioWorker
protected org.xnio.XnioWorker createXnioWorker() -
getSslContext
-
createByteBufferPool
protected io.undertow.server.DefaultByteBufferPool createByteBufferPool() -
createWebSocketChannel
protected io.undertow.websockets.core.WebSocketChannel createWebSocketChannel() -
createWebSocketChannel
protected io.undertow.websockets.core.WebSocketChannel createWebSocketChannel(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url, int redirectionNbr) -
createConnectionBuilder
protected io.undertow.websockets.client.WebSocketClient.ConnectionBuilder createConnectionBuilder(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url) -
addSslContext
protected void addSslContext(io.undertow.websockets.client.WebSocketClient.ConnectionBuilder connectionBuilder) -
createWebsocketUri
-
addCustomHeaders
-
addCustomCookies
-
addHttpAuthHeaders
-
createSupportedSubProtocols
-
createSupportedExtensions
-
sendConnectionClosedAppEvent
-
sendOnStringMessageClientEvent
Sends a "String message" event to the app. -
sendOnBytesMessageClientEvent
protected void sendOnBytesMessageClientEvent(byte[] message) Sends a "Bytes message" event to the app. -
sendOnConnectionClosedMessageClientEvent
Sends a "Connection closed message" event to the app. -
sendClientEventInNewThread
Sends an event to the client in a separated thread. -
getThreadExecutorForClientEventsTimeoutAmount
protected int getThreadExecutorForClientEventsTimeoutAmount()The timeout amount before cancelling a task when sending events to the application. -
getThreadExecutorForClientEventsTimeoutTimeUnit
The timeout asdasd before cancelling a task when sending events to the application. -
getThreadExecutorForClientEvents
The ExecutorService to use to send events to the client. -
getThreadExecutorForClientEventsThreadNumber
protected int getThreadExecutorForClientEventsThreadNumber()The maximum number of concurrent threads used when sending events to the application. -
getThreadExecutorForClientEventsThreadThreadFactory
The ThreadFactory to use for the Executor that sends events to the client.- Returns:
- the ThreadFactory to use or
null
to use the default one.
-