使用apache.cxf.headers.Header创建自定义soap标头

时间:2017-03-15 15:15:05

标签: java xml apache soap cxf

我想创建一个Soap头结构,如下所示:

<soapenv:Header>
      <wataniya:auth xmlns:wataniya="http://osb.wataniya.com">
         <username> TestUser</username>
         <password> TestPassword </password>
      </wataniya:auth>
</soapenv:Header>

我写了一段代码:

QName qName = new QName("http://osb.wataniya.com", "auth", "watania"); 

        Element authElement = doc.getDocumentElement();

        Element usernameElement = doc.createElement("username");
        usernameElement.setTextContent("TestUser");

        Element passwordElement = doc.createElement("password");
        passwordElement.setTextContent("TestPassword");

        authElement.appendChild(usernameElement);
        authElement.appendChild(passwordElement);

        Header header =  new Header(qName, authElement);

我使用了以下导入(供参考):

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.camel.CamelExecutionException;
import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.headers.Header;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.MessageContentsList;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

但我遇到问题,无法按预期生成标题。

任何线索......提前谢谢

0 个答案:

没有答案