使用 Apache Camel 使用 RESTful Web 服务 [英] Consuming a RESTful web service using Apache Camel

查看:28
本文介绍了使用 Apache Camel 使用 RESTful Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用骆驼来使用一个安静的 Web 服务.

I am trying to consume a restful Web service using camel.

为此,我正在配置动态端点 url,因为 RESTful url 是在运行时创建的.每次我使用 CamelContext 类的以下方法检查特定端点 url 是否在我的骆驼上下文中注册为路由时.

For that I am configuring dynamic endpoint url as the RESTful url is created at the runtime. Everytime I am checking if the particular endpoint url is registered as a route in my camel context using following method of CamelContext class.

端点 hasEndpoint(String uri);

Endpoint hasEndpoint(String uri);

在这种情况下,如果端点未注册,那么我会使用自定义路由构建器将路由添加到我的骆驼上下文中.

In this case, if the endpoint is not registered then I add a route to my camel context using a custom Route Builder.

我为此使用了骆驼 HTTP 组件.到目前为止,这对我来说效果很好.

I am using camel HTTP component for this. This is working fine for me as of now.

但是,我认为这在性能方面并不好,因为每次我必须检查路由是否已在骆驼上下文中注册,如果没有,则在进行网络服务调用之前注册相同.

However, I believe performance wise this is not good as everytime I have to check if a route is registered with the camel context and if not then register the same before making the webservice call.

有人可以告诉我是否有更好的方法在骆驼中使用 RESTful Web 服务吗?

Can some body please tell me if there is a better way to consume RESTful Web services in camel?

我还想知道我正在使用的 RESTful 网络服务是否使用 OAuth 2.0 协议,我是否需要更改代码中的任何内容,因为我只是在使用它?

I also want to know if the RESTful webservice I am consuming uses OAuth 2.0 protocol, do I need to change anything in my code as I am just consuming it?

问候,尼洛帕

感谢您的回复.

我正在检查该路线是否已经存在,以确保我最终不会将重复的路线添加到骆驼上下文中.

I am checking if the route is already exists to make sure I don't end up adding duplicate route(s) to the camel context.

关于长期存在的路线和路线动态,你能解释一下吗?如何实现路线动态?

Regarding long lived routes and route dynamics, can u please explain a bit regarding this? How do I implement route dynamics?

如果您能指点我一些 CXF-RS 生成器示例,这也会很有帮助.我阅读了 CXFRS 的文档,但无法清楚地理解它.

It would also be helpful if you could point me to some CXF-RS producer example.. I read the documentation of CXFRS but could not understand it clearly.

谢谢尼洛帕

推荐答案

究竟为什么需要在拨打电话前检查路由是否已注册?您也许应该设置一个更长寿的路由,并动态路由到 resfull 资源.

Exactly why do you need to check if the route is registred or not before making the call? You should perhaps setup a more long lived route and route dynamic towards resfull resources.

至于 Rest with camel,我认为 HTTP 组件做得很好,但也有更高级别的组件可以使用,更专为 REST 设计.CXFRSRestlet,restlet 的生产者示例可以在 Apache Camel 源单元测试中找到,例如 RestletProducerGetTest.java.

As for Rest with camel, I think the HTTP component does a great job, but there are higher level components to use as well, more designed for REST. CXFRS and Restlet, producer examples for restlet can be found in the Apache Camel source unit tests, such as this RestletProducerGetTest.java.

至于 oAuth 2.0,Camel 内置了一些 oAuth 支持,特别是对于 google.查找 gauth 组件.甚至还有一个教程,但它可能与您的案例不一致,它仍然可能提供一些背景信息,以便您解决问题:http://camel.apache.org/tutorial-oauth.html

As for oAuth 2.0, Camel has some oAuth support built-in, especially for google. Look for the gauth component. There is even a tutorial, however it might not be aligned with your case, it still might give some background so you could solve your issues: http://camel.apache.org/tutorial-oauth.html

这篇关于使用 Apache Camel 使用 RESTful Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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