The following patch seems to help. It is applied to the common code in 
the asyncweb project. Does this look reasonable? Any thoughts? I embed 
the decoder in a CumulativeProtocolDecoder and also reuse the 
HttpResponseDecoder that has been attached to the session. David

Index: src/main/java/org/apache/asyncweb/common/codec/HttpCodecFactory.java
===================================================================
--- 
src/main/java/org/apache/asyncweb/common/codec/HttpCodecFactory.java    
(revision 1296269)
+++ 
src/main/java/org/apache/asyncweb/common/codec/HttpCodecFactory.java    
(working copy)
@@ -70,7 +70,11 @@
          }
          else
          {
-            return new HttpResponseDecoder();
+            ProtocolDecoder decoder = 
(ProtocolDecoder)session.getAttribute("SessionProtocolDecoder");
+            if (decoder != null) return decoder;
+            decoder = new HttpResponseDecoder();
+            session.setAttribute("SessionProtocolDecoder", decoder);
+            return decoder;
          }
      }
  }
Index: 
src/main/java/org/apache/asyncweb/common/codec/HttpResponseDecoder.java
===================================================================
--- 
src/main/java/org/apache/asyncweb/common/codec/HttpResponseDecoder.java    
(revision 1296269)
+++ 
src/main/java/org/apache/asyncweb/common/codec/HttpResponseDecoder.java    
(working copy)
@@ -21,24 +21,41 @@

  import java.util.List;

+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
  import org.apache.mina.filter.codec.ProtocolDecoderOutput;
  import org.apache.mina.filter.codec.statemachine.DecodingState;
  import 
org.apache.mina.filter.codec.statemachine.DecodingStateProtocolDecoder;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;

  /**
   * @author The Apache MINA Project ([email protected])
   */
-public class HttpResponseDecoder extends DecodingStateProtocolDecoder {
+public class HttpResponseDecoder extends CumulativeProtocolDecoder {
+
+    private DecodingStateProtocolDecoder decoderDelegate;
+    private boolean amDone = false;
+
      public HttpResponseDecoder() {
-        super(new HttpResponseDecodingState() {
+        decoderDelegate = new DecodingStateProtocolDecoder(new 
HttpResponseDecodingState() {
              @Override
              protected DecodingState finishDecode(List<Object> 
childProducts,
                      ProtocolDecoderOutput out) throws Exception {
                  for (Object m: childProducts) {
                      out.write(m);
                  }
+                amDone = true;
                  return null;
              }
          });
      }
+
+    public boolean doDecode(
+            IoSession session, IoBuffer in, ProtocolDecoderOutput out)
+             throws Exception {
+        decoderDelegate.decode(session, in, out);
+        return amDone;
+    }
  }

On 3/5/2012 1:45 PM, David R Robison wrote:
> The problem sees to be that the DecodingStateProtocolDecoder class
> assumes that each complete "event" is contained in one packet. There is
> no way for it to tell that the "event" is continued across multiple
> packets. David
>
> On 3/5/2012 1:21 PM, David R Robison wrote:
>> I am trying to use the asyncweb common codecs to read a large JPEG
>> (>130,000 bytes) from a web service. It appears that the codecs read
>> the first packet but do no handle the reconstruction of multiple
>> packets into one response. Am I missing something? Is this supported?
>> Any ideas? David
>>

-- 

David R Robison
Open Roads Consulting, Inc.
103 Watson Road, Chesapeake, VA 23320
phone: (757) 546-3401
e-mail: [email protected]
web: http://openroadsconsulting.com
blog: http://therobe.blogspot.com
book: http://www.xulonpress.com/bookstore/bookdetail.php?PB_ISBN=9781597816526



This email communication (including any attachments) may contain confidential 
and/or privileged material intended solely for the individual or entity to 
which it is addressed.
If you are not the intended recipient, please delete this email immediately.

Reply via email to