0

I'm using this awesome example here to create a simple SAAJ Soap Client to the IBM Watson Explorer Soap Webservice.

Working Soap client example

But I can't get authentication working.

In the createSOAPRequest method call just add...

...
MimeHeaders headers = soapMessage.getMimeHeaders();
String encoded = new sun.misc.BASE64Encoder().encode((username+":"+password).getBytes());
String authString = "Basic " + encoded;
headers.addHeader("Authorization", authString);
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
...

But this won't work. I've tried many permutations of this code. Am I doing something wrong? Also how do I know the service wants the BASE64Encoder?

Joshua Hedges
  • 307
  • 4
  • 16
  • What does it mean that won't work? I think the client side is correct, it sends the basicauth header well. The server side does not accept it? Did you write the server side too? Is there the counterpart that can check and process your basic auth header? – m4gic Aug 31 '18 at 08:44
  • It is good to learn this low level basics of assembling a SOAP request, although I would recommend to switch to some higher level, you should use CXF of jax-ws for this, it is much easier (your final goal is, if I am not wrong, to call a SOAP service with basic auth, and this can be achieved easier I think). – m4gic Aug 31 '18 at 08:47
  • This will be put in a jar file that will run on Hadoop and I want to keep it as lite as possible. I won't be expanding it past this one webservice call, ever, so I don't want to pull in JAX-WS if I don't have to. – Joshua Hedges Aug 31 '18 at 12:08
  • I didn't write the server side. It's actually connecting to Watson Explorer. Maybe it requires a more complex authentication soap packet. Is there something beyond "basic" that I can use? I keep getting the error "insufficient privileges for user" but I know the user has sufficient rights. – Joshua Hedges Aug 31 '18 at 12:10
  • oh and if I comment out the Authorization header, so no authorization header is sent I get the same authorization error, so I'm sure it's something to do with the authroization header sent. – Joshua Hedges Aug 31 '18 at 12:11
  • Is your webservice belongs to IBM Watson Explorer? Maybe it would be easier to figure out how to do it right if you read the documentation of the product you are trying to connect to. Maybe you can found working examples too. I would suggest to add the product and its version to the question. – m4gic Aug 31 '18 at 13:02

0 Answers0