On 9 décembre 2013 at 11:10:49, Stuart Douglas (sdouglas@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@dindane.com> 
> To: undertow-dev@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@lists.jboss.org 
> https://lists.jboss.org/mailman/listinfo/undertow-dev