use of org.ballerinalang.net.http.HTTPServicesRegistry in project ballerina by ballerina-lang.
the class NonListeningRegister 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);
}
context.setReturnValues();
}
use of org.ballerinalang.net.http.HTTPServicesRegistry in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
try {
Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
// Creating server connector
Struct serviceEndpointConfig = serviceEndpoint.getStructField(HttpConstants.SERVICE_ENDPOINT_CONFIG);
ListenerConfiguration listenerConfiguration = getListerConfig(serviceEndpointConfig);
ServerConnector httpServerConnector = HttpConnectionManager.getInstance().createHttpServerConnector(listenerConfiguration);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVER_CONNECTOR, httpServerConnector);
// Adding service registries to native data
WebSocketServicesRegistry webSocketServicesRegistry = new WebSocketServicesRegistry();
HTTPServicesRegistry httpServicesRegistry = new HTTPServicesRegistry(webSocketServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVICE_REGISTRY, httpServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.WS_SERVICE_REGISTRY, webSocketServicesRegistry);
// set filters
setFilters(serviceEndpointConfig, serviceEndpoint);
context.setReturnValues((BValue) null);
} catch (Throwable throwable) {
BStruct errorStruct = HttpUtil.getHttpConnectorError(context, throwable);
context.setReturnValues(errorStruct);
}
}
use of org.ballerinalang.net.http.HTTPServicesRegistry in project ballerina by ballerina-lang.
the class Services method invokeNew.
public static HTTPCarbonMessage invokeNew(CompileResult compileResult, String pkgName, String endpointName, HTTPTestRequest request) {
ProgramFile programFile = compileResult.getProgFile();
BStruct connectorEndpoint = BLangConnectorSPIUtil.getPackageEndpoint(programFile, pkgName, endpointName);
HTTPServicesRegistry httpServicesRegistry = (HTTPServicesRegistry) connectorEndpoint.getNativeData("HTTP_SERVICE_REGISTRY");
TestCallableUnitCallback callback = new TestCallableUnitCallback(request);
request.setCallback(callback);
HttpResource resource = HttpDispatcher.findResource(httpServicesRegistry, request);
if (resource == null) {
return callback.getResponseMsg();
}
// TODO below should be fixed properly
// basically need to find a way to pass information from server connector side to client connector side
Map<String, Object> properties = null;
if (request.getProperty(HttpConstants.SRC_HANDLER) != null) {
Object srcHandler = request.getProperty(HttpConstants.SRC_HANDLER);
properties = Collections.singletonMap(HttpConstants.SRC_HANDLER, srcHandler);
}
BValue[] signatureParams = HttpDispatcher.getSignatureParameters(resource, request);
callback.setRequestStruct(signatureParams[0]);
Executor.submit(resource.getBalResource(), callback, properties, null, signatureParams);
callback.sync();
return callback.getResponseMsg();
}
use of org.ballerinalang.net.http.HTTPServicesRegistry 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