You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Zheng, Chuck" <ch...@ebay.com> on 2007/05/03 23:44:20 UTC

can codec be chained up?

I am wondering if I can have 2 codecs chain up with one feeding the
other.  
 
One use case could be: using exisiting TextLineCodec with build a new
codec to deal with Http request/response semantic.  The TextLineCodec
already handles line delimiting.  The new HttpCodec only need to handle
Http request formating and result parsing.  I guess then need to be
registered like this:
 
SocketConnectorConfig cfg = new SocketConnectorConfig();
cfg.getFilterChain().addLast( "httpCodec", new ProtocolCodecFilter( new
HttpCodecFactory() ) );
cfg.getFilterChain().addLast( "textCodec", new ProtocolCodecFilter( new
TextLineCodecFactory( Charset.forName("UTF-8"))));
 
connector.connect( serverAddress, myHandler, cfg);
 
One problem I see is that ProtocolEncoderOutput used by Http
Encoder.encode() only has method write(ByteBuffer buf) which force the
HttpCode to encode the request into ByteBuffer, but downstream
TextLineEncoder.encode() expect a string!!!
 
For the response, TextLIneDecoder already return strings, but Http
Decoder.decode() takes ByteBuffer as in.
 
The above setting does not work in my experiments.  What's the best way
to do this in MINA?
 
Thx
Chuck
 

Re: can codec be chained up?

Posted by peter royal <pr...@apache.org>.
On May 3, 2007, at 11:44 PM, Zheng, Chuck wrote:
> One problem I see is that ProtocolEncoderOutput used by Http
> Encoder.encode() only has method write(ByteBuffer buf) which force the
> HttpCode to encode the request into ByteBuffer, but downstream
> TextLineEncoder.encode() expect a string!!!

You are on the right track conceptually. The MINA ProtocolCodecFilter  
is to handle conversion from a ByteBuffer to something else, and  
back. So if you want to use MINA's support for text protocols, you'll  
have to make your own filter that works with the HttpCodecFactory

-pete


-- 
proyal@apache.org - http://fotap.org/~osi