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

(Camel 2.9.2)

A very simple use case, but I can not find the answer. My code boils down to the following:

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", the camel answers, "Unknown parameters = [{amp; bar = null]]."

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

Any ideas?

+4
source share
3 answers

How from Camel 2.11 you can use raw syntax

For instance:

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

In the above example, we declare the password value as raw, and the actual password will be printed, for example, se + re? t & 23

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

+7
source

You can specify a password as part of uri authority, for example, in front. It should also be escaped to% 26, but there was an error in Camel that did not parse the escaped value. Try 2.10 when it comes out.

+1
source

The RAW() syntax works, but it is Camel-proprietary syntax. In our usecase, this is encumbered after processing the URI.

We used an alternative solution: the component is configured as using raw URIs ( Component.useRawUri() == true ). The component parameters are then simply encoded ( foo%26bar ) and passed through Camel unchanged. I find this solution better, since character percent encoding is the standard way to express sensitive characters.

0
source

All Articles