2013-04-30 8 views
5

का उपयोग करते हुए संदेश जब मैं SOAP संदेश से नीचे unrmarshall, मुझे अपवाद मिल रहा है। क्या कोई मुझे बता सकता है कि क्या गलत है?Unmarshall SOAP संदेश JAXB

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:hios="http://schemas.datacontract.org/2004/07/HIOSCommonObjects"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:ValidIssuersProducts> 
     <!--Optional:--> 
     <tem:li> 
      <!--Zero or more repetitions:--> 
      <hios:IssuerProductRequest> 
       <!--Optional:--> 
       <hios:Issuer>33104</hios:Issuer> 
       <!--Optional:--> 
       <hios:Product>33104VA001</hios:Product> 
      </hios:IssuerProductRequest> 
     </tem:li> 
     </tem:ValidIssuersProducts> 
    </soapenv:Body> 
</soapenv:Envelope> 

Unmarshalling कोड के रूप में नीचे है, clazz "ValidIssuersProducts की पूरी तरह से योग्य नाम" अनुरोध है।

public static <T> Object unmarshall(String xml, String clazz) throws ClassNotFoundException, JAXBException { 
     JAXBContext context = JAXBContext.newInstance(Class.forName(clazz)); 
     ByteArrayInputStream input = new ByteArrayInputStream (xml.getBytes());  
     Unmarshaller unmarshaller = context.createUnmarshaller(); 
     //JAXBElement<ValidIssuersProducts> obj = (JAXBElement<ValidIssuersProducts>) unmarshaller.unmarshal(new StreamSource(input), ValidIssuersProducts.class); 

     ValidIssuersProducts value = (ValidIssuersProducts)unmarshaller.unmarshal(input); 
     return value; 

    } 

मैं अपवाद नीचे हो रही है:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{http://tempuri.org/}ArrayOfIssuerProductRequest>,<{http://tempuri.org/}ArrayOfIssuerProductResponse>,<{http://tempuri.org/}IssuerProductRequest>,<{http://tempuri.org/}IssuerProductResponse>,<{http://tempuri.org/}ValidIssuersProducts>,<{http://tempuri.org/}ValidIssuersProductsResponse> 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1049) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148) 
    at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239) 
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122) 

उत्तर

5

आप नेस्टेड तत्व ValidIssuersProducts जो अपने मैप की सामग्री के बजाय सोप Envelope तत्व से मेल खाती है से unmarshal की जरूरत है। आप XML को पार्स करने के लिए एक स्थिर XMLStreamReader का उपयोग कर सकते हैं और सही तत्व पर अग्रिम कर सकते हैं और फिर उस बिंदु पर 'XMLStreamReader से unmarshal का उपयोग कर सकते हैं।

अधिक जानकारी के लिए

संबंधित मुद्दे