Netty Framework - Exception occurs while adding content to HTTP Response (Channel Buffer) -


i using java http proxy (littleproxy) developed on netty framework. in simple example, i've added http response filter process image content, , attach processed content response message. below code snippet, using.

// buffered channel output writer. dynamicchannelbuffer dychannelbuf = new dynamicchannelbuffer(chanbuff.order(), chanbuff.capacity()); dychannelbuf.clear();  log.debug("capacity of channel buffer is: " + dychannelbuf.capacity()); channelbufferoutputstream buffoutstream = new channelbufferoutputstream(dychannelbuf);  byte[] bytebuf = new byte[4096]; int bytesread = -1; int offset = 0;  try {                        while ((bytesread = instream.read(bytebuf)) != -1) {     buffoutstream.write(bytebuf, offset, bytesread);     offset += bytesread;     }                        } catch (indexoutofboundsexception e) { e.printstacktrace(); // buffer not good. not process image. log.debug("marked file: " + markedfilename + " can not sent");                     buffoutstream.close(); instream.close(); return false; }  // modifies response response.setcontent(buffoutstream.buffer()); response.setheader("content-type", conttype); response.setheader("content-length", filelen); 

i getting below exception specific image. of other images working fine. can me understand if handing response message above correctly?

================================= exception ====================

http/1.1 200 ok server: apache last-modified: tue, 14 may 2013 04:24:43 gmt accept-ranges: bytes content-length: 11193 cneonction: close content-type: image/jpeg cache-control: private, max-age=605454 expires: wed, 22 may 2013 05:08:40 gmt date: wed, 15 may 2013 04:57:46 gmt connection: keep-alive  java.lang.arrayindexoutofboundsexception     @ java.lang.system.arraycopy(native method)     @ org.jboss.netty.buffer.heapchannelbuffer.setbytes(heapchannelbuffer.java:132)     @ org.jboss.netty.buffer.dynamicchannelbuffer.setbytes(dynamicchannelbuffer.java:182)     @ org.jboss.netty.buffer.abstractchannelbuffer.writebytes(abstractchannelbuffer.java:444)     @ org.jboss.netty.buffer.dynamicchannelbuffer.writebytes(dynamicchannelbuffer.java:236)     @ org.jboss.netty.buffer.channelbufferoutputstream.write(channelbufferoutputstream.java:67)     @ org.media.processor.libraryimpl.processresponse(libraryimpl.java:110)     @ org.media.processor.mediahandler$1.filterresponse(mediahandler.java:29)     @ org.littleshoot.proxy.httprelayinghandler.messagereceived(httprelayinghandler.java:191)     @ org.jboss.netty.channel.simplechannelupstreamhandler.handleupstream(simplechannelupstreamhandler.java:70)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline$defaultchannelhandlercontext.sendupstream(defaultchannelpipeline.java :791)     @ org.jboss.netty.channel.simplechannelhandler.messagereceived(simplechannelhandler.java:142)     @ org.jboss.netty.channel.simplechannelhandler.handleupstream(simplechannelhandler.java:88)     @ org.jboss.netty.handler.timeout.idlestateawarechannelhandler.handleupstream(idlestateawarechannelhandler.java:36)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline$defaultchannelhandlercontext.sendupstream(defaultchannelpipeline.java :791)     @ org.jboss.netty.handler.timeout.idlestatehandler.messagereceived(idlestatehandler.java:294)     @ org.jboss.netty.channel.simplechannelupstreamhandler.handleupstream(simplechannelupstreamhandler.java:70)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline$defaultchannelhandlercontext.sendupstream(defaultchannelpipeline.java :791)     @ org.jboss.netty.handler.codec.http.httpchunkaggregator.messagereceived(httpchunkaggregator.java:148)     @ org.jboss.netty.channel.simplechannelupstreamhandler.handleupstream(simplechannelupstreamhandler.java:70)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline$defaultchannelhandlercontext.sendupstream(defaultchannelpipeline.java :791)     @ org.jboss.netty.handler.codec.http.httpcontentdecoder.messagereceived(httpcontentdecoder.java:108)     @ org.jboss.netty.channel.simplechannelupstreamhandler.handleupstream(simplechannelupstreamhandler.java:70)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline$defaultchannelhandlercontext.sendupstream(defaultchannelpipeline.java :791)     @ org.jboss.netty.channel.channels.firemessagereceived(channels.java:296)     @ org.jboss.netty.handler.codec.frame.framedecoder.unfoldandfiremessagereceived(framedecoder.java:459)     @ org.jboss.netty.handler.codec.replay.replayingdecoder.calldecode(replayingdecoder.java:536)     @ org.jboss.netty.handler.codec.replay.replayingdecoder.messagereceived(replayingdecoder.java:485)     @ org.jboss.netty.channel.simplechannelupstreamhandler.handleupstream(simplechannelupstreamhandler.java:70)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:564)     @ org.jboss.netty.channel.defaultchannelpipeline.sendupstream(defaultchannelpipeline.java:559)     @ org.jboss.netty.channel.channels.firemessagereceived(channels.java:268)     @ org.jboss.netty.channel.channels.firemessagereceived(channels.java:255)     @ org.jboss.netty.channel.socket.nio.nioworker.read(nioworker.java:88)     @ org.jboss.netty.channel.socket.nio.abstractnioworker.process(abstractnioworker.java:107)     @ org.jboss.netty.channel.socket.nio.abstractnioselector.run(abstractnioselector.java:312)     @ org.jboss.netty.channel.socket.nio.abstractnioworker.run(abstractnioworker.java:88)     @ org.jboss.netty.channel.socket.nio.nioworker.run(nioworker.java:178)     @ org.jboss.netty.util.threadrenamingrunnable.run(threadrenamingrunnable.java:108)     @ org.jboss.netty.util.internal.deadlockproofworker$1.run(deadlockproofworker.java:42)     @ java.util.concurrent.threadpoolexecutor.runworker(unknown source)     @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source)     @ java.lang.thread.run(unknown source) 6771   2013-05-15 00:57:45,813 debug [new i/o worker #1] proxy.httprelayinghandler.shouldcloseremoteconnection (httprela yinghandler.java:463) - not closing -- response keep alive for: defaulthttpresponse(chunked: false) 

your problem here:

while ((bytesread = instream.read(bytebuf)) != -1) {     buffoutstream.write(bytebuf, offset, bytesread);     offset += bytesread; }   

the parameter offset offset start copy in source data (i.e. in bytebuf). because have fixed array , fill new values have use 0 offset here.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -