[undertow-dev] Read request body in HttpHandler
Stuart Douglas
sdouglas at redhat.com
Thu Feb 11 14:51:53 EST 2016
RequestBufferingHandler is a performance enhancing handler that is designed to be used for blocking requests, basically
it allows you to fully read the request before the request gets dispatched to a (potentially limited) thread pool.
If you want to read the full body in a non blocking manner the easiest way is to just use the following, it will read the full request into a buffer and then invoke the provided callback:
HttpServerExchange.getRequestReceiver().receiveFullBytes((exchange, data) -> {
//do stuff with the data
},
(exchange, exception) -> {
//optional error handler
}
)
Stuart
----- Original Message -----
> From: "Friso van Vollenhoven" <f.van.vollenhoven at gmail.com>
> To: undertow-dev at lists.jboss.org
> Sent: Thursday, 11 February, 2016 11:12:11 PM
> Subject: [undertow-dev] Read request body in HttpHandler
>
> Hi all,
>
> I'm not sure if this is the right channel to go for help, but there seems to
> be no separate user list, so I'll take a shot here.
>
> I need to create a HttpHandler that fully reads the request body and stores
> it into a buffer or byte[] before ending the exchange. For this, I'm trying
> to digest what Undertow's RequestBufferingHandler does.
>
> It seems that I have to take care of the scenario where the handler is called
> before the entire request body is available on the stream by doing the
> following:
> - read from the stream
> - check whether I've hit the end of the stream when as many bytes as possible
> have been read
> - if not, register a listener on the stream and continue handling the request
> from there
> - if so, handle the request from the handler directly
> - finally close the stream
>
> Can someone assert that the above is correct?
>
> Also, are there general pointers to what I'd like to achieve (read the
> request body into a buffer)?
>
>
> Many thanks, cheers,
> Friso
>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
More information about the undertow-dev
mailing list