Some nwbie question - how to integrate Netty into WebApp

olekg olekg at pbpolsoft.com.pl
Fri Sep 11 20:51:30 EDT 2009




Frederic Bregier wrote:
> 
> Hi,
> 
> To send a response in Http, you have two modes, chunked (one message split
> in several pieces) and not chunked (1 piece only). The difference must be
> set in the first header (Transfer-Encoding to chunked or not present).
> 
> So if you want to send by chunk, you have to create the first response
> with the TransferEncoding set in the header to chunked and with no data in
> the body (no channelBuffer attached to the first response).
> You then write this answer to the connected channel.
> 
> Then you can send as many chunks as you want by creating each time your
> own HttpChunk (DefaultHttpChunk) setting the next ChannelBuffer each time.
> Again, write all HttpChunk to the connected channel.
> 
> The last written chunk must be an empty one (ChannelBuffer is an empty
> one, not null).
> 
> Then after the last chunk, you can close the connection if you want.
> 
> If possible, the first response should contains a Content-Length header
> value (if known).
> 
> HTH,
> Frederic
> 


Hello Frederic,

Thank you for you reply. I have already created something you described :

//only headres in response object
e.getChannel().write(response);

//portions of data as chunks every 20 seconds (to simulate Tomcat sample
that works)
DefaultHttpChunk chunk = new DefaultHttpChunk( buf);

        for( int i = 0; i < 11; i++) {
        	e.getChannel().write(chunk);
        	try {
				Thread.sleep(10000);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
        }


I also set in HttpSefrverPipelineFactory :

pipeline.addLast("streamer", new ChunkedWriteHandler());

Unfortunately it does not work, however the data that are sent are almost (I
cannot find the difference) the same as Tomcat sample sends. It is
JavaScript injection into  IFrame. I can see the request/response data flow
in tcpmon (a tool from Axis project) or with Firebug plugin in Firefox :

It looks like :

HTTP/1.1 200 OK
Transfer-Encoding: chunked

35
<script>parent.printTime("Hello its Netty");</script>
35
<script>parent.printTime("Hello its Netty");</script>

The Tomcat sample works while this one with Netty - not.

regards Olek
-- 
View this message in context: http://n2.nabble.com/Some-nwbie-question-how-to-integrate-Netty-into-WebApp-tp3617235p3629459.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list