使用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. iOS比较枚举NSOrderedSame NSOrderedAscending NSOrderedDescending使用小结

    项目开发中偶然间看到这种比较枚举,之前没注意过,仔细研究了一下结果还挺有意思,我们可以用升降序相等来帮助理解比较结果. NSString 两个字符串的比较,用 a compare:b 来比,得出的结果 ...

  2. iOSwkwebView 打开 TXT/PDF 文件乱码的问题

    最近做资料文件下载下来并查看的时候,用 WKWebView 打开office 类型的文件的时候是没问题的,但是打开测试人员上传的一个 TXT/PDF 文件就出现了乱码问题,经过查看,应该是文件的编码问 ...

  3. modbus基础

    Modbus是一种单主站的主从通信模式,Modbus只能有一个主站,允许多个从站(0-247):从站之间不能交流:主站发送数据,从站应答: 一主多从 : 1. 地址码,表,功能码 地址码一般是Modb ...

  4. 【信创问题】解决东方通(TongWeb)报错 java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider

    写在前边 今天帮现场同事定位问题,情况是项目同事使用东方通(TongWeb7.0)部署公司项目时,出现以下报错导致服务启动失败. 简单排查了下发现:war包内WEB-INF/lib/javax.per ...

  5. KubeSphere 社区双周报 | 本周六上海站 Meetup 准时开启 | 2023.7.21-08.03

    KubeSphere 社区双周报主要整理展示新增的贡献者名单和证书.新增的讲师证书以及两周内提交过 commit 的贡献者,并对近期重要的 PR 进行解析,同时还包含了线上/线下活动和布道推广等一系列 ...

  6. 格点拉格朗日插值与PME算法

    技术背景 在前面的一篇博客中,我们介绍了拉格朗日插值法的基本由来和表示形式.这里我们要介绍一种拉格朗日插值法的应用场景:格点拉格朗日插值法.这种场景的优势在于,如果我们要对整个实数空间进行求和或者积分 ...

  7. vscode中整合豆包MarsCode编程助手

    豆包MarsCode是字节跳动旗下的一款AI工具,最近在刷帖子时看到已经可以在vscode中通过插件安装MarsCode工具,接下来我们来看下操作流程以及使用效果. 第一步:首先需要注册下豆包账号 豆 ...

  8. Mongo oplog理解

    转载请注明出处: oplog(操作日志)是MongoDB中用于记录所有写操作的日志.它是一个特殊的集合,存储在副本集的主节点中.oplog用于确保副本集中的副节点与主节点的数据保持一致.当主节点执行写 ...

  9. Redis工具可视化工具Redis Desktop Manager(附安装包)

    前言 redis工具,我相信每个开发都需要,如果每次查都去client执行指令,我怕查完之后,老大就要发版咯.我之前一直用的Redis可视化工具RedisDesktopManager,总觉得差点意思, ...

  10. redis哨兵模式下主从切换后,php实现自动切换

    redis的哨兵模式,在主服务器挂掉后,会通过选举将对应的从服务器切换为主服务器,以此来达到服务的高可用性. 在业务层面如果主从做了切换可能相对应的服务器IP地址会发生改变,这样会带来程序的的正常运行 ...