Preemtive authorization with java soap client

1.5k views Asked by At

How to make authorization preemptive using SOAPEnvelope mime headers?

SOAPEnvelope envelope = soapPart.getEnvelope();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
mimeHeaders.addHeader("Content-type", "text/xml");

String authorization = new sun.misc.BASE64Encoder().encode(("user:pass").getBytes());
mimeHeaders.addHeader("Authorization", "Basic " + authorization);
1

There are 1 answers

1
Abhishek Pandey On

Add the SOAPAction. I was also facing the same issue. In my case SOAPAction is the operation name.

MimeHeaders hd = soapMessage.getMimeHeaders();
hd.addHeader("SOAPAction", "getUserDetails");
String authorization = new sun.misc.BASE64Encoder().encode((username+":"+password).getBytes());
hd.addHeader("Authorization", "Basic " + authorization);