设置 SOAP-Header
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-
open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
wssecurity-utility-1.0.xsd">
<wsse:Username>East</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-
200401-wss-username-token-profile-1.0#PasswordText">XTsaiyy</
wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body><ns3:getAllCountries
xmlns:ns2="http://schema.ultraservice.neustar.com/v01/"
xmlns:ns3="http://webservice.api.ultra.neustar.com/v01/"/></soapenv:Bo
dy>
</soapenv:Envelope>
红色部分为 SOAP-header 哪么我们要怎么设置 Client 中加入 SOAP-
Header 来做相关的验证信息呢!代码实现如下:
1. HeaderHandler.java
package cn.knet.ultradns.soap.header;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
/*
<wsse:Security soapenv:mustUnderstand="1"