Search in sources :

Example 21 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project http-client by biasedbit.

the class DummyHttpServer method init.

// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
    Executor bossExecutor = Executors.newCachedThreadPool();
    Executor workerExecutor = Executors.newCachedThreadPool();
    ChannelFactory factory;
    if (useOldIo)
        factory = new OioServerSocketChannelFactory(bossExecutor, workerExecutor);
    else
        factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (useSsl) {
                SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("decoder", new HttpRequestDecoder());
            if (compressionLevel > 0)
                pipeline.addLast("compressor", new HttpContentCompressor(compressionLevel));
            // 5MB
            pipeline.addLast("aggregator", new HttpChunkAggregator(5242880));
            pipeline.addLast("handler", new RequestHandler());
            return pipeline;
        }
    });
    channelGroup = new DefaultChannelGroup("hotpotato-dummy-server-" + Integer.toHexString(hashCode()));
    SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
    Channel serverChannel = bootstrap.bind(bindAddress);
    channelGroup.add(serverChannel);
    return (running = serverChannel.isBound());
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) SSLEngine(javax.net.ssl.SSLEngine) InetSocketAddress(java.net.InetSocketAddress) OioServerSocketChannelFactory(org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) SslHandler(org.jboss.netty.handler.ssl.SslHandler) Executor(java.util.concurrent.Executor) OioServerSocketChannelFactory(org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 22 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project http-client by biasedbit.

the class UploadMirrorHttpServer method init.

// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
    Executor bossExecutor = Executors.newCachedThreadPool();
    Executor workerExecutor = Executors.newCachedThreadPool();
    ChannelFactory factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (useSsl) {
                SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("codec", new HttpServerCodec());
            pipeline.addLast("handler", new RequestHandler());
            return pipeline;
        }
    });
    channelGroup = new DefaultChannelGroup("hotpotato-upload-server-" + Integer.toHexString(hashCode()));
    SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
    Channel serverChannel = bootstrap.bind(bindAddress);
    channelGroup.add(serverChannel);
    return (running = serverChannel.isBound());
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) SSLEngine(javax.net.ssl.SSLEngine) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) SslHandler(org.jboss.netty.handler.ssl.SslHandler) Executor(java.util.concurrent.Executor) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 23 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project load-balancer by RestComm.

the class TestHttpServerPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = pipeline();
    if (!terminateTLSTraffic) {
        SslConfiguration sslConfig = new SslConfiguration();
        sslConfig.setKeyStorePath(TestHttpServerPipelineFactory.class.getClassLoader().getResource("keystore").getFile());
        sslConfig.setKeyStorePassword("123456");
        sslConfig.setTrustStorePath(TestHttpServerPipelineFactory.class.getClassLoader().getResource("keystore").getFile());
        sslConfig.setTrustStorePassword("123456");
        SslContextFactory factory = new SslContextFactory(sslConfig);
        SSLEngine sslEngine = factory.newSslEngine();
        sslEngine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(sslEngine));
    }
    pipeline.addLast("decoder", new HttpRequestDecoder());
    // http://code.google.com/p/commscale/issues/detail?id=5 support for HttpChunks
    // https://telestax.atlassian.net/browse/LB-8 if commented accessing the RestComm Management console fails, so making the maxContentLength Configurable
    pipeline.addLast("aggregator", new HttpChunkAggregator(maxContentLength));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    // pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("handler", new HttpServerRequestHandler(requestCount, requests, chunkResponse, badSever));
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SSLEngine(javax.net.ssl.SSLEngine) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 24 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project load-balancer by RestComm.

the class ClientConnectionImpl method connect.

@Override
public Boolean connect() {
    ChannelFuture channelFuture = null;
    try {
        if (logger.isDebugEnabled())
            logger.debug("LB trying to connect to server " + config.getHost() + " " + config.getPort());
        channelFuture = clientBootstrap.connect(new InetSocketAddress(config.getHost(), config.getPort()), new InetSocketAddress(localSmppAddress, 0)).sync();
        channel = channelFuture.getChannel();
        if (config.isUseSsl()) {
            SslConfiguration sslConfig = config.getSslConfiguration();
            if (sslConfig == null)
                throw new IllegalStateException("sslConfiguration must be set");
            try {
                SslContextFactory factory = new SslContextFactory(sslConfig);
                SSLEngine sslEngine = factory.newSslEngine();
                sslEngine.setUseClientMode(true);
                channel.getPipeline().addFirst(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
            } catch (Exception e) {
                logger.error("Unable to create SSL session: " + e.getMessage(), e);
            }
        }
    } catch (Exception ex) {
        return false;
    }
    if (clientState != ClientState.REBINDING)
        clientState = ClientState.OPEN;
    return true;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) SslHandler(org.jboss.netty.handler.ssl.SslHandler) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException)

Aggregations

SslHandler (org.jboss.netty.handler.ssl.SslHandler)24 SSLEngine (javax.net.ssl.SSLEngine)16 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)10 SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)8 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)8 InetSocketAddress (java.net.InetSocketAddress)7 ChannelHandler (org.jboss.netty.channel.ChannelHandler)5 Channel (org.jboss.netty.channel.Channel)4 ChannelFuture (org.jboss.netty.channel.ChannelFuture)4 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)4 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)4 SmppSessionPduDecoder (com.cloudhopper.smpp.channel.SmppSessionPduDecoder)3 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)3 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)3 SocketAddress (java.net.SocketAddress)3 SSLContext (javax.net.ssl.SSLContext)3 DefaultPduTranscoder (com.cloudhopper.smpp.transcoder.DefaultPduTranscoder)2 DefaultPduTranscoderContext (com.cloudhopper.smpp.transcoder.DefaultPduTranscoderContext)2 Executor (java.util.concurrent.Executor)2 ChannelHandlerFactory (org.apache.camel.component.netty.ChannelHandlerFactory)2