Question

I looked for solutions on SO for this but none of them seem to apply to my case. So here goes: I have an application that needs to make a service call to a third party domain. I am using jersey client to make this service call. The code for making this call is

ClientResponse resp = resourceWithParams.
                      header("Authorization", getAccessKeyId() + ":" +
                      hmacSha1.toUpperCase()).
                      post(ClientResponse.class,"");

where resourceWithParams is the jersey web resource. Note that even though its is a POST, the web service is expecting a query string and empty body. It might be questionable design but that is what we have to work with.

This setup is working just fine on my local machine as well as on our preprod server. However on our production servers it gives an exception:

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused

There are a couple of points below that might be helpful in pointing me in the right direction:

1) We get a valid response when we use curl on the prod server command line to send a request to the web service so seems like there are no firewall issues. This is happening only when we try it through the web application, i.e. through the java code using jersey client.

2) There are no proxies set up on the prod servers

3) Works fine from localhost.

4) The Rest webservice uses https and the correct certificates are installed on our server which is proved by the fact that curling the webservice on prod works fine.

Any ideas on what the issue might be and where we should start looking?

EDIT:

As mentioned we were using https to connect to the webservice. If we use http instead, it does seem to be working.

Was it helpful?

Solution

I suggest you set up a tcpdump session to see where the connection refused is coming from. In particular, see what the source IP and destination IP addresses are, for both the successful connections and the unsuccessful ones.

There are two possibilities the above is designed to test for:

  1. You say you're not using proxy servers, but Java actually has a separate proxy configuration from the rest of the system, so it may be that your Java is configured to use a non-functional proxy server.
  2. Your Java system could be sending requests using a different source IP address to the one that your curl is using.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top