Approach 1 stacktrace
javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://username:password@10.XXX.15.XX/ClientExt/NewAPI/api.asmx?wsdl. It failed with: Server returned HTTP response code: 401 for URL: http://username:password@10.XXX.15.XX/ClientExt/NewAPI/api.asmx?wsdl. at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:250) at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:231) at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:194) at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:163) at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:348) at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:306) at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:215) at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:196) at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:192) at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104) at javax.xml.ws.Service.(Service.java:77) at org.tempuri.Api.(Api.java:82)
approach 1:
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
approach 2
HttpURLConnection myURLConnection = (HttpURLConnection)url.openConnection();
String userCredentials = "username:password";
String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
myURLConnection.setRequestProperty ("Authorization", basicAuth);
myURLConnection.setRequestMethod("GET");
myURLConnection.setDoInput(true);
myURLConnection.setConnectTimeout(1500000);
myURLConnection.connect();
int responseCode = myURLConnection.getResponseCode();//returns 200 and error
I am getting response Code 200 in approach 2, also getting above stacktrace as error message.
Then, I tried with Authenticator(approach 1), it is working fine if I call in javaTester file but getting below error message when calling through application.
org.apache.axis2.AxisFault: HTTP ( 401 ) Unauthorized address : http://10.XXX.15.XX/ClientExt/NewAPI/api.asmx