use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.
the class ServerConnectorRegistry method registerService.
/**
* This method is used to register service to relevant server connector implementation.
*
* @param serviceInfo to be registered.
*/
public void registerService(ServiceInfo serviceInfo) {
if (!serverConnectorMap.containsKey(serviceInfo.getEndpointName())) {
throw BLangExceptionHelper.getRuntimeException(RuntimeErrors.INVALID_SERVICE_PROTOCOL, serviceInfo.getEndpointName());
}
Service service = buildService(serviceInfo);
serverConnectorMap.get(serviceInfo.getEndpointName()).serviceRegistered(service);
}
use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.
the class RegisterWebSubSubscriberServiceEndpoint method execute.
@Override
public void execute(Context context) {
Service service = BLangConnectorSPIUtil.getServiceRegistered(context);
Struct subscriberServiceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct serviceEndpoint = ConnectorSPIModelHelper.createStruct((BStruct) ((BStruct) (subscriberServiceEndpoint.getVMValue())).getRefField(1));
WebSubServicesRegistry webSubServicesRegistry = (WebSubServicesRegistry) serviceEndpoint.getNativeData(WebSubSubscriberConstants.WEBSUB_SERVICE_REGISTRY);
webSubServicesRegistry.registerWebSubSubscriberService(service);
context.setReturnValues();
}
use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct clientEndpointConfig = clientEndpoint.getStructField(HttpConstants.CLIENT_ENDPOINT_CONFIG);
String remoteUrl = clientEndpointConfig.getStringField(WebSocketConstants.CLIENT_URL_CONFIG);
Value clientServiceType = clientEndpointConfig.getTypeField(WebSocketConstants.CLIENT_SERVICE_CONFIG);
Service service = BLangConnectorSPIUtil.getServiceFromType(context.getProgramFile(), clientServiceType);
if (service == null) {
throw new BallerinaConnectorException("Cannot find client service: " + clientServiceType);
}
if (WebSocketConstants.WEBSOCKET_CLIENT_ENDPOINT_NAME.equals(service.getEndpointName())) {
WebSocketService wsService = new WebSocketService(service);
// TODO: Fix this validation
// WebSocketServiceValidator.validateServiceEndpoint(wsService);
WsClientConnectorConfig clientConnectorConfig = new WsClientConnectorConfig(remoteUrl);
Value[] subProtocolValues = clientEndpointConfig.getArrayField(WebSocketConstants.CLIENT_SUBPROTOCOLS_CONFIG);
if (subProtocolValues != null) {
clientConnectorConfig.setSubProtocols(Arrays.stream(subProtocolValues).map(Value::getStringValue).toArray(String[]::new));
}
Map<String, Value> headerValues = clientEndpointConfig.getMapField(WebSocketConstants.CLIENT_CUSTOMHEADERS_CONFIG);
if (headerValues != null) {
clientConnectorConfig.addHeaders(getCustomHeaders(headerValues));
}
long idleTimeoutInSeconds = clientEndpointConfig.getIntField(WebSocketConstants.CLIENT_IDLETIMOUT_CONFIG);
if (idleTimeoutInSeconds > 0) {
clientConnectorConfig.setIdleTimeoutInMillis((int) (idleTimeoutInSeconds * 1000));
}
clientEndpointConfig.addNativeData(WebSocketConstants.CLIENT_SERVICE_CONFIG, wsService);
clientEndpointConfig.addNativeData(WebSocketConstants.CLIENT_CONNECTOR_CONFIGS, clientConnectorConfig);
} else {
throw new BallerinaConnectorException("Incorrect endpoint: " + service.getEndpointName());
}
context.setReturnValues();
}
use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.
the class Register method execute.
@Override
public void execute(Context context) {
Service service = BLangConnectorSPIUtil.getServiceRegistered(context);
Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
HTTPServicesRegistry httpServicesRegistry = getHttpServicesRegistry(serviceEndpoint);
WebSocketServicesRegistry webSocketServicesRegistry = getWebSocketServicesRegistry(serviceEndpoint);
// TODO: In HTTP to WebSocket upgrade register WebSocket service in WebSocketServiceRegistry
if (HttpConstants.HTTP_SERVICE_ENDPOINT_NAME.equals(service.getEndpointName())) {
httpServicesRegistry.registerService(service);
}
if (WebSocketConstants.WEBSOCKET_ENDPOINT_NAME.equals(service.getEndpointName())) {
WebSocketService webSocketService = new WebSocketService(service);
webSocketServicesRegistry.registerService(webSocketService);
}
if (!isConnectorStarted(serviceEndpoint)) {
startServerConnector(serviceEndpoint, httpServicesRegistry, webSocketServicesRegistry);
}
context.setReturnValues();
}
Aggregations