使用netty做http服务器的时候 用android链接 会出现这个错误

原因是http-aggregator顺序有问题

(ps:目前大部分国内博客都是这个排序有点坑爹):

官方文档说明:For convenience, consider putting a HttpServerCodec before the HttpObjectAggregator as it functions as both a HttpRequestDecoder and a HttpResponseEncoder.

package com.sencorsta.ids.httptest;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
* Created by apple on 17/10/21.
*/
public class HttpServer {

public static void start(final int port) throws Exception {
EventLoopGroup boss = new NioEventLoopGroup();
EventLoopGroup woker = new NioEventLoopGroup();
ServerBootstrap serverBootstrap = new ServerBootstrap();
HttpServerHandler httpServerHandler=new HttpServerHandler();
try {

serverBootstrap.channel(NioServerSocketChannel.class).group(boss, woker)
.childOption(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected 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(httpServerHandler);
}
});

ChannelFuture future = serverBootstrap.bind(port).sync();
future.channel().closeFuture().sync();
} finally {
boss.shutdownGracefully();
woker.shutdownGracefully();
}
}

public static void main(String[] args) throws Exception {
start(8080);
}
}
把上面的ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));这一行

放到coder下面就可以了

package com.sencorsta.ids.httptest;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
* Created by apple on 17/10/21.
*/
public class HttpServer {

public static void start(final int port) throws Exception {
EventLoopGroup boss = new NioEventLoopGroup();
EventLoopGroup woker = new NioEventLoopGroup();
ServerBootstrap serverBootstrap = new ServerBootstrap();
HttpServerHandler httpServerHandler=new HttpServerHandler();
try {

serverBootstrap.channel(NioServerSocketChannel.class).group(boss, woker)
.childOption(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
ch.pipeline().addLast("http-encoder", new HttpResponseEncoder());
ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));
ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
ch.pipeline().addLast(httpServerHandler);
}
});

ChannelFuture future = serverBootstrap.bind(port).sync();
future.channel().closeFuture().sync();
} finally {
boss.shutdownGracefully();
woker.shutdownGracefully();
}
}

public static void main(String[] args) throws Exception {
start(8080);
}
}
参考资料:官方说明

