use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.
the class RetrieveSecret method execute.
@Override
public void execute(Context context) {
String secret = ((BStruct) BLangConnectorSPIUtil.getService(context.getProgramFile(), ((BServiceType) ((BTypeDescValue) (context).getLocalWorkerData().refRegs[0]).value())).getAnnotationList(WebSubSubscriberConstants.WEBSUB_PACKAGE_PATH, WebSubSubscriberConstants.ANN_NAME_WEBSUB_SUBSCRIBER_SERVICE_CONFIG).get(0).getValue().getVMValue()).getStringField(3);
context.setReturnValues(new BString(secret));
}
use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.
the class NonBlockingExecute method execute.
@Override
public void execute(Context context) {
BStruct serviceStub = (BStruct) context.getRefArgument(SERVICE_STUB_REF_INDEX);
if (serviceStub == null) {
notifyErrorReply(context, "Error while getting connector. gRPC Client connector is " + "not initialized properly");
return;
}
Object connectionStub = serviceStub.getNativeData(SERVICE_STUB);
if (connectionStub == null) {
notifyErrorReply(context, "Error while getting connection stub. gRPC Client connector " + "is not initialized properly");
return;
}
String methodName = context.getStringArgument(0);
if (methodName == null) {
notifyErrorReply(context, "Error while processing the request. RPC endpoint doesn't " + "set properly");
return;
}
com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor = MessageRegistry.getInstance().getMethodDescriptor(methodName);
if (methodDescriptor == null) {
notifyErrorReply(context, "No registered method descriptor for '" + methodName + "'");
return;
}
if (connectionStub instanceof GrpcNonBlockingStub) {
BValue payloadBValue = context.getRefArgument(1);
Message requestMsg = MessageUtils.generateProtoMessage(payloadBValue, methodDescriptor.getInputType());
GrpcNonBlockingStub grpcNonBlockingStub = (GrpcNonBlockingStub) connectionStub;
BTypeDescValue serviceType = (BTypeDescValue) context.getRefArgument(2);
Service callbackService = BLangConnectorSPIUtil.getServiceFromType(context.getProgramFile(), getTypeField(serviceType));
try {
MethodDescriptor.MethodType methodType = getMethodType(methodDescriptor);
if (methodType.equals(MethodDescriptor.MethodType.UNARY)) {
grpcNonBlockingStub.executeUnary(requestMsg, new DefaultStreamObserver(callbackService), methodName);
} else if (methodType.equals(MethodDescriptor.MethodType.SERVER_STREAMING)) {
grpcNonBlockingStub.executeServerStreaming(requestMsg, new DefaultStreamObserver(callbackService), methodName);
} else {
notifyErrorReply(context, "Error while executing the client call. Method type " + methodType.name() + " not supported");
return;
}
context.setReturnValues();
return;
} catch (RuntimeException | GrpcClientException e) {
notifyErrorReply(context, "gRPC Client Connector Error :" + e.getMessage());
return;
}
}
notifyErrorReply(context, "Error while processing the request message. Connection Sub " + "type not supported");
}
use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.
the class BallerinaHTTPConnectorListener method getRequestFilterContext.
private BValue getRequestFilterContext(HttpResource httpResource) {
BStruct filterCtxtStruct = BLangConnectorSPIUtil.createBStruct(httpResource.getBalResource().getResourceInfo().getServiceInfo().getPackageInfo().getProgramFile(), PROTOCOL_PACKAGE_HTTP, "FilterContext");
filterCtxtStruct.setRefField(0, new BTypeDescValue(httpResource.getBalResource().getResourceInfo().getServiceInfo().getType()));
filterCtxtStruct.setStringField(0, httpResource.getParentService().getName());
filterCtxtStruct.setStringField(1, httpResource.getName());
return filterCtxtStruct;
}
use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.
the class AbstractSQLAction method getStructType.
protected BStructType getStructType(Context context) {
BStructType structType = null;
BTypeDescValue type = (BTypeDescValue) context.getNullableRefArgument(2);
if (type != null) {
structType = (BStructType) type.value();
}
return structType;
}
use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.
the class ServiceTypeTest method testServiceType.
@Test
public void testServiceType() {
BValue[] returns = BRunUtil.invoke(compileResult, "testServiceType");
Assert.assertTrue(returns[0] instanceof BTypeDescValue);
Assert.assertEquals(returns[0].stringValue(), "HelloWorld");
final BTypeDescValue value = (BTypeDescValue) returns[0];
Assert.assertTrue(value.value() instanceof BServiceType);
}
Aggregations