I am trying to connect to a WSDL file and keep getting this error:
Bad auth String (could not parse username/password): String index out of range: -1
I am able to connect to a local WSDL file without any errors, but now I am trying to connect a file on an external server. I was provided with a username and password, but am unsure of how to pass these arguments in.
Here is where I am entering in my login credentials:
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
String loginPassword = "myusername:mypassword";
soapMessage.getMimeHeaders().addHeader("Authorization", "Basic " + loginPassword);
On another note, I am printing statements after my Soap Request, which appears to be working and after my Soap Response. The Bad auth String (could not parse username/password): String index out of range: -1
I know that are more secure ways of entering a username and password, but at this point I am just trying to make a successful call.
Username password for Basic authentication is Base 64 encoded. Hope this will help.
I have a sample for Basic authentication for Inputstream:-
public static InputStream getInputStream(String location) throws IOException {
URL url = new URL(location);
URLConnection uc = url.openConnection();
String username = "";
String password = "";
String userpass = username + ":" + password;
String basicAuth = "Basic "
+ javax.xml.bind.DatatypeConverter.printBase64Binary(userpass
.getBytes());
uc.setRequestProperty("Authorization", basicAuth);
return uc.getInputStream();
}
Another very unsecure way of doing it is by http://user:[email protected]. Only use this on developer environment.