Class WebsocketEndpoint

java.lang.Object
com.tccc.kos.commons.web.client.WebsocketEndpoint

public class WebsocketEndpoint extends Object
Data class containing fields that identify a websocket endpoint. It is used by various websocket clients when connecting to a server.

A websocket endpoint has two pieces of data:

  • A universal resource identifier (URI), sometimes known by its more-specific term, universal resource locator (URL).
  • A set of (optional) header values, which are name/value pairs.

Examples

Using the URI string constructor

 
  public void someMethod() {
      WebsocketEndpoint endpoint = new WebsocketEndpoint("https://twitter.com/api/path/to/page?param1=value1");
      endpoint.setHeader("header1", "value1");
      endpoint.setHeader("header2", "value2");
  }
 
 

Using the URI and headers constructor

 
  public void someMethod() {
      URI uri = new URI("https", "twitter.com", "/api/path/to/page", null);
      Map<String, String> headers = new ArrayMap<>();
      headers.put("header1", "value1");
      headers.put("header2", "value2");
      WebsocketEndpoint endpoint = new WebsocketEndpoint(uri, headers);
  }
 
 
Since:
1.0
Version:
2022-08-30
See Also:
  • Constructor Details

    • WebsocketEndpoint

      public WebsocketEndpoint()
      Creates an empty websocket endpoint.
    • WebsocketEndpoint

      public WebsocketEndpoint(String str) throws URISyntaxException
      Creates a websocket endpoint by parsing the given string.
      Parameters:
      str - the string that is parsed into a URI
      Throws:
      URISyntaxException
    • WebsocketEndpoint

      public WebsocketEndpoint(URI uri)
      Creates a websocket endpoint using the given URI.
      Parameters:
      uri - the universal resource identifier
    • WebsocketEndpoint

      public WebsocketEndpoint(URI uri, Map<String,String> headers)
      Creates a websocket endpoint using the given URI and headers.
      Parameters:
      uri - the universal resource identifier
      headers - the set of name/value websocket headers
  • Method Details

    • getUri

      public URI getUri()
      Retrieves this endpoint's URI.
      Returns:
      the endpoint's URI, which can be null
    • setUri

      public void setUri(URI uri)
      Sets this endpoint's URI. This method typically used in conjunction with the default (no-args) constructor.
      Parameters:
      uri - the universal resource identifier
    • getHeaders

      public Map<String,String> getHeaders()
      Retrieves this endpoint's headers.
      Returns:
      the endpoint's headers, which cannot be null , but can be empty
    • addHeader

      public WebsocketEndpoint addHeader(String name, String value)
      Adds a header to this endpoint.
      Parameters:
      name - header name
      value - header value
    • toString

      public String toString()
      Overrides:
      toString in class Object