Le 31/07/2014 23:59, Carlos Alegria Galicia a écrit : > Emmanuel, > > Thanks a lot for your answer. After considering your comment and debugging > the client-server communication, I found out that, when the issue "happens" > (I assume this is happening when session Idle is present and there are > missing bytes in the state holding object), the server actually reads the > same amount of bytes sent by the client. > > I think then that I am incorrectly reading the input buffer in my Filter. I > am currently doing this: > > ... > if (in.hasRemaining()) { > > int byteCount = in.limit(); > byte data[] = new byte[byteCount]; > in.get(data); > > try { > ctx.out.write(data); > ctx.bytes -= byteCount; > } catch (IOException ioe) { > ctx.out.close(); > nextFilter.exceptionCaught(session, ioe); > return; > } > > } > ... > > Is this the proper way of retrieving the data from a buffer?
Not exactly. Here, you are creating a buffer which will be potentially too big. You have to take care of the current position in the ByterBuffer when you compute the length of the buffer. Here, you should do something like : byte data[] = new byte[in.remaining()]; in.get(data); as explained in http://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html#remaining%28%29