use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project incubator-pulsar by apache.
the class DiscoveryServiceTest method connectToService.
/**
* creates ClientHandler channel to connect and communicate with server
*
* @param serviceUrl
* @param latch
* @return
* @throws URISyntaxException
*/
public static NioEventLoopGroup connectToService(String serviceUrl, CountDownLatch latch, boolean tls) throws URISyntaxException {
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
if (tls) {
SslContextBuilder builder = SslContextBuilder.forClient();
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
X509Certificate[] certificates = SecurityUtility.loadCertificatesFromPemFile(TLS_CLIENT_CERT_FILE_PATH);
PrivateKey privateKey = SecurityUtility.loadPrivateKeyFromPemFile(TLS_CLIENT_KEY_FILE_PATH);
builder.keyManager(privateKey, (X509Certificate[]) certificates);
SslContext sslCtx = builder.build();
ch.pipeline().addLast("tls", sslCtx.newHandler(ch.alloc()));
}
ch.pipeline().addLast(new ClientHandler(latch));
}
});
URI uri = new URI(serviceUrl);
InetSocketAddress serviceAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
b.connect(serviceAddress).addListener((ChannelFuture future) -> {
if (!future.isSuccess()) {
throw new IllegalStateException(future.cause());
}
});
return workerGroup;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project autobahn-java by crossbario.
the class NettyWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
if (options == null) {
if (mOptions == null) {
options = new TransportOptions();
} else {
options = new TransportOptions();
options.setAutoPingInterval(mOptions.getAutoPingInterval());
options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
}
}
URI uri;
uri = new URI(mUri);
int port = validateURIAndGetPort(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
final SslContext sslContext = getSSLContext(scheme);
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
TransportOptions opt = options;
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
if (sslContext != null) {
channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
}
channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
}
});
mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
mHandler.getHandshakeFuture().sync();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project spring-cloud-gateway by spring-cloud.
the class GatewayAutoConfigurationTests method nettyHttpClientDefaults.
@Test
public void nettyHttpClientDefaults() {
new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class, GatewayAutoConfiguration.class)).withPropertyValues("debug=true").run(context -> {
assertThat(context).hasSingleBean(HttpClient.class);
HttpClient httpClient = context.getBean(HttpClient.class);
HttpClientOptions options = httpClient.options();
PoolResources poolResources = options.getPoolResources();
assertThat(poolResources).isNotNull();
// TODO: howto test PoolResources
ClientProxyOptions proxyOptions = options.getProxyOptions();
assertThat(proxyOptions).isNull();
SslContext sslContext = options.sslContext();
assertThat(sslContext).isNull();
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project spring-cloud-gateway by spring-cloud.
the class GatewayAutoConfigurationTests method nettyHttpClientConfigured.
@Test
public void nettyHttpClientConfigured() {
new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class, GatewayAutoConfiguration.class)).withPropertyValues("spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager=true", "spring.cloud.gateway.httpclient.pool.type=fixed", "spring.cloud.gateway.httpclient.proxy.host=myhost").run(context -> {
assertThat(context).hasSingleBean(HttpClient.class);
HttpClient httpClient = context.getBean(HttpClient.class);
HttpClientOptions options = httpClient.options();
PoolResources poolResources = options.getPoolResources();
assertThat(poolResources).isNotNull();
// TODO: howto test PoolResources
ClientProxyOptions proxyOptions = options.getProxyOptions();
assertThat(proxyOptions).isNotNull();
assertThat(proxyOptions.getAddress().get().getHostName()).isEqualTo("myhost");
SslContext sslContext = options.sslContext();
assertThat(sslContext).isNotNull();
// TODO: howto test SslContext
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext 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);
}
}
Aggregations