當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServerCodec類代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpServerCodec的典型用法代碼示例。如果您正苦於以下問題:Java HttpServerCodec類的具體用法?Java HttpServerCodec怎麽用?Java HttpServerCodec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpServerCodec類屬於io.netty.handler.codec.http包,在下文中一共展示了HttpServerCodec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupWSChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
            ch.pipeline().addLast("httpServer", new HttpServerCodec());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
            ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
            ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
            ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
            ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
            ch.pipeline().addLast("error", new WSExceptionHandler());
        }
    };

}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:18,代碼來源:Server.java

示例2: initChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
        protected void initChannel(SocketChannel ch) throws Exception {
            try {
                ch.config().setOption(ChannelOption.IP_TOS, 0x18);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
            } catch (ChannelException ex) {
                // IP_TOS not supported by platform, ignore
            }
            ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
            
            PacketRegistry r = new PacketRegistry();

            ch.pipeline().addLast(new HttpServerCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(65536));
            ch.pipeline().addLast(new WebSocketHandler());
            ch.pipeline().addLast(new PacketDecoder(r));
            ch.pipeline().addLast(new PacketEncoder(r));
            ch.pipeline().addLast(new ClientHandler(server));
        }
 
開發者ID:AlexMog,項目名稱:SurvivalMMO,代碼行數:21,代碼來源:NetworkManager.java

示例3: initChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.TCP_NODELAY, true);
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
    
    PacketRegistry r = new PacketRegistry();

    ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30));
    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder(r));
    ch.pipeline().addLast(new PacketEncoder(r));
    ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer));
}
 
開發者ID:FightForSub,項目名稱:FFS-PubSub,代碼行數:21,代碼來源:NetworkManager.java

示例4: initChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
 
開發者ID:CalypsoToolz,項目名稱:FPAgar,代碼行數:17,代碼來源:NetworkManager.java

示例5: initChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new Handshaker());
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
 
開發者ID:ClitherProject,項目名稱:Clither-Server,代碼行數:18,代碼來源:NetworkManager.java

示例6: initChannel

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
	ChannelPipeline pipeline = ch.pipeline();
	//編解碼http請求
	pipeline.addLast(new HttpServerCodec());
	//聚合解碼HttpRequest/HttpContent/LastHttpContent到FullHttpRequest
	//保證接收的Http請求的完整性
	pipeline.addLast(new HttpObjectAggregator(64 *1024));
	//寫文件內容
	pipeline.addLast(new ChunkedWriteHandler());
	//處理FullHttpRequest
	pipeline.addLast(new HttpRequestHandler("/ws"));
	//處理其他的WebSocketFrame
	pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
	//處理TextWebSocketFrame
	pipeline.addLast(new TextWebSocketFrameHandler(group));
}
 
開發者ID:janzolau1987,項目名稱:study-netty,代碼行數:18,代碼來源:ChatServerInitializer.java

示例7: configure

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
public void configure(final ChannelPipeline pipeline) {
    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("log-io", LogLevel.DEBUG));

    pipeline.addLast("http-server", new HttpServerCodec());

    if (logger.isDebugEnabled())
        pipeline.addLast(new LoggingHandler("http-io", LogLevel.DEBUG));

    pipeline.addLast(new HttpObjectAggregator(settings.maxContentLength));

    if (authenticator != null) {
        // Cannot add the same handler instance to multiple times unless
        // it is marked as @Sharable, indicating a race condition will
        // not occur. It may not be a safe assumption that the handler
        // is sharable so create a new handler each time.
        authenticationHandler = authenticator.getClass() == AllowAllAuthenticator.class ?
                null : new HttpBasicAuthenticationHandler(authenticator);
        if (authenticationHandler != null)
            pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
    }

    pipeline.addLast("http-gremlin-handler", httpGremlinEndpointHandler);
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:26,代碼來源:HttpChannelizer.java

示例8: addByteDecoderWhenFullReactorPipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler decoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerLast("decoder", decoder)
	           .addHandlerFirst("decoder$extract",
			           NettyPipeline.inboundHandler(ADD_EXTRACTOR));

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"decoder$extract",
					"decoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:24,代碼來源:NettyContextTest.java

示例9: addNonByteDecoderWhenFullReactorPipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Test
public void addNonByteDecoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler decoder = new ChannelHandlerAdapter() {
	};

	testContext.addHandlerLast("decoder", decoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"decoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:22,代碼來源:NettyContextTest.java

示例10: addByteEncoderWhenFullReactorPipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler encoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerFirst("encoder", encoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"encoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:21,代碼來源:NettyContextTest.java

示例11: addNonByteEncoderWhenFullReactorPipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Test
public void addNonByteEncoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler encoder = new ChannelHandlerAdapter() {
	};

	testContext.addHandlerFirst("encoder", encoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"encoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:22,代碼來源:NettyContextTest.java

示例12: addSeveralByteEncodersWhenCodec

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
	ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
	ChannelHandler encoder2 = new LineBasedFrameDecoder(13);

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });

	testContext.addHandlerFirst("encoder1", encoder1)
	           .addHandlerFirst("encoder2", encoder2);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"encoder2",
					"encoder1",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:24,代碼來源:NettyContextTest.java

示例13: configurePipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
    if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
        ctx.pipeline().addLast(new Http2MultiplexCodec(true, new HelloWorldHttp2Handler()));
        return;
    }

    if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
        ctx.pipeline().addLast(new HttpServerCodec(),
                               new HttpObjectAggregator(MAX_CONTENT_LENGTH),
                               new HelloWorldHttp1Handler("ALPN Negotiation"));
        return;
    }

    throw new IllegalStateException("unknown protocol: " + protocol);
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:17,代碼來源:Http2OrHttpHandler.java

示例14: configurePipeline

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
    if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
        ctx.pipeline().addLast(new HelloWorldHttp2HandlerBuilder().build());
        return;
    }

    if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
        ctx.pipeline().addLast(new HttpServerCodec(),
                               new HttpObjectAggregator(MAX_CONTENT_LENGTH),
                               new HelloWorldHttp1Handler("ALPN Negotiation"));
        return;
    }

    throw new IllegalStateException("unknown protocol: " + protocol);
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:17,代碼來源:Http2OrHttpHandler.java

示例15: createInitializer

import io.netty.handler.codec.http.HttpServerCodec; //導入依賴的package包/類
protected ChannelInitializer<Channel> createInitializer() {

	return new ChannelInitializer<Channel>() {

		@Override
		protected void initChannel(Channel ch) throws Exception {
			ChannelPipeline p = ch.pipeline();
			p.addLast(new HttpServerCodec() );
			p.addLast(new ChunkedWriteHandler());
			p.addLast(new HttpObjectAggregator(64 * 1024));
			p.addLast(new EchoServerHttpRequestHandler("/ws"));
			p.addLast(new WebSocketServerProtocolHandler("/ws"));
			p.addLast(new EchoServerWSHandler());
		}
	};
}
 
開發者ID:bekwam,項目名稱:examples-javafx-repos1,代碼行數:17,代碼來源:EchoServerWS.java


注:本文中的io.netty.handler.codec.http.HttpServerCodec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。