Axis2 wsdl2java抛出InvocationTargetException

时间:2016-08-29 10:46:50

标签: xml jaxb axis2 wsdl2java

我遇到了使用axis2从wsdl生成Java代码的问题(尝试使用版本1.6.2和1.7.3): 使用这个工具(wsdl2java -uri%MY_WSDL_LOCATION%-d jaxbri),我得到:

Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:294)
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:50)
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.apache.axis2.wsdl.codegen.extension.JAXBRIExtension.engage(JAXBRIExtension.java:112)
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:247)
... 2 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.axis2.wsdl.codegen.extension.JAXBRIExtension.engage(JAXBRIExtension.java:101)
... 3 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Unable to generate code using jaxbri
at org.apache.axis2.jaxbri.CodeGenerationUtility.processSchemas(CodeGenerationUtility.java:355)
... 8 more
Caused by: java.lang.RuntimeException: Unable to generate code using jaxbri
at org.apache.axis2.jaxbri.CodeGenerationUtility.processSchemas(CodeGenerationUtility.java:247)
... 8 more

我正在使用的wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://rg.ru/ens" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://site.ru/ens">
<types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://site.ru/ens">
        <s:element name="GetGiftCardBalance">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" name="CardNumber" type="s:string"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="GetGiftCardBalanceResponse">
            <s:complexType>
                <s:sequence>
                    <s:element name="GetGiftCardBalanceResult" type="s0:Balance"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:complexType name="Balance">
            <s:sequence>
                <s:element minOccurs="0" name="CardNumber" type="s:string"/>
                <s:element minOccurs="0" name="Value" type="s:string"/>
                <s:element minOccurs="0" name="Status" type="s0:Status"/>
            </s:sequence>
        </s:complexType>
        <s:complexType name="Status">
            <s:sequence>
                <s:element minOccurs="0" name="code" type="s:long"/>
                <s:element minOccurs="0" name="description">
                    <s:simpleType>
                        <s:restriction base="s:string">
                            <s:maxLength value="1000"/>
                        </s:restriction>
                    </s:simpleType>
                </s:element>
                <s:element minOccurs="0" name="type">
                    <s:simpleType>
                        <s:restriction base="s:string">
                            <s:enumeration value="PLAIN"/>
                            <s:enumeration value="HTML"/>
                        </s:restriction>
                    </s:simpleType>
                </s:element>
            </s:sequence>
        </s:complexType>
        <s:element name="dayClosing">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" name="day" type="s:date"/>
                    <s:element minOccurs="0" name="shop">
                        <s:simpleType>
                            <s:restriction base="s:string">
                                <s:maxLength value="2"/>
                            </s:restriction>
                        </s:simpleType>
                    </s:element>
                    <s:element minOccurs="0" name="cashbox" type="s:long"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="dayClosingResponse">
            <s:complexType>
                <s:sequence>
                    <s:element name="dayClosingResult" type="s0:DayClosingResponse"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:complexType name="DayClosingResponse">
            <s:sequence>
                <s:element minOccurs="0" name="status" type="s0:Status"/>
                <s:element minOccurs="0" name="operations" type="s0:ArrayOfItemsOperation"/>
            </s:sequence>
        </s:complexType>
        <s:complexType name="ArrayOfItemsOperation">
            <s:sequence>
                <s:element maxOccurs="unbounded" minOccurs="0" name="Items" nillable="true" type="s0:Operation"/>
            </s:sequence>
        </s:complexType>
        <s:complexType name="Operation">
            <s:sequence>
                <s:element minOccurs="0" name="eventStamp" type="s:dateTime"/>
                <s:element minOccurs="0" name="card" type="s:string"/>
                <s:element minOccurs="0" name="sum" type="s:long"/>
            </s:sequence>
        </s:complexType>
        <s:element name="getGiftCardBalanceWithPIN">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" name="PINCode" type="s:string"/>
                    <s:element minOccurs="0" name="CardNumber" type="s:string"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="getGiftCardBalanceWithPINResponse">
            <s:complexType>
                <s:sequence>
                    <s:element name="getGiftCardBalanceWithPINResult" type="s0:Balance"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="purchase">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" name="card" type="s:string"/>
                    <s:element minOccurs="0" name="sum" type="s:long"/>
                    <s:element minOccurs="0" name="OrderNumber" type="s:string"/>
                    <s:element minOccurs="0" name="shop">
                        <s:simpleType>
                            <s:restriction base="s:string">
                                <s:maxLength value="2"/>
                            </s:restriction>
                        </s:simpleType>
                    </s:element>
                    <s:element minOccurs="0" name="cashbox" type="s:long"/>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="purchaseResponse">
            <s:complexType>
                <s:sequence>
                    <s:element name="purchaseResult" type="s0:Status"/>
                </s:sequence>
            </s:complexType>
        </s:element>
    </s:schema>
