Example usage for io.netty.channel ChannelPipeline channel

List of usage examples for io.netty.channel ChannelPipeline channel

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline channel.

Prototype

Channel channel();

Source Link

Document

Returns the Channel that this pipeline is attached to.

Usage

From source file:io.crate.plugin.PipelineRegistry.java

License:Apache License

public void registerItems(ChannelPipeline pipeline) {
    for (PipelineRegistry.ChannelPipelineItem item : addBeforeList) {
        pipeline.addBefore(item.base, item.name, item.handlerFactory.get());
    }//from www. j  a  v  a 2s . c om

    if (sslContextProvider != null) {
        SslContext sslContext = sslContextProvider.get();
        if (sslContext != null) {
            SslHandler sslHandler = sslContext.newHandler(pipeline.channel().alloc());
            pipeline.addFirst(sslHandler);
        }
    }
}

From source file:io.crate.protocols.postgres.SslReqHandler.java

License:Apache License

/**
 * Process receives incoming data from the Netty pipeline. It
 * may request more data by returning the WAITING_FOR_INPUT
 * state. The process method should return DONE when it has
 * finished processing. It may add additional elements to the
 * pipeline. The handler is responsible for to position the
 * buffer read marker correctly such that successive readers
 * see the correct data. The handler is expected to position the
 * marker after the SSLRequest payload./* www . java 2 s. c om*/
 * @param buffer The buffer with incoming data
 * @param pipeline The Netty pipeline which may be modified
 * @return The state of the handler
 */
public State process(ByteBuf buffer, ChannelPipeline pipeline) {
    if (buffer.readableBytes() < SSL_REQUEST_BYTE_LENGTH) {
        return State.WAITING_FOR_INPUT;
    }
    // mark the buffer so we can jump back if we don't handle this startup
    buffer.markReaderIndex();
    // reads the total message length (int) and the SSL request code (int)
    if (buffer.readInt() == SSL_REQUEST_BYTE_LENGTH && buffer.readInt() == SSL_REQUEST_CODE) {
        // received optional SSL negotiation pkg
        if (sslContext != null) {
            writeByteAndFlushMessage(pipeline.channel(), 'S');
            SslHandler sslHandler = sslContext.newHandler(pipeline.channel().alloc());
            pipeline.addFirst(sslHandler);
        } else {
            writeByteAndFlushMessage(pipeline.channel(), 'N');
        }
        buffer.markReaderIndex();
    } else {
        buffer.resetReaderIndex();
    }
    return State.DONE;
}

From source file:io.liveoak.container.protocols.PipelineConfigurator.java

License:Open Source License

public void switchToPlainHttp(ChannelPipeline pipeline) {
    // turn off automatic socket read for better http body read control
    pipeline.addLast("channel-resetter", new ChannelResetterHandler(this));
    pipeline.channel().config().setAutoRead(false);
    pipeline.remove(WebSocketHandshakerHandler.class);
    //pipeline.addLast(new DebugHandler("server-pre-cors"));
    pipeline.addLast("cors-origin-handler", new CORSHandler());
    pipeline.addLast("cors-preflight-handler", new CORSPreflightOptionsHandler());
    //pipeline.addLast( new DebugHandler( "server-post-cors" ) );

    pipeline.addLast("deflater", new HttpContentCompressor(1));

    pipeline.addLast("http-resource-decoder", new HttpResourceRequestDecoder(this.codecManager));
    pipeline.addLast("http-resource-encoder", new HttpResourceResponseEncoder(this.codecManager));
    pipeline.addLast("http-request-body-handler", new HttpRequestBodyHandler());
    pipeline.addLast("interceptor", new InterceptorHandler("http", this.interceptorManager));
    pipeline.addLast("request-context-disposer", new RequestContextDisposerHandler());

    //pipeline.addLast("auth-handler", new AuthHandler(this.client));
    //pipeline.addLast("authz-handler", new AuthzHandler(this.client));

    pipeline.addLast("subscription-watcher", new SubscriptionWatcher(this.subscriptionManager));
    //pipeline.addLast( new DebugHandler( "server-debug" ) );
    pipeline.addLast("resource-state-handler", new ResourceStateHandler(this.workerPool));
    pipeline.addLast("object-handler", new ResourceHandler(this.globalContext, this.workerPool));
    pipeline.addLast("error-handler", new ErrorHandler());
}

From source file:io.nebo.container.NettyEmbeddedServletInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast("codec", new HttpServerCodec(4096, 8192, 8192, false));
    p.addLast("servletInput", new ServletContentHandler(servletContext, p.channel()));
    p.addLast(servletExecutor, "filterChain", requestDispatcherHandler);
}

From source file:io.reactivex.netty.pipeline.ssl.SslPipelineConfigurator.java

License:Apache License

@Override
public void configureNewPipeline(ChannelPipeline pipeline) {
    pipeline.addFirst(new SslHandler(sslEngineFactory.createSSLEngine(pipeline.channel().alloc())));
}

From source file:io.vertx.core.http.impl.HttpServerImpl.java

License:Open Source License

