io.undertow.util.StringReadChannelListener is probably the simples example.
Basically the idea is you keep calling read() until it returns 0 (or -1
if the stream is done), then when it returns 0 you call
channel.getReadSetter().set(myReadListener)
channel.resumeReads()
your listener will be notified when more data is available and you can
attempt to read again.
We have been talking about adding some kind of simpler async reader API,
however we are not sure yet exactly what form this will take.
Stuart
Mike Stefaniak wrote:
I ended up dispatching to a worker thread and using input stream. I
do
need access to the raw post data. Do you have an example of how to use
channel so I could try it for comparison sake?
On Tue, Jan 6, 2015 at 12:07 AM, Stuart Douglas <sdouglas(a)redhat.com
<mailto:sdouglas@redhat.com>> wrote:
By second method do you mean the input stream or the parsers?
If you just want form data just use the built in parsers, if you
need access to the raw bytes then you need the input stream or the
channel. The channel lets you use non-blocking IO which can perform
better, however it is a bit harder to use that the input stream as
you need to register callbacks.
Stuart
----- Original Message -----
> From: "Mike Stefaniak" <mstefaniak(a)choicestream.com
<mailto:mstefaniak@choicestream.com>>
> To: "Stuart Douglas" <sdouglas(a)redhat.com
<mailto:sdouglas@redhat.com>>
> Cc: undertow-dev(a)lists.jboss.org
<mailto:undertow-dev@lists.jboss.org>
> Sent: Tuesday, 6 January, 2015 3:26:30 PM
> Subject: Re: [undertow-dev] HttpServerExchange post data
>
> Thanks, I ended up figuring out how to do the second method you
listed. Is
> there any advantage to one verse the other?
>
> On Sun, Jan 4, 2015 at 6:19 PM, Stuart Douglas
<sdouglas(a)redhat.com <mailto:sdouglas@redhat.com>> wrote:
>
> > If you just want access to the raw data you have a 2 options:
> >
> > HttpServerExchange.getRequestChannel()
> > HttpServerExchange.getInputStream() (exchange should have
startBlocking
> > called, and you need to dispatch to a worker thread so as not
to block an
> > IO thread)
> >
> > If you want access to parsed form/multipart data then you can use
> > io.undertow.server.handlers.form.EagerFormParsingHandler, and
the use
> > exchange.gutAttachment(FormDataParser.FORM_DATA) to get access
to the
> > parsed data.
> >
> > Stuart
> >
> >
> > ----- Original Message -----
> > > From: "Mike Stefaniak" <mstefaniak(a)choicestream.com
<mailto:mstefaniak@choicestream.com>>
> > > To: undertow-dev(a)lists.jboss.org
<mailto:undertow-dev@lists.jboss.org>
> > > Sent: Friday, 2 January, 2015 10:32:35 AM
> > > Subject: [undertow-dev] HttpServerExchange post data
> > >
> > > I can't figure out how to get the content of post data
> > >
> > > My server start
> > >
> > > Undertow.builder()
> > > .addHttpListener(8080, "0.0.0.0")
> > > .setHandler(Handlers.routing().post("/bid", new
BidHandler()))
> > > .build()
> > > .start();
> > >
> > > And the handler class
> > >
> > > public final class BidHandler implements HttpHandler {
> > >
> > > @Override
> > > public void handleRequest(final HttpServerExchange exchange)
throws
> > Exception
> > > {
> > > ........
> > > }
> > > }
> > >
> > >
> > > If I make a curl request like so
> > >
> > > curl -H "Content-Type: application/json" -X POST -i -d
'{"some":
> > "value"}'
> > >
http://127.0.0.1:8080/bid
> > >
> > > It gets to the handler, but I can't figure out to access the
post data
> > from
> > > the request
> > >
> > > Thanks
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > undertow-dev mailing list
> > > undertow-dev(a)lists.jboss.org
<mailto:undertow-dev@lists.jboss.org>
> > >
https://lists.jboss.org/mailman/listinfo/undertow-dev
> >
>