You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Marek Sedlak <bo...@gmail.com> on 2015/01/27 17:34:10 UTC

HttpServer - messageReceived

Hello,

I have been trying to implement a simple http server. Firstly using
TextLineCodecFactory, but it became little useles for parsing binary data
comming in request.
What I decided to do, is basically TCP server, and reading requests
manually. All I need to do is to get byte array data of request.

in method messageReceived(Object o) the data come, but sometimes (usually
on POST/PATCH requests) the body comes in another call of this method.

Then I dont know when the data is complete. Can you please guide me? I am
using MINA 2.0.9.

(I also tried this
https://apache.googlesource.com/mina/+/798385ee1c4e7c679b3ad0067ce562abc948b7de/examples/src/main/java/org/apache/mina/examples/http/HttpTest.java
approch,
where it is pretty clear to see when to know the request data are
completely read, but I dont seem to find the import org.apache.mina.
transport.nio.tcp.NioTcpServer; or any docs about it,

maybe it is 3.X version? or is this issue even possible to solve in 2.0.9?

Thank you and MINA rocks!!


-- 
If an experiment works, something has gone wrong :P

Re: HttpServer - messageReceived

Posted by Marek Sedlak <bo...@gmail.com>.
Hello Emanuel,
thank you for your tips, it seems to be working for me, I am checking the
data manually, little bit customized to our needs,
thanks for the reply!
Regards,
Marek

2015-01-27 19:41 GMT+01:00 Emmanuel Lécharny <el...@gmail.com>:

> Le 27/01/15 17:34, Marek Sedlak a écrit :
> > Hello,
> >
> > I have been trying to implement a simple http server. Firstly using
> > TextLineCodecFactory, but it became little useles for parsing binary data
> > comming in request.
> > What I decided to do, is basically TCP server, and reading requests
> > manually. All I need to do is to get byte array data of request.
> >
> > in method messageReceived(Object o) the data come, but sometimes (usually
> > on POST/PATCH requests) the body comes in another call of this method.
> >
> > Then I dont know when the data is complete. Can you please guide me? I am
> > using MINA 2.0.9.
>
> This is typically what happen with TCP fragmentation.
>
> The data may arrive chunk by chunk. You can even imagine receiving them
> one byte by one byte...
>
> So you have to take care of such a fragmentation, which is not exactly
> simple with a protocol like HTTP, where you have no information
> whatsoever about the size of what you are going to receive.
>
> The best possible solution would be to decode what you get, excpecting
> it's not going to be cut in the middle. If you don't have anough data,
> then you have to suspend the decoding, and wait for more data...
>
>
>


-- 
If an experiment works, something has gone wrong :P

Re: HttpServer - messageReceived

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 27/01/15 17:34, Marek Sedlak a écrit :
> Hello,
>
> I have been trying to implement a simple http server. Firstly using
> TextLineCodecFactory, but it became little useles for parsing binary data
> comming in request.
> What I decided to do, is basically TCP server, and reading requests
> manually. All I need to do is to get byte array data of request.
>
> in method messageReceived(Object o) the data come, but sometimes (usually
> on POST/PATCH requests) the body comes in another call of this method.
>
> Then I dont know when the data is complete. Can you please guide me? I am
> using MINA 2.0.9.

This is typically what happen with TCP fragmentation.

The data may arrive chunk by chunk. You can even imagine receiving them
one byte by one byte...

So you have to take care of such a fragmentation, which is not exactly
simple with a protocol like HTTP, where you have no information
whatsoever about the size of what you are going to receive.

The best possible solution would be to decode what you get, excpecting
it's not going to be cut in the middle. If you don't have anough data,
then you have to suspend the decoding, and wait for more data...



Re: HttpServer - messageReceived

Posted by Marek Sedlak <bo...@gmail.com>.
Hello Ravi,
thanks for the tip, thanks for the reply!
Regards,
Marek

2015-01-28 3:36 GMT+01:00 Ravi Huang <ra...@gmail.com>:

> Mina has a demo codec for http, you can test it:
> <dependency>
> <groupId>org.apache.mina</groupId>
> <artifactId>mina-http</artifactId>
> <version>2.0.9</version>
> </dependency>
>
> 2015-01-28 0:34 GMT+08:00 Marek Sedlak <bo...@gmail.com>:
>
> > Hello,
> >
> > I have been trying to implement a simple http server. Firstly using
> > TextLineCodecFactory, but it became little useles for parsing binary data
> > comming in request.
> > What I decided to do, is basically TCP server, and reading requests
> > manually. All I need to do is to get byte array data of request.
> >
> > in method messageReceived(Object o) the data come, but sometimes (usually
> > on POST/PATCH requests) the body comes in another call of this method.
> >
> > Then I dont know when the data is complete. Can you please guide me? I am
> > using MINA 2.0.9.
> >
> > (I also tried this
> >
> >
> https://apache.googlesource.com/mina/+/798385ee1c4e7c679b3ad0067ce562abc948b7de/examples/src/main/java/org/apache/mina/examples/http/HttpTest.java
> > approch,
> > where it is pretty clear to see when to know the request data are
> > completely read, but I dont seem to find the import org.apache.mina.
> > transport.nio.tcp.NioTcpServer; or any docs about it,
> >
> > maybe it is 3.X version? or is this issue even possible to solve in
> 2.0.9?
> >
> > Thank you and MINA rocks!!
> >
> >
> > --
> > If an experiment works, something has gone wrong :P
> >
>



-- 
If an experiment works, something has gone wrong :P

Re: HttpServer - messageReceived

Posted by Ravi Huang <ra...@gmail.com>.
Mina has a demo codec for http, you can test it:
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-http</artifactId>
<version>2.0.9</version>
</dependency>

2015-01-28 0:34 GMT+08:00 Marek Sedlak <bo...@gmail.com>:

> Hello,
>
> I have been trying to implement a simple http server. Firstly using
> TextLineCodecFactory, but it became little useles for parsing binary data
> comming in request.
> What I decided to do, is basically TCP server, and reading requests
> manually. All I need to do is to get byte array data of request.
>
> in method messageReceived(Object o) the data come, but sometimes (usually
> on POST/PATCH requests) the body comes in another call of this method.
>
> Then I dont know when the data is complete. Can you please guide me? I am
> using MINA 2.0.9.
>
> (I also tried this
>
> https://apache.googlesource.com/mina/+/798385ee1c4e7c679b3ad0067ce562abc948b7de/examples/src/main/java/org/apache/mina/examples/http/HttpTest.java
> approch,
> where it is pretty clear to see when to know the request data are
> completely read, but I dont seem to find the import org.apache.mina.
> transport.nio.tcp.NioTcpServer; or any docs about it,
>
> maybe it is 3.X version? or is this issue even possible to solve in 2.0.9?
>
> Thank you and MINA rocks!!
>
>
> --
> If an experiment works, something has gone wrong :P
>