2012-02-06 74 views
2

自從幾天以來,我一直在與一個奇怪的問題鬥爭。客戶提供Webservice 和WSDL。我通過使用wsimport和一些jaxb自定義來導入WSDL。所有Java 類都生成沒有任何錯誤。JAXB:Unmarshaller嘗試實例化抽象類(忽略xsi:類型)

當我使用Java類來解讀我得到了下面的異常的反應:

06.02.2012 09:18:50 com.sun.xml.bind.v2.ClassFactory create 
INFO: failed to create a new instance of class net.bipro.v2_1_0_1_0.namespace.datentypen.STEGefahr 
java.lang.InstantiationException 
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:122) 
    at com.sun.xml.bind.v2.ClassFactory.create(ClassFactory.java:131) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:609) 
    at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl$TransducerImpl.parse(RuntimeClassInfoImpl.java:392) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.TextLoader.text(TextLoader.java:69) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:514) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.processText(SAXConnector.java:181) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.endElement(SAXConnector.java:154) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:217) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:189) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:142) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:151) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:169) 
    at de.company.bipro.tarifierung.TestApp.<init>(TestApp.java:39) 
    at de.company.bipro.tarifierung.TestApp.main(TestApp.java:143) 

我響應對象減少到最小有效的XML:

<taa:getQuoteResponse 
    xmlns:taa="http://www.bipro.net/namespace/tarifierung" 
    xmlns:leben="http://www.bipro.net/namespace/leben" 
    xmlns:sachen="http://www.bipro.net/namespace/sachen" 
    xmlns:haftpflicht="http://www.bipro.net/namespace/haftpflicht" 
    xmlns:fahrzeug="http://www.bipro.net/namespace/fahrzeug" 
    xmlns:xyzkfz="http://www.xyz.de/kfz/namespace" 
    xmlns:xyz-komposit="http://www.xyz.de/komposit/namespace" 
    xmlns:sach="http://www.bipro.net/namespace/sach" 
    xmlns:xyzleben="http://www.xyz.de/leben/namespace" 
    xmlns:xyz="http://www.xyz.de/namespace" 
    xmlns:partner="http://www.bipro.net/namespace/partner" 
    xmlns:mime="http://www.w3.org/2005/05/xmlmime" 
    xmlns:komposit="http://www.bipro.net/namespace/komposit" 
    xmlns:kfz="http://www.bipro.net/namespace/kraftfahrt" 
    xmlns:allgemein="http://www.bipro.net/namespace/allgemein"> 
    <taa:Response>  
    <taa:Tarifierung>  
     <taa:Verkaufsprodukt>   
     <taa:Produkt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="komposit:CT_SUHVersicherung">   
      <taa:Elementarprodukt xsi:type="komposit:CT_Deckung">    
      <komposit:Gefahr xmlns:daten="http://www.bipro.net/namespace/datentypen" xsi:type="daten:STE_GefahrBasis">L</komposit:Gefahr>    
      </taa:Elementarprodukt> 
     </taa:Produkt> 
     </taa:Verkaufsprodukt>  
    </taa:Tarifierung> 
    </taa:Response> 
</taa:getQuoteResponse> 

下面是數據類型定義:

<xsd:complexType abstract="true" name="STE_Gefahr"> 
    <xsd:simpleContent> 
     <xsd:extension base="xsd:string"/> 
    </xsd:simpleContent> 
</xsd:complexType> 

<xsd:complexType final="#all" name="STE_GefahrBasis"> 
    <xsd:simpleContent> 
     <xsd:restriction base="daten:STE_Gefahr"> 
      <xsd:enumeration value="F"><xsd:annotation><xsd:documentation>Feuer</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="L"><xsd:annotation><xsd:documentation>Leitungswasser</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="S"><xsd:annotation><xsd:documentation>Sturm</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="H"><xsd:annotation><xsd:documentation>Hagel</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="E"><xsd:annotation><xsd:documentation>Einbruchdiebstahl</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="G"><xsd:annotation><xsd:documentation>Glas</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="U"><xsd:annotation><xsd:documentation>Ueberspannungsschaeden</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="N"><xsd:annotation><xsd:documentation>Nutzfeuer</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M"><xsd:annotation><xsd:documentation>Elementarschaeden (alle Gefahren)</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="B"><xsd:annotation><xsd:documentation>Beraubung</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M01"><xsd:annotation><xsd:documentation>Ueberschwemmung</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M02"><xsd:annotation><xsd:documentation>Erdbeben</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M03"><xsd:annotation><xsd:documentation>Schneedruck</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M04"><xsd:annotation><xsd:documentation>Erdrutsch</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M05"><xsd:annotation><xsd:documentation>Vulkanausbruch</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M06"><xsd:annotation><xsd:documentation>Lawine</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M07"><xsd:annotation><xsd:documentation>Rueckstau</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M08"><xsd:annotation><xsd:documentation>Erdsenkung</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M09"><xsd:annotation><xsd:documentation>Starkregen</xsd:documentation></xsd:annotation></xsd:enumeration> 
      <xsd:enumeration value="M99"><xsd:annotation><xsd:documentation>sonstige Elementarschaeden</xsd:documentation></xsd:annotation></xsd:enumeration> 
     </xsd:restriction> 
    </xsd:simpleContent> 
</xsd:complexType> 

我不知道爲什麼xsi:類型被忽略。特別是因爲在其他元素中, 也使用子類它工作正常。

我也用當前的JAXBRI替換了JDK自帶的默認jaxb - 仍然是 同樣的錯誤。

有沒有人有一個想法是什麼錯?我想,我已經「矇蔽由線」: -/

問候 MausFan

回答

1

你的問題是一樣的一個報道here。它仍然以Java 1.6.0_27顯示,這似乎與jaxb-ri-2.2-147相對應。但是,如果使用Java 1.7.0_02執行相同的代碼,所有工作都正常。這指出了您正在使用的JAXB版本的問題,因此請嘗試切換到新的JAXB/JDK(在我的情況下,成功的測試在NetBeans 7.1 w/JDK 1.7.0_02上運行)。

+0

感謝您的回答。雖然我安裝了JDK 7u2,但我仍然遇到同樣的錯誤。但爲了確定這一點,我將檢查CLASSPATH和使用的檔案。 – MausFan 2012-02-07 13:15:58

+0

肯定它必須工作。我能夠重現它,並通過切換到1.7,讓它消失。我能夠從示例XML中讀取「L」,所以解組是成功的。 – 2012-02-07 14:23:32