1

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);
J33nn
  • 3,034
  • 5
  • 30
  • 46
  • What's the problem with this exactly? – Marcel Stör Dec 08 '13 at 21:50
  • Soap service doesn't authorize request when it's called like this. Vendor has told me to use preemprive authorization type to make it work. While testing with SoapUI everything works fine but I don't know how to make my client to authorize preemtive. – J33nn Dec 08 '13 at 21:54
  • You should first debug and check whether `authorization` has the same value (i.e. is the same string) as what you send in SoapUI. Consider that `getBytes()` uses the platform default encoding which may or may not be what you want. – Marcel Stör Dec 08 '13 at 21:58

1 Answers1

0

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);
  • Please don't post the same answer to more than one question. If the questions are basically the same, [flag them](https://stackoverflow.com/privileges/flag-posts) as duplicates. Otherwise, customize the answer to the question. – Nathan Tuggy Aug 08 '17 at 04:28