Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC and X-HTTP-Method-Override parameter

I'm using Spring MVC, and I have a function to update a user's profile:

@RequestMapping(value = "/{userName}" + EndPoints.USER_PROFILE,
    method = RequestMethod.PUT)
public @ResponseBody ResponseEntity<?> updateUserProfile(
    @PathVariable String userName, @RequestBody UserProfileDto userProfileDto) {
    // Process update user's profile
} 

I've started using JMeter, and for some reason they have a problem with sending a PUT request with a body (either in a request body or using a request parameter hack).

I know that in Jersey you can add a filter to process the X-HTTP-Method-Override request parameter, so that you can send a POST request and override it using the header parameter.

Is there any way to do this in Spring MVC?

Thanks!

like image 574
Ido Cohn Avatar asked Mar 12 '13 15:03

Ido Cohn


1 Answers

Spring MVC has the HiddenHttpMethodFilter which allows you to include a request parameter (_method) to override the http method. You just need to add the filter into your filter chain in web.xml.

I'm not aware of an out-of-the-box solution to use the X-HTTP-Method-Override header, but you can create a filter similar to the HiddenHttpMethodFilter yourself which uses the header to change the value rather than the request parameter.

like image 128
codelark Avatar answered Sep 18 '22 07:09

codelark