8

(骆驼2.9.2)

非常简单的用例,但我似乎找不到答案。我的代码归结为:

String user = "user";
String password = "foo&bar";

String uri = "smtp://hostname:25?username=" + user +
    "&password=" + password + 
    "&to=somthing@something.com"; // etc. You get the idea

from("seda:queue:myqueue").to(uri);

Camel 抛出 ResolveEndpointFailedException 并带有“未知参数=[{bar=null}]”。

如果我尝试“foo%26bar”,我会得到相同的结果。

如果我尝试“foo&bar”,骆驼会以“未知参数=[{amp;bar=null}]”响应。

我尝试使用 URISupport 创建 URI。它将 & 转义为 %26,然后我再次得到“Unknown parameters=[{bar=null}]”。

有任何想法吗?

4

3 回答 3

10

从 Camel 2.11 开始,您可以使用原始语法

例如:

.to("ftp:joe@myftpserver.com?password=RAW(se+re?t&23)&binary=true"

在上面的例子中,我们将密码值声明为 raw,而实际的密码将是键入的,例如 se+re?t&23

https://cwiki.apache.org/confluence/display/CAMEL/How+do+I+configure+endpoints

于 2013-05-07T13:42:30.180 回答
1

You can specify the password as part of the authority of the uri, eg in the front. Also the & should be escaped to %26, but there was a bug in Camel that didnt parse the escaped value to well. Try 2.10 when its out.

于 2012-06-14T04:11:46.993 回答
0

RAW()语法有效,但它是 Camel 专有的语法。在我们的用例中,它会在处理 URI 之后产生负担。

我们使用了替代解决方案:将组件配置为使用原始 URI ( Component.useRawUri() == true)。然后,组件参数只需编码一次 ( foo%26bar) 并通过 Camel 而不做任何更改。我认为这个解决方案更好,因为百分号编码是表达敏感字符的标准方式。

于 2016-01-21T14:37:39.523 回答