Search in sources :

Example 1 with BNullType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BNullType in project ballerina by ballerina-lang.

the class ServiceProtoUtils method getResponseMessage.

private static Message getResponseMessage(ResourceNode resourceNode) throws GrpcServerException {
    org.wso2.ballerinalang.compiler.semantics.model.types.BType responseType;
    BLangInvocation sendExpression = getInvocationExpression(resourceNode.getBody());
    if (sendExpression != null) {
        responseType = getReturnType(sendExpression);
    } else {
        // if compiler plugin could not find
        responseType = new BNullType();
    }
    return responseType != null ? generateMessageDefinition(responseType) : null;
}
Also used : BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BNullType(org.wso2.ballerinalang.compiler.semantics.model.types.BNullType)

Example 2 with BNullType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BNullType in project ballerina by ballerina-lang.

the class ServiceProtoUtils method getStreamingServiceDefinition.

private static Service getStreamingServiceDefinition(ServiceNode serviceNode, ServiceConfiguration serviceConfig, File.Builder fileBuilder) throws GrpcServerException {
    // Protobuf service definition builder.
    Service.Builder serviceBuilder = Service.newBuilder(serviceNode.getName().getValue());
    Message requestMessage = null;
    Message responseMessage = null;
    for (ResourceNode resourceNode : serviceNode.getResources()) {
        if (ON_MESSAGE_RESOURCE.equals(resourceNode.getName().getValue())) {
            requestMessage = getRequestMessage(resourceNode);
            Message respMsg = getResponseMessage(resourceNode);
            if (respMsg != null && !(MessageKind.EMPTY.equals(respMsg.getMessageKind()))) {
                responseMessage = getResponseMessage(resourceNode);
                break;
            }
        }
        if (ON_COMPLETE_RESOURCE.equals(resourceNode.getName().getValue())) {
            Message respMsg = getResponseMessage(resourceNode);
            if (respMsg != null && !(MessageKind.EMPTY.equals(respMsg.getMessageKind()))) {
                responseMessage = respMsg;
            }
        }
    }
    if (requestMessage == null) {
        throw new GrpcServerException("Cannot find request message definition for streaming service: " + serviceNode.getName().getValue());
    }
    if (responseMessage == null) {
        responseMessage = generateMessageDefinition(new BNullType());
    /*throw new GrpcServerException("Cannot find response message definition for streaming service: " +
                    serviceNode.getName().getValue());*/
    }
    if (requestMessage.getMessageKind() == MessageKind.USER_DEFINED) {
        if (!fileBuilder.getRegisteredMessages().contains(requestMessage.getDescriptorProto())) {
            fileBuilder.setMessage(requestMessage);
        }
    }
    if (requestMessage.getDependency() != null) {
        if (!fileBuilder.getRegisteredDependencies().contains(requestMessage.getDependency())) {
            fileBuilder.setDependeny(requestMessage.getDependency());
        }
    }
    if (responseMessage.getDependency() != null) {
        if (!fileBuilder.getRegisteredDependencies().contains(responseMessage.getDependency())) {
            fileBuilder.setDependeny(responseMessage.getDependency());
        }
    }
    Method resourceMethod = Method.newBuilder(serviceConfig.getRpcEndpoint()).setClientStreaming(serviceConfig.isClientStreaming()).setServerStreaming(serviceConfig.isServerStreaming()).setInputType(requestMessage.getMessageType()).setOutputType(responseMessage.getMessageType()).build();
    serviceBuilder.addMethod(resourceMethod);
    return serviceBuilder.build();
}
Also used : Message(org.ballerinalang.net.grpc.proto.definition.Message) EmptyMessage(org.ballerinalang.net.grpc.proto.definition.EmptyMessage) WrapperMessage(org.ballerinalang.net.grpc.proto.definition.WrapperMessage) UserDefinedMessage(org.ballerinalang.net.grpc.proto.definition.UserDefinedMessage) Service(org.ballerinalang.net.grpc.proto.definition.Service) Method(org.ballerinalang.net.grpc.proto.definition.Method) BNullType(org.wso2.ballerinalang.compiler.semantics.model.types.BNullType) ResourceNode(org.ballerinalang.model.tree.ResourceNode) GrpcServerException(org.ballerinalang.net.grpc.exception.GrpcServerException)

Aggregations

BNullType (org.wso2.ballerinalang.compiler.semantics.model.types.BNullType)2 ResourceNode (org.ballerinalang.model.tree.ResourceNode)1 GrpcServerException (org.ballerinalang.net.grpc.exception.GrpcServerException)1 EmptyMessage (org.ballerinalang.net.grpc.proto.definition.EmptyMessage)1 Message (org.ballerinalang.net.grpc.proto.definition.Message)1 Method (org.ballerinalang.net.grpc.proto.definition.Method)1 Service (org.ballerinalang.net.grpc.proto.definition.Service)1 UserDefinedMessage (org.ballerinalang.net.grpc.proto.definition.UserDefinedMessage)1 WrapperMessage (org.ballerinalang.net.grpc.proto.definition.WrapperMessage)1 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)1