密码骆驼组件enpoints选项被改变,如何prevent呢? [英] Camel component enpoints options for password is altered, how to prevent this?

查看:213
本文介绍了密码骆驼组件enpoints选项被改变,如何prevent呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在骆驼我使用http4组件,使远程服务器上的REST请求。

In Camel I am using the http4 component to make REST request on a remote server.

组件文档指出凭据应放在选项上这样的端点

The component documentation states that the credentials should be put in the options on the endpoint like this:

https4://myremote.server.com/?authUsername=xxx&authPassword=yyy

这是工作很好,直到有人把密码与另一个环境中的+字。
我们注意到,+字符作为在其中产生一个错误的服务器的空间发射。
由骆驼文档中搜索更深,我们发现一个页面有解释是一个RAW功能,使用这样的:

This was working well until someone put a password with a '+' character on another environment. We notice that the '+' character is transmitted as a space in the server which generates an error. By searching deeper in the Camel documentation we found a page explaining there is a "RAW" function to use like this:

https4://myremote.server.com/?authUsername=xxx&authPassword=RAW(yyy)

保持不变密码

不幸的是此功能只被在骆驼2.11版本和我们不打算升级到ServiceMix的5.1.x版的时刻推出。

Unfortunately this function has only been introduced in the Camel 2.11 version and for the moment we are not planning to upgrade to ServiceMix 5.1.x.

我们目前正在ServiceMix的4.5.x和骆驼的版本是2.10.7。

We are currently on serviceMix 4.5.x and the camel version is 2.10.7.

我在路由尝试这些(一一):

I tried these in the route (one by one):


  • .setProperty(授权,基本{base64Hash})

  • .setHeader(授权,基本{base64Hash})

  • .setProperty(HttpHeaders.AUTHORIZATION,基本{base64Hash})

  • .setHeader(HttpHeaders.AUTHORIZATION,基本{base64Hash})

  • .setProperty("Authorization", "Basic {base64Hash}")
  • .setHeader("Authorization", "Basic {base64Hash}")
  • .setProperty(HttpHeaders.AUTHORIZATION, "Basic {base64Hash}")
  • .setHeader(HttpHeaders.AUTHORIZATION, "Basic {base64Hash}")

但远程服务器发送了我401。

but the remote server sends me a 401 (Unauthorized).

现在的问题是:有没有其他替代派人http4组件凭据比使用端点上的选项

The question is: is there any other alternative to send credentials for http4 component than using the option on the endpoint?

推荐答案

我终于找到了一种方法,我不得不很需要叫一个额外的参数服务器问题: X-转发,原
那么下面的方式工作得非常好,而不是传递凭据端点选项:

I finally found a way and the problem I had was the server that need an extra parameter called : X-Forwarded-Proto, then the following way works very well instead passing the credentials in the endpoint option:

from(in.getEndpointUri())
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
    .setHeader(Exchange.HTTP_PATH, simple("/path/to/my/resource/1234"))
    .setHeader(Exchange.HTTP_QUERY, constant("type=accessories&view=blue"))
    .setHeader("X-Forwarded-Proto", constant("https"))
    .setHeader("Authorization", constant("Basic bXl1c2VybmFtZTpwYXNzd29yZDEyMzQ="))

    .to("https4://myremote.server.com/myrestservices")
    .convertBodyTo(String.class)
    ;

后,用绿豆或​​处理器产生的Base64哈希很容易。

After, using a bean or processor to generate the Base64 hash would be easy.

这篇关于密码骆驼组件enpoints选项被改变,如何prevent呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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