Class WebSocketExtension

java.lang.Object
com.neovisionaries.ws.client.WebSocketExtension
Direct Known Subclasses:
PerMessageCompressionExtension

public class WebSocketExtension extends Object
A class to hold the name and the parameters of a WebSocket extension.
  • Field Details

  • Constructor Details

    • WebSocketExtension

      public WebSocketExtension(String name)
      Constructor with an extension name.
      Parameters:
      name - The extension name.
      Throws:
      IllegalArgumentException - The given name is not a valid token.
    • WebSocketExtension

      public WebSocketExtension(WebSocketExtension source)
      Copy constructor.
      Parameters:
      source - A source extension. Must not be null.
      Throws:
      IllegalArgumentException - The given argument is null.
      Since:
      1.6
  • Method Details

    • getName

      public String getName()
      Get the extension name.
      Returns:
      The extension name.
    • getParameters

      public Map<String,String> getParameters()
      Get the parameters.
      Returns:
      The parameters.
    • containsParameter

      public boolean containsParameter(String key)
      Check if the parameter identified by the key is contained.
      Parameters:
      key - The name of the parameter.
      Returns:
      true if the parameter is contained.
    • getParameter

      public String getParameter(String key)
      Get the value of the specified parameter.
      Parameters:
      key - The name of the parameter.
      Returns:
      The value of the parameter. null may be returned.
    • setParameter

      public WebSocketExtension setParameter(String key, String value)
      Set a value to the specified parameter.
      Parameters:
      key - The name of the parameter.
      value - The value of the parameter. If not null, it must be a valid token. Note that RFC 6455 says "When using the quoted-string syntax variant, the value after quoted-string unescaping MUST conform to the 'token' ABNF."
      Returns:
      this object.
      Throws:
      IllegalArgumentException -
      • The key is not a valid token.
      • The value is not null and it is not a valid token.
    • toString

      public String toString()
      Stringify this object into the format "{name}[; {key}[={value}]]*".
      Overrides:
      toString in class Object
    • validate

      void validate() throws WebSocketException
      Validate this instance. This method is expected to be overridden.
      Throws:
      WebSocketException
    • parse

      public static WebSocketExtension parse(String string)
      Parse a string as a WebSocketExtension. The input string should comply with the format described in 9.1. Negotiating Extensions in RFC 6455.
      Parameters:
      string - A string that represents a WebSocket extension.
      Returns:
      A new WebSocketExtension instance that represents the given string. If the input string does not comply with RFC 6455, null is returned.
    • extractValue

      private static String extractValue(String[] pair)
    • createInstance

      private static WebSocketExtension createInstance(String name)