[undertow-dev] Force a HttpHandler to accept POST only

Samy Dindane samy at dindane.com
Mon Dec 9 08:27:19 EST 2013


On 9 décembre 2013 at 11:10:49, Stuart Douglas (sdouglas at redhat.com) wrote:
What do you want to happen if it is not a post request? 

I was thinking about a 404 error, but indeed, 405 is more relevant. 

The simplest way is just: 

if(!exchange.getRequestMethod().equals(Methods.POST)) { 
exchange.setResponseCode(405); 
exchange.endExchange(); 
return; 
} 
This way suits me, thank you. 

How can I retrieve the POST parameters ? I only can access the GET ones with getQueryParameters().

If you want to pick a handler to invoke based on the method you can use: 

Handlers.predicate(Predicates.method(Methods.POST), postHandler, nonPostHandler); 
Do you think it’s a good idea to create a handler for any 404 error page and use it here ? 

If so, is it possible to set it as the default handler for all 404 errors ? (I can do the check manually but I’m wondering if it is supported by default) 



Stuart 

----- Original Message ----- 
> From: "Samy Dindane" <samy at dindane.com> To: undertow-dev at lists.jboss.org 
> Sent: Sunday, 8 December, 2013 6:09:23 PM 
> Subject: [undertow-dev] Force a HttpHandler to accept POST only 
> 
> Hi folks, 
> 
> I have a HttpHandler that I want to reach with POST requests only . 
> I tried exchange.setRequestMethod(new HttpString("POST”)) inside 
> handleRequest() , but the HttpHandler still responds to GET requests. 
> 
> Is there any way to do this? 
> 
> In case you’d like to check out the code, it can be found here . 
> Thank you. 
> 
> Samy 
> 
> _______________________________________________ 
> undertow-dev mailing list 
> undertow-dev at lists.jboss.org 
> https://lists.jboss.org/mailman/listinfo/undertow-dev 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20131209/2da108a7/attachment-0001.html 


More information about the undertow-dev mailing list