本文整理汇总了Java中io.netty.handler.stream.ChunkedWriteHandler类的典型用法代码示例。如果您正苦于以下问题:Java ChunkedWriteHandler类的具体用法?Java ChunkedWriteHandler怎么用?Java ChunkedWriteHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChunkedWriteHandler类属于io.netty.handler.stream包,在下文中一共展示了ChunkedWriteHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendHttpPipeline
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
public final ChannelPipeline appendHttpPipeline(ChannelPipeline channelPipeline) {
// 服务端,对响应编码。属于ChannelOutboundHandler,逆序执行
channelPipeline.addLast("encoder", new HttpResponseEncoder());
// 服务端,对请求解码。属于ChannelIntboundHandler,按照顺序执行
channelPipeline.addLast("decoder", new HttpRequestDecoder());
//即通过它可以把 HttpMessage 和 HttpContent 聚合成一个 FullHttpRequest,并定义可以接受的数据大小,在文件上传时,可以支持params+multipart
channelPipeline.addLast("aggregator", new HttpObjectAggregator(maxConentLength));
//块写入写出Handler
channelPipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
// 对传输数据进行压缩,这里在客户端需要解压缩处理
// channelPipeline.addLast("deflater", new HttpContentCompressor());
HttpServletHandler servletHandler = new HttpServletHandler();
servletHandler.addInterceptor(new ChannelInterceptor());
//servletHandler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
// 自定义Handler
channelPipeline.addLast("handler", servletHandler);
// 异步
// channelPipeline.addLast(businessExecutor, new AsyncHttpServletHandler());
return channelPipeline;
}
示例2: initChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast("codec", new HttpClientCodec());
// Remove the following line if you don't want automatic content decompression.
pipeline.addLast("inflater", new HttpContentDecompressor());
// to be used since huge file transfer
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
pipeline.addLast("handler", new HttpUploadClientHandler());
}
示例3: initChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的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));
}
示例4: preparePipeline
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
* This adds a ChunkedWriter to the pipeline to extract chunks from the
* {@link io.netty.handler.stream.ChunkedInput} that the strategy produces. This step
* is skipped if the handler is already present, and the placement of the handler
* depends on the presence of the ReactiveBridge handler (see {@link NettyPipeline}).
*
* @param context the context from which to obtain the channel and pipeline
*/
@Override
public final void preparePipeline(NettyContext context) {
this.addHandler = context.channel()
.pipeline()
.get(NettyPipeline.ChunkedWriter) == null;
if (addHandler) {
boolean hasReactiveBridge = context.channel()
.pipeline()
.get(NettyPipeline.ReactiveBridge) != null;
if (hasReactiveBridge) {
context.channel()
.pipeline()
.addBefore(NettyPipeline.ReactiveBridge,
NettyPipeline.ChunkedWriter,
new ChunkedWriteHandler());
}
else {
context.channel()
.pipeline()
.addLast(NettyPipeline.ChunkedWriter, new ChunkedWriteHandler());
}
}
}
示例5: start
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
public void start(int port) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));
ch.pipeline().addLast("http-encoder", new HttpResponseEncoder());
ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
ch.pipeline().addLast("serverHandler", new HttpServerHandler());
}
}).option(ChannelOption.SO_BACKLOG, 1024).childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
}
示例6: addHttpServerCodec
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
public static void addHttpServerCodec(@NotNull ChannelPipeline pipeline) {
pipeline.addLast("httpRequestEncoder", new HttpResponseEncoder());
// https://jetbrains.zendesk.com/agent/tickets/68315
pipeline.addLast("httpRequestDecoder", new HttpRequestDecoder(16 * 1024, 16 * 1024, 8192));
pipeline.addLast("httpObjectAggregator", new HttpObjectAggregator(MAX_CONTENT_LENGTH));
// could be added earlier if HTTPS
if (pipeline.get(ChunkedWriteHandler.class) == null) {
pipeline.addLast("chunkedWriteHandler", new ChunkedWriteHandler());
}
pipeline.addLast("corsHandler", new CorsHandlerDoNotUseOwnLogger(CorsConfig
.withAnyOrigin()
.allowCredentials()
.allowNullOrigin()
.allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.PATCH)
.allowedRequestHeaders("origin", "accept", "authorization", "content-type")
.build()));
}
示例7: main
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
public static void main(String[] args) {
String ip = "127.0.0.1";
int port = 8080;
ChannelInitializer<SocketChannel> channelInit = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
CorsConfig corsConfig = CorsConfig.withAnyOrigin()
.allowedRequestHeaders("content-type","accept","MyCustomHeader")
.allowedRequestMethods(PUT,POST,GET,DELETE)
.build();
p.addLast(new HttpResponseEncoder());
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new ChunkedWriteHandler());
p.addLast(new CorsHandler(corsConfig));
p.addLast(new SimpleCORSHandler());
}
};
NettyServerUtil.newHttpServerBootstrap(ip, port, channelInit);
}
示例8: initializerFactory
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Bean(name = "channelInitializer")
public ChannelInitializer<SocketChannel> initializerFactory(final ApplicationContext contxt) {
return new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
SimpleChannelInboundHandler<?> channelInboundHandler = contxt.getBean(NettyHttpChannelHandler.class);
ChannelPipeline pipeline = ch.pipeline();
// HTTP
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpResponseEncoder());
pipeline.addLast(new HttpContentCompressor());
pipeline.addLast(new ChunkedWriteHandler());
// 设置处理的Handler
pipeline.addLast(channelInboundHandler);
}
};
}
示例9: configNewChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Override
public void configNewChannel(NioSocketChannel channel) {
super.configNewChannel(channel);
ChannelPipeline pipeline = channel.pipeline();
// 添加 SSL 数据支持
if (requestConfig.https()) {
SslContext sslContent = NettyCenter.singleInstance().getSimpleClientSslContext();
SSLEngine engine = sslContent.newEngine(channel.alloc());
pipeline.addLast("ssl", new SslHandler(engine));
}
// 客户端接收到的是httpResponse响应,所以要使用HttpResponseDecoder进行解码
pipeline.addLast("decoder", new HttpResponseDecoder());
// 客户端发送的是httprequest,所以要使用HttpRequestEncoder进行编码
pipeline.addLast("encoder", new HttpRequestEncoder());
// 接收的请求累计器
pipeline.addLast("aggegator", new HttpObjectAggregator(0x30000));
// mime 类型写出
pipeline.addLast("streamew", new ChunkedWriteHandler());
// 添加解压器
pipeline.addLast("decompressor", new HttpContentDecompressor());
// add new handler
pipeline.addLast("handler", new NettyHttpRequestChannelHandler());
}
示例10: createInitializer
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的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());
}
};
}
示例11: HttpAPIServer
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
public HttpAPIServer(Holder holder) {
super(holder.props.getProperty("listen.address"),
holder.props.getIntProperty("http.port"), holder.transportTypeHolder);
String adminRootPath = holder.props.getProperty("admin.rootPath", "/admin");
final HttpAndWebSocketUnificatorHandler httpAndWebSocketUnificatorHandler =
new HttpAndWebSocketUnificatorHandler(holder, port, adminRootPath);
final LetsEncryptHandler letsEncryptHandler = new LetsEncryptHandler(holder.sslContextHolder.contentHolder);
channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline()
.addLast("HttpServerCodec", new HttpServerCodec())
.addLast("HttpServerKeepAlive", new HttpServerKeepAliveHandler())
.addLast("HttpObjectAggregator", new HttpObjectAggregator(holder.limits.webRequestMaxSize, true))
.addLast(letsEncryptHandler)
.addLast("HttpChunkedWrite", new ChunkedWriteHandler())
.addLast("HttpUrlMapper", new UrlReWriterHandler("/favicon.ico", "/static/favicon.ico"))
.addLast("HttpStaticFile", new StaticFileHandler(holder.props, new StaticFile("/static"),
new StaticFileEdsWith(CSVGenerator.CSV_DIR, ".csv.gz")))
.addLast("HttpWebSocketUnificator", httpAndWebSocketUnificatorHandler);
}
};
}
示例12: initWebSocketPipeline
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
private void initWebSocketPipeline(ChannelHandlerContext ctx, String websocketPath) {
ChannelPipeline pipeline = ctx.pipeline();
//websockets specific handlers
pipeline.addLast("WSWebSocketServerProtocolHandler", new WebSocketServerProtocolHandler(websocketPath, true));
pipeline.addLast("WSWebSocket", new WebSocketHandler(stats));
pipeline.addLast("WSMessageDecoder", new MessageDecoder(stats));
pipeline.addLast("WSSocketWrapper", new WebSocketWrapperEncoder());
pipeline.addLast("WSMessageEncoder", new MessageEncoder(stats));
pipeline.addLast("WSWebSocketGenericLoginHandler", genericLoginHandler);
pipeline.remove(this);
pipeline.remove(ChunkedWriteHandler.class);
pipeline.remove(UrlReWriterHandler.class);
pipeline.remove(StaticFileHandler.class);
pipeline.remove(LetsEncryptHandler.class);
}
示例13: initChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
if (enableGzip) {
p.addLast(new HttpContentCompressor());
}
p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
p.addLast(new ChunkedWriteHandler());
if (enableCors) {
CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
p.addLast(new CorsHandler(corsConfig));
}
if (null != blade.webSocketPath()) {
p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
p.addLast(new WebSockerHandler(blade));
}
service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
p.addLast(new HttpServerHandler());
}
示例14: initChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel channel) throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = channel.pipeline();
// Uncomment the following line if you want HTTPS
// SSLEngine engine =
// SecureChatSslContextFactory.getServerContext().createSSLEngine();
// engine.setUseClientMode(false);
// pipeline.addLast("ssl", new SslHandler(engine));
pipeline.addLast("decoder", new HttpRequestDecoder());
//pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
pipeline.addLast("deflater", new HttpContentCompressor());
pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
}
示例15: initChannel
import io.netty.handler.stream.ChunkedWriteHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
if (sslFactory != null) {
pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
}
int maxChunkSize = getConfig().getInt(ConfVars.SHUFFLE_FETCHER_CHUNK_MAX_SIZE.varname,
ConfVars.SHUFFLE_FETCHER_CHUNK_MAX_SIZE.defaultIntVal);
pipeline.addLast("codec", new HttpServerCodec(maxUrlLength, 8192, maxChunkSize));
pipeline.addLast("aggregator", new HttpObjectAggregator(1 << 16));
pipeline.addLast("chunking", new ChunkedWriteHandler());
pipeline.addLast("shuffle", PullServer);
// TODO factor security manager into pipeline
// TODO factor out encode/decode to permit binary shuffle
// TODO factor out decode of index to permit alt. models
}