Class WebsocketFactoryBuilder

java.lang.Object
de.chojo.universalis.websocket.builder.WebsocketFactoryBuilder

public class WebsocketFactoryBuilder extends Object
Class to build a WebSocketFactory. Results in a UniversalisWsBuilder
  • Constructor Details

    • WebsocketFactoryBuilder

      public WebsocketFactoryBuilder()
  • Method Details

    • setSSLSocketFactory

      public WebsocketFactoryBuilder setSSLSocketFactory(SSLSocketFactory factory)
      Set an SSL socket factory. See WebSocketFactory.createSocket(URI) for details.
      Parameters:
      factory - An SSL socket factory.
      Returns:
      this instance.
    • setSSLContext

      public WebsocketFactoryBuilder setSSLContext(SSLContext context)
      Set an SSL context to get a socket factory. See WebSocketFactory.createSocket(URI) for details.
      Parameters:
      context - An SSL context.
      Returns:
      this instance.
    • setConnectionTimeout

      public WebsocketFactoryBuilder setConnectionTimeout(int timeout)
      Set the timeout value in milliseconds for socket connection. A timeout of zero is interpreted as an infinite timeout.
      Parameters:
      timeout - The connection timeout value in milliseconds.
      Returns:
      this object.
      Throws:
      IllegalArgumentException - The given timeout value is negative.
      Since:
      1.10
    • setSocketTimeout

      public WebsocketFactoryBuilder setSocketTimeout(int timeout)
      Set the timeout value in milliseconds for socket read and write operations. A timeout of zero is interpreted as an infinite timeout.

      This can be changed later with getSocket().setSoTimeout(int).

      Parameters:
      timeout - The socket timeout value in milliseconds.
      Returns:
      this object.
      Throws:
      IllegalArgumentException - The given timeout value is negative.
      Since:
      2.14
      See Also:
    • setDualStackMode

      public WebsocketFactoryBuilder setDualStackMode(com.neovisionaries.ws.client.DualStackMode mode)
      Set the dual stack mode that will be applied when establishing a socket connection.
      Parameters:
      mode - The dual stack mode to be applied.
      Returns:
      this object.
    • setDualStackFallbackDelay

      public WebsocketFactoryBuilder setDualStackFallbackDelay(int delay)
      Set the dual stack fallback delay in milliseconds that will be applied when establishing a socket connection.
      Parameters:
      delay - The dual stack fallback delay in milliseconds.
      Returns:
      this object.
    • setVerifyHostname

      public WebsocketFactoryBuilder setVerifyHostname(boolean verifyHostname)
      Set the flag which indicates whether the hostname in the server's certificate should be verified or not. The default value is true.

      Manual hostname verification has been enabled since the version 2.1. Because the verification is executed manually after Socket.connect(SocketAddress, int) succeeds, the hostname verification is always executed even if you has passed an SSLContext which naively accepts any server certificate (e.g. NaiveSSLContext). However, this behavior is not desirable in some cases and you may want to disable the hostname verification. This setter method exists for the purpose and you can disable hostname verification by passing false to this method.

      Parameters:
      verifyHostname - true to enable hostname verification. false to disable hostname verification.
      Returns:
      this object.
      Since:
      2.3
    • setServerNames

      public WebsocketFactoryBuilder setServerNames(String[] serverNames)
      Set server names for SNI (Server Name Indication).

      If setServerNames(List<SNIServerName>) method of SSLParameters class is available in the underlying system, the method is called to set up server names for SNI (Server Name Indication).

      Parameters:
      serverNames - List of host names.
      Returns:
      this object.
      Since:
      2.4
    • setServerName

      public WebsocketFactoryBuilder setServerName(String serverName)
      Set a server name for SNI (Server Name Indication).

      This method internally creates a String array of size 1 which contains the given serverName and calls setServerNames(String[]).

      Parameters:
      serverName - A host name.
      Returns:
      this object.
      Since:
      2.4
    • build

      public UniversalisWsBuilder build()
      Build the factory and returns an universalis websocket builder with the factory.
      Returns:
      universalis websocket builder