http流响应不支持的消息类型:class org.jboss.netty.handler.stream.ChunkedStream

时间:2012-04-08 21:45:55

标签: http streaming inputstream netty outputstream

我正在尝试编写基于netty的http服务器,它将文本作为输入并返回图像作为输出。该图像基于输入文本即时生成。

我将org.jboss.netty.example.http.file.HttpStaticFileServerHandler的逻辑复制到我自己的处理程序中,而不是在通道中编写DefaultFileRegion作为输出,

final FileRegion region = new DefaultFileRegion(raf.getChannel(), 0, fileLength);
writeFuture = ch.write(region);

我在自己的处理程序中执行以下操作:

InputStream imageIOStream = imageGenerator.generateImage(inputText);
ChannelFuture writeFuture = ch.write(new ChunkedStream(imageIOStream));

但是当我尝试写回客户端时,我在服务器上遇到以下异常。

java.lang.IllegalArgumentException: unsupported message type: class     org.jboss.netty.handler.stream.ChunkedStream
at    org.jboss.netty.channel.socket.nio.SocketSendBufferPool.acquire(SocketSendBufferPool.java:56)
at org.jboss.netty.channel.socket.nio.NioWorker.write0(NioWorker.java:463)
at  org.jboss.netty.channel.socket.nio.NioWorker.writeFromUserCode(NioWorker.java:390)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:137)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:76)
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:68)
at org.jboss.netty.channel.Channels.write(Channels.java:611)
at org.jboss.netty.channel.Channels.write(Channels.java:578)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:251)

有人可以帮助我。

1 个答案:

答案 0 :(得分:3)

在您的渠道中,您是否设置了以下内容?

pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

请参阅https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerPipelineFactory.java