<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1514297293525_11014"><span></span></div><div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" id="yui_3_16_0_ym19_1_1514297293525_11018" style="display: block;">  <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1514297293525_11017"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1514297293525_11016"> <div dir="ltr" id="yui_3_16_0_ym19_1_1514297293525_11015"> <font id="yui_3_16_0_ym19_1_1514297293525_11019" face="Arial" size="2"> <br>----- Forwarded Message -----<br> <b><span style="font-weight:bold;">From:</span></b> KT Nabe &lt;th_nabe@yahoo.com&gt;<br> <b><span style="font-weight: bold;">To:</span></b> "undertow-dev@lists.jboss.org" &lt;undertow-dev@lists.jboss.org&gt; <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, December 26, 2017 5:34 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Idiomatic POST body handling<br> </font> </div> <div class="y_msg_container" id="yui_3_16_0_ym19_1_1514297293525_11053"><br><div id="yiv1248712822"><div id="yui_3_16_0_ym19_1_1514297293525_11052"><div style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_ym19_1_1514297293525_11051"><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4055">Hello,</div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4244"><br></div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4104">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?&nbsp; Obviously would need a way to say, "parse entity/body bytes as String".</div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4184"><br></div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4245">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.</div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4255">Here's what I've been doing in the default handler:</div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4272"><br></div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4274"><br></div><div id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4273" dir="ltr">if (exchange.isInIOThread()</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4336">&nbsp;&nbsp; dispatch(this)</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4337"><br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4348">else</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4319">&nbsp; exchange.getRequestReceiver().receiveFullString(exchange -&gt;&nbsp; .....)</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4356"><br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4425">But it's occurred to me that this is inefficient, since I'm (I think):</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4424">IO Thread -&gt; dispatch -&gt; Worker-Thread -&gt; IO-Thread (to drain/parse body as String) -&gt; WorkerThread (receiveFullString callback)</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4482"><br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4484">Now the above works, but I don't think it's optimal<br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4481">I do want the receiveFullString callback to execute in an worker thread (since it blocks), this is why I included the initial dispatch call,&nbsp; basically I just want a handler lambda to be:</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4655"><br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4624">if exchange.isInIOThread()</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4654">&nbsp;&nbsp; assert&nbsp;&nbsp; body-has-been-fully-drained-and-parsed-as-string</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4625">&nbsp;&nbsp; dispatch(this)</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4626">else:</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4634">&nbsp; String body = exchange.getBodyAsString??</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4694">&nbsp;.....</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4706"><br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4708">I'm assuming exchange.getRequestReceiver().receiveFullString is *always* asynchronous.</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4771">What's the best way to do this, since it's such a common pattern?</div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4772">Thanks<br></div><div dir="ltr" id="yiv1248712822yui_3_16_0_ym19_1_1514293755957_4599">&nbsp;&nbsp; <br></div></div></div></div><br><br></div> </div> </div>  </div></div></body></html>