0
我們正在實現一個需要在SOAP頭元素中檢索用戶名和密碼並將其用於進一步使用/處理的JAX-WS Web服務。 當我們檢索用戶名/密碼時,它會變爲空。請幫忙。SOAP消息檢索
if (Boolean.FALSE.equals(context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
try {
SOAPMessage sm = context.getMessage();
//SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
SOAPHeader sh = envelope.getHeader();
System.out.println("Message: "+envelope);
System.out.println("Envelope: "+envelope);
System.out.println("Header: "+sh.toString());
Iterator it = sh.examineAllHeaderElements();
while(it.hasNext()){
System.out.println(it.next());
}
String username;
username = sh.getAttribute("Username");
// username = sh.getAttributeValue("Username");
//String password = sh.getAttribute("Password");
System.out.println("uid:"+username);
//System.out.println("pass: "+password);
context.put("Username", username);
//context.put("Passsword", password);
// default scope is HANDLER (i.e., not readable by SEI
// implementation)
context.setScope("Username", MessageContext.Scope.APPLICATION);
樣品 TestUser wsse:Username> TestPassword wsse:Password> wsse:UsernameToken> wsse:Security> –
user2036302
然後,您的郵件根本不包含標頭。你確定這個標題是它應該在哪裏? –
實際上,用戶名和密碼不是soap頭元素的屬性(它們是嵌套元素)。 – user2036302