Package ej.websocket
Class WebSocketURI
- java.lang.Object
-
- ej.websocket.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 Summary
Fields Modifier and Type Field Description static intDEFAULT_NOT_SECURE_PORTThe default port for a ws:// URI as defined in RFC6455 (see section 3).static intDEFAULT_SECURE_PORTThe default port for a wss:// URI.
-
Constructor Summary
Constructors Constructor Description WebSocketURI(String host)Create a new (not secure) websocket URI.WebSocketURI(String host, int port)Create a new (not secure) websocket URI.WebSocketURI(String host, int port, String resourceName)Create a new (not secure) websocket URI.WebSocketURI(String host, int port, String resourceName, boolean isSecure)Create a new websocket URI.WebSocketURI(String host, String resourceName)Create a new (not secure) websocket URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetHost()Get the host (hostname or IP address).intgetPort()Get the port of the host.StringgetResourceName()Get the resource name, that is the name of the remote websocket endpoint.booleanisSecure()Tell if the websocket is secured or not.StringtoString()Returns a string representation of the object.
-
-
-
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 hostport- port of the remote hostresourceName- identifier for the service provided by the serverisSecure- 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 hostport- port of the remote hostresourceName- 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, String resourceName) throws IllegalArgumentException
Create a new (not secure) websocket URI. Default port (DEFAULT_NOT_SECURE_PORT) is used.- Parameters:
host- hostname or IP address of the remote hostresourceName- identifier for the service provided by the server- Throws:
IllegalArgumentException- 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 hostport- port of the remote host- Throws:
IllegalArgumentException- if resourceName is null
-
WebSocketURI
public WebSocketURI(String host) throws IllegalArgumentException
Create a new (not secure) websocket URI. Resource name is assumed to be "/". Default port (DEFAULT_NOT_SECURE_PORT) is used.- Parameters:
host- hostname or IP address 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:ObjectReturns a string representation of the object. In general, thetoStringmethod 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
toStringmethod for classObjectreturns 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())
-
-