New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for DELETE with body to RestTemplate through exchange method [SPR-12361] #16966
Comments
Rossen Stoyanchev commented It sounds like the request is going out successfully since there is an actual response status from the server. What's the underlying reason for the 400 response? Can you find out from the server log? |
Manuel Jordan commented Hi Rossen Enabling Debug
Immediately below
Where the server side is @RequestMapping(value="/{id}/two", method=RequestMethod.DELETE)
public ResponseEntity<String> deletePersonTwo(@PathVariable Integer id, @RequestBody Person person){
logger.info("PersonRestController - deletePersonTwo - id: {} - {}", id, person.toString());
personMapRepository.deletePersonTwo(id, person);
return new ResponseEntity<>("Delete forever", HttpStatus.MOVED_PERMANENTLY);
} Be aware about the Update works fine and has the following structure: @RequestMapping(value="/{id}", method=RequestMethod.PUT)
public ResponseEntity<String> updatePerson(@PathVariable Integer id, @RequestBody Person person){
logger.info("PersonRestController - updatePerson - id: {} - {}", id, person.toString());
personMapRepository.savePerson(person);
return new ResponseEntity<>("Update successful", HttpStatus.OK);
} Practically for the server side Get and Put have the same structure. In the original post you can see how the server side is called through the RestTemplate for the Get and Put respectively with the exchange method. |
Rossen Stoyanchev commented This all looks like client-side logging. Still no clues as to why the server thinks it's a bad request. Can you check the server log? Most likely there is an exception somewhere that's getting mapped to HttpServletResponse.SC_BAD_REQUEST by the DefaultHandlerExceptionResolver. |
Manuel Jordan commented About the log information In my STS directory installation exists the following directory path base-instance/logs and there is a file with only the following:
I can't find other directory named log in other place. Pls indicate me where I should find the complete error stack trace. My application has a Main class, when it is executed some customized information is shown in the Console view. In the same application meanwhile the web server is running, there is other Console view. I forget to share the following: First: Code (part) from the Main class: restClient.createPerson();
person = null;
person = restClient.getPerson("1");
logger.info("{}", person.toString());
//restClient.deletePersonOne("1");
restClient.deletePersonTwo(person);
//restClient.deletePersonThree("1"); Second: the console view for the Web application
Wondered about the:
If for HttpMethod.PUT works fine and has the same structure and it is executed from the Main. the two following forms works without any problem restClient.createPerson();
Person person = null;
person = restClient.getPerson("1");
person.setFirstName(person.getFirstName().toUpperCase());
person.setLastName(person.getLastName().toUpperCase());
restClient.updatePersonOne(person);
person = null;
person = restClient.getPerson("1");
person.setAge(100);
person.setWeight(77.66);
restClient.updatePersonTwo(person);
person = null;
person = restClient.getPerson("1"); BTW: The restClient.getPerson method prints very well each updated Person retrieved form the Web Server. So why java.io.EOFException appears for the HttpMethod.DELETE and not for HttpMethod.UPDATE Both are the same practically. Seems I am forgetting an innocent detail. |
Rossen Stoyanchev commented Okay thanks Manuel Jordan, that's all I need for now. |
Juergen Hoeller commented Let's see what we can do for 4.1.2 still... if easy enough. Juergen |
Manuel Jordan commented Thanks to you. Very powerful and flexible Spring Rest support. |
Rossen Stoyanchev commented Appears HttpUrlConnection only started supporting HTTP DELETE with body in JDK 1.8 (https://bugs.openjdk.java.net/browse/JDK-7157360). |
Rossen Stoyanchev commented I've made the following additional change related to DELETE with HttpUrlConnection. Effectively /cc Janne Valkealahti if you can please try once more with this fix. |
Janne Valkealahti commented Thanks Rossen, just tried it and problem with xd-shell went away :) |
Manuel Jordan opened SPR-12361 and commented
If I delete a resource through an id and with the delete method, it works fine
But delete method is void, therefore I can't get reply and status from the server.
Just playing, through the exchange method together with HttpMethod.PUT, I can do the following:
And works fine, until here two points
Thinking in the same idea, I have tried use the exchange method together with HttpMethod.DELETE
It with the intention to
Observe: I want send an object to be deleted, not an id.
But always I get the following:
I did a research:
According with the links: Delete has no support for request body. Wondered why this behaviour
Could be improved it the API?
Affects: 4.0.7, 4.1.1
Issue Links:
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: