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