I thought that's what StreamWriterFilter is supposed to do. This is how I
was hoping it would work:

FilterChain


LoggingFilter
ObjectSerializationCodec
StreamWriterFilter

When a POJO arrives (Command Messages) I get them through the
ObjectSerializationCodec Filter and the StreamWritrFilter simply ignores
them as the object is not a FileInputStream object. This seems to work
well. However, when a FileInputStream object is what's being sent (Im
receiving a file)... I want the ObjectSerializationCodec to ignore those
so the StreamWriterFilter deals with them. This is the part that I'm
having issues with... I can't seem to bypass the doDecode though. Another
item I'm not sure I fully understand is why the ObjectSerializationCodec
filter is not bypassing the FileInputStream objects to begin with as those
should already be a byte buffer.

Thanks for all the help!

On 11/25/11 11:32 AM, "Emmanuel Lécharny" <elecha...@apache.org> wrote:

>On 11/25/11 5:17 PM, Cesar Barria wrote:
>> Yup... The @Overrides are being called appropriately. I think my problem
>> is here... I just don't know how to fix it.
>> This returns false which I think just indicates not enough buffer data
>> available to decode... So it will call the doDecode method on the
>> ObjecSerializationCodec class again instead of moving on to the
>> StreamWriterFilter class.
>
>When you are dealing with a file, you must accumulate the incoming data,
>as the file content will be send piece by piece. You have to encapsulate
>your messages by a marker to distinguish between the two cases (file or
>serialied object), otherwise you won't be able to know what kind of data
>you are dealing with.
>
>Bottom line, you have to define the protocol you are using and the
>associated encoder/decoder.
>
>For instance, the messages will look likes :
>[flag] [size] [data]
>
>where [flag] can be a byte indicating if it's a file (0) or an object
>(1), followed by the data size and the data itself. Of course, if the
>data is a serialized object, then you will have to serialize it to a
>stream and send it, and on the other end, to deserialize it.
>
>You can copy the ObjectSerializationEn/DeCoder, modify it and use it to
>make it deal with this first byte and the 2 cases. A bit more work, but
>you already have almost all the code written...
>>
>>
>> @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);
>>       }
>> }
>> }
>>
>> On the encoder everything appears to be working appropriately:
>>
>>   @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);
>>        }
>> }
>>
>>
>>
>>
>>
>>
>> On 11/25/11 9:49 AM, "Emmanuel Lécharny"<elecha...@apache.org>  wrote:
>>
>>> On 11/25/11 3:41 PM, Cesar Barria wrote:
>>>> I was hoping that these three @Overrides would bypass the
>>>>serialization
>>>> codec and allow streamwritefilter to deal with the files
>>> It should, but are you sure that they are called everytime a file is
>>> sent ? Add some logs in your code to be sure.
>>>
>>>
>>> -- 
>>> Regards,
>>> Cordialement,
>>> Emmanuel Lécharny
>>> www.iktek.com
>>>
>>>
>>
>>
>
>
>-- 
>Regards,
>Cordialement,
>Emmanuel Lécharny
>www.iktek.com
>
>


Reply via email to