Example usage for io.netty.handler.ssl SslContext newServerContext

List of usage examples for io.netty.handler.ssl SslContext newServerContext

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslContext newServerContext.

Prototype

@Deprecated
public static SslContext newServerContext(SslProvider provider, File certChainFile, File keyFile,
        String keyPassword, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
        ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout) throws SSLException 

Source Link

Document

Creates a new server-side SslContext .

Usage

From source file:io.aos.netty5.spdy.server.SpdyServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey(), null, null,
            IdentityCipherSuiteFilter.INSTANCE,
            Arrays.asList(SelectedProtocol.SPDY_3_1.protocolName(), SelectedProtocol.HTTP_1_1.protocolName()),
            JettyNpnSslEngineWrapper.instance(), 0, 0);

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*  ww w  .  ja  va 2 s. c o m*/
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SpdyServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.err
                .println("Open your SPDY-enabled web browser and navigate to https://127.0.0.1:" + PORT + '/');
        System.err.println("If using Chrome browser, check your SPDY sessions at chrome://net-internals/#spdy");

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:netty.mmb.http2.Server.Http2Server.java

License:Apache License

public static void main(String[] args) throws Exception {
    // SSL/*from  w  w  w .jav  a 2  s  .  com*/
    final SslContext sslCtx;
    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);
    } else {
        sslCtx = null;
    }
    // EventLoopGroup
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        //            
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                //                    log
                .handler(new LoggingHandler(LogLevel.INFO))
                //                    Http2Server
                .childHandler(new Http2ServerInitializer(sslCtx));

        //            
        Channel ch = b.bind(PORT).sync().channel();

        System.err.println("Open your HTTP/2-enabled web browser and navigate to " + (SSL ? "https" : "http")
                + "://127.0.0.1:" + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}