1 //从MessageContet中获取头域中的值 2 public HeaderBean getBeanFromRequest(org.apache.axis2.context.MessageContext msgContext) 3 { 4 HeaderBean headerBean = new HeaderBean(); 5 org.apache.axiom.soap.SOAPHeader headers = (org.apache.axiom.soap.SOAPHeader)msgContext.getEnvelope().getHeader(); 6 Iterator iterator = headers.getChildElements(); 7 try 8 { 9 while(iterator.hasNext()) 10 { 11 OMElement omheader = (OMElement) iterator.next(); 12 if (omheader == null) 13 { 14 break; 15 } 16 else if ("MessageID".equals(omheader.getLocalName())) 17 { 18 String MessageID = omheader.getText().trim(); 19 headerBean.setMessageID(MessageID); 20 /*System.out.println((new StringBuilder()) 21 .append("notifyParticipantState : MessageID --> ") 22 .append(MessageID).toString());*/ 23 } 24 else if ("MEName".equals(omheader.getLocalName())) 25 { 26 String MEName = omheader.getText().trim(); 27 headerBean.setmEName(MEName); 28 /*System.out.println((new StringBuilder()) 29 .append("notifyParticipantState : MEName --> ") 30 .append(MEName).toString());*/ 31 } 32 else if ("Authentication".equals(omheader.getLocalName())) 33 { 34 String Authentication = omheader.getText().trim(); 35 Iterator authIterator = omheader.getChildElements(); 36 System.out.println((new StringBuilder()) 37 .append("notifyParticipantState : Authentication --> ") 38 .append(Authentication).toString()); 39 while(authIterator.hasNext()) 40 { 41 OMElement omlement = (OMElement) authIterator.next(); 42 if (omlement == null) 43 { 44 break; 45 } 46 else if ("Username".equals(omlement.getLocalName())) 47 { 48 String userName = omlement.getText().trim(); 49 headerBean.setUsername(userName); 50 /*System.out.println((new StringBuilder()) 51 .append("notifyParticipantState : Username --> ") 52 .append(Username).toString());*/ 53 } 54 else if ("Password".equals(omlement.getLocalName())) 55 { 56 String password = omlement.getText().trim(); 57 headerBean.setPassword(password); 58 /*System.out.println((new StringBuilder()) 59 .append("notifyParticipantState : Password --> ") 60 .append(Password).toString());*/ 61 } 62 } 63 } 64 } 65 } 66 catch(Exception ex) 67 { 68 ex.printStackTrace(); 69 } 70 71 return headerBean; 72 }
header头消息如下:
1 <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 2 <mgr:MessageID xmlns:mgr="http://mgr.soap.boss.bmp.ecs.huawei.com.MEDIAX">123</mgr:MessageID> 3 <mgr:MEName xmlns:mgr="http://mgr.soap.boss.bmp.ecs.huawei.com.MEDIAX">123</mgr:MEName> 4 <mgr:Authentication xmlns:mgr="http://mgr.soap.boss.bmp.ecs.huawei.com.MEDIAX"> 5 <mgr:Username>test</mgr:Username> 6 <mgr:Password>test</mgr:Password> 7 </mgr:Authentication> 8 </soapenv:Header>