使用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. 黑客工具:Amass – 寻找子域

    安装 所有信息都可以在 OWASP Amass 项目的 Github 页面上找到:https://github.com/OWASP/Amass.我们将一起完成安装过程,以便更快地部署. 转到发布页面并 ...

  2. Web渗透09_文件包含漏洞

    1 文件包含漏洞描述 开发人员编写代码时独立性好是一个很重要的要求,这边一个数据库类,那边一个模型类.几百行的整体代码,在整合时两行行代码就可以包含进来使用.文件包含有助于独立的代码之间的配合!有时引 ...

  3. 深度解读RDS for MySQL 审计日志功能和原理

    本文分享自华为云社区<[华为云MySQL技术专栏]RDS for MySQL 审计日志功能介绍>,作者:GaussDB数据库. 1. 背景 在生产环境中,当数据库出现故障或问题时,运维人员 ...

  4. SSIS ODBC方式连接mysql数据库

    系统环境:WIN 10 64位 1.安装Mysql odbc connector 插件 文章说明链接: https://www.cnblogs.com/santiagoMunez/p/4780301. ...

  5. 异源数据同步 → 如何获取 DataX 已同步数据量?

    开心一刻 今天,表妹问我:哥,我男朋友过两天要生日了,你们男生一般喜欢什么,帮忙推荐个礼物呗我:预算多少表妹:预算300我:20块买条黑丝,剩下280给自己买支口红,你男朋友生日那天你都给自己用上表妹 ...

  6. 【转载】【深度学习服务器组装】【DIY土豪級別電腦】1.5TB記憶體192核心384線程雙路EPYC9654+RTX4090=神豪的量化+深度學習電腦

    视频地址: https://www.youtube.com/watch?v=_VMvGuVGI1M

  7. ubuntu服务器上部署EMQX SLL

    1.     安装MQTT的简易服务器集成环境EMQX $wget https://www.emqx.com/zh/downloads/broker/5.1.6/emqx-5.1.6-ubuntu18 ...

  8. golang 正则表达式

    package main import "bytes" import "fmt" import "regexp" func main() { ...

  9. go官方包依赖管理工具之mod

    1.1.go mod是什么 go mod 是Golang 1.11 版本引入的官方包(package)依赖管理工具,用于解决之前没有地方记录依赖包具体版本的问题,方便依赖包的管理. 之前Golang ...

  10. 从零开始学java(第一天)

    上班日学习时间很短,而且很多事情会耽搁,就会写的比较少 近几期的笔记以复习为主,后面会逐渐拓展对我个人来说的新知识 1. 复习了一下typore的语法,方便以后记笔记用 # MarkDown学习(# ...