private void configureHttp1(ChannelPipeline pipeline) {
    if (logEnabled) {
        pipeline.addLast("logging", new LoggingHandler());
    }//from   w  ww.jav a  2  s  .  c  om
    if (USE_FLASH_POLICY_HANDLER) {
        pipeline.addLast("flashpolicy", new FlashPolicyHandler());
    }
    pipeline.addLast("httpDecoder", new HttpRequestDecoder(options.getMaxInitialLineLength(),
            options.getMaxHeaderSize(), options.getMaxChunkSize(), false));
    pipeline.addLast("httpEncoder", new VertxHttpResponseEncoder());
    if (options.isDecompressionSupported()) {
        pipeline.addLast("inflater", new HttpContentDecompressor(true));
    }
    if (options.isCompressionSupported()) {
        pipeline.addLast("deflater", new HttpChunkContentCompressor(options.getCompressionLevel()));
    }
    if (sslHelper.isSSL() || options.isCompressionSupported()) {
        // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); // For large file / sendfile support
    }
    if (options.getIdleTimeout() > 0) {
        pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
    }
    pipeline.addLast("handler", new ServerHandler(pipeline.channel()));
}

From source file:org.apache.zookeeper.server.NettyServerCnxnFactory.java

License:Apache License

private synchronized void initSSL(ChannelPipeline p)
        throws X509Exception, KeyManagementException, NoSuchAlgorithmException {
    String authProviderProp = System.getProperty(x509Util.getSslAuthProviderProperty());
    SSLContext sslContext;//w  ww  . ja  v  a 2 s . c  om
    if (authProviderProp == null) {
        sslContext = x509Util.getDefaultSSLContext();
    } else {
        sslContext = SSLContext.getInstance("TLSv1");
        X509AuthenticationProvider authProvider = (X509AuthenticationProvider) ProviderRegistry
                .getProvider(System.getProperty(x509Util.getSslAuthProviderProperty(), "x509"));

        if (authProvider == null) {
            LOG.error("Auth provider not found: {}", authProviderProp);
            throw new SSLContextException(
                    "Could not create SSLContext with specified auth provider: " + authProviderProp);
        }

        sslContext.init(new X509KeyManager[] { authProvider.getKeyManager() },
                new X509TrustManager[] { authProvider.getTrustManager() }, null);
    }

    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(false);
    sslEngine.setNeedClientAuth(true);

    p.addLast("ssl", new SslHandler(sslEngine));
    LOG.info("SSL handler added for channel: {}", p.channel());
}

From source file:org.waarp.common.crypto.ssl.WaarpSslUtility.java

License:Open Source License

/**
 * Add a SslHandler in a pipeline when the channel is already active
 * //from  w  w w .j  a  v  a  2  s  . c  o m
 * @param future
 *            might be null, condition to start to add the handler to the pipeline
 * @param pipeline
 * @param sslHandler
 * @param listener
 *            action once the handshake is done
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void addSslHandler(ChannelFuture future, final ChannelPipeline pipeline,
        final ChannelHandler sslHandler,
        final GenericFutureListener<? extends Future<? super Channel>> listener) {
    if (future == null) {
        logger.debug("Add SslHandler: " + pipeline.channel());
        pipeline.addFirst("SSL", sslHandler);
        ((SslHandler) sslHandler).handshakeFuture().addListener(listener);
    } else {
        future.addListener(new GenericFutureListener() {
            public void operationComplete(Future future) throws Exception {
                logger.debug("Add SslHandler: " + pipeline.channel());
                pipeline.addFirst("SSL", sslHandler);
                ((SslHandler) sslHandler).handshakeFuture().addListener(listener);
            }
        });
    }
    logger.debug("Checked Ssl Handler to be added: " + pipeline.channel());
}

From source file:ratpack.http.client.internal.ContentStreamingRequestAction.java

License:Apache License

@Override
protected void addResponseHandlers(ChannelPipeline p, Fulfiller<? super StreamedResponse> fulfiller) {
    p.addLast("httpResponseHandler", new SimpleChannelInboundHandler<HttpResponse>(false) {
        @Override//from w  ww .  java  2 s .c o  m
        public void channelRead0(ChannelHandlerContext ctx, HttpResponse msg) throws Exception {
            // Switch auto reading off so we can control the flow of response content
            p.channel().config().setAutoRead(false);
            execution.onCleanup(() -> {
                if (!subscribedTo.get() && ctx.channel().isOpen()) {
                    ctx.close();
                }
            });

            final Headers headers = new NettyHeadersBackedHeaders(msg.headers());
            final Status status = new DefaultStatus(msg.status());

            success(fulfiller, new DefaultStreamedResponse(p, status, headers));
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            ctx.close();
            error(fulfiller, cause);
        }
    });
}

From source file:ratpack.http.internal.ConnectionIdleTimeout.java

License:Apache License

public ConnectionIdleTimeout(ChannelPipeline channelPipeline, Duration timeout) {
    this.channelPipeline = channelPipeline;
    this.timeout = timeout;

    channelPipeline.channel().attr(ATTRIBUTE_KEY).set(this);

    if (!timeout.isZero()) {
        init(timeout);/*from   w  w  w .  java  2s.  co m*/
    }
}