1

I am using below code for my webservice client :

HelloService hello = new HelloService();
HelloPortType helloPort = cliente.getHelloPort();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(helloPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getClient().setProxyServer("proxy");
http.getClient().setProxyServerPort(8080);
http.getProxyAuthorization().setUserName("user proxy");
http.getProxyAuthorization().setPassword("password proxy");

But the end url of my webservice is a https url. This code seems to work only for http url. Is there a way to set the https proxy for the cxf client ?

2 Answers2

1

I have not seen in the documentation the way to configure https

Try this

http.getClient().setProxyServerType (ProxyServerType.SOCKS)

Because the HTTP proxy (default cxf value) can ONLY be used to handle HTTP traffic (see http://www.jguru.com/faq/view.jsp?EID=227532)

Also you need to know if the proxy server you use support this protocol. To get HTTPS connections over proxy servers is needed to use a HTTP CONNECT query on the proxy, then the connection is tunnelled through the proxy, so the certificate verification is done as usual, as if the client was talking directly to the end server

See HTTPS connections over proxy servers (You can be also behing a proxy like Squid using SSL bump)

If SOCKS does not work, try to configure https proxy at jdk level with the system properties. See javadoc https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html

  System.setProperty("https.proxyHost", host)

  System.setProperty("https.proxyPort", port) //probably 443

Set also http.proxyUser and http.proxyPassword

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142
  • Thanks for the answer. We cannot use the system level proxy setting as there are multiple connections from same jvm and we need to use the proxy only for 1 of them. – Pranali Choudhari Jul 21 '16 at 22:29
  • Have you checked if your proxy is able to bypass the https traffic? – pedrofb Jul 22 '16 at 15:50
0

Ok, so proxy was fine. I was setting a connection timeout in the policy and also the proxy. Seems the HTTP CLIENT did not merge the properties because our code was creating a new policy object to set timeout instead of setting in the same one.

Resolved the issue and it worked fine with https url too.