CXF java.lang.ClassCastException:com.sun.org.apache.xerces.internal.dom.ElementNSImpl无法强制转换为com.tibco.ur.schemas.getocr.Output
我有一个定义“anyType”元素的WSDL:CXF java.lang.ClassCastException:com.sun.org.apache.xerces.internal.dom.ElementNSImpl无法强制转换为com.tibco.ur.schemas.getocr.Output,java,xml,web-services,xsd,cxf,Java,Xml,Web Services,Xsd,Cxf,我有一个定义“anyType”元素的WSDL: <?xml version="1.0" encoding="UTF-8"?> <!--Created by TIBCO WSDL--> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.tibco.com/UR/schemas/GenericWS" xmlns:soap="htt
<?xml version="1.0" encoding="UTF-8"?>
<!--Created by TIBCO WSDL-->
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.tibco.com/UR/schemas/GenericWS" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="Untitled" targetNamespace="http://www.tibco.com/UR/schemas/GenericWS">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gws="http://www.tibco.com/UR/schemas/GenericWS" targetNamespace="http://www.tibco.com/UR/schemas/GenericWS" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.tibco.com/UR/schemas/GetBranch" schemaLocation="GetBranch.xsd" />
<xs:import namespace="http://www.tibco.com/UR/schemas/GetOCR" schemaLocation="GetOCR.xsd" />
...
<xs:complexType name="ResultList">
<xs:sequence>
<xs:element name="Result" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Status">
<xs:complexType>
<xs:sequence>
<xs:element name="Return" type="xs:int"/>
<xs:element name="Message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="gws:Input" minOccurs="0"/>
<xs:element ref="gws:Output" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="QiD" type="xs:string"/>
<xs:attribute name="Service" type="xs:string"/>
<xs:attribute name="Version" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="TiD" type="xs:string"/>
</xs:complexType>
<xs:element name="Input" type="xs:anyType"/>
<xs:element name="Output" type="xs:anyType"/>
<xs:element name="Queries" type="gws:QueryList"/>
<xs:element name="Results" type="gws:ResultList"/>
</xs:schema>
</wsdl:types>
<wsdl:service name="GenericWS.Service">
<wsdl:port name="PortTypeEndpoint" binding="tns:PortTypeEndpointBinding">
<soap:address location="http://localhost:8101/Generic/GenericWS.Service.serviceagent/PortTypeEndpoint"/>
</wsdl:port>
</wsdl:service>
<wsdl:portType name="PortType">
<wsdl:operation name="Operation">
<wsdl:input message="tns:Request"/>
<wsdl:output message="tns:Response"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PortTypeEndpointBinding" type="tns:PortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Operation">
<soap:operation style="document" soapAction="/Generic/GenericWS.Service.serviceagent/PortTypeEndpoint/Operation"/>
<wsdl:input>
<soap:body use="literal" parts="Input"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" parts="Output"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:message name="Request">
<wsdl:part name="Input" element="tns:Queries"/>
</wsdl:message>
<wsdl:message name="Response">
<wsdl:part name="Output" element="tns:Results"/>
</wsdl:message>
</wsdl:definitions>
返回的XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:Results xmlns:ns0="http://www.tibco.com/UR/schemas/GenericWS">
<ns0:Result Service="GetOCR" QiD="ref_89100-00281"
Version="00">
<ns0:Status>
<ns0:Return>0</ns0:Return>
<ns0:Message>Ok</ns0:Message>
</ns0:Status>
<ns0:Input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tibco_c2s_ns0="http://www.tibco.com/UR/schemas/GetOCR"
xsi:type="tibco_c2s_ns0:Input">
<tibco_c2s_ns0:CO_EXTREF>89100-00281</tibco_c2s_ns0:CO_EXTREF>
<tibco_c2s_ns0:ValidTodayOnly>false</tibco_c2s_ns0:ValidTodayOnly>
</ns0:Input>
<ns0:Output>
<ns1:Store xmlns:ns1="http://www.tibco.com/UR/schemas/GetOCR">
<ns1:ID>4814</ns1:ID>
<ns1:Label>FOOT LOCKER</ns1:Label>
<ns1:OCR>
<ns1:Date>
<ns1:Year>2014</ns1:Year>
<ns1:Month>3</ns1:Month>
</ns1:Date>
<ns1:Sales>
<ns1:VatType>NET</ns1:VatType>
<ns1:Currency>EUR</ns1:Currency>
<ns1:Amount>1728832.0</ns1:Amount>
</ns1:Sales>
我尝试了很多方法(使用ElementsImpl),但都没有效果:-(
任何想法都欢迎
根据wsdl/顶级模式,“Output”元素是一个xsd:anyType。因此,JAXB将把它解组到DOM元素,除非有关于它是什么类型的信息。这基本上意味着需要一个xsi:type=“tns:Output”属性 如果您知道它将是一个输出,请更改wsdl中的模式,使输出元素的类型为Output(对于输入,我也会这样做)
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.8</version>
<executions>
<execution>
<id>generate-sources-cxf-Generic</id>
<phase>generate-sources</phase>
<configuration>
<wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/GenericWS.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
final GenericWSService genericWSService = new GenericWSService();
final PortType portType = genericWSService.getPortTypeEndpoint();
...
final ResultList resultList = portType.operation(queryList);
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:Results xmlns:ns0="http://www.tibco.com/UR/schemas/GenericWS">
<ns0:Result Service="GetOCR" QiD="ref_89100-00281"
Version="00">
<ns0:Status>
<ns0:Return>0</ns0:Return>
<ns0:Message>Ok</ns0:Message>
</ns0:Status>
<ns0:Input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tibco_c2s_ns0="http://www.tibco.com/UR/schemas/GetOCR"
xsi:type="tibco_c2s_ns0:Input">
<tibco_c2s_ns0:CO_EXTREF>89100-00281</tibco_c2s_ns0:CO_EXTREF>
<tibco_c2s_ns0:ValidTodayOnly>false</tibco_c2s_ns0:ValidTodayOnly>
</ns0:Input>
<ns0:Output>
<ns1:Store xmlns:ns1="http://www.tibco.com/UR/schemas/GetOCR">
<ns1:ID>4814</ns1:ID>
<ns1:Label>FOOT LOCKER</ns1:Label>
<ns1:OCR>
<ns1:Date>
<ns1:Year>2014</ns1:Year>
<ns1:Month>3</ns1:Month>
</ns1:Date>
<ns1:Sales>
<ns1:VatType>NET</ns1:VatType>
<ns1:Currency>EUR</ns1:Currency>
<ns1:Amount>1728832.0</ns1:Amount>
</ns1:Sales>
final List<ResultList.Result> results = resultList.getResult();
for (final ResultList.Result result : results) {
final ResultList.Result.Status status = result.getStatus();
final int codeRetour = status.getReturn();
final String message = status.getMessage();
final List<Object> outputs = result.getOutput();
for (final Object output : outputs) {
final Output outputOCR = (Output) output;
final List<Output.Store> stores = outputOCR.getStore();
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to com.tibco.ur.schemas.getocr.Output