Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP calls through a SOCKS Proxy in Java

I have a situation where I communicate with a vendor via REST services. Within our organization there are firewalls galore, and doing this sort of thing requires the use of a specific SOCKS proxy configuration.
Note that it must be this SOCKS proxy; an HTTP proxy will not work in our environment.
Once the proxy configurations were done, the connection through the proxy is handled with relative ease using the code below:

URL url = new URL("https://url.for.the.web.service.com");
Proxy proxy = new Proxy(Proxy.Type.SOCKS,new InetSocketAddress("our.socks.proxy.server.com",1080));
HttpsURLConnection con = (HttpsURLConnection)url.openConnection(proxy);

I have received an additional requirement to attach to some additional web services for the vendor. Unfortunately, these are older handling for the vendor and are done as SOAP services.
Although I'm old and grizzled, this is my first run at client side SOAP. Using the help I already got from your site (thanks for the site btw; I use it all the time for reference, including getting through the REST implementation and first round of SOCKS last spring), I was able to get my SOAP proxy classes generated through Eclipse. But when I try to run the generated code to access a service I run straight into the firewall, because it is not being specified in that generated code.

I've been looking through it and I think I've identified the generated class where my changes need to go, that being the WSDLName_Locator class extended from the Axis client class Service. Although I can find a URL object for the WSDL location in the generated code, there is no equivalent opening of a connection to which I can attach my SOCKS proxy. The handling goes down into the bowels of the Axis handling and does I know not what. It may alternatively be in the BasicHttpBinding_IWSDLNameStub.

I've been googling and looking at Javadoc for every class used in that generated code, looking for any references to proxy and I'm coming up empty. But this is complicated by the fact that in the SOAP vernacular the generated code itself is called a proxy, so I get large numbers of false positives on any search I try, and also by the fact that all of the more recent info online seems to relate to Android app development, which I am not doing. The AxisEngine and AxisEngineConfiguration classes seem promising, but I haven’t found a way to connect a proxy there either.

My need is simply this: where and how in that generated SOAP code can I do the equivalent attachment to the proxy, so that that linkage is carried into the Axis handling? My hope is that someone has done this before.

I haven’t included any of the generated code because I would need to obfuscate it beyond the ability to run anyway, it's voluminous because it covers a number of services, and my assumption is that the generated output is similar from one WSDL generation to the next. But I will provide any additional detail that is required.

Thanks in advance for any help you can provide.

like image 827
dan.brunton Avatar asked Oct 22 '25 16:10

dan.brunton


1 Answers

I tried googling again to see if my question would come up in the results... and yes, right at the top. But also returned was a link to this question:

Call SOAP web-service using Windows proxy settings in Java

In that answer, the techniques for setting proxy values as System property are shown, although the question relates to use of another class, ProxySelector which I suspect is why my searches were coming up empty. I hadn't tried that technique because it hadn't worked for setting the SOCKS proxy when I was doing the REST part last spring.

So simply specifying:

    System.setProperty("socksProxyHost","our.socks.proxy.server.com");
    System.setProperty("socksProxyPort","1080");

before invoking the web service call was all that was needed.

like image 113
dan.brunton Avatar answered Oct 25 '25 04:10

dan.brunton