Class WebsocketRequestBuilderDefault

java.lang.Object
org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase<WebsocketRequestBuilder>
org.spincast.plugins.httpclient.websocket.builders.WebsocketRequestBuilderDefault
All Implemented Interfaces:
org.spincast.plugins.httpclient.HttpRequestBuilder<WebsocketRequestBuilder>, WebsocketRequestBuilder

public class WebsocketRequestBuilderDefault extends org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase<WebsocketRequestBuilder> implements WebsocketRequestBuilder
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
  • Constructor Details

  • Method Details

    • getSpincastHttpClientWithWebsocketConfig

      protected SpincastHttpClientWithWebsocketConfig getSpincastHttpClientWithWebsocketConfig()
    • getSpincastHttpClientWithWebsocketUtils

      protected SpincastHttpClientWithWebsocketUtils getSpincastHttpClientWithWebsocketUtils()
    • createMethodSpecificHttpRequest

      protected org.spincast.shaded.org.apache.http.client.methods.HttpRequestBase createMethodSpecificHttpRequest(String url)
      Specified by:
      createMethodSpecificHttpRequest in class org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase<WebsocketRequestBuilder>
    • getPingsIntervalSeconds

      protected int getPingsIntervalSeconds()
    • getWebsocketClientReader

      protected WebsocketClientHandler getWebsocketClientReader()
    • ping

      public WebsocketRequestBuilder ping(int seconds)
      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 interface WebsocketRequestBuilder
      Parameters:
      seconds - the interval in seconds or <= 0 to disable the pings.
    • send

      public org.spincast.plugins.httpclient.HttpResponse send()
      Description copied from interface: WebsocketRequestBuilder
      Sends the request and gets the HTTP response. Does not make the actual upgrade to a WebSocket connection! Use the connect(...) method if you want the actual WebSocket connection to be made.

      This version is useful to debug the intermediate HTTP upgrade response made from the server before the actual WebSocket connection is established.

      Specified by:
      send in interface org.spincast.plugins.httpclient.HttpRequestBuilder<WebsocketRequestBuilder>
      Specified by:
      send in interface WebsocketRequestBuilder
      Overrides:
      send in class org.spincast.plugins.httpclient.builders.HttpRequestBuilderBase<WebsocketRequestBuilder>
    • addWebsocketRequestHeaders

      protected void addWebsocketRequestHeaders()
    • connect

      public WebsocketClientWriter connect(WebsocketClientHandler websocketClientHandler)
      Description copied from interface: WebsocketRequestBuilder
      Sends the request and establish the WebSocket connection.
      Specified by:
      connect in interface WebsocketRequestBuilder
      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

      protected void startSendingPings(SpincastWebsocketClientWriter writer)
    • getXnio

      protected org.xnio.Xnio getXnio()
    • createXnioWorker

      protected org.xnio.XnioWorker createXnioWorker()
    • getSslContext

      protected SSLContext 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

      protected URI createWebsocketUri(String url)
    • addCustomHeaders

      protected void addCustomHeaders(Map<String,List<String>> headers)
    • addCustomCookies

      protected void addCustomCookies(Map<String,List<String>> headers)
    • addHttpAuthHeaders

      protected void addHttpAuthHeaders(Map<String,List<String>> headers)
    • createSupportedSubProtocols

      protected List<String> createSupportedSubProtocols()
    • createSupportedExtensions

      protected List<io.undertow.websockets.WebSocketExtension> createSupportedExtensions()
    • sendConnectionClosedAppEvent

      protected void sendConnectionClosedAppEvent(WebsocketClientHandler reader)
    • sendOnStringMessageClientEvent

      protected void sendOnStringMessageClientEvent(String message)
      Sends a "String message" event to the app.
    • sendOnBytesMessageClientEvent

      protected void sendOnBytesMessageClientEvent(byte[] message)
      Sends a "Bytes message" event to the app.
    • sendOnConnectionClosedMessageClientEvent

      protected void sendOnConnectionClosedMessageClientEvent(int code, String reason)
      Sends a "Connection closed message" event to the app.
    • sendClientEventInNewThread

      protected void sendClientEventInNewThread(Runnable runnable)
      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

      protected TimeUnit getThreadExecutorForClientEventsTimeoutTimeUnit()
      The timeout asdasd before cancelling a task when sending events to the application.
    • getThreadExecutorForClientEvents

      protected ExecutorService 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

      protected ThreadFactory 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.