You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Anderson <al...@gmail.com> on 2013/09/05 13:41:17 UTC

Using HTTP and HTTPS proxies with Camel HTTP Component

I'm writing some test code which uses and HTTP/HTTPS proxy to mock 3rd
party webservices.

For non-camel code, I configure the proxy using the java system properties:
http.proxyHost, http.proxyPort, https.proxyHost, https.proxyPort,
http.nonProxyHosts.

These settings seem to be ignored by camel, so I have also explicitly
set the HTTP proxy in camelContext (code is groovy):

    camelContext.properties['http.proxyHost'] =
System.properties['http.proxyHost']
    camelContext.properties['http.proxyPort'] =
System.properties['http.proxyPort']

These settings work fine *for HTTP*.  However, I can't find
documentation for getting HTTPS working.

I've tried setting other properties on the camel context, such as
https.proxyPort, http.proxyScheme, http.proxyAuthSceme,
https.proxyScheme, https.proxyAuthScheme to no avail (although I've
seen a couple of different exceptions).

I'd be happy to document my findings, but thought I should first check:

* is this a known issue?
* has it been fixed in later version of camel? (I'm using 2.9.4)
* should I expect to be able to proxy both HTTP and HTTPS to either
different or the same ports using Camel without reconfiguring in
between requests?

Thanks for any help,

Alex


For interest, most common exception I got:

    ## 05 Sep 2013 13:49:32,931 ## seda.SedaConsumer Error processing
exchange. Exchange[Message: test]. Caused by: [java.io.IOException -
Stream closed]
    java.io.IOException: Stream closed
        at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:151)
        at java.io.BufferedInputStream.available(BufferedInputStream.java:398)
        at org.apache.commons.httpclient.ContentLengthInputStream.available(ContentLengthInputStream.java:213)
        ...

Re: Using HTTP and HTTPS proxies with Camel HTTP Component

Posted by Alex Anderson <al...@frontlinesms.com>.
On 15 September 2013 05:36, Christian Posta <ch...@gmail.com> wrote:
> Alex,
>
> As Christian M. points out, use the camel config on the endpoint, not the
> way you're doing in your OP.
>
> Cheers
>
>
> On Wed, Sep 11, 2013 at 6:03 AM, Alex Anderson <al...@frontlinesms.com>wrote:
>
>> On 10 September 2013 22:49, Christian Müller
>> <ch...@gmail.com> wrote:
>> > Did you tried setting the proxy host/port as we described here [1]?
>>
>> Hi Christian,
>>
>> Thanks for the suggestion.  Do you mean something other than what I
>> referred to in my original post?
>>
>> >    camelContext.properties['http.proxyHost'] =
>> System.properties['http.proxyHost']
>> >    camelContext.properties['http.proxyPort'] =
>> System.properties['http.proxyPort']
>>
>> Alex
>>
>
>
>
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta

Thanks for the pointers - will probably give this a go next week.

As I'm using this to mock 3rd party services for a camel-based system
under test, changing endpoint URLs is not convenient, but it's very
helpful to know that other methods do not work.

Re: Using HTTP and HTTPS proxies with Camel HTTP Component

Posted by Christian Posta <ch...@gmail.com>.
Alex,

As Christian M. points out, use the camel config on the endpoint, not the
way you're doing in your OP.

Cheers


On Wed, Sep 11, 2013 at 6:03 AM, Alex Anderson <al...@frontlinesms.com>wrote:

> On 10 September 2013 22:49, Christian Müller
> <ch...@gmail.com> wrote:
> > Did you tried setting the proxy host/port as we described here [1]?
>
> Hi Christian,
>
> Thanks for the suggestion.  Do you mean something other than what I
> referred to in my original post?
>
> >    camelContext.properties['http.proxyHost'] =
> System.properties['http.proxyHost']
> >    camelContext.properties['http.proxyPort'] =
> System.properties['http.proxyPort']
>
> Alex
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Using HTTP and HTTPS proxies with Camel HTTP Component

Posted by Christian Müller <ch...@gmail.com>.
I mean something like this [1].
As I understood your post, you try to achieve this by setting system
properties and/or camel context properties...

[1]
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java;h=d9e9721005ce4ffd7851d79ade62d195ef3cc14d;hb=HEAD

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Wed, Sep 11, 2013 at 3:03 PM, Alex Anderson <al...@frontlinesms.com>wrote:

> On 10 September 2013 22:49, Christian Müller
> <ch...@gmail.com> wrote:
> > Did you tried setting the proxy host/port as we described here [1]?
>
> Hi Christian,
>
> Thanks for the suggestion.  Do you mean something other than what I
> referred to in my original post?
>
> >    camelContext.properties['http.proxyHost'] =
> System.properties['http.proxyHost']
> >    camelContext.properties['http.proxyPort'] =
> System.properties['http.proxyPort']
>
> Alex
>

Re: Using HTTP and HTTPS proxies with Camel HTTP Component

Posted by Alex Anderson <al...@frontlinesms.com>.
On 10 September 2013 22:49, Christian Müller
<ch...@gmail.com> wrote:
> Did you tried setting the proxy host/port as we described here [1]?

Hi Christian,

Thanks for the suggestion.  Do you mean something other than what I
referred to in my original post?

>    camelContext.properties['http.proxyHost'] = System.properties['http.proxyHost']
>    camelContext.properties['http.proxyPort'] = System.properties['http.proxyPort']

Alex

Re: Using HTTP and HTTPS proxies with Camel HTTP Component

Posted by Christian Müller <ch...@gmail.com>.
Did you tried setting the proxy host/port as we described here [1]?

[1] http://camel.apache.org/http.html

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Thu, Sep 5, 2013 at 1:41 PM, Alex Anderson <
alexanderandersonofandover@gmail.com> wrote:

> I'm writing some test code which uses and HTTP/HTTPS proxy to mock 3rd
> party webservices.
>
> For non-camel code, I configure the proxy using the java system properties:
> http.proxyHost, http.proxyPort, https.proxyHost, https.proxyPort,
> http.nonProxyHosts.
>
> These settings seem to be ignored by camel, so I have also explicitly
> set the HTTP proxy in camelContext (code is groovy):
>
>     camelContext.properties['http.proxyHost'] =
> System.properties['http.proxyHost']
>     camelContext.properties['http.proxyPort'] =
> System.properties['http.proxyPort']
>
> These settings work fine *for HTTP*.  However, I can't find
> documentation for getting HTTPS working.
>
> I've tried setting other properties on the camel context, such as
> https.proxyPort, http.proxyScheme, http.proxyAuthSceme,
> https.proxyScheme, https.proxyAuthScheme to no avail (although I've
> seen a couple of different exceptions).
>
> I'd be happy to document my findings, but thought I should first check:
>
> * is this a known issue?
> * has it been fixed in later version of camel? (I'm using 2.9.4)
> * should I expect to be able to proxy both HTTP and HTTPS to either
> different or the same ports using Camel without reconfiguring in
> between requests?
>
> Thanks for any help,
>
> Alex
>
>
> For interest, most common exception I got:
>
>     ## 05 Sep 2013 13:49:32,931 ## seda.SedaConsumer Error processing
> exchange. Exchange[Message: test]. Caused by: [java.io.IOException -
> Stream closed]
>     java.io.IOException: Stream closed
>         at
> java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:151)
>         at
> java.io.BufferedInputStream.available(BufferedInputStream.java:398)
>         at
> org.apache.commons.httpclient.ContentLengthInputStream.available(ContentLengthInputStream.java:213)
>         ...
>