Example usage for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler

List of usage examples for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler.

Prototype

public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions,
            int maxFrameSize) 

Source Link

Usage

From source file:net.anyflow.menton.http.WebServerChannelInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    if ("true".equalsIgnoreCase(Settings.SELF.getProperty("menton.logging.writelogOfNettyLogger"))) {
        ch.pipeline().addLast("log", new LoggingHandler("menton/server", LogLevel.DEBUG));
    }//  w  w  w.  j a v  a 2 s  . c o  m

    if (useSsl) {
        SslContext sslCtx = SslContextBuilder
                .forServer(Settings.SELF.certChainFile(), Settings.SELF.privateKeyFile()).build();

        logger.debug("SSL Provider : {}", SslContext.defaultServerProvider());

        ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()));
    }

    ch.pipeline().addLast(HttpServerCodec.class.getName(), new HttpServerCodec());
    ch.pipeline().addLast(HttpObjectAggregator.class.getName(), new HttpObjectAggregator(1048576));
    ch.pipeline().addLast(HttpContentCompressor.class.getName(), new HttpContentCompressor());
    ch.pipeline().addLast(HttpRequestRouter.class.getName(), new HttpRequestRouter());

    if (websocketFrameHandlerClass != null) {
        WebsocketFrameHandler wsfh = websocketFrameHandlerClass.newInstance();

        ch.pipeline().addLast(WebSocketServerProtocolHandler.class.getName(),
                new WebSocketServerProtocolHandler(wsfh.websocketPath(), wsfh.subprotocols(),
                        wsfh.allowExtensions(), wsfh.maxFrameSize()));

        ch.pipeline().addLast(wsfh);
    }
}

From source file:org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer.java

License:Apache License

@Override
public void configure(final ChannelPipeline pipeline) {
    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-io", LogLevel.DEBUG));

    logger.debug("HttpRequestDecoder settings - maxInitialLineLength={}, maxHeaderSize={}, maxChunkSize={}",
            settings.maxInitialLineLength, settings.maxHeaderSize, settings.maxChunkSize);
    pipeline.addLast("http-request-decoder", new HttpRequestDecoder(settings.maxInitialLineLength,
            settings.maxHeaderSize, settings.maxChunkSize));

    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-decoder-aggregator", LogLevel.DEBUG));

    logger.debug("HttpObjectAggregator settings - maxContentLength={}, maxAccumulationBufferComponents={}",
            settings.maxContentLength, settings.maxAccumulationBufferComponents);
    final HttpObjectAggregator aggregator = new HttpObjectAggregator(settings.maxContentLength);
    aggregator.setMaxCumulationBufferComponents(settings.maxAccumulationBufferComponents);
    pipeline.addLast("aggregator", aggregator);

    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-aggregator-encoder", LogLevel.DEBUG));

    pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
    pipeline.addLast("request-handler",
            new WebSocketServerProtocolHandler("/gremlin", null, false, settings.maxContentLength));

    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-aggregator-encoder", LogLevel.DEBUG));

    pipeline.addLast("ws-frame-encoder", wsGremlinResponseFrameEncoder);
    pipeline.addLast("response-frame-encoder", gremlinResponseFrameEncoder);
    pipeline.addLast("request-text-decoder", wsGremlinTextRequestDecoder);
    pipeline.addLast("request-binary-decoder", wsGremlinBinaryRequestDecoder);
    pipeline.addLast("request-close-decoder", wsGremlinCloseRequestDecoder);

    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-aggregator-encoder", LogLevel.DEBUG));

    if (authenticationHandler != null)
        pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
}