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

查看:369
本文介绍了使用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 Web服务是否使用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?

关于Nilotpal,

Regards, Nilotpal

感谢您的答复.

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

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.

谢谢 Nilotpal

Thanks Nilotpal

推荐答案

请问为什么在拨打电话之前需要检查路由是否已注册?您也许应该设置一条寿命更长的路由,并将路由动态化为重新分配资源.

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,我认为HTTP组件做得很好,但是也可以使用更高级别的组件,它们是针对REST设计的. CXFRS Restlet ,restlet的生产者示例可以在Apache Camel源单元测试中找到,例如

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天全站免登陆