'how to set https proxy in cxf client ?
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 ?
Solution 1:[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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | Pranali Choudhari |