You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Hiller, Dean" <De...@nrel.gov> on 2012/12/12 00:44:09 UTC

re-usable async http parsing code?

I need re-usable async http parsing code. Does mina perhaps contain some api for just the parsing portion? (I always have a belief that parsers should be separate and re-usable and not tied to the framework so I hope mina's is reusable as well).

ie. It would be great to feed in bytes like so and it returns null if there is not yet enough bytes

private byte[] previousData

byte[] data = incomingMergedWithPreviousData(previousData);

HttpResponse resp = httpResponseParser.parse(data); //HttpResponse has two subclasses maybe?  HttpHeaders and HttpChunk (in case chunking is going on)

If(resp == null) {

    previousData = data;

    Return;

}

previousData = new byte[0]; //reset since we are done parsing

//fire response to someone to process it

OR maybe I could re-use the code a different way. All I know is I get bytes that don't always have all the http headers yet since it is asynch stuff. Any way to parse stuff?

NOTE: Also, I want to do chunking so I am not sure it should return HttpResponse every time but maybe an List where one subclass is HttpHeaders and another is HttpChunk.

thanks,

Dean

Re: re-usable async http parsing code?

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 12/18/12 3:41 PM, Hiller, Dean a écrit :
> A bit late back to this thread but +1 from my side since as a user I
> expected at least one nio library would have taken the approach that
> parsing(decoding/encoding) should be a separate library from actual nio
> frameworks.  Instead it appears every library embedded/wired their parser
> to be too coupled with the framework :(.
>
> The same goes for SSL as well ;).  We wrote a SSL implementation that is
> very easy to wire into an nio framework(open source) but it knows nothing
> of the nio framework that uses it. (one we wrote about 7/8 years ago on
> sourceforge before we knew about mina/netty).  We did end up having to add
> "Object passthrough" as a parameter in the api so the user can pass
> through some information which is necessary sometimes, but it still didn't
> need to be tightly coupled.

Interesting. Is it based on SSLEngine ?


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


Re: re-usable async http parsing code?

Posted by "Hiller, Dean" <De...@nrel.gov>.
A bit late back to this thread but +1 from my side since as a user I
expected at least one nio library would have taken the approach that
parsing(decoding/encoding) should be a separate library from actual nio
frameworks.  Instead it appears every library embedded/wired their parser
to be too coupled with the framework :(.

The same goes for SSL as well ;).  We wrote a SSL implementation that is
very easy to wire into an nio framework(open source) but it knows nothing
of the nio framework that uses it. (one we wrote about 7/8 years ago on
sourceforge before we knew about mina/netty).  We did end up having to add
"Object passthrough" as a parameter in the api so the user can pass
through some information which is necessary sometimes, but it still didn't
need to be tightly coupled.

Dean

On 12/13/12 10:29 AM, "Arnaud bourree" <ar...@gmail.com> wrote:

>OK, I just take a look to LdapCodec and get you point.
>
>Arnaud.
>
>2012/12/13 Emmanuel Lécharny <el...@gmail.com>:
>> Le 12/13/12 5:41 PM, Arnaud bourree a écrit :
>>> I don't follow: Mina codecs process IOBuffer which is Mina specific.
>>> If you want to made codec independent you should used reader/writer or
>>> streams, then you loose Mina power.
>> Nope.
>>
>> You can (shoud) disconnect the decoder completely.
>>
>> In fact a decoder should work with no interaction with MINA. This is
>> what we have done with ApacheDS : our decoder has no knowledge about
>> MINA, it's capable of decoding a LDAP request even if the data arrives
>> in small chunks, and it works absolutely well with MINA.
>>
>> All our decoding tests are done with the decoder, and no MINA around.
>>
>>
>> --
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.iktek.com
>>


Re: re-usable async http parsing code?

Posted by Arnaud bourree <ar...@gmail.com>.
OK, I just take a look to LdapCodec and get you point.

Arnaud.

2012/12/13 Emmanuel Lécharny <el...@gmail.com>:
> Le 12/13/12 5:41 PM, Arnaud bourree a écrit :
>> I don't follow: Mina codecs process IOBuffer which is Mina specific.
>> If you want to made codec independent you should used reader/writer or
>> streams, then you loose Mina power.
> Nope.
>
> You can (shoud) disconnect the decoder completely.
>
> In fact a decoder should work with no interaction with MINA. This is
> what we have done with ApacheDS : our decoder has no knowledge about
> MINA, it's capable of decoding a LDAP request even if the data arrives
> in small chunks, and it works absolutely well with MINA.
>
> All our decoding tests are done with the decoder, and no MINA around.
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>

Re: re-usable async http parsing code?

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 12/13/12 5:41 PM, Arnaud bourree a écrit :
> I don't follow: Mina codecs process IOBuffer which is Mina specific.
> If you want to made codec independent you should used reader/writer or
> streams, then you loose Mina power.
Nope.

You can (shoud) disconnect the decoder completely.

In fact a decoder should work with no interaction with MINA. This is
what we have done with ApacheDS : our decoder has no knowledge about
MINA, it's capable of decoding a LDAP request even if the data arrives
in small chunks, and it works absolutely well with MINA.

All our decoding tests are done with the decoder, and no MINA around.


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


Re: re-usable async http parsing code?

Posted by Arnaud bourree <ar...@gmail.com>.
I don't follow: Mina codecs process IOBuffer which is Mina specific.
If you want to made codec independent you should used reader/writer or
streams, then you loose Mina power.

Arnaud.

2012/12/12 Julien Vermillard <jv...@gmail.com>:
> IMO It's a good idea to provide a codec framework really independent of the
> transport code. To be further thought..
>
>
> On Wed, Dec 12, 2012 at 8:31 AM, Emmanuel Lécharny <el...@gmail.com>wrote:
>
>> Le 12/12/12 12:44 AM, Hiller, Dean a écrit :
>> > I need re-usable async http parsing code. Does mina perhaps contain some
>> api for just the parsing portion? (I always have a belief that parsers
>> should be separate and re-usable and not tied to the framework so I hope
>> mina's is reusable as well).
>>
>> You can have a look at the HttpDecoder class, in the http module
>> (
>> http://svn.apache.org/viewvc/mina/mina/tags/2.0.7/mina-http/src/main/java/org/apache/mina/http/
>> ).
>>
>> It expects to get a session as a parameter, but the session is basically
>> just used to store a state, allowing the parser to stop and restart when
>> more bytes are received. You can most certainly replace the session by a
>> Map or any other data structure storing the current state.
>>
>> --
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.iktek.com
>>
>>

Re: re-usable async http parsing code?

Posted by Julien Vermillard <jv...@gmail.com>.
IMO It's a good idea to provide a codec framework really independent of the
transport code. To be further thought..


On Wed, Dec 12, 2012 at 8:31 AM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Le 12/12/12 12:44 AM, Hiller, Dean a écrit :
> > I need re-usable async http parsing code. Does mina perhaps contain some
> api for just the parsing portion? (I always have a belief that parsers
> should be separate and re-usable and not tied to the framework so I hope
> mina's is reusable as well).
>
> You can have a look at the HttpDecoder class, in the http module
> (
> http://svn.apache.org/viewvc/mina/mina/tags/2.0.7/mina-http/src/main/java/org/apache/mina/http/
> ).
>
> It expects to get a session as a parameter, but the session is basically
> just used to store a state, allowing the parser to stop and restart when
> more bytes are received. You can most certainly replace the session by a
> Map or any other data structure storing the current state.
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>

Re: re-usable async http parsing code?

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 12/12/12 12:44 AM, Hiller, Dean a écrit :
> I need re-usable async http parsing code. Does mina perhaps contain some api for just the parsing portion? (I always have a belief that parsers should be separate and re-usable and not tied to the framework so I hope mina's is reusable as well).

You can have a look at the HttpDecoder class, in the http module
(http://svn.apache.org/viewvc/mina/mina/tags/2.0.7/mina-http/src/main/java/org/apache/mina/http/).

It expects to get a session as a parameter, but the session is basically
just used to store a state, allowing the parser to stop and restart when
more bytes are received. You can most certainly replace the session by a
Map or any other data structure storing the current state.

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