[undertow-dev] Fw: Idiomatic POST body handling

KT Nabe th_nabe at yahoo.com
Tue Dec 26 09:12:08 EST 2017



     
----- Forwarded Message -----
 From: KT Nabe <th_nabe at yahoo.com>
 To: "undertow-dev at lists.jboss.org" <undertow-dev at lists.jboss.org> 
 Sent: Tuesday, December 26, 2017 5:34 AM
 Subject: Idiomatic POST body handling
   
Hello,
Is there an idiomatic/preferred/recommended way to configure an httphandler in such a way that it is invoked only after all of the request headers *and* body have been *both* drained (read from socket) and parsed?  Obviously would need a way to say, "parse entity/body bytes as String".
I've inferred that standard http-handlers are only invoked after the http headers have been drained and parsed, and that they are invoked on an io thread.Here's what I've been doing in the default handler:

if (exchange.isInIOThread()   dispatch(this)
else  exchange.getRequestReceiver().receiveFullString(exchange ->  .....)
But it's occurred to me that this is inefficient, since I'm (I think):IO Thread -> dispatch -> Worker-Thread -> IO-Thread (to drain/parse body as String) -> WorkerThread (receiveFullString callback)
Now the above works, but I don't think it's optimal
I do want the receiveFullString callback to execute in an worker thread (since it blocks), this is why I included the initial dispatch call,  basically I just want a handler lambda to be:
if exchange.isInIOThread()   assert   body-has-been-fully-drained-and-parsed-as-string   dispatch(this)else:  String body = exchange.getBodyAsString?? .....
I'm assuming exchange.getRequestReceiver().receiveFullString is *always* asynchronous.What's the best way to do this, since it's such a common pattern?Thanks
   


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20171226/e493b6ea/attachment-0001.html 


More information about the undertow-dev mailing list