2

几天以来,我一直在努力解决一个奇怪的问题。客户提供 Web 服务和 WSDL。我通过使用 wsimport 和一些 jaxb 自定义来导入 WSDL。生成所有 Java 类都没有任何错误。

当我使用 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:type 被忽略。特别是因为在其他也使用子类的元素中它工作得很好。

我还用当前的 JAXBRI 替换了 JDK 附带的默认 jaxb - 仍然是同样的错误。

有谁知道出了什么问题?我想,我已经“被线蒙蔽了”:-/

问候 MausFan

4

2 回答 2

1

您比我处于更好的位置。由于应用程序服务器,我绑定到 Java 1.5。在这种一般情况下,仍然没有解决方案,请参阅 http://java.net/jira/browse/JAXB-890

于 2012-03-21T16:31:22.000 回答
1

您的问题与此处报告的问题相同。它仍然在 Java 1.6.0_27 中体现出来,它似乎对应于 jaxb-ri-2.2-147。但是,如果使用 Java 1.7.0_02 执行相同的代码,则一切正常。这表明您正在使用的 JAXB 版本存在问题,因此请尝试切换到新的 JAXB/JDK(在我的情况下,成功的测试是在带有 JDK 1.7.0_02 的 NetBeans 7.1 上运行的)。

于 2012-02-06T16:52:27.253 回答