2016-06-16 1 views
3

XML文書をSOAPヘッダーに挿入するための明確な方法(文字列連結なし)はありますか?私はスキーマをコンパイルするためにJAXBを使用しましたが、今はSOAPエンベロープでラップする必要があります。私が使用したボディ用 :JavaのSOAPヘッダーにXMLを挿入する方法

SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); 
soapMessage.getSOAPBody().addDocument(userDataDocument); 

は今ヘッダーのために私はまた、ドキュメントを追加する必要がありますが、APIは以前、私が簡単である文字列の連結を使用しますが

addDocument 

を持っていません私の心の中で最も柔軟な方法ではありません。 私は単なるQnameを追加するのではなく、XML文書全体を追加しています。 これを行う方法はありますか?

答えて

3

は... addDocumentのソースを使用して、これを考え出し

public static SOAPBodyElement addDocumentToSoapHeader(Document document, SOAPMessage soapMessage) throws SOAPException { 
    SOAPBodyElement newBodyElement = null; 
    DocumentFragment docFrag = document.createDocumentFragment(); 
    Element rootElement = document.getDocumentElement(); 
    if(rootElement != null) { 
     docFrag.appendChild(rootElement); 
     Document ownerDoc = soapMessage.getSOAPHeader().getOwnerDocument(); 
     org.w3c.dom.Node replacingNode = ownerDoc.importNode(docFrag, true); 
     //this.addNode(replacingNode); 
     soapMessage.getSOAPHeader().appendChild(replacingNode); 

    } 

    return newBodyElement; 
} 
関連する問題