You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Oliver Becherer <ic...@oliver-becherer.name> on 2014/07/23 21:57:06 UTC

Using CXF with Https Proxy

hi all,

i'm just stuck with a problem using cxf : 

i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
to the usual endpoint but over a proxy server that only accepts https.

so these are the base facts : 

Service Endpoint : https://some-usual-soap-endpoint.com

Proxy Server : https://some-weird-https-proxy.com
Proxy Port : 7777

This is my approach : 

HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setProxyServer("some-weird-https-proxy.com");
policy.setProxyServerPort(7777);
			
Client client = ClientProxy.getClient(awspt);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setClient(policy);


so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.

can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?

any help is highly appreciated!

kind regards

O

Re: Using CXF with Https Proxy

Posted by Jose María Zaragoza <de...@gmail.com>.
2014-07-24 16:37 GMT+02:00 Oliver Becherer <ic...@oliver-becherer.name>:
> hi,
>
> i assume this scenario is quite unusal (regarding answers), so i tried to find a valid workaround and currently i'm trying it like this :
>
> Client client = ClientProxy.getClient(MYWEBSERVICEPORT);
> client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "https://some-weird-https-proxy.com") ;
>
>
> this is working fine so far, but to tell the proxy where he has to deliver the message to, i'd had to
> modify http protocol header, especially the Host variable.
>
> -> unfortunately it seems, as if the Host Variable in http header is overwritten somewhere deeeeep into the Interceptor Chain or at least in Transport layer
> -> my custom interceptor is setting Host Variable, but within outgoing Request, its again overwritten from framework
>
>
> Could somebody please direct me , how i can avoid, that cxf is automatically setting http header Host variable?

Maybe I'm wrong but I don't know what have to do Host HTTP header with
 proxy forwarding requests .
I think that proxy server shouldn't use Host header for nothing. I
should use URI requested
For example, a request with proxy settings would be as

GET  https://some-weird-https-proxy.com HTTP/1.1
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5
OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Host: some-weird-https-proxy.com
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive

But I think that Host header shouldn't be used by proxy to forward the request
am I wrong ?


Regards





>
> thanks a lot!
>
> kind regards
>
> O
>
>
> Am 23.07.2014 um 21:57 schrieb Oliver Becherer <ic...@oliver-becherer.name>:
>
>> hi all,
>>
>> i'm just stuck with a problem using cxf :
>>
>> i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
>> to the usual endpoint but over a proxy server that only accepts https.
>>
>> so these are the base facts :
>>
>> Service Endpoint : https://some-usual-soap-endpoint.com
>>
>> Proxy Server : https://some-weird-https-proxy.com
>> Proxy Port : 7777
>>
>> This is my approach :
>>
>> HTTPClientPolicy policy = new HTTPClientPolicy();
>> policy.setProxyServer("some-weird-https-proxy.com");
>> policy.setProxyServerPort(7777);
>>
>> Client client = ClientProxy.getClient(awspt);
>> HTTPConduit http = (HTTPConduit) client.getConduit();
>> http.setClient(policy);
>>
>>
>> so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.
>>
>> can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?
>>
>> any help is highly appreciated!
>>
>> kind regards
>>
>> O
>

Re: Using CXF with Https Proxy

Posted by Daniel Kulp <dk...@apache.org>.

I think the HOST header might be set down deep in the URLConnection call someplace.  Not really sure.

Here’s my suggestion:   
Create an instance of org.apache.cxf.transport.https.HttpsURLConnectionFactory and call the createConnection method in it passing in a Proxy object and TLSClientParameters (if needed) and the URL.   Use that HttpURLConnection to try and do a post of a sample message to the server.  If you can get that to work via request properties or similar, then we may be able to get things updated to match whatever you get working.  


Dan



On Jul 24, 2014, at 10:37 AM, Oliver Becherer <ic...@oliver-becherer.name> wrote:

> hi,
> 
> i assume this scenario is quite unusal (regarding answers), so i tried to find a valid workaround and currently i'm trying it like this : 
> 
> Client client = ClientProxy.getClient(MYWEBSERVICEPORT);
> client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "https://some-weird-https-proxy.com") ;
> 
> 
> this is working fine so far, but to tell the proxy where he has to deliver the message to, i'd had to
> modify http protocol header, especially the Host variable.
> 
> -> unfortunately it seems, as if the Host Variable in http header is overwritten somewhere deeeeep into the Interceptor Chain or at least in Transport layer
> -> my custom interceptor is setting Host Variable, but within outgoing Request, its again overwritten from framework
> 
> 
> Could somebody please direct me , how i can avoid, that cxf is automatically setting http header Host variable?
> 
> thanks a lot!
> 
> kind regards
> 
> O
> 			
> 
> Am 23.07.2014 um 21:57 schrieb Oliver Becherer <ic...@oliver-becherer.name>:
> 
>> hi all,
>> 
>> i'm just stuck with a problem using cxf : 
>> 
>> i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
>> to the usual endpoint but over a proxy server that only accepts https.
>> 
>> so these are the base facts : 
>> 
>> Service Endpoint : https://some-usual-soap-endpoint.com
>> 
>> Proxy Server : https://some-weird-https-proxy.com
>> Proxy Port : 7777
>> 
>> This is my approach : 
>> 
>> HTTPClientPolicy policy = new HTTPClientPolicy();
>> policy.setProxyServer("some-weird-https-proxy.com");
>> policy.setProxyServerPort(7777);
>> 			
>> Client client = ClientProxy.getClient(awspt);
>> HTTPConduit http = (HTTPConduit) client.getConduit();
>> http.setClient(policy);
>> 
>> 
>> so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.
>> 
>> can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?
>> 
>> any help is highly appreciated!
>> 
>> kind regards
>> 
>> O
> 

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Using CXF with Https Proxy

Posted by Oliver Becherer <ic...@oliver-becherer.name>.
hi,

i assume this scenario is quite unusal (regarding answers), so i tried to find a valid workaround and currently i'm trying it like this : 

Client client = ClientProxy.getClient(MYWEBSERVICEPORT);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "https://some-weird-https-proxy.com") ;


this is working fine so far, but to tell the proxy where he has to deliver the message to, i'd had to
modify http protocol header, especially the Host variable.

-> unfortunately it seems, as if the Host Variable in http header is overwritten somewhere deeeeep into the Interceptor Chain or at least in Transport layer
-> my custom interceptor is setting Host Variable, but within outgoing Request, its again overwritten from framework


Could somebody please direct me , how i can avoid, that cxf is automatically setting http header Host variable?

thanks a lot!

kind regards

O
			

Am 23.07.2014 um 21:57 schrieb Oliver Becherer <ic...@oliver-becherer.name>:

> hi all,
> 
> i'm just stuck with a problem using cxf : 
> 
> i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
> to the usual endpoint but over a proxy server that only accepts https.
> 
> so these are the base facts : 
> 
> Service Endpoint : https://some-usual-soap-endpoint.com
> 
> Proxy Server : https://some-weird-https-proxy.com
> Proxy Port : 7777
> 
> This is my approach : 
> 
> HTTPClientPolicy policy = new HTTPClientPolicy();
> policy.setProxyServer("some-weird-https-proxy.com");
> policy.setProxyServerPort(7777);
> 			
> Client client = ClientProxy.getClient(awspt);
> HTTPConduit http = (HTTPConduit) client.getConduit();
> http.setClient(policy);
> 
> 
> so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.
> 
> can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?
> 
> any help is highly appreciated!
> 
> kind regards
> 
> O


Re: Using CXF with Https Proxy

Posted by Oliver Becherer <ic...@oliver-becherer.name>.
hi,

thank you for the feedback - it seems as if i finally got it working : 

1. i overwrite Service Endpoint for the Single Request with the Proxy URL : client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "https:/some-weird-https-proxy.com") ;

