我试图使用基本授权和处理程序调用SOAP Webservice,但是API以401未经授权的方式响应。
@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;
}
当我使用SOAP UI并手动添加Authorization Header(来自调试代码的值)时,我可以从端点接收到响应,但是现在使用代码会失败。
任何提示都将非常有帮助。谢谢。
true
而不是返回outboundProperty
吗? - Mohsen