Package com.tccc.kos.commons.web.client
Class WebsocketEndpoint
java.lang.Object
com.tccc.kos.commons.web.client.WebsocketEndpoint
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 Summary
ConstructorsConstructorDescriptionCreates an empty websocket endpoint.WebsocketEndpoint
(String str) Creates a websocket endpoint by parsing the given string.WebsocketEndpoint
(URI uri) Creates a websocket endpoint using the given URI.WebsocketEndpoint
(URI uri, Map<String, String> headers) Creates a websocket endpoint using the given URI and headers. -
Method Summary
-
Constructor Details
-
WebsocketEndpoint
public WebsocketEndpoint()Creates an empty websocket endpoint. -
WebsocketEndpoint
Creates a websocket endpoint by parsing the given string.- Parameters:
str
- the string that is parsed into a URI- Throws:
URISyntaxException
-
WebsocketEndpoint
Creates a websocket endpoint using the given URI.- Parameters:
uri
- the universal resource identifier
-
WebsocketEndpoint
Creates a websocket endpoint using the given URI and headers.- Parameters:
uri
- the universal resource identifierheaders
- the set of name/value websocket headers
-
-
Method Details
-
getUri
Retrieves this endpoint's URI.- Returns:
- the endpoint's URI, which can be
null
-
setUri
Sets this endpoint's URI. This method typically used in conjunction with the default (no-args) constructor.- Parameters:
uri
- the universal resource identifier
-
getHeaders
Retrieves this endpoint's headers.- Returns:
- the endpoint's headers, which cannot be
null
, but can be empty
-
addHeader
Adds a header to this endpoint.- Parameters:
name
- header namevalue
- header value
-
toString
-