Search in sources :

Example 1 with HTTPServicesRegistry

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();
}
Also used : HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) Service(org.ballerinalang.connector.api.Service) WebSocketService(org.ballerinalang.net.http.WebSocketService) WebSocketService(org.ballerinalang.net.http.WebSocketService) Struct(org.ballerinalang.connector.api.Struct)

Example 2 with HTTPServicesRegistry

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);
    }
}
Also used : ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) BStruct(org.ballerinalang.model.values.BStruct) HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 3 with HTTPServicesRegistry

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();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) HttpResource(org.ballerinalang.net.http.HttpResource) BValue(org.ballerinalang.model.values.BValue) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 4 with HTTPServicesRegistry

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();
}
Also used : HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) Service(org.ballerinalang.connector.api.Service) WebSocketService(org.ballerinalang.net.http.WebSocketService) WebSocketService(org.ballerinalang.net.http.WebSocketService) Struct(org.ballerinalang.connector.api.Struct)

Aggregations

HTTPServicesRegistry (org.ballerinalang.net.http.HTTPServicesRegistry)4 Struct (org.ballerinalang.connector.api.Struct)3 WebSocketServicesRegistry (org.ballerinalang.net.http.WebSocketServicesRegistry)3 Service (org.ballerinalang.connector.api.Service)2 BStruct (org.ballerinalang.model.values.BStruct)2 WebSocketService (org.ballerinalang.net.http.WebSocketService)2 BValue (org.ballerinalang.model.values.BValue)1 HttpResource (org.ballerinalang.net.http.HttpResource)1 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)1 ListenerConfiguration (org.wso2.transport.http.netty.config.ListenerConfiguration)1 ServerConnector (org.wso2.transport.http.netty.contract.ServerConnector)1