unsupported message type: DefaultFullHttpResponse (expected: ByteBuf, FileRegion) 原因以及解决办法的更多相关文章

  1. C++:undefined reference to vtable 原因与解决办法[转]

    [转]undefined reference to vtable 原因与解决办法 最近在写一套基础类库用于SG解包blob字段统计,在写完了所有程序编译时遇到一个郁闷无比的错误: MailBox.o( ...

  2. jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法

    jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法   在调用一个jquery的ajax方法时我们有时会需要该方法返回一个值或者给某个全局变量赋值,可是我们 ...

  3. 各种编码问题产生原因以及解决办法---------响应编码,请求编码,URL编码

     响应编码 产生原因以及解决办法: 示例: package cn.yzu; import java.io.IOException; import javax.servlet.ServletExcept ...

  4. .Net内存泄露原因及解决办法

    .Net内存泄露原因及解决办法 1.    什么是.Net内存泄露 (1).NET 应用程序中的内存 您大概已经知道,.NET 应用程序中要使用多种类型的内存,包括:堆栈.非托管堆和托管堆.这里我们需 ...

  5. com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1问题出现的原因及解决办法

    转自:https://blog.csdn.net/shinchan_/article/details/37818927 com/opensymphony/xwork2/spring/SpringObj ...

  6. Oracle死锁产生的原因和解决办法

    如果有两个会话,每个会话都持有另一个会话想要的资源,此时就会发生死锁.用下面实验来说明死锁的产生原因和解决办法.SESSION1:SQL> create table t2 as select * ...

  7. HttpClient的CircularRedirectException异常原因及解决办法

    HttpClient的CircularRedirectException异常原因及解决办法 这两天在使用我自己爬虫抓取网页的时候总是出现 org.apache.http.client.ClientPr ...

  8. php_curl.dll libssh2.dll 始终无法加载的原因 及解决办法

    在StackOverflow得到最终原因及解决办法 http://stackoverflow.com/questions/16424117/php-unable-to-load-php-curl-dl ...

  9. mysql保存中文乱码的原因和解决办法

    当你遇到这个mysql保存中文乱码问题的时候,期待找到mysql保存中文乱码的原因和解决办法这样一篇能解决问题的文章是多么激动人心.    也许30%的程序员会选择自己百度,结果发现网友已经贴了很多类 ...

  10. eclipse中tomcat发布失败(Could not delete May be locked by another process)原因及解决办法

    在eclipse中tomcat发布项目时,偶尔出现了以下情况: publishing to tomcat v7.0 services at localhost has encountered a pr ...

随机推荐

  1. Java日期时间API系列28-----Jdk8中java.time包中的新的日期时间API类,计算节假日和二十四节气。

    1.节日信息计算代码 package com.xkzhangsan.time.holiday; import java.time.DayOfWeek; import java.time.LocalDa ...

  2. 巅峰对话在线研讨 Q&A:Oracle Database 21c vs openGauss 2.0新特性解读和架构演进

    2021年11月11日,墨天轮<巅峰对话>栏目邀请到了两位数据库领域的巅峰人物:云和恩墨创始人盖国强老师,和来自清华大学计算机与技术系的李国良教授,为大家带来了在线研讨<Oracle ...

  3. springboot admin 整合nacos,context-path问题

    1.在使用springboot admin 整合nacos时发现问题,springboot admin server访问admin client的默认地址为http://ip:port/actuato ...

  4. 云原生周刊:KubeSphere 宣布开源 Thanos 的企业级发行版 Whizard

    开源项目推荐 Admiralty Admiralty 是一个 Kubernetes 控制器系统,可以智能地在多个集群之间调度工作负载.它使用简单,并且易于与其他工具集成. Cozystack Cozy ...

  5. python实战-编写请求方法重试(用途:请求重试、也可用于其他场景)、日志、执行耗时、手机号与邮箱校验装饰器

    更新日志 2023.2.9 增加重试装饰器 防止函数原信息被改变使用:@functools.wraps(func)装饰执行函数 # _*_ coding: UTF-8 _*_ "" ...

  6. 7 个非常实用的 Shell 拿来就用脚本实例!

    前天,在群里看到有一位读者分享了几道 Shell 脚本实例题目,索性看到了,不如来写写巩固下基础知识,如下: 1. 并发从数台机器中获取 hostname,并记录返回信息花费的时长,重定向到一个文件 ...

  7. Oracle的用户如何优雅地达成软件合规目标

    企业一旦发展到了一定规模,就会衍生软件100%合规正版化的需求. 而对于使用到Oracle的用户,当然,具体核定的购买数量和off等商务问题,需要客户管理层直接和对应的Oracle销售代表进行商务谈判 ...

  8. python处理大量数据excel表格中间格式神器pickle.pkl文件操作说明

    读取写入千万级别的excel文件费时费力,调试起来比较慢,面对这个问题,第一步可以先无脑全部转换成pkl文件,这样几乎和内存操作一样的速度. 例如: t=pd.read_excel("12月 ...

  9. FFmpeg转码音视频时间戳设置分析

    音频时间戳设置 以下代码基于FFmpeg n5.1.2进行分析 以下文档中有关音频的具体时间戳数据来自以下转码命令: ./ffmpeg_g -rw_timeout 5000000 -i 'rtmp:/ ...

  10. Ocelot集成Consul实现api网关与服务发现

    前言 没看dotnet微服务之API网关Ocelot的请先看,这篇文章接上面文章 安装consul #自定义网络,自定义网络可以指定容器IP,这样服务器重启consul集群也可以正常运行. docke ...