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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations