3

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?

nwinkler
  • 52,665
  • 21
  • 154
  • 168
Marvin
  • 81
  • 1
  • 7

4 Answers4

5

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!

Marvin
  • 81
  • 1
  • 7
  • Thanks Marvin, your answer got me in the right direction although it's outdated by now ;-) I have provided an answer for a more recent camel version below. – BitfulByte Feb 16 '22 at 17:10
1

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>
Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76
0

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.

Willem Jiang
  • 3,291
  • 1
  • 14
  • 14
  • I guessed it : I read about this in many examples, and there were always a CXF client. Thanks for your confirmation! – Marvin Jul 18 '13 at 16:44
0

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

BitfulByte
  • 4,117
  • 1
  • 30
  • 40