Camel component parameters returned password parameters, how to prevent this?

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

The documentation component states that credentials should be placed in parameters on the endpoint, for example:

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

      

This worked well until someone supplied the password with a "+" in a different environment. We notice that the "+" character is being passed in as space on the server that generates the error. In more detail in the Camel documentation, we found a page explaining that there is a "RAW" function to use as follows:

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

      

to keep the password intact.

Unfortunately, this feature was only introduced in Camel version 2.11 and at this time we have no plans to upgrade to ServiceMix 5.1.x.

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

I tried them on 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 is sending me 401 (unauthorized).

Question: is there any other alternative for sending credentials for the http4 component than using the option on the endpoint?

0


source to share


2 answers


I finally found a way, and the problem was on my server that needed an additional parameter: X-Forwarded-Proto

then the following way works very well, passing credentials in the endpoint options instead:

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 cpu to generate the Base64 hash it would be easy.

0


source


Please replace the character +

in your password %2B

in your camel endpoint URI and it should work.



0


source







All Articles