diff --git a/example/src/main/java/io/netty/example/http2/client/Http2Client.java b/example/src/main/java/io/netty/example/http2/client/Http2Client.java index 18f1402b38..01728a5574 100644 --- a/example/src/main/java/io/netty/example/http2/client/Http2Client.java +++ b/example/src/main/java/io/netty/example/http2/client/Http2Client.java @@ -33,6 +33,7 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBeh import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; @@ -63,19 +64,19 @@ public final class Http2Client { final SslContext sslCtx; if (SSL) { SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; - sslCtx = SslContext.newClientContext(provider, - null, InsecureTrustManagerFactory.INSTANCE, - Http2SecurityUtil.CIPHERS, - /* NOTE: the following filter may not include all ciphers required by the HTTP/2 specification - * Please refer to the HTTP/2 specification for cipher requirements. */ - SupportedCipherSuiteFilter.INSTANCE, - new ApplicationProtocolConfig( - Protocol.ALPN, - SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedProtocol.HTTP_2.protocolName(), - SelectedProtocol.HTTP_1_1.protocolName()), - 0, 0); + sslCtx = SslContextBuilder.forClient() + .sslProvider(provider) + /* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification. + * Please refer to the HTTP/2 specification for cipher requirements. */ + .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) + .trustManager(InsecureTrustManagerFactory.INSTANCE) + .applicationProtocolConfig(new ApplicationProtocolConfig( + Protocol.ALPN, + SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, + SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, + SelectedProtocol.HTTP_2.protocolName(), + SelectedProtocol.HTTP_1_1.protocolName())) + .build(); } else { sslCtx = null; } diff --git a/example/src/main/java/io/netty/example/http2/server/Http2Server.java b/example/src/main/java/io/netty/example/http2/server/Http2Server.java index c98aec7f22..d86b616c12 100644 --- a/example/src/main/java/io/netty/example/http2/server/Http2Server.java +++ b/example/src/main/java/io/netty/example/http2/server/Http2Server.java @@ -32,6 +32,7 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBeh import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.util.SelfSignedCertificate; @@ -52,19 +53,18 @@ public final class Http2Server { if (SSL) { SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; SelfSignedCertificate ssc = new SelfSignedCertificate(); - sslCtx = SslContext.newServerContext(provider, - ssc.certificate(), ssc.privateKey(), null, - Http2SecurityUtil.CIPHERS, - /* NOTE: the following filter may not include all ciphers required by the HTTP/2 specification - * Please refer to the HTTP/2 specification for cipher requirements. */ - SupportedCipherSuiteFilter.INSTANCE, - new ApplicationProtocolConfig( - Protocol.ALPN, - SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedProtocol.HTTP_2.protocolName(), - SelectedProtocol.HTTP_1_1.protocolName()), - 0, 0); + sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) + .sslProvider(provider) + /* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification. + * Please refer to the HTTP/2 specification for cipher requirements. */ + .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) + .applicationProtocolConfig(new ApplicationProtocolConfig( + Protocol.ALPN, + SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, + SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, + SelectedProtocol.HTTP_2.protocolName(), + SelectedProtocol.HTTP_1_1.protocolName())) + .build(); } else { sslCtx = null; } diff --git a/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java b/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java index 4dc6ae4fdb..d6f8c755fe 100644 --- a/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java +++ b/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java @@ -24,17 +24,10 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.handler.codec.http2.Http2OrHttpChooser.SelectedProtocol; -import io.netty.handler.codec.http2.Http2SecurityUtil; import io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec; import io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator; -import io.netty.handler.ssl.ApplicationProtocolConfig; -import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol; -import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior; -import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslProvider; -import io.netty.handler.ssl.SupportedCipherSuiteFilter; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import java.io.BufferedReader; @@ -53,18 +46,8 @@ public final class MemcacheClient { // Configure SSL. final SslContext sslCtx; if (SSL) { - sslCtx = SslContext.newClientContext(null, - null, InsecureTrustManagerFactory.INSTANCE, Http2SecurityUtil.CIPHERS, - /* NOTE: the following filter may not include all ciphers required by the HTTP/2 specification - * Please refer to the HTTP/2 specification for cipher requirements. */ - SupportedCipherSuiteFilter.INSTANCE, - new ApplicationProtocolConfig( - Protocol.ALPN, - SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, - SelectedProtocol.HTTP_2.protocolName(), - SelectedProtocol.HTTP_1_1.protocolName()), - 0, 0); + sslCtx = SslContextBuilder.forClient() + .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); } else { sslCtx = null; }