Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP connections through a proxy using URLEndpoint

Tags:

java

url

soap

proxy

I've had to update a previous java application that requests a SOAP response from an external web service. This service is outside our firewall which now requires us to go through a proxy instead of hitting the URL directly.

Currently the Java App uses URLEndpoint that takes a string for the URL. Usually when I am getting to a URL through a proxy I create a URL like so:

URL url = new URL("http", "theproxy.com", 5555, finalUrl);

The problem is URLEndpoint only takes a string for the url, I tried to convert URL to string using toExternalForm() but it malformed the URL.

Any ideas as to a way around this?

EDIT: I can't use System.setProperty as this runs with a whole heap of other Java applications in tomcat.

second edit: I can't set a system properties as it will override all other applications running on the server, I can't use jsocks as the proxy we run through squid proxy which does not support socks4/5

Any help appreciated.

like image 423
Rudiger Avatar asked Feb 08 '11 00:02

Rudiger


1 Answers

That's not how proxy's work. The way a proxy works is that you take your normal URL:

http://example.com/service

and instead of looking up "example.com" and port 80, the message is sent to your proxy host instead (http://theproxy.com:5555).

Java has built in proxy handling using http.proxyHost and http.proxyPort System properties.

So in your case you would need to do:

System.setProperty("http.proxyHost", "theproxy.com");
System.setProperty("http.proxyPort", "5555");

Then your code should, ideally, "Just Work".

Here is a page documenting the proxy properties.

like image 112
Will Hartung Avatar answered Nov 14 '22 22:11

Will Hartung