如何在 Apache Camel 中使用 Oauth Header 调用 REST API? [英] How to call REST API with Oauth Header in Apache Camel?

查看:95
本文介绍了如何在 Apache Camel 中使用 Oauth Header 调用 REST API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有 OAuth1.0 授权的 API.我想使用授权 Oauth 标头调用该 API:-
我已经使用从服务器收到的令牌/密钥创建了授权标头(ConsumerKey、keyalias 和密码),并希望通过调用发回令牌或 OAuth 标头.

I am consuming an API with OAuth1.0 authorization. I want to make call to that API with the authorization Oauth header:-
I have created the authorization header from the token/key received from the server using- (ConsumerKey,keyalias and password) and want to send back the token or the OAuth header with the call.

我已经在处理器(实现骆驼处理器的类)中完成了所有这些事情,现在想做:-

I have did all these things in a Processor(Class implementing Camel Processor) and now want to do:-

  1. 在处理器本身中使用此 Oauth 标头(字符串类型)调用其余 API.
  2. 否则发送此标头作为交换,并在骆驼的 to() 端点中获取此值,然后在其中调用 REST API.
  1. Either call the rest API with this Oauth header(of type String) in the processor itself.
  2. Else send this header in exchange and get this value in camel's to() endpoint and then in it call the REST API.

事情是我只想用 Oauth 标头在 处理器 中调用休息.然后,如果可能,尝试访问 to() 端点中的标头并进行调用.

Thing is i just want to make rest a call in processor with Oauth header. And then if possible try to access the header in to() endpoint and make the call.

推荐答案

您可以在处理器中设置 Authorization 标头,然后使用 .to()

You can set the Authorization header in your processor and then send the REST request with .to()

public void process(Exchange exchange) throws Exception {
    String token = //your logic to get the token
    exchange.getIn().setHeader("Authorization", "Bearer " + token)
}

.to("your/rest/endpoint") 

Camel 自动将消息头复制到外发消息上.

Camel automatically copies over the message headers onto the outgoing message.

这篇关于如何在 Apache Camel 中使用 Oauth Header 调用 REST API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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