I was hoping that these three @Overrides would bypass the serialization codec 
and allow streamwritefilter to deal with the files

@Override
 protected boolean doDecode(IoSession session, IoBuffer in, 
ProtocolDecoderOutput out) throws Exception {
     if (session.getAttribute("state") == SessionState.RECV_FILE || 
session.getAttribute("state") == SessionState.SEND_FILE)
         return false;
     else {
         return super.doDecode(session, in, out);
     }
 }
}


  @Override
  public void encode(IoSession session, Object message, ProtocolEncoderOutput 
out) throws Exception {
     if (session.getAttribute("state") == SessionState.RECV_FILE || 
session.getAttribute("state") == SessionState.SEND_FILE)
          return;
      else
          super.encode(session, message, out);
      }
}

   @Override
   public void filterWrite(NextFilter nextFilter, IoSession session, 
WriteRequest writeRequest) throws Exception {
       if (writeRequest.getMessage() instanceof FileInputStream)
//        if (session.getAttribute("state") == SessionState.RECV_FILE || 
session.getAttribute("state") == SessionState.SEND_FILE)
           nextFilter.filterWrite(session, writeRequest);
       else
           super.filterWrite(nextFilter, session, writeRequest);
   }
}

Cesar Barria


On Nov 25, 2011, at 1:59 AM, "Emmanuel Lecharny" <elecha...@gmail.com> wrote:

On 11/25/11 7:40 AM, Cesar Barria wrote:
> I'm new to MINA and have been working on a small project for a few weeks now. 
> My application is fairly simple… I'm sending commands to a server via POJO 
> messages. In some cases the server or the client will send a file instead of 
> a POJO. I'm using the StreamWriteFilter and the ObjectSerializationCodec 
> ProtocolCodecFilter. I can send objects back and forth fairly successfully, 
> but I can't send large files and sometimes even small files fail to be sent.
> 
> Here is the exception I get when sending files:
> 
> 00:46:09] pool-4-thread-4 WARN  [] [] [client.ClientIoSessionHandler] - 
> Exception: class org.apache.mina.filter.codec.ProtocolDecoderException State: 
> RECV_FILE_WAIT
> [00:46:09] pool-4-thread-4 ERROR  [] [] [client.ClientIoSessionHandler] - 
> Throwable:
> org.apache.mina.filter.codec.ProtocolDecoderException: 
> org.apache.mina.core.buffer.BufferDataException: dataLength: 1347093252
> 
> 
> Any ideas why am I getting this exception? How should I go about having the 
> ObjectSerializationCodec handle the POJOs while StreamWriteFilter  handles 
> the files?

Hi,

I haven't spent too much time analyzing the detail of your code, but I'm 
wondering if there isn't a difference in the encoder and decoder, when it comes 
to deal with files being sent : to me, it seems that the decoder is expecting 
the received message to be a serialized object, even if it's a file, and try to 
decode the first 4 bytes of the incoming message (which are containing the size 
of the transmitted object).

You should probably add some information in your sent messages to tell the 
decoder that it has to deal with a serialized object *or* a file.


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com



Reply via email to