Package ej.websocket

Class WebSocketURI


  • public class WebSocketURI
    extends Object
    WebSocketURI is a container for a WebSocket URI as described in RFC 6455. See section 3 (and section 4.1).

    Limitations of this implementation:

    • Queries with ? are not checked.
    • Fragments are not checked.
    • '#' character is not managed.
    • Field Detail

      • DEFAULT_NOT_SECURE_PORT

        public static final int DEFAULT_NOT_SECURE_PORT
        The default port for a ws:// URI as defined in RFC6455 (see section 3). If port is not specified during URI creation, then this port will be used.
        See Also:
        Constant Field Values
      • DEFAULT_SECURE_PORT

        public static final int DEFAULT_SECURE_PORT
        The default port for a wss:// URI. If port is not specified during URI creation, then this port will be used.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WebSocketURI

        public WebSocketURI​(String host,
                            int port,
                            String resourceName,
                            boolean isSecure)
                     throws IllegalArgumentException
        Create a new websocket URI.
        Parameters:
        host - hostname or IP address of the remote host
        port - port of the remote host
        resourceName - identifier for the service provided by the server
        isSecure - flag indicating if the websocket is secure (wss) or not
        Throws:
        IllegalArgumentException - if host is null or empty; if port is 0 (zero); if resourceName is null
      • WebSocketURI

        public WebSocketURI​(String host,
                            int port,
                            String resourceName)
                     throws IllegalArgumentException
        Create a new (not secure) websocket URI.
        Parameters:
        host - hostname or IP address of the remote host
        port - port of the remote host
        resourceName - identifier for the service provided by the server
        Throws:
        IllegalArgumentException - if host is null or empty; if port is 0 (zero); if resourceName is null
      • WebSocketURI

        public WebSocketURI​(String host,
                            int port)
                     throws IllegalArgumentException
        Create a new (not secure) websocket URI. Resource name is assumed to be "/".
        Parameters:
        host - hostname or IP address of the remote host
        port - port of the remote host
        Throws:
        IllegalArgumentException - if resourceName is null
    • Method Detail

      • getHost

        public String getHost()
        Get the host (hostname or IP address).
        Returns:
        hostname of the peer
      • getPort

        public int getPort()
        Get the port of the host.
        Returns:
        port of the remote peer
      • getResourceName

        public String getResourceName()
        Get the resource name, that is the name of the remote websocket endpoint.
        Returns:
        the request-URI of the remote endpoint
      • isSecure

        public boolean isSecure()
        Tell if the websocket is secured or not.
        Returns:
        true is this URI is intended to be create a secured connection (wss://); false otherwise (ws://)
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

        The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

         getClass().getName() + '@' + Integer.toHexString(hashCode())
         
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object.