Search code examples
web-servicesauthenticationsoapproxyapache-axis

SocketTimeoutException after connecting via proxy with authentication


I wrote code to communicate with a non-public webservice and everything seemed to work even when connecting via proxy. The problem started after changing to proxy with authorization. I get the following warning:

WARN  [HttpMethodDirector] Required credentials not available for BASIC <any realm>@destination.url.com:80
WARN  [HttpMethodDirector] Preemptive authentication requested but no default credentials available

After which an exception is thrown: java.net.SocketTimeoutException: Read timed out

"destination.url.com" is the destination address, so I guess I went past the proxy.

I read somewhere on stackoverflow that this warning is usually thrown when passing in a username/password when don't need to. I don't know if it's true. Using HttpProxy to connect to a host with preemtive authentication

Also here some guys point the same problem, but reproducible by running through a non-authenticated proxy to an authenticated remote repository. My situation is the opposite. The destination doesn't require authorization (the authorization data are put into the body of SOAP messages). https://www.jfrog.com/jira/browse/RTFACT-4147

Any ideas how to help my situation? Here is some of my code:

MyStub stub = new MyStub();
Options Options = stub._getServiceClient().getOptions();

Options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,"utf-8");
Options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,org.apache.axis2.Constants.VALUE_FALSE);

HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();
proxyProperties.setProxyName("proxyAddress");
proxyProperties.setProxyPort("proxyPort");
proxyProperties.setUserName("proxyUsername");
proxyProperties.setPassWord("proxyPassword");

Options.setProperty(org.apache.axis2.transport.http.HTTPConstants.PROXY,proxyProperties);

Solution

    1. It happens that the warning has nothing to do with the exception. Exception is thrown because the webservice doesn't support chunked messages. Simply adding this solves the problem:

    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

    1. The warning itself is strange, but there is a way to remove it, by simply adding any login and password. The destination doesn't require any, but the warning vanishes.