Swap to SslContextBuilder in examples
Motivation: Using factory methods of SslContext is deprecated. Code should be using SslContextBuilder instead. This would have been done when the old methods were deprecated, but memcache and http2 examples didn't exist in the 4.0 branch which the PR was against. Modifications: Swap to the new construction pattern. Result: No more deprecated warnings during build of examples. Users are instructed to use the new pattern.
This commit is contained in:
parent
f23b7b4efd
commit
2927cdd504
@ -33,6 +33,7 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBeh
|
|||||||
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
|
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
|
||||||
import io.netty.handler.ssl.OpenSsl;
|
import io.netty.handler.ssl.OpenSsl;
|
||||||
import io.netty.handler.ssl.SslContext;
|
import io.netty.handler.ssl.SslContext;
|
||||||
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
import io.netty.handler.ssl.SslProvider;
|
import io.netty.handler.ssl.SslProvider;
|
||||||
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
|
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
|
||||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||||
@ -64,19 +65,19 @@ public final class Http2Client {
|
|||||||
final SslContext sslCtx;
|
final SslContext sslCtx;
|
||||||
if (SSL) {
|
if (SSL) {
|
||||||
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
|
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
|
||||||
sslCtx = SslContext.newClientContext(provider,
|
sslCtx = SslContextBuilder.forClient()
|
||||||
null, InsecureTrustManagerFactory.INSTANCE,
|
.sslProvider(provider)
|
||||||
Http2SecurityUtil.CIPHERS,
|
/* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification.
|
||||||
/* 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. */
|
||||||
* Please refer to the HTTP/2 specification for cipher requirements. */
|
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
|
||||||
SupportedCipherSuiteFilter.INSTANCE,
|
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||||
new ApplicationProtocolConfig(
|
.applicationProtocolConfig(new ApplicationProtocolConfig(
|
||||||
Protocol.ALPN,
|
Protocol.ALPN,
|
||||||
SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
||||||
SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
||||||
SelectedProtocol.HTTP_2.protocolName(),
|
SelectedProtocol.HTTP_2.protocolName(),
|
||||||
SelectedProtocol.HTTP_1_1.protocolName()),
|
SelectedProtocol.HTTP_1_1.protocolName()))
|
||||||
0, 0);
|
.build();
|
||||||
} else {
|
} else {
|
||||||
sslCtx = null;
|
sslCtx = null;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBeh
|
|||||||
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
|
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
|
||||||
import io.netty.handler.ssl.OpenSsl;
|
import io.netty.handler.ssl.OpenSsl;
|
||||||
import io.netty.handler.ssl.SslContext;
|
import io.netty.handler.ssl.SslContext;
|
||||||
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
import io.netty.handler.ssl.SslProvider;
|
import io.netty.handler.ssl.SslProvider;
|
||||||
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
|
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
|
||||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||||
@ -52,19 +53,18 @@ public final class Http2Server {
|
|||||||
if (SSL) {
|
if (SSL) {
|
||||||
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
|
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
|
||||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||||
sslCtx = SslContext.newServerContext(provider,
|
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||||
ssc.certificate(), ssc.privateKey(), null,
|
.sslProvider(provider)
|
||||||
Http2SecurityUtil.CIPHERS,
|
/* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification.
|
||||||
/* 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. */
|
||||||
* Please refer to the HTTP/2 specification for cipher requirements. */
|
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
|
||||||
SupportedCipherSuiteFilter.INSTANCE,
|
.applicationProtocolConfig(new ApplicationProtocolConfig(
|
||||||
new ApplicationProtocolConfig(
|
Protocol.ALPN,
|
||||||
Protocol.ALPN,
|
SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
||||||
SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
||||||
SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL,
|
SelectedProtocol.HTTP_2.protocolName(),
|
||||||
SelectedProtocol.HTTP_2.protocolName(),
|
SelectedProtocol.HTTP_1_1.protocolName()))
|
||||||
SelectedProtocol.HTTP_1_1.protocolName()),
|
.build();
|
||||||
0, 0);
|
|
||||||
} else {
|
} else {
|
||||||
sslCtx = null;
|
sslCtx = null;
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,8 @@ import io.netty.channel.socket.SocketChannel;
|
|||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec;
|
import io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec;
|
||||||
import io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator;
|
import io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator;
|
||||||
import io.netty.handler.codec.spdy.SpdyOrHttpChooser.SelectedProtocol;
|
|
||||||
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.IdentityCipherSuiteFilter;
|
|
||||||
import io.netty.handler.ssl.SslContext;
|
import io.netty.handler.ssl.SslContext;
|
||||||
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -51,15 +46,8 @@ public final class MemcacheClient {
|
|||||||
// Configure SSL.
|
// Configure SSL.
|
||||||
final SslContext sslCtx;
|
final SslContext sslCtx;
|
||||||
if (SSL) {
|
if (SSL) {
|
||||||
sslCtx = SslContext.newClientContext(
|
sslCtx = SslContextBuilder.forClient()
|
||||||
null, InsecureTrustManagerFactory.INSTANCE, null,
|
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||||
IdentityCipherSuiteFilter.INSTANCE,
|
|
||||||
new ApplicationProtocolConfig(
|
|
||||||
Protocol.ALPN,
|
|
||||||
SelectorFailureBehavior.FATAL_ALERT,
|
|
||||||
SelectedListenerFailureBehavior.FATAL_ALERT,
|
|
||||||
SelectedProtocol.HTTP_1_1.protocolName()),
|
|
||||||
0, 0);
|
|
||||||
} else {
|
} else {
|
||||||
sslCtx = null;
|
sslCtx = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user