问题
I need to call rest DELETE operation with body content. I have alternative way to do this but this is our requirement. I have tried the following way but unable to get an output. Can you give me an IDEA to achieve this?
Here's my code :
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, simple("DELETE"))
.setHeader(Exchange.CONTENT_LENGTH, simple("64"))
.setBody(simple("<stundent>...</student>")))
.to("http://10.1.1.1:8080/rest/student/delete/1029");
回答1:
As I stated in your other SO, do not use a DELETE
but a PUT
operation.
EDIT:
Digging into the source code of HttpProducer, you can see that the request is filled if methodToUse.isEntityEnclosed()
is true
(line 367). However, this is only the case for PUT
and POST
as only those method implementations extend the class EntityEnclosingMethod. Unfortunately for you, this is not the case for DELETE
.
回答2:
Just in case, the feature is available from Camel version 2.19.0 in http4 component with deleteWithBody option. We could just add it to the URL like below.
.to(http4://10.1.1.1:8080/rest/student/delete/1029?deletewithBody=true)
For Reference
- Sample Camel Test Case
- Source Code HttpProducer
来源:https://stackoverflow.com/questions/22876781/how-to-call-rest-api-delete-operation-with-body-content-from-apache-camel