How to set proxy while using camel-http

Marvin picture Marvin · Jul 11, 2013 · Viewed 7.3k times · Source

I am new to camel, and ended up stucked on a proxy problem. I have such a route I use to store resulat from a recurrent http call to a file:

from("quartz://collector/test?cron=0+0/2+*+?+*+*")                      
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))    
    .setHeader(Exchange.HTTP_QUERY, constant("Id=50")
.to("http://www.anywebsite/question.php")
    .setHeader(Exchange.FILE_NAME,constant("${date:now:yyyyMMddHHmmssSSS}.xml"))
.inOnly(someFolder);

My problem is that I need to specify a proxy (host + port) to go through or I'll be stucked trying to get the information. I tried various ways, including setting "http.proxyHost" and ""http.proxyPort" from the routeBuilder (through getContext().setProperties) and from the bundle-context.xml wrapped in a "properties/property" tag. I also tried to set it in the endpoint (the camel-http doc saying you can set it to the httpenpoint) by adding &proxyHost=myHost&proxyPort=myPort to it.

None worked..

Il also tried to set up a http-conduit from posts I read through google such as (choosing one or the other according to the deployment target):

<http-conf:conduit name="*.http-conduit">
<!-- when behind proxy -->
        <http-conf:client Connection="close" ConnectionTimeout="3000" ReceiveTimeout="10000" ProxyServer="p-goodwat" ProxyServerPort="3128"/> 
<!-- when no proxy -->
    <http-conf:client Connection="close" ConnectionTimeout="3000" ReceiveTimeout="10000" />
</http-conf:conduit>

But this didn't work either... and also, I would like to be able to do it automatically, without having to update camel-context according to where it will be installed.

So, do you see a way to set it, and set it dynamically?

Answer

Marvin picture Marvin · Jul 12, 2013

After a few attemps, I managed to have it worked... looks like the problem did not come from my solution, but from the fact I did not increment the bundle version... thus, my solutions were just not taken into consideration.

So, the solution that worked for me is setting the endpoint for the context from my routeBuilder, like : getContext().setProperty("http.proxyHost",10.100.100.1);
getContext().setProperty("http.proxyPort",2111);

Now, it does work.

Thanks for those who had a look!