Search in sources :

Example 1 with SSLHandlerFactory

use of org.ballerinalang.net.grpc.ssl.SSLHandlerFactory in project ballerina by ballerina-lang.

the class InitEndpoint method execute.

@Override
public void execute(Context context) {
    try {
        Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
        Struct serviceEndpointConfig = serviceEndpoint.getStructField(EndpointConstants.ENDPOINT_CONFIG);
        EndpointConfiguration configuration = EndpointUtils.getEndpointConfiguration(serviceEndpointConfig);
        io.grpc.ServerBuilder serverBuilder;
        if (configuration.getSslConfig() != null) {
            SslContext sslCtx = new SSLHandlerFactory(configuration.getSslConfig()).createHttp2TLSContextForServer();
            serverBuilder = GrpcServicesBuilder.initService(configuration, sslCtx);
        } else {
            serverBuilder = GrpcServicesBuilder.initService(configuration, null);
        }
        serviceEndpoint.addNativeData(SERVICE_BUILDER, serverBuilder);
        context.setReturnValues();
    } catch (Throwable throwable) {
        BStruct err = getConnectorError(context, throwable);
        context.setError(err);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) EndpointConfiguration(org.ballerinalang.net.grpc.config.EndpointConfiguration) SSLHandlerFactory(org.ballerinalang.net.grpc.ssl.SSLHandlerFactory) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) SslContext(io.netty.handler.ssl.SslContext)

Example 2 with SSLHandlerFactory

use of org.ballerinalang.net.grpc.ssl.SSLHandlerFactory in project ballerina by ballerina-lang.

the class InitEndpoint method execute.

@Override
public void execute(Context context) {
    try {
        Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
        // Creating client endpoint with channel as native data.
        Struct endpointConfig = clientEndpoint.getStructField(EndpointConstants.ENDPOINT_CONFIG);
        EndpointConfiguration configuration = EndpointUtils.getEndpointConfiguration(endpointConfig);
        ManagedChannel channel;
        if (configuration.getSslConfig() == null) {
            channel = ManagedChannelBuilder.forAddress(configuration.getHost(), configuration.getPort()).usePlaintext(true).build();
        } else {
            SslContext sslContext = new SSLHandlerFactory(configuration.getSslConfig()).createHttp2TLSContextForClient();
            channel = NettyChannelBuilder.forAddress(generateSocketAddress(configuration.getHost(), configuration.getPort())).flowControlWindow(65 * 1024).maxInboundMessageSize(MAX_MESSAGE_SIZE).sslContext(sslContext).build();
        }
        clientEndpoint.addNativeData(CHANNEL_KEY, channel);
    } catch (Throwable throwable) {
        BStruct errorStruct = MessageUtils.getConnectorError(context, throwable);
        context.setError(errorStruct);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ManagedChannel(io.grpc.ManagedChannel) EndpointConfiguration(org.ballerinalang.net.grpc.config.EndpointConfiguration) SSLHandlerFactory(org.ballerinalang.net.grpc.ssl.SSLHandlerFactory) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

SslContext (io.netty.handler.ssl.SslContext)2 Struct (org.ballerinalang.connector.api.Struct)2 BStruct (org.ballerinalang.model.values.BStruct)2 EndpointConfiguration (org.ballerinalang.net.grpc.config.EndpointConfiguration)2 SSLHandlerFactory (org.ballerinalang.net.grpc.ssl.SSLHandlerFactory)2 ManagedChannel (io.grpc.ManagedChannel)1