use of org.ballerinalang.net.http.WebSocketClientConnectorListener in project ballerina by ballerina-lang.
the class Start method execute.
@Override
public void execute(Context context) {
HttpWsConnectorFactory connectorFactory = HttpUtil.createHttpWsConnectionFactory();
Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct clientEndpointConfig = clientEndpoint.getStructField(HttpConstants.CLIENT_ENDPOINT_CONFIG);
Object configs = clientEndpointConfig.getNativeData(WebSocketConstants.CLIENT_CONNECTOR_CONFIGS);
if (configs == null || !(configs instanceof WsClientConnectorConfig)) {
throw new BallerinaConnectorException("Initialize the service before starting it");
}
WebSocketClientConnector clientConnector = connectorFactory.createWsClientConnector((WsClientConnectorConfig) configs);
WebSocketClientConnectorListener clientConnectorListener = new WebSocketClientConnectorListener();
Object serviceConfig = clientEndpointConfig.getNativeData(WebSocketConstants.CLIENT_SERVICE_CONFIG);
if (serviceConfig == null || !(serviceConfig instanceof WebSocketService)) {
throw new BallerinaConnectorException("Initialize the service before starting it");
}
WebSocketService wsService = (WebSocketService) serviceConfig;
HandshakeFuture handshakeFuture = clientConnector.connect(clientConnectorListener);
handshakeFuture.setHandshakeListener(new WsHandshakeListener(context, wsService, clientConnectorListener));
context.setReturnValues();
}
Aggregations