Repository navigation
Closed
Closed
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement
Milestone
Description
Manuel Jordan opened SPR-12361 and commented
If I delete a resource through an id and with the delete method, it works fine
restTemplate.delete("http://localhost:8080/spring-utility/person/{id}/one", id);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:
ResponseEntity<String> response =
restTemplate.exchange("http://localhost:8080/spring-utility/person/{id}",
HttpMethod.PUT,
new HttpEntity<Person>(person),
String.class,
person.getId());And works fine, until here two points
- I can get a a reply and status from the server
- I can send a request body
Thinking in the same idea, I have tried use the exchange method together with HttpMethod.DELETE
ResponseEntity<String> response =
restTemplate.exchange("http://localhost:8080/spring-utility/person/{id}/two",
HttpMethod.DELETE,
new HttpEntity<Person>(person),
String.class,
person.getId()); It with the intention to
- get a a reply and status from the server
- send a request body - better control against send an id
Observe: I want send an object to be deleted, not an id.
But always I get the following:
DELETE request for "http://localhost:8080/spring-utility/person/1/two" resulted in 400 (Bad Request); invoking error handler
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 400 Bad Request
I did a research:
- Add support for DELETE with body to RestTemplate it for Spring 3, I don't know if Spring 4 has other intentions.
- Spring RestTemplate calling the Delete method with a request body (Delete With Request Body) he has created its own solution
- HttpMethod.Delete not working with RestTemplate of Spring-Android he has direct access to the API
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:
- RestTemplate doesnt support DELETE with RequestBody [SPR-14065] #18637 RestTemplate doesnt support DELETE with RequestBody ("is duplicated by")
- Add support for DELETE with body to RestTemplate [SPR-7867] #12524 Add support for DELETE with body to RestTemplate
- Add support for DELETE with body to AsyncRestTemplate [SPR-12291] #16896 Add support for DELETE with body to AsyncRestTemplate
- AsyncRestTemplate should trigger no-output HTTP requests immediately as well [SPR-14093] #18665 AsyncRestTemplate should trigger no-output HTTP requests immediately as well
0 votes, 6 watchers
Reacted by Marco Lackovic
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement
Activity
spring-projects-issues commentedon Oct 22, 2014
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?
spring-projects-issues commentedon Oct 22, 2014
Manuel Jordan commented
Hi Rossen
Enabling Debug
Immediately below
Where the server side is
Be aware about the Update works fine and has the following structure:
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.
spring-projects-issues commentedon Oct 22, 2014
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.
spring-projects-issues commentedon Oct 22, 2014
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:
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
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.
spring-projects-issues commentedon Oct 22, 2014
Rossen Stoyanchev commented
Okay thanks Manuel Jordan, that's all I need for now.
spring-projects-issues commentedon Oct 22, 2014
Juergen Hoeller commented
Let's see what we can do for 4.1.2 still... if easy enough.
Juergen
spring-projects-issues commentedon Oct 22, 2014
Manuel Jordan commented
Thanks to you. Very powerful and flexible Spring Rest support.
spring-projects-issues commentedon Nov 10, 2014
Rossen Stoyanchev commented
Appears HttpUrlConnection only started supporting HTTP DELETE with body in JDK 1.8 (https://bugs.openjdk.java.net/browse/JDK-7157360).
spring-projects-issues commentedon Nov 10, 2014
Rossen Stoyanchev commented
I've made the following additional change related to DELETE with HttpUrlConnection.
Effectively
doOutputis turned off if the actual buffered body array is empty. This should make the main use case of DELETE without a body work as before. However when there is a body, or when streaming is enabled (i.e.bufferRequestBody=false) and content is actually attempted to be streamed, an exception will still occur with JDK 1.6 and 1.7 in contrast to how it worked before where the body was silently ignored./cc Janne Valkealahti if you can please try once more with this fix.
spring-projects-issues commentedon Nov 10, 2014
Janne Valkealahti commented
Thanks Rossen, just tried it and problem with xd-shell went away :)