Question

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?

Was it helpful?

Solution

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!

OTHER TIPS

Using XML Config:

<camelContext id="context" xmlns="http://camel.apache.org/schema/spring">
    <properties>
        <property key="http.proxyHost" value="127.0.0.1"/>
        <property key="http.proxyPort" value="8888"/>
   </properties>
</camelContext>

I don't think http-conduit setting is working for you this time, as you don't use any CXF client to invoke the service.

Although Marvin answered his own question, his answer is outdated.

At least for more recent Camel versions the solution changed to this:

 context.getGlobalOptions().put("http.proxyHost", "172.168.18.9");
 context.getGlobalOptions().put("http.proxyPort", "8080");

You can get a hold on the context by using getContext() when extending RouteBuilder.

Source: Camel documentation found at https://camel.apache.org/components/3.15.x/http-component.html#_configuring_a_proxy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top