Search in sources :

Example 1 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.

the class HttpServerSharedPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
    }
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("handler", channelFactory.getChannelHandler());
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 2 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.

the class NettyConfiguration method parseURI.

public void parseURI(URI uri, Map<String, Object> parameters, NettyComponent component, String... supportedProtocols) throws Exception {
    protocol = uri.getScheme();
    boolean found = false;
    for (String supportedProtocol : supportedProtocols) {
        if (protocol != null && protocol.equalsIgnoreCase(supportedProtocol)) {
            found = true;
            break;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("Unrecognized Netty protocol: " + protocol + " for uri: " + uri);
    }
    setHost(uri.getHost());
    if (uri.getPort() != -1) {
        setPort(uri.getPort());
    }
    ssl = component.getAndRemoveOrResolveReferenceParameter(parameters, "ssl", boolean.class, false);
    sslHandler = component.getAndRemoveOrResolveReferenceParameter(parameters, "sslHandler", SslHandler.class, sslHandler);
    passphrase = component.getAndRemoveOrResolveReferenceParameter(parameters, "passphrase", String.class, passphrase);
    keyStoreFormat = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFormat", String.class, keyStoreFormat == null ? "JKS" : keyStoreFormat);
    securityProvider = component.getAndRemoveOrResolveReferenceParameter(parameters, "securityProvider", String.class, securityProvider == null ? "SunX509" : securityProvider);
    keyStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFile", File.class, keyStoreFile);
    trustStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreFile", File.class, trustStoreFile);
    keyStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreResource", String.class, keyStoreResource);
    trustStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreResource", String.class, trustStoreResource);
    clientPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientPipelineFactory", ClientPipelineFactory.class, clientPipelineFactory);
    serverPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverPipelineFactory", ServerPipelineFactory.class, serverPipelineFactory);
    // set custom encoders and decoders first
    List<ChannelHandler> referencedEncoders = component.resolveAndRemoveReferenceListParameter(parameters, "encoders", ChannelHandler.class, null);
    addToHandlersList(encoders, referencedEncoders, ChannelHandler.class);
    List<ChannelHandler> referencedDecoders = component.resolveAndRemoveReferenceListParameter(parameters, "decoders", ChannelHandler.class, null);
    addToHandlersList(decoders, referencedDecoders, ChannelHandler.class);
    // then set parameters with the help of the camel context type converters
    EndpointHelper.setReferenceProperties(component.getCamelContext(), this, parameters);
    EndpointHelper.setProperties(component.getCamelContext(), this, parameters);
    // additional netty options, we don't want to store an empty map, so set it as null if empty
    options = IntrospectionSupport.extractProperties(parameters, "option.");
    if (options != null && options.isEmpty()) {
        options = null;
    }
    // add default encoders and decoders
    if (encoders.isEmpty() && decoders.isEmpty()) {
        if (isAllowDefaultCodec()) {
            // are we textline or object?
            if (isTextline()) {
                Charset charset = getEncoding() != null ? Charset.forName(getEncoding()) : CharsetUtil.UTF_8;
                encoders.add(ChannelHandlerFactories.newStringEncoder(charset));
                ChannelBuffer[] delimiters = delimiter == TextLineDelimiter.LINE ? Delimiters.lineDelimiter() : Delimiters.nulDelimiter();
                decoders.add(ChannelHandlerFactories.newDelimiterBasedFrameDecoder(decoderMaxLineLength, delimiters));
                decoders.add(ChannelHandlerFactories.newStringDecoder(charset));
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Using textline encoders and decoders with charset: {}, delimiter: {} and decoderMaxLineLength: {}", new Object[] { charset, delimiter, decoderMaxLineLength });
                }
            } else {
                // object serializable is then used
                encoders.add(ChannelHandlerFactories.newObjectEncoder());
                decoders.add(ChannelHandlerFactories.newObjectDecoder());
                LOG.debug("Using object encoders and decoders");
            }
        } else {
            LOG.debug("No encoders and decoders will be used");
        }
    } else {
        LOG.debug("Using configured encoders and/or decoders");
    }
}
Also used : Charset(java.nio.charset.Charset) ChannelHandler(org.jboss.netty.channel.ChannelHandler) File(java.io.File) SslHandler(org.jboss.netty.handler.ssl.SslHandler) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 3 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.

the class NettyEndpoint method getSSLSession.

protected SSLSession getSSLSession(ChannelHandlerContext ctx) {
    final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
    SSLSession sslSession = null;
    if (sslHandler != null) {
        sslSession = sslHandler.getEngine().getSession();
    }
    return sslSession;
}
Also used : SSLSession(javax.net.ssl.SSLSession) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 4 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.

the class DefaultClientPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // create a new pipeline
    ChannelPipeline channelPipeline = Channels.pipeline();
    SslHandler sslHandler = configureClientSSLOnDemand();
    if (sslHandler != null) {
        // must close on SSL exception
        sslHandler.setCloseOnSSLException(true);
        LOG.debug("Client SSL handler configured and added to the ChannelPipeline: {}", sslHandler);
        addToPipeline("ssl", channelPipeline, sslHandler);
    }
    List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
        ChannelHandler decoder = decoders.get(x);
        if (decoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
        }
        addToPipeline("decoder-" + x, channelPipeline, decoder);
    }
    List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
        ChannelHandler encoder = encoders.get(x);
        if (encoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
        }
        addToPipeline("encoder-" + x, channelPipeline, encoder);
    }
    // do we use request timeout?
    if (producer.getConfiguration().getRequestTimeout() > 0) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
        }
        ChannelHandler timeout = new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
        addToPipeline("timeout", channelPipeline, timeout);
    }
    // our handler must be added last
    addToPipeline("handler", channelPipeline, new ClientChannelHandler(producer));
    LOG.trace("Created ChannelPipeline: {}", channelPipeline);
    return channelPipeline;
}
Also used : ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) ClientChannelHandler(org.apache.camel.component.netty.handlers.ClientChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler) ClientChannelHandler(org.apache.camel.component.netty.handlers.ClientChannelHandler)

Example 5 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project cdap by caskdata.

the class SSLHandlerFactory method create.

public SslHandler create() {
    SSLEngine engine = serverContext.createSSLEngine();
    engine.setUseClientMode(false);
    SslHandler handler = new SslHandler(engine);
    handler.setEnableRenegotiation(false);
    return handler;
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

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