-> this assures, request is delivered with https to proxy

2. i modify Http Header variable in Interceptor on the right phase : 

-> Phase WRITE seems to be the right position for

Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
		
requestHeaders.put("Host", Arrays.asList("https://some-usual-soap-endpoint.com"));
message.put(Message.PROTOCOL_HEADERS, requestHeaders);


3. finally i can see within debug logs  :

 DEBUG org.apache.cxf.transport.http.Headers - Host: https://some-usual-soap-endpoint.com

ID: 1
Address: https:/some-weird-https-proxy.com
Encoding: UTF-8
Content-Type: text/xml
Headers: {Host=[https://some-usual-soap-endpoint.com], 
Payload: <soap:Envelope > SOME STRANGE SOAP STUFF</soap:Envelope>



kind regards

O

 
			

Am 24.07.2014 um 22:56 schrieb Christian Schneider <ch...@die-schneider.net>:

> I would propose to create a second service client for the service that uses the https address.
> 
> Then you can use the http client for most operations and the https one for your one request. If you need to hide that you can
> create a small java class that implements the service interface and delegates to the correct one of the two proxies depending on the called operation.
> 
> That should be a lot easier then making CXF do the magic.
> 
> Christian
> 
> 
> On 23.07.2014 21:57, Oliver Becherer wrote:
>> hi all,
>> 
>> i'm just stuck with a problem using cxf :
>> 
>> i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
>> to the usual endpoint but over a proxy server that only accepts https.
>> 
>> so these are the base facts :
>> 
>> Service Endpoint : https://some-usual-soap-endpoint.com
>> 
>> Proxy Server : https://some-weird-https-proxy.com
>> Proxy Port : 7777
>> 
>> This is my approach :
>> 
>> HTTPClientPolicy policy = new HTTPClientPolicy();
>> policy.setProxyServer("some-weird-https-proxy.com");
>> policy.setProxyServerPort(7777);
>> 			
>> Client client = ClientProxy.getClient(awspt);
>> HTTPConduit http = (HTTPConduit) client.getConduit();
>> http.setClient(policy);
>> 
>> 
>> so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.
>> 
>> can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?
>> 
>> any help is highly appreciated!
>> 
>> kind regards
>> 
>> O
> 
> 
> -- 
> Christian Schneider
> http://www.liquid-reality.de
> 
> Open Source Architect
> http://www.talend.com
> 


Re: Using CXF with Https Proxy

Posted by Christian Schneider <ch...@die-schneider.net>.
I would propose to create a second service client for the service that 
uses the https address.

Then you can use the http client for most operations and the https one 
for your one request. If you need to hide that you can
create a small java class that implements the service interface and 
delegates to the correct one of the two proxies depending on the called 
operation.

That should be a lot easier then making CXF do the magic.

Christian


On 23.07.2014 21:57, Oliver Becherer wrote:
> hi all,
>
> i'm just stuck with a problem using cxf :
>
> i implemented a soap client to a webservice using cxf 2.6.1 and its working fine... now i have the challenge of sending one single service operation
> to the usual endpoint but over a proxy server that only accepts https.
>
> so these are the base facts :
>
> Service Endpoint : https://some-usual-soap-endpoint.com
>
> Proxy Server : https://some-weird-https-proxy.com
> Proxy Port : 7777
>
> This is my approach :
>
> HTTPClientPolicy policy = new HTTPClientPolicy();
> policy.setProxyServer("some-weird-https-proxy.com");
> policy.setProxyServerPort(7777);
> 			
> Client client = ClientProxy.getClient(awspt);
> HTTPConduit http = (HTTPConduit) client.getConduit();
> http.setClient(policy);
>
>
> so far so good, but the requests are reaching the proxy not using https, but http and the proxy is not accepting this.
>
> can you help me, how to configure the Proxy Server within my Client, so Request is sent using https?
>
> any help is highly appreciated!
>
> kind regards
>
> O


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com