Camel:如何在&URI(不作为分隔符)中包含&符作为数据?

Mat*_*ers 6 java apache-camel

(骆驼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);
Run Code Online (Sandbox Code Playgroud)

Camel抛出ResolveEndpointFailedException并显示"Unknown parameters = [{bar = null}]".

如果我尝试"foo%26bar",我会得到相同的结果.

如果我尝试"foo& bar",骆驼会回答"未知参数= [{amp; bar = null}]."

我尝试使用URISupport创建URI.它将&转移到%26,然后我再次得到"Unknown parameters = [{bar = null}]".

有任何想法吗?

小智 9

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

例如:

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

在上面的示例中,我们将密码值声明为raw,并将实际密码设置为type,例如se + re?t&23

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


Cla*_*sen 1

您可以将密码指定为 uri 权限的一部分,例如在前面。另外, & 应该转义为 %26,但是 Camel 中存在一个错误,无法很好地解析转义值。等 2.10 出来了再试试。