SOAP connections through a proxy using URLEndpoint

I had to update a previous Java application that requests a SOAP response from an external web service. This service is located outside of our firewall, which now requires a proxy server from us instead of a direct URL.

Currently, a Java application uses URLEndpoint, which takes a string for a URL. Usually, when I get the URL through a proxy, I create the following URL:

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

The problem is that URLEndpoint only accepts a string for url, I tried to convert the url to string using toExternalForm (), but it distorted the url.

Any ideas on this?

EDIT: I cannot use System.setProperty as it works with a whole bunch of other Java applications in tomcat.

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

Any help was appreciated.

+7
source share
3 answers

This is not how proxies work. The way the proxy works is that you take your regular URL:

 http://example.com/service 

and instead of searching for β€œexample.com” and port 80, a message is sent instead of your proxy host ( http://theproxy.com/10555 ).

Java has built-in proxy processing using the properties http.proxyHost and http.proxyPort.

So, in your case, you will need:

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

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

Here is a page with proxy properties documentation.

+7
source

Use Apache HttpClient and do it as this example.

0
source

About the URL constructor with setting up a separate proxy server:

http://edn.embarcadero.com/article/29783

(sorry, you do not have privileges to comment)

0
source

All Articles