【问题标题】:How to invoke a method in restful web service using camel-cxf?如何使用 camel-cxf 在 RESTful Web 服务中调用方法?
【发布时间】:2013-02-01 06:27:35
【问题描述】:

我想使用 apache camel 调用休息服务。目前我正在使用 cxfrs 组件来配置我的端点。我的路线如下所示:

from("cxfrs://http://127.0.0.1:8080/RestServiceApp/?resourceClasses="com.sample.Server.HelloWorld").log("Route Started"); 

我的问题是我想调用服务器类中存在的方法(在我的例子中是 HelloWorld)。你能告诉我如何调用一个特定的方法吗?

【问题讨论】:

标签: rest apache-camel cxfrs


【解决方案1】:

Camel 不调用资源类方法。来自 Camel 网站 http://camel.apache.org/cxfrs.html 上的文档:

此类仅用于配置 JAXRS 属性。方法 在将消息路由到端点期间不会执行, 相反,路由本身负责所有处理。

您需要编写一个自定义的处理逻辑,例如:

<from uri="cxfrs://http://127.0.0.1:8080/RestServiceApp/?resourceClasses="com.sample.Server.HelloWorld">
<choice>
    <when>
        <simple>${header.operationName} == 'operation1'</simple>
        <to uri="direct:operation1" />
    </when>
    <when>
        <simple>${header.operationName} == 'operation2'</simple>
        <to uri="direct:operation2" />
    </when>
    ....
</choice>

【讨论】:

  • 感谢亚历山大的回复。但我想调用托管在远程服务器上的 Web 服务。根据apache cxfrs文档,如果要通过camel-cxfrs producer调用REST服务,那么需要在消息头中放入操作名。但是,如果我正在执行 from(rest_service_route).process(new MyProcessor()) ,则永远不会调用处理器。请帮助我。
猜你喜欢
  • 2016-12-31
  • 1970-01-01
  • 1970-01-01
  • 2012-08-16
  • 1970-01-01
  • 1970-01-01
  • 2016-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多