i am trying to call a SOAP Webservice using handlers with Basic Authorization but somehow API is responding with 401 unauthorized.
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
String authString = parameter.getUser() + ":" + parameter.getPassword();
try {
Map<String, List<String>> headers = (Map<String, List<String>>)
context.get(MessageContext.HTTP_REQUEST_HEADERS);
if (null == headers) {
headers = new HashMap<String, List<String>>();
}
headers.put("Authorization", Collections.singletonList(
"Basic " + new String(Base64.encode(authString.getBytes()))));
} catch(Exception e) {
log4j.error(e.getMessage(), e);
}
}
return outboundProperty;
}
When i use SOAP UI and manually add the Authorziation Header (value from code during debug) then i recieve response from the Endpoint but using code it fails as of now.
Any pointers would be really helpful. Thanks