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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWebsocketRequestBuilderDefault(String url, CookieFactory cookieFactory, HttpResponseFactory spincastHttpResponseFactory, SpincastHttpClientWithWebsocketUtils spincastHttpClientWithWebsocketUtils, SpincastHttpClientWithWebsocketConfig spincastHttpClientWithWebsocketConfig) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCustomCookies(Map<String, List<String>> headers) protected voidaddCustomHeaders(Map<String, List<String>> headers) protected voidaddHttpAuthHeaders(Map<String, List<String>> headers) protected voidaddSslContext(io.undertow.websockets.client.WebSocketClient.ConnectionBuilder connectionBuilder) protected voidconnect(WebsocketClientHandler websocketClientHandler) Sends the request and establish the WebSocket connection.protected io.undertow.server.DefaultByteBufferPoolprotected io.undertow.websockets.client.WebSocketClient.ConnectionBuildercreateConnectionBuilder(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url) protected org.spincast.shaded.org.apache.http.client.methods.HttpRequestBaseCreates the HttpRequestBase depending on the HTTP method.protected List<io.undertow.websockets.WebSocketExtension>protected io.undertow.websockets.core.WebSocketChannelprotected io.undertow.websockets.core.WebSocketChannelcreateWebSocketChannel(org.xnio.XnioWorker worker, io.undertow.server.DefaultByteBufferPool bufferPool, String url, int redirectionNbr) protected URIcreateWebsocketUri(String url) protected org.xnio.XnioWorkerprotected intprotected SpincastHttpClientWithWebsocketConfigprotected SpincastHttpClientWithWebsocketUtilsprotected SSLContextprotected ExecutorServiceThe ExecutorService to use to send events to the client.protected intThe maximum number of concurrent threads used when sending events to the application.protected ThreadFactoryThe ThreadFactory to use for the Executor that sends events to the client.protected intThe timeout amount before cancelling a task when sending events to the application.protected TimeUnitThe timeout asdasd before cancelling a task when sending events to the application.protected WebsocketClientHandlerprotected io.undertow.websockets.core.WebSocketCallback<Void>protected org.xnio.XniogetXnio()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 voidsendClientEventInNewThread(Runnable runnable) Sends an event to the client in a separated thread.protected voidprotected voidsendOnBytesMessageClientEvent(byte[] message) Sends a "Bytes message" event to the app.protected voidsendOnConnectionClosedMessageClientEvent(int code, String reason) Sends a "Connection closed message" event to the app.protected voidsendOnStringMessageClientEvent(String message) Sends a "String message" event to the app.protected voidMethods 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, setRequestConfigMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:HttpRequestBuilderBaseCreates the HttpRequestBase depending on the HTTP method.- Specified by:
createMethodSpecificHttpRequestin classHttpRequestBuilderBase<WebsocketRequestBuilder>
-
getPingsIntervalSeconds
protected int getPingsIntervalSeconds() -
getWebsocketClientReader
-
ping
Description copied from interface:WebsocketRequestBuilderYou 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
<= 0to 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:
pingin interfaceWebsocketRequestBuilder- Parameters:
seconds- the interval in seconds or <= 0 to disable the pings.
-
send
Description copied from interface:HttpRequestBuilderSends the request and gets the HTTP response.- Specified by:
sendin interfaceHttpRequestBuilder<WebsocketRequestBuilder>- Specified by:
sendin interfaceWebsocketRequestBuilder- Overrides:
sendin classHttpRequestBuilderBase<WebsocketRequestBuilder>- Returns:
- A object containg the parsed information of the response.
-
addWebsocketRequestHeaders
protected void addWebsocketRequestHeaders() -
connect
Description copied from interface:WebsocketRequestBuilderSends the request and establish the WebSocket connection.- Specified by:
connectin 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
nullto use the default one.
-