2017-07-21 73 views
1

我有有一個方法用2個PARAMS服務的方法:JAXB解組的XML文檔anytype類型

public int ReadXmlDocAsString(@WebParam(name = "password") String password, 
            @WebParam(name = "doc") com.vincari.hl7.jaxws.xmlDoc<Object> doc){ 

    } 

我xmlDoc中類如下:

public class xmlDoc<T> { 
@XmlMixed 
@XmlAnyElement(lax = true) 
protected List<T> content; 
public List<T> getContent() { 
    if (content == null) { 
     content = new ArrayList<T>(); 
    } 
    return this.content; 
} 
public void setContent() { 
    content = this.content; 
} 
} 

和我的樣品皁要求是:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sample="http://sample.vincari.com/"> 
<soap:Header/> 
<soap:Body> 
     <sample:ReadXmlDocAsString> 
     <!--Optional:--> 
     <password>1234</password> 
     <!--Zero or more repetitions:--> 
     <doc> 
     <Header Application="SourceApp"> 
     <CustomerData> 
     <Customer AccountNumber="1234" customername="ABCD"> 
     </Customer> 
     <CustomerData> 
     </Header> 
     </doc> 
     </sample:InsertPatientInfoImpl> 
    </soap:Body> 
</soap:Envelope> 

我能夠使用cxf部署webservice。但是當我嘗試映射doc對象並嘗試將其作爲字符串獲取時。我用toString並嘗試使用DOMSource進行轉換。我怎樣才能將其轉換爲字符串。任何幫助非常感謝。

回答

1
Document inputDoc = ((Element) doc.getContent().get(0)).getOwnerDocument(); 
String inputPayload = ""; 
StringWriter sw = new StringWriter(); 
      TransformerFactory tf = TransformerFactory.newInstance(); 
      Transformer transformer = tf.newTransformer(); 
      transformer.transform(new DOMSource(inputDoc), new StreamResult(sw)); 
      inputPayload = sw.toString(); 
      System.out.println("Read the input stream successfully "+ inputPayload); 

當您在wsdl參數中使用anytype進行映射時。它將映射到一個列表或其他集合,然後我們需要使用DOM將它映射到一個字符串。