List of usage examples for io.netty.handler.ssl SslHandler SslHandler
public SslHandler(SSLEngine engine)
From source file:org.asynchttpclient.providers.netty.channel.Channels.java
License:Apache License
public SslHandler createSslHandler(String peerHost, int peerPort) throws IOException, GeneralSecurityException { SSLEngine sslEngine = null;/*w ww.j av a 2 s .c om*/ if (nettyProviderConfig.getSslEngineFactory() != null) { sslEngine = nettyProviderConfig.getSslEngineFactory().newSSLEngine(); } else { SSLContext sslContext = config.getSSLContext(); if (sslContext == null) sslContext = SslUtils.getInstance().getSSLContext(config.isAcceptAnyCertificate()); sslEngine = sslContext.createSSLEngine(peerHost, peerPort); sslEngine.setUseClientMode(true); } SslHandler sslHandler = new SslHandler(sslEngine); if (handshakeTimeoutInMillis > 0) sslHandler.setHandshakeTimeoutMillis(handshakeTimeoutInMillis); return sslHandler; }
From source file:org.asynchttpclient.providers.netty4.channel.ChannelManager.java
License:Open Source License
public SslHandler createSslHandler(String peerHost, int peerPort) throws IOException, GeneralSecurityException { SSLEngine sslEngine = sslEngineFactory.newSSLEngine(peerHost, peerPort); SslHandler sslHandler = new SslHandler(sslEngine); if (handshakeTimeout > 0) sslHandler.setHandshakeTimeoutMillis(handshakeTimeout); return sslHandler; }
From source file:org.atmosphere.nettosphere.NettyChannelInitializer.java
License:Apache License
@Override protected void initChannel(Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); if (config.sslContext() != null) { SSLEngine e = config.sslContext().createSSLEngine(); config.sslContextListener().onPostCreate(e); pipeline.addLast("ssl", new SslHandler(e)); }/*from w ww. ja v a 2s.c om*/ if (config.nettySslContext() != null) { pipeline.addLast("ssl", config.nettySslContext().newHandler(ch.alloc())); } pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(config.maxChunkContentLength())); if (config.supportChunking()) { pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); } for (ChannelInboundHandler h : config.channelUpstreamHandlers()) { pipeline.addLast(h.getClass().getName(), h); } pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(BridgeRuntime.class.getName(), bridgeRuntime); }
From source file:org.ballerinalang.test.util.websocket.client.WebSocketTestClient.java
License:Open Source License
/** * Handshake with the remote server.//w w w . j av a2 s . c o m */ public void handshake() throws InterruptedException { group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { ChannelPipeline pipeline = ch.pipeline(); if (sslEnabled) { SSLEngine sslEngine = createSSLContextFromTruststores().createSSLEngine(); sslEngine.setUseClientMode(true); pipeline.addLast(new SslHandler(sslEngine)); } pipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, webSocketHandler); } }); channel = bootstrap.connect(uri.getHost(), uri.getPort()).sync().channel(); webSocketHandler.handshakeFuture().sync(); }
From source file:org.bridje.http.impl.HttpServerImpl.java
License:Apache License
@Override public void start() { try {//from w w w . j a va 2 s . c o m LOG.log(Level.INFO, "Starting {0}, Listen: {1} Port: {2} {3}", new Object[] { config.getName(), config.getListen(), String.valueOf(config.getPort()), (config.isSsl() ? "SSL: " + config.getSslAlgo() : "") }); group = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class) .localAddress(this.config.createInetSocketAddress()) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { if (sslContext != null) { SSLEngine engine = sslContext.createSSLEngine(); engine.setUseClientMode(false); ch.pipeline().addLast("ssl", new SslHandler(engine)); } ch.pipeline().addLast("codec", new HttpServerCodec()); ch.pipeline().addLast("switch", new HttpWsSwitch(handlers)); ch.pipeline().addLast("handler", new HttpServerChannelHandler(HttpServerImpl.this)); ch.pipeline().addLast("compressor", new HttpContentCompressor()); } }); ChannelFuture f = b.bind(this.config.getPort()).sync(); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } } catch (InterruptedException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } }
From source file:org.conscrypt.testing.NettyServer.java
License:Apache License
public void start() { group = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(group);/*from w w w . ja v a2 s.c om*/ b.channel(NioServerSocketChannel.class); b.option(SO_BACKLOG, 128); b.childOption(SO_KEEPALIVE, true); b.childHandler(new ChannelInitializer<Channel>() { @Override public void initChannel(final Channel ch) throws Exception { SslContext context = TestUtil.newNettyServerContext(cipher); SSLEngine sslEngine = context.newEngine(ch.alloc()); ch.pipeline().addFirst(new SslHandler(sslEngine)); ch.pipeline().addLast(new MessageDecoder()); } }); // Bind and start to accept incoming connections. ChannelFuture future = b.bind(port); try { future.await(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted waiting for bind"); } if (!future.isSuccess()) { throw new RuntimeException("Failed to bind", future.cause()); } channel = future.channel(); }
From source file:org.dcache.http.HttpsTransferService.java
License:Open Source License
@Override protected void addChannelHandlers(ChannelPipeline pipeline) { pipeline.addLast("ssl", new SslHandler(_sslEngine)); super.addChannelHandlers(pipeline); }
From source file:org.dna.mqtt.moquette.server.netty.metrics.SSLHandlerFactory.java
License:Open Source License
/** * Create sslHandler object/* w w w .j a v a2 s.co m*/ * @return SslHandler object */ public ChannelHandler create() { SSLEngine sslEngine = sslContext.createSSLEngine(); sslEngine.setUseClientMode(false); return new SslHandler(sslEngine); }
From source file:org.eclipse.californium.elements.tcp.TlsClientConnector.java
License:Open Source License
@Override protected void onNewChannelCreated(SocketAddress remote, Channel ch) { SSLEngine sslEngine = createSllEngine(remote); sslEngine.setUseClientMode(true);/*from ww w . j av a2s .c om*/ SslHandler sslHandler = new SslHandler(sslEngine); sslHandler.setHandshakeTimeoutMillis(handshakeTimeoutMillis); ch.pipeline().addFirst(sslHandler); }
From source file:org.eclipse.californium.elements.tcp.TlsServerConnector.java
License:Open Source License
@Override protected void onNewChannelCreated(Channel ch) { SSLEngine sslEngine = createSllEngineForChannel(ch); switch (clientAuthMode) { case NONE:/*from w w w .jav a2 s . c o m*/ break; case WANTED: sslEngine.setWantClientAuth(true); break; case NEEDED: sslEngine.setNeedClientAuth(true); break; } sslEngine.setUseClientMode(false); SslHandler sslHandler = new SslHandler(sslEngine); sslHandler.setHandshakeTimeoutMillis(handshakeTimeoutMillis); ch.pipeline().addFirst(sslHandler); }