I've been fighting this problem for the past day and a half and finally broke down after my searching failed to produce anything to resolve my issue.
I have a Spring-boot application that makes SOAP calls to a remote server. Everything works great from with STS, or running locally on my development laptop (either through STS>Run, mvn spring-boot:run, or running the jar file locally. When I deploy the code (a fat jar) to our corp development server all of my requests fail with "Connection refused (Connection refused)".
To triage I made the same request via Curl on the development server to see where the problem lies:
BARE REQUEST:
curl http://some.remote.server
--> curl: (7) Failed connect to :80; Connection refused
REQUEST WITH PROXY SETTINGS/AUTH:
export http_proxy=http://<proxy_user>:<proxy_pass>@<proxy_host>:<proxy_port>
curl -x $http_proxy http://some.remote.server
--> Success!
So at this point I'm pretty sure that the problem I'm seeing is that my calls to aren't getting routed through the proxy.
I've tried to add the proxy settings to the code, but I don't like the idea of reducing the portability (besides, it didn't work).
I've tried setting the parameters on the command line via:
java -Dhttp.proxyHost=<corp proxy host addr> -Dhttp.proxyPort=3128 -Dhttp.proxyUser=<proxy username> -Dhttp.proxyPassword=<proxy pass> -jar Application.jar
Nothing I'm doing makes a bit of difference.
What other tools / techniques can I use to diagnose / resolve this issue I'm seeing? I'm running out of hair to pull!
[note: eventually this will run from a Docker container, but I have removed as much of the moving parts as I can to simplify the solution. I think I'm doing something really basic incorrectly as I'm sure this isn't a unique problem.]
public String makeTestRequest()
{
try
{
final String authUser = PROXY_USER;
final String authPassword = PROXY_PASS;
Authenticator.setDefault(
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
authUser, authPassword.toCharArray());
}
}
);
System.setProperty("http.proxyUser", PROXY_USER);
System.setProperty("http.proxyPassword", PROXY_PASS);
System.setProperty("http.proxyHost", PROXY_HOST);
System.setProperty("http.proxyPort", String.valueOf(PROXY_PORT));
URL url = new URL(REMOTE_URL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
System.out.println("Proxy? " + con.usingProxy()); // proxy?
con.setRequestMethod("GET");
int status = con.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM)
{
String location = con.getHeaderField("Location");
URL newUrl = new URL(location);
con = (HttpURLConnection) newUrl.openConnection();
}
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null)
{
content.append(inputLine);
}
// cleanup / return
in.close();
con.disconnect();
return content.toString();
}
catch (Exception e)
{
e.printStackTrace();
return e.getMessage();
}
}