How to call Rest API DELETE operation with BODY content from Apache Camel?

浪尽此生 提交于 2019-12-13 05:05:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!