Camel component endpoints options for password is altered, how to prevent this?

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Camel component endpoints options for password is altered, how to prevent this?



In Camel I am using the http4 component to make REST request on a remote server.



The component documentation states that the credentials should be put in the options on the endpoint like this:


https4://myremote.server.com/?authUsername=xxx&authPassword=yyy



This was working well until someone put a password with a '+' character on another environment.
We notice that the '+' character is transmitted as a space in the server which generates an error.
By searching deeper in the Camel documentation we found a page explaining there is a "RAW" function to use like this:


https4://myremote.server.com/?authUsername=xxx&authPassword=RAW(yyy)



to keep the password unchanged.



Unfortunately this function has only been introduced in the Camel 2.11 version and for the moment we are not planning to upgrade to ServiceMix 5.1.x.



We are currently on serviceMix 4.5.x and the camel version is 2.10.7.



I tried these in the route (one by one):


.setProperty("Authorization", "Basic {base64Hash}")


.setHeader("Authorization", "Basic {base64Hash}")


.setProperty(HttpHeaders.AUTHORIZATION, "Basic {base64Hash}")


.setHeader(HttpHeaders.AUTHORIZATION, "Basic {base64Hash}")



but the remote server sends me a 401 (Unauthorized).



The question is: is there any other alternative to send credentials for http4 component than using the option on the endpoint?




2 Answers
2



Please replace the + character in your password with %2B in your Camel endpoint URI and it should work.


+


%2B





We already tried this, but it is still translated as a space when decoding the options.
– рüффп
Sep 1 '14 at 10:11



I finally found a way and the problem I had was the server that need an extra parameter called : X-Forwarded-Proto,
then the following way works very well instead passing the credentials in the endpoint option:


X-Forwarded-Proto


from(in.getEndpointUri())
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.setHeader(Exchange.HTTP_PATH, simple("/path/to/my/resource/1234"))
.setHeader(Exchange.HTTP_QUERY, constant("type=accessories&view=blue"))
.setHeader("X-Forwarded-Proto", constant("https"))
.setHeader("Authorization", constant("Basic bXl1c2VybmFtZTpwYXNzd29yZDEyMzQ="))

.to("https4://myremote.server.com/myrestservices")
.convertBodyTo(String.class)
;



After, using a bean or processor to generate the Base64 hash would be easy.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

gz3RtbYljnxj6QhvQyq4j8CSZXEbBGJk2N4LglBVs2gXr1fkThI MfNUvnSeIGnXOPfDfWAEamioSeyWih,S09KH8dQ 3Nn,0Vyd
aTnV2PG,BSafpTVpYnTH79cJyVsfx WH4GvyQDdCR,34UR

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty