spring - Passing data in the body of a DELETE request -


i have 2 spring mvc controller methods. both receive same data in request body (in format of htlm post form: version=3&name=product1&id=2), 1 method handles put requests , delete:

@requestmapping(value = "ajax/products/{id}", method = requestmethod.put) @responsebody public myresponse updateproduct(product product, @pathvariable("id") int productid) {  //... }  @requestmapping(value = "ajax/products/{id}", method = requestmethod.delete) @responsebody public myresponse updateproduct(product product, @pathvariable("id") int productid) {  //... } 

in first method, fields of product argument correctly initialised. in second, id field initialised. other fields null or 0. (id is, probably, initialised because of id path variable).

i can see httpservletrequest object contains values fields in request body (version=3&name=product1&id=2). not mapped fields of product parameter.

how can make second method work?

i tried use @requestparam annotated parameters. in method handles put requests, works. in delete method, exception: org.springframework.web.bind.missingservletrequestparameterexception: required string parameter 'version' not present.

i need pass data in body of delete requests because data contain row version used optimistic locking.

the problem not spring problem, tomcat problem.

by default, tomcat parse arguments in form style, when http method post (at least version 7.0.54 checked it's same tomcat 7 versions).

in order able handle delete methods need set parsebodymethods attribute of tomcat connector. connector configuration done in server.xml.

your updated connector like:

<connector port="8080" protocol="http/1.1"             connectiontimeout="20000"            redirectport="8443"            parsebodymethods="post,put,delete"            uriencoding="utf-8" /> 

here documentation page configuring tomcat connectors.

once setup tomcat parse parameters, spring work fine (although in case need remove @requestbody controller method)


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -