<div dir="ltr"><div><div><div><div><div><div><div>Hi Vladmir,<br><br></div>I've faced the same problem before, but reading each byte manually didn't fit my needs.<br></div>When the JDK 1.4 released Java NIO API, they have already created a common way to<br>
</div>read data with less development effort, I'm talking about java.nio.channels.Channels class, which<br></div>has many helper methods able to convert data from old IO API to NIO API.<br><br></div>My prefered method is <i>Channels.newReader. </i>This method is able to convert a <span class="">StreamSourceChannel</span><br>
to a lightweight Reader implementation.<span class=""></span> I like this method because many object marshallers are<br></div>ready to handle Java IO Reader implementations.<br><br></div><a href="https://gist.github.com/miere/c2da3e8783e7db176097">Here is a sample implementation</a> with this approach.<br>
Note: could be some typos as I've wrote this code manually to send this mail.<br><div><div><br></div><div>I really hope it helps you.<br></div><div>Please Undertow devs let me know If I'm missing some important point on this.<br>
</div><div><br></div><div>Regards.<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 18, 2014 at 5:16 AM, Vladimir Tsukur <span dir="ltr"><<a href="mailto:flushdia@gmail.com" target="_blank">flushdia@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for explaining the option with getRequestChannel! Got it working by reading content into a pre-allocated ByteBuffer.<div class="">
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style="font-family:arial,sans-serif;font-size:13px">if it returns 0 register a read listener and call resumeReads()</span></blockquote><div><br></div></div><div>One thing I don't fully understand though is your note about registering a read listener (+ calling resumeReads) and why this is needed. Is it a mandatory step, and if it is, are you referring to application-specific read listener or Undertow's io.undertow.server.protocol.http.HttpReadListener? I guess this is pretty basic question, so it would be great if you can just point me to the right place at documentation, so that I can figure it out.</div>
<div class="">
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">Thinking about it we probably just need some way to buffer a complete/partial message and then invoke a callback with the data.</span></blockquote>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div><span style="font-family:arial,sans-serif;font-size:13px">Yep, I guess this would be easier for the app developer to use.</span></div>
</div><div class="HOEnZb"><div class="h5">
<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 18, 2014 at 2:34 AM, Stuart Douglas <span dir="ltr"><<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can use the getRequestChannel() method to get the request channel. Basically call read() on the channel till it returns either 0 or -1, if it returns -1 you are done, if it returns 0 register a read listener and call resumeReads().<br>
<br>
I have always been meaning to add a nicer non-blocking API for this, but I have never been exactly sure what would be required here. Thinking about it we probably just need some way to buffer a complete/partial message and then invoke a callback with the data.<br>
<br>
Stuart<br>
<br>
Vladimir Tsukur wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
One of the ways to obtain request entity is to call<br>
HttpServerExchange.<u></u>startBlocking and then read content from the<br>
HttpServerExchange.<u></u>getInputStream.<br>
<br>
Is there a way to obtain request entity in a non-blocking way?<br>
<br>
--<br>
Vladimir Tsukur<br>
Software Architect, Design Engineer and Scrum Master<br>
<br></div></div>
______________________________<u></u>_________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/undertow-dev</a><br>
</blockquote>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Vladimir Tsukur<br>Software Architect, Design Engineer and Scrum Master
</div>
</div></div><br>_______________________________________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br></blockquote></div><br></div>