如何使用 Apache Camel 的 BODY 内容调用 Rest API DELETE 操作?

How to call Rest API DELETE operation with BODY content from Apache Camel?(如何使用 Apache Camel 的 BODY 内容调用 Rest API DELETE 操作?)

本文介绍了如何使用 Apache Camel 的 BODY 内容调用 Rest API DELETE 操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用正文内容调用 rest DELETE 操作.我有其他方法可以做到这一点,但这是我们的要求.我尝试了以下方式,但无法获得输出.你能给我一个想法来实现这个吗?

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?

这是我的代码:

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");

推荐答案

正如我在你的其他 SO,不要使用 DELETE 而是 PUT 操作.

As I stated in your other SO, do not use a DELETE but a PUT operation.

深入HttpProducer,如果methodToUse.isEntityEnclosed() 是 true(第 367 行).但是,这仅适用于 PUTPOST,因为只有这些方法实现扩展了类 EntityEnclosingMethod.不幸的是,DELETE 并非如此.

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.

这篇关于如何使用 Apache Camel 的 BODY 内容调用 Rest API DELETE 操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 Apache Camel 的 BODY 内容调用 Rest API DELETE 操作?

基础教程推荐