Camel: How to include an ampersand as data in a URI (NOT as a delimiter)?

丶灬走出姿态 提交于 2019-12-23 09:19:45

问题


(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 throws a ResolveEndpointFailedException with "Unknown parameters=[{bar=null}]."

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

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

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

Any ideas?


回答1:


As from Camel 2.11 you could use raw syntax

For instance:

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

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




回答2:


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.




回答3:


The RAW() syntax works, yet it is Camel-proprietary syntax. In our usecase it burdened following processing of URI.

We used alternative solution: component configured as using raw URIs (Component.useRawUri() == true). Component parameters are then simply once encoded (foo%26bar) and pass through Camel without change. I consider this solution better as percent-sign encoding is standard way of expressing sensitive characters.



来源:https://stackoverflow.com/questions/11018987/camel-how-to-include-an-ampersand-as-data-in-a-uri-not-as-a-delimiter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!