Search in sources :

Example 41 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class GetClient method execute.

@Override
public void execute(Context context) {
    BStruct endpoint = (BStruct) context.getRefArgument(0);
    BStruct connection = (BStruct) endpoint.getRefField(0);
    context.setReturnValues(connection);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct)

Example 42 with BStruct

use of org.ballerinalang.model.values.BStruct 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 43 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class WebSocketDispatcher method dispatchTextMessage.

public static void dispatchTextMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketTextMessage textMessage) {
    WebSocketService wsService = connectionInfo.getService();
    Resource onTextMessageResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_TEXT_MESSAGE);
    if (onTextMessageResource == null) {
        return;
    }
    List<ParamDetail> paramDetails = onTextMessageResource.getParamDetails();
    BValue[] bValues = new BValue[paramDetails.size()];
    bValues[0] = connectionInfo.getWsConnection();
    BStruct wsTextFrame = wsService.createTextFrameStruct();
    wsTextFrame.setStringField(0, textMessage.getText());
    if (textMessage.isFinalFragment()) {
        wsTextFrame.setBooleanField(0, 1);
    } else {
        wsTextFrame.setBooleanField(0, 0);
    }
    bValues[1] = wsTextFrame;
    // TODO handle BallerinaConnectorException
    Executor.submit(onTextMessageResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) Resource(org.ballerinalang.connector.api.Resource)

Example 44 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class WebSocketDispatcher method dispatchPingMessage.

private static void dispatchPingMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketControlMessage controlMessage) {
    WebSocketService wsService = connectionInfo.getService();
    Resource onPingMessageResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_PING);
    if (onPingMessageResource == null) {
        pingAutomatically(controlMessage);
        return;
    }
    List<ParamDetail> paramDetails = onPingMessageResource.getParamDetails();
    BValue[] bValues = new BValue[paramDetails.size()];
    bValues[0] = connectionInfo.getWsConnection();
    BStruct wsPingFrame = wsService.createPingFrameStruct();
    byte[] data = controlMessage.getByteArray();
    wsPingFrame.setBlobField(0, data);
    bValues[1] = wsPingFrame;
    // TODO handle BallerinaConnectorException
    Executor.submit(onPingMessageResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) Resource(org.ballerinalang.connector.api.Resource)

Example 45 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class WebSocketDispatcher method dispatchCloseMessage.

public static void dispatchCloseMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketCloseMessage closeMessage) {
    WebSocketService wsService = connectionInfo.getService();
    Resource onCloseResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_CLOSE);
    if (onCloseResource == null) {
        return;
    }
    List<ParamDetail> paramDetails = onCloseResource.getParamDetails();
    BValue[] bValues = new BValue[paramDetails.size()];
    bValues[0] = connectionInfo.getWsConnection();
    BStruct wsCloseFrame = wsService.createCloseFrameStruct();
    wsCloseFrame.setIntField(0, closeMessage.getCloseCode());
    wsCloseFrame.setStringField(0, closeMessage.getCloseReason());
    bValues[1] = wsCloseFrame;
    // TODO handle BallerinaConnectorException
    Executor.submit(onCloseResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) Resource(org.ballerinalang.connector.api.Resource)

Aggregations

BStruct (org.ballerinalang.model.values.BStruct)460 BValue (org.ballerinalang.model.values.BValue)187 Test (org.testng.annotations.Test)161 BString (org.ballerinalang.model.values.BString)131 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)53 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)39 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)37 BInteger (org.ballerinalang.model.values.BInteger)33 BMap (org.ballerinalang.model.values.BMap)29 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)26 BStructType (org.ballerinalang.model.types.BStructType)25 IOException (java.io.IOException)23 BBoolean (org.ballerinalang.model.values.BBoolean)23 BJSON (org.ballerinalang.model.values.BJSON)22 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)21 StructInfo (org.ballerinalang.util.codegen.StructInfo)21 EventContext (org.ballerinalang.nativeimpl.io.events.EventContext)20 File (java.io.File)17 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)17 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)16