2012-02-06 71 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