hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asankha C. Perera" <asan...@apache.org>
Subject Re: Truncated content-length delimited message bodies
Date Thu, 12 May 2011 19:01:59 GMT
On 05/13/2011 12:10 AM, Asankha C. Perera wrote:
> I'm seeing the exception being thrown from the decoder and being 
> handled, and being thrown and somehow not getting caught properly - 
> intermittently.. Have been trying to nail the exact issue, but I need 
> a bit more time. Any ideas?
Hi Oleg

The problem seems to be like this.. I have a ContentListener 
implementation, and from its contentAvailable() the following gets invoked.

                 transferred = fileChannel.transferFrom(
                     new ContentDecoderChannel(decoder), idx, 
Integer.MAX_VALUE);

Looking at the Java source below, it seems like the IOException is 
propagated only when "tw" is > 0 .. I do not understand why they do that..

regards
asankha

private static final int TRANSFER_SIZE = 8192;

     private long transferFromArbitraryChannel(ReadableByteChannel src,
                                               long position, long count)
         throws IOException
     {
         // Untrusted target: Use a newly-erased buffer
         int c = (int)Math.min(count, TRANSFER_SIZE);
         ByteBuffer bb = Util.getTemporaryDirectBuffer(c);
         long tw = 0;                    // Total bytes written
         long pos = position;
         try {
             Util.erase(bb);
             while (tw < count) {
                 bb.limit(Math.min((int)(count - tw), TRANSFER_SIZE));
                 // ## Bug: Will block reading src if this channel
                 // ##      is asynchronously closed
                 int nr = src.read(bb);
                 if (nr <= 0)
                     break;
                 bb.flip();
                 int nw = write(bb, pos);
                 tw += nw;
                 if (nw != nr)
                     break;
                 pos += nw;
                 bb.clear();
             }
             return tw;
         } catch (IOException x) {
             if (tw > 0)
                 return tw;
             throw x;
         } finally {
             Util.releaseTemporaryDirectBuffer(bb);
         }
     }

-- 

Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message