如何调用REST API删除与来自Apache骆驼主体内容的操作? [英] How to call Rest API DELETE operation with BODY content from Apache Camel?

查看:245
本文介绍了如何调用REST API删除与来自Apache骆驼主体内容的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打电话休息与正文内容删除操作。我有另一种方式来做到这一点,但是这是我们的要求。我曾尝试以下方法,但无法得到的输出。你能不能给我一个想法,以实现这一目标?

这里是我的code:

 从(直接:启动)
.setHeader(Exchange.HTTP_METHOD,简单(删除))
.setHeader(Exchange.CONTENT_LENGTH,简单(64))
.setBody(简单(< stundent> ...< /学生>)))
。要(http://10.1.1.1:8080/rest/student/delete/1029);


解决方案

正如我在你的其他规定<一个href=\"http://stackoverflow.com/questions/22715289/content-type-is-not-supported-in-camel-delete-method\">SO,不使用删除 PUT 操作。

编辑:

挖掘到的<一个源$ C ​​$ C href=\"http://grep$c$c.com/file/repo1.maven.org/maven2/org.apache.camel/camel-http/2.12.1/org/apache/camel/component/http/HttpProducer.java\"相对=nofollow> HttpProducer ,你可以看到,该请求被填充,如果 methodToUse.isEntityEnclosed()真正(行367)。然而,这仅仅是为 PUT POST 因为只有那些方法实现扩展的类<一的情况下href=\"http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/EntityEnclosingMethod.html\"相对=nofollow> EntityEnclosingMethod 。不幸的是你,这是不适合的情况下删除

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

解决方案

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.

这篇关于如何调用REST API删除与来自Apache骆驼主体内容的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