On Mon, 2007-01-08 at 17:57 +0530, Asankha C. Perera wrote:
> Hi Oleg
> 
> Thanks for the offer to help us.. Would you have any example/scratch 
> code which might help me get started up? I am looking for a way to 
> create an InputStream of the request body and kick off my processing of 
> the message - while it may be the case that my complete message has not 
> been fully read. So I would start as follows:
> 
> public void requestReceived(final NHttpServerConnection conn) {
>     // I assume that the request header is fully read at this point, and 
> want to create an InputStream which I want to pass into my application 
> code which will execute in another thread than the NHttpServiceHandler
>     ...
>     processInNewThread(conn.getHttpRequest(), inputStreamToReadBody);
> }
> 
> so I start to process my message in my new thread, and my application 
> thread may now block waiting for more input to become available..As more 
> input becomes available, I want to pump this through to my stream, so 
> that my application thread can consume it..
> 
> public void inputReady(final NHttpServerConnection conn, final 
> ContentDecoder decoder) {
>     // pump available content into the stream
> }
> 
> Could you let me know if the above approach is correct.

Hi Asankha

The above described above sounds correct to me. This example (URL below)
should help you get started. The sample application is a ultra-trivial
async HTTP server that utilizes InputStream/OutputStream based request
handlers running in a separate worker thread. One can use similar
technique on the client side as well. By using largish session buffers
(say ~30K) one ensure the worker threads almost never get blocked in I/O
operations when dealing with average requests. Worker threads would only
have to block when dealing with content larger than the capacity of the
session buffers. 

http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpServer.java


>  Also I am 
> thinking that I could use Piped streams to achieve the above. But a 
> question that comes to my mind is.. if my application thread has read 
> what it wants (say the soap header) and is now processing the message, 
> the inputReady method may get called during this time.. so if my buffer 
> is full, and I do not want inputReady() to block, but I want 
> inputReady() to be called again and again, until I accept the complete 
> message
> 

You can use ContentIOControl interface to temporarily suspend inputReady
notifications and reactive them once the session buffer has enough
capacity to accept more content. 

http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/ContentIOControl.java

Also see:

http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java

Your feedback (positive or negative) would be very much appreciated.

Cheers

Oleg



> thanks
> asankha
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to