WebSocket Client Service
The WebSocket Client service is a component of the Cloud Gateway. It enables applications to establish a WebSocket connection with a WebSocket server endpoint. The Predix Edge implementation exposes the WebSocket Client through the Java WebSocket API (JSR-356). This allows applications running on Predix Edge to be WebSocket-provider agnostic.
Example Use Cases
- A service attempts to connect to a
WebSocket
endpoint to send and receive data. The component first gets an instance of the client container, which implements theWebSocketContainer
interface through a dependency injection. The service then calls aconnectToServer()
method and passes aClientEndpoint
-annotatedWebSocket
class to the method. - A service attempts to connect to a
WebSocket
endpoint to transfer/receive data. The component first gets an instance of the client container, which implements theWebSocketContainer
interface through dependency injection. It then calls aconnectToServer()
method and passes aClientEndpoint
-annotated WebSocket object instance to the method. This method allows the consumer to register a WebSocketClientEndpoint
with a configured state as opposed to an uninstantiated class.
SSL Context
The WebSocket Client uses the global SSLContext set in the Security Admin configuration file at <Predix Machine runtime container location>/security to enable WebSockets over TLS. After being configured, the client automatically establishes a TLS connection when connecting to a WSS URI.
Dependencies
- The following Maven dependency is required:
<dependency> <groupId>javax.websocket</groupId> <artifactId>javax.websocket-api</artifactId> <version>1.0</version> </dependency>
- The following OSGi import is required to consume the bundle:
Import-Package: javax.websocket;version="[1.0,2)"