</types>
<message name="GetGiftCardBalanceSoapIn">
    <part name="parameters" element="s0:GetGiftCardBalance"/>
</message>
<message name="GetGiftCardBalanceSoapOut">
    <part name="parameters" element="s0:GetGiftCardBalanceResponse"/>
</message>
<message name="dayClosingSoapIn">
    <part name="parameters" element="s0:dayClosing"/>
</message>
<message name="dayClosingSoapOut">
    <part name="parameters" element="s0:dayClosingResponse"/>
</message>
<message name="getGiftCardBalanceWithPINSoapIn">
    <part name="parameters" element="s0:getGiftCardBalanceWithPIN"/>
</message>
<message name="getGiftCardBalanceWithPINSoapOut">
    <part name="parameters" element="s0:getGiftCardBalanceWithPINResponse"/>
</message>
<message name="purchaseSoapIn">
    <part name="parameters" element="s0:purchase"/>
</message>
<message name="purchaseSoapOut">
    <part name="parameters" element="s0:purchaseResponse"/>
</message>
<portType name="ProcessingSoap">
    <operation name="GetGiftCardBalance">
        <input message="s0:GetGiftCardBalanceSoapIn"/>
        <output message="s0:GetGiftCardBalanceSoapOut"/>
    </operation>
    <operation name="dayClosing">
        <input message="s0:dayClosingSoapIn"/>
        <output message="s0:dayClosingSoapOut"/>
    </operation>
    <operation name="getGiftCardBalanceWithPIN">
        <input message="s0:getGiftCardBalanceWithPINSoapIn"/>
        <output message="s0:getGiftCardBalanceWithPINSoapOut"/>
    </operation>
    <operation name="purchase">
        <input message="s0:purchaseSoapIn"/>
        <output message="s0:purchaseSoapOut"/>
    </operation>
</portType>
<binding name="ProcessingSoap" type="s0:ProcessingSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="GetGiftCardBalance">
        <soap:operation soapAction="http://site.ru/ens/giftcards.Processing.GetGiftCardBalance" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="dayClosing">
        <soap:operation soapAction="http://site.ru/ens/giftcards.Processing.dayClosing" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="getGiftCardBalanceWithPIN">
        <soap:operation soapAction="http://site.ru/ens/giftcards.Processing.getGiftCardBalanceWithPIN" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="purchase">
        <soap:operation soapAction="http://site.ru/ens/giftcards.Processing.purchase" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
</binding>
<service name="Processing">
    <port name="ProcessingSoap" binding="s0:ProcessingSoap">
        <soap:address location="http://ip:57772/csp/crm/giftcards.Processing.cls"/>
    </port>
</service>
</definitions>

我在Windows 10,Windows 7 PC上尝试了这个,效果相同。

1 个答案:

答案 0 :(得分:2)

生成的类名中存在名称冲突。如果你运行wsimport,你会看到错误:

[ERROR] A class/interface with the same name "ru.rg.ens.DayClosingResponse" is already in use. Use a class customization to resolve this conflict.

您可以通过将结果元素的类型名称从 DayClosingResponse 更改为 DayClosingResponseType 进行修复,以便它不会与包装器元素名称冲突,例如:用:

    <s:element name="dayClosingResponse">
        <s:complexType>
            <s:sequence>
                <s:element name="dayClosingResult" type="s0:DayClosingResponseType"/>
            </s:sequence>
        </s:complexType>
    </s:element>
    <s:complexType name="DayClosingResponseType">
        <s:sequence>
            <s:element minOccurs="0" name="status" type="s0:Status"/>
            <s:element minOccurs="0" name="operations" type="s0:ArrayOfItemsOperation"/>
        </s:sequence>
    </s:complexType>