Example usage for io.netty.handler.ssl SslHandler SslHandler

List of usage examples for io.netty.handler.ssl SslHandler SslHandler

Introduction

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

Prototype

public SslHandler(SSLEngine engine) 

Source Link

Document

Creates a new instance which runs all delegated tasks directly on the EventExecutor .

Usage

From source file:com.corundumstudio.socketio.SocketIOChannelInitializer.java

License:Apache License

/**
 * Adds the ssl handler/* www.j  a  v a  2 s .  c o m*/
 *
 * @return
 */
protected void addSslHandler(ChannelPipeline pipeline) {
    if (sslContext != null) {
        SSLEngine engine = sslContext.createSSLEngine();
        engine.setUseClientMode(false);
        pipeline.addLast(SSL_HANDLER, new SslHandler(engine));
    }
}

From source file:com.couchbase.client.core.endpoint.AbstractEndpoint.java

License:Apache License

/**
 * Create a new {@link AbstractEndpoint}.
 *
 * @param hostname the hostname/ipaddr of the remote channel.
 * @param bucket the name of the bucket.
 * @param password the password of the bucket.
 * @param port the port of the remote channel.
 * @param environment the environment of the core.
 * @param responseBuffer the response buffer for passing responses up the stack.
 *//*from  w w  w.j a va 2  s .  c  om*/
protected AbstractEndpoint(final String hostname, final String bucket, final String password, final int port,
        final CoreEnvironment environment, final RingBuffer<ResponseEvent> responseBuffer,
        boolean isTransient) {
    super(LifecycleState.DISCONNECTED);
    this.bucket = bucket;
    this.password = password;
    this.responseBuffer = responseBuffer;
    this.env = environment;
    this.isTransient = isTransient;
    if (environment.sslEnabled()) {
        this.sslEngineFactory = new SSLEngineFactory(environment);
    }

    Class<? extends Channel> channelClass = NioSocketChannel.class;
    if (environment.ioPool() instanceof EpollEventLoopGroup) {
        channelClass = EpollSocketChannel.class;
    } else if (environment.ioPool() instanceof OioEventLoopGroup) {
        channelClass = OioSocketChannel.class;
    }

    ByteBufAllocator allocator = env.bufferPoolingEnabled() ? PooledByteBufAllocator.DEFAULT
            : UnpooledByteBufAllocator.DEFAULT;

    boolean tcpNodelay = environment().tcpNodelayEnabled();
    bootstrap = new BootstrapAdapter(
            new Bootstrap().remoteAddress(hostname, port).group(environment.ioPool()).channel(channelClass)
                    .option(ChannelOption.ALLOCATOR, allocator).option(ChannelOption.TCP_NODELAY, tcpNodelay)
                    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, env.socketConnectTimeout())
                    .handler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel channel) throws Exception {
                            ChannelPipeline pipeline = channel.pipeline();
                            if (environment.sslEnabled()) {
                                pipeline.addLast(new SslHandler(sslEngineFactory.get()));
                            }
                            if (LOGGER.isTraceEnabled()) {
                                pipeline.addLast(LOGGING_HANDLER_INSTANCE);
                            }
                            customEndpointHandlers(pipeline);
                        }
                    }));
}

From source file:com.datastax.driver.core.JdkSSLOptions.java

License:Apache License

@Override
public SslHandler newSSLHandler(SocketChannel channel) {
    SSLEngine engine = newSSLEngine(channel);
    return new SslHandler(engine);
}

From source file:com.eucalyptus.ws.IoHandlers.java

License:Open Source License

public static ChannelHandler internalHttpsHandler() {
    return new SslHandler(SslSetup.getClientEngine());
}

From source file:com.github.ambry.rest.NettyServerChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    // If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
    // in the pipeline for every connection.
    // i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
    ChannelPipeline pipeline = ch.pipeline();
    // connection stats handler to track connection related metrics
    pipeline.addLast("connectionStatsHandler", connectionStatsHandler);
    // if SSL is enabled, add an SslHandler before the HTTP codec
    if (sslFactory != null) {
        InetSocketAddress peerAddress = ch.remoteAddress();
        String peerHost = peerAddress.getHostName();
        int peerPort = peerAddress.getPort();
        SslHandler sslHandler = new SslHandler(
                sslFactory.createSSLEngine(peerHost, peerPort, SSLFactory.Mode.SERVER));
        pipeline.addLast("sslHandler", sslHandler);
    }//from w w w .j a v  a  2 s . c o  m
    pipeline
            // for http encoding/decoding.
            .addLast("codec",
                    new HttpServerCodec(nettyConfig.nettyServerMaxInitialLineLength,
                            nettyConfig.nettyServerMaxHeaderSize, nettyConfig.nettyServerMaxChunkSize))
            // for health check request handling
            .addLast("healthCheckHandler", new HealthCheckHandler(restServerState, nettyMetrics))
            // for public access logging
            .addLast("publicAccessLogHandler", new PublicAccessLogHandler(publicAccessLogger, nettyMetrics))
            // for detecting connections that have been idle too long - probably because of an error.
            .addLast("idleStateHandler", new IdleStateHandler(0, 0, nettyConfig.nettyServerIdleTimeSeconds))
            // for safe writing of chunks for responses
            .addLast("chunker", new ChunkedWriteHandler())
            // custom processing class that interfaces with a BlobStorageService.
            .addLast("processor", new NettyMessageProcessor(nettyMetrics, nettyConfig, requestHandler));
}

From source file:com.github.ambry.tools.perf.rest.NettyPerfClient.java

License:Open Source License

/**
 * Starts the NettyPerfClient./*  w w w  .  j a  v a 2 s  . co  m*/
 * @throws InterruptedException
 */
protected void start() {
    logger.info("Starting NettyPerfClient");
    reporter.start();
    group = new NioEventLoopGroup(concurrency);
    b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            if (sslFactory != null) {
                ch.pipeline().addLast(
                        new SslHandler(sslFactory.createSSLEngine(host, port, SSLFactory.Mode.CLIENT)));
            }
            ch.pipeline().addLast(new HttpClientCodec()).addLast(new ChunkedWriteHandler())
                    .addLast(new ResponseHandler());
        }
    });
    logger.info("Connecting to {}:{}", host, port);
    b.remoteAddress(host, port);
    perfClientStartTime = System.currentTimeMillis();
    for (int i = 0; i < concurrency; i++) {
        b.connect().addListener(channelConnectListener);
    }
    isRunning = true;
    logger.info("Created {} channel(s)", concurrency);
    logger.info("NettyPerfClient started");
}

From source file:com.github.mrstampy.gameboot.otp.netty.client.EncryptedClientInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new SslHandler(createSslEngine()));
    pipeline.addLast(new LengthFieldPrepender(2));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(clientHandler);// w w  w . j  a va2s  .com
}

From source file:com.github.mrstampy.gameboot.otp.netty.server.EncryptedServerInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new SslHandler(createSslEngine()));
    pipeline.addLast(new LengthFieldPrepender(2));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(utils.getBean(OtpEncryptedNettyHandler.class));
}

From source file:com.github.mrstampy.kitchensync.test.SslInitializer.java

License:Open Source License

@Override
protected void initChannel(DatagramChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new SslHandler(context.createSSLEngine()));
    pipeline.addLast(new KiSyMessageHandler());
}

From source file:com.github.rmannibucau.featuredmock.http.FeaturedChannelInitializer.java

License:Apache License

public FeaturedChannelInitializer(final ContentTypeMapper[] mappers, final SSLEngine engine) {
    if (engine == null) {
        this.sslHandler = null;
    } else {/*from   w  w  w. j  a va2  s  .  c  o  m*/
        this.sslHandler = new SslHandler(engine);
    }
    this.handler = new FeaturedHandler(mappers);
}