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 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)
      Description copied from class: HttpRequestBuilderBase
      Creates the HttpRequestBase depending on the HTTP method.
      Specified by:
      createMethodSpecificHttpRequest in class 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 HttpResponse send()
      Description copied from interface: HttpRequestBuilder
      Sends the request and gets the HTTP response.
      Specified by:
      send in interface HttpRequestBuilder<WebsocketRequestBuilder>
      Specified by:
      send in interface WebsocketRequestBuilder
      Overrides:
      send in class HttpRequestBuilderBase<WebsocketRequestBuilder>
      Returns:
      A object containg the parsed information of the response.
    • 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.