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

2022-01-19 00:00:00 java apache-camel

(骆驼 2.9.2)

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

Very simple use case, but I can't seem to find the answer. My code boils down to this:

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}]".

Camel throws a ResolveEndpointFailedException with "Unknown parameters=[{bar=null}]."

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

If I try "foo%26bar," I get the same result.

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

If I try "foo&bar" camel responds with "Unknown parameters=[{amp;bar=null}]."

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

I tried using URISupport to create the URI. It escapes the & to %26, and then I get "Unknown parameters=[{bar=null}]" again.

有什么想法吗?

推荐答案

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

As from Camel 2.11 you could use raw syntax

例如:

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

在上面的示例中,我们将密码值声明为原始值,并且实际密码将与输入的密码相同,例如 se+re?t&23

In the above example, we have declare the password value as raw, and the actual password would be as typed, eg se+re?t&23

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

相关文章