use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project reactor-netty by reactor.
the class TcpServerTests method sendFileSecure.
@Test
public void sendFileSecure() throws CertificateException, SSLException, InterruptedException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(ssc.cert()).build();
NettyContext context = TcpServer.create(opt -> opt.sslContext(sslServer)).newHandler((in, out) -> in.receive().asString().flatMap(word -> "GOGOGO".equals(word) ? out.sendFile(largeFile).then() : out.sendString(Mono.just("NOPE")))).block();
MonoProcessor<String> m1 = MonoProcessor.create();
MonoProcessor<String> m2 = MonoProcessor.create();
NettyContext client1 = TcpClient.create(opt -> opt.port(context.address().getPort()).sslContext(sslClient)).newHandler((in, out) -> {
in.receive().asString().log("-----------------CLIENT1").subscribe(m1::onNext);
return out.sendString(Mono.just("gogogo")).neverComplete();
}).block();
NettyContext client2 = TcpClient.create(opt -> opt.port(context.address().getPort()).sslContext(sslClient)).newHandler((in, out) -> {
in.receive().asString(StandardCharsets.UTF_8).take(2).reduceWith(String::new, String::concat).log("-----------------CLIENT2").subscribe(m2::onNext);
return out.sendString(Mono.just("GOGOGO")).neverComplete();
}).block();
String client1Response = m1.block();
String client2Response = m2.block();
client1.dispose();
client1.onClose().block();
client2.dispose();
client2.onClose().block();
context.dispose();
context.onClose().block();
Assertions.assertThat(client1Response).isEqualTo("NOPE");
Assertions.assertThat(client2Response).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here ->").contains("<- 1024 mark here").endsWith("End of File");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project reactor-netty by reactor.
the class HttpServerTests method sendFileSecure.
@Test
public void sendFileSecure() throws CertificateException, SSLException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newHandler((req, resp) -> resp.sendFile(largeFile)).block();
HttpClientResponse response = HttpClient.create(opt -> opt.port(context.address().getPort()).sslContext(sslClient)).get("/foo").block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String body = response.receive().aggregate().asString(StandardCharsets.UTF_8).block();
assertThat(body).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project reactor-netty by reactor.
the class HttpClientTest method sshExchangeAbsoluteGet.
@Test
public void sshExchangeAbsoluteGet() throws CertificateException, SSLException {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newHandler((req, resp) -> resp.sendString(Flux.just("hello ", req.uri()))).block();
HttpClientResponse response = HttpClient.create(opt -> applyHostAndPortFromContext(opt, context).sslContext(sslClient)).get("/foo").block();
context.dispose();
context.onClose().block();
String responseString = response.receive().aggregate().asString(CharsetUtil.UTF_8).block();
assertThat(responseString).isEqualTo("hello /foo");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project reactor-netty by reactor.
the class ByteBufFluxTest method doTestByteBufFluxFromPath.
private void doTestByteBufFluxFromPath(boolean withSecurity) throws Exception {
Consumer<HttpServerOptions.Builder> serverOptions;
Consumer<HttpClientOptions.Builder> clientOptions;
final int serverPort = SocketUtils.findAvailableTcpPort();
if (withSecurity) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
serverOptions = ops -> ops.port(serverPort).sslContext(sslServer);
clientOptions = ops -> ops.port(serverPort).sslContext(sslClient);
} else {
serverOptions = ops -> ops.port(serverPort);
clientOptions = ops -> ops.port(serverPort);
}
Path path = Paths.get(getClass().getResource("/largeFile.txt").toURI());
HttpServer.create(serverOptions).newHandler((req, res) -> res.send(ByteBufFlux.fromPath(path)).then()).block(Duration.ofSeconds(30));
AtomicLong counter = new AtomicLong(0);
HttpClient.create(clientOptions).get("/download").flatMapMany(NettyInbound::receive).doOnNext(b -> counter.addAndGet(b.readableBytes())).blockLast(Duration.ofSeconds(30));
assertTrue(counter.get() == 1245);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project drill by apache.
the class SSLConfigServer method initNettySslContext.
@Override
public SslContext initNettySslContext() throws DrillException {
final SslContext sslCtx;
if (!userSslEnabled) {
return null;
}
KeyManagerFactory kmf;
TrustManagerFactory tmf;
try {
if (keyStorePath.isEmpty()) {
throw new DrillException("No Keystore provided.");
}
kmf = initializeKeyManagerFactory();
tmf = initializeTrustManagerFactory();
sslCtx = SslContextBuilder.forServer(kmf).trustManager(tmf).protocols(protocol).sslProvider(getProvider()).build();
} catch (Exception e) {
// Catch any SSL initialization Exceptions here and abort.
throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized - ").append("[ ").append(e.getMessage()).append("]. ").toString());
}
this.nettySslContext = sslCtx;
return sslCtx;
}
Aggregations