title: CXF java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to com.tibco.ur.schemas.getocr.Output
body: <p>I have a WSDL that defines an "anyType" element :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--Created by TIBCO WSDL--&gt;
  &lt;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"&gt;
      &lt;wsdl:types&gt;
          &lt;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"&gt;
  
              &lt;xs:import namespace="http://www.tibco.com/UR/schemas/GetBranch" schemaLocation="GetBranch.xsd" /&gt;
              &lt;xs:import namespace="http://www.tibco.com/UR/schemas/GetOCR" schemaLocation="GetOCR.xsd" /&gt;
  
              ...
              &lt;xs:complexType name="ResultList"&gt;
                  &lt;xs:sequence&gt;
                      &lt;xs:element name="Result" minOccurs="0" maxOccurs="unbounded"&gt;
                          &lt;xs:complexType&gt;
                              &lt;xs:sequence&gt;
                                  &lt;xs:element name="Status"&gt;
                                      &lt;xs:complexType&gt;
                                          &lt;xs:sequence&gt;
                                              &lt;xs:element name="Return" type="xs:int"/&gt;
                                              &lt;xs:element name="Message" type="xs:string"/&gt;
                                          &lt;/xs:sequence&gt;
                                      &lt;/xs:complexType&gt;
                                  &lt;/xs:element&gt;
                                  &lt;xs:element ref="gws:Input" minOccurs="0"/&gt;
                                  &lt;xs:element ref="gws:Output" minOccurs="0" maxOccurs="unbounded"/&gt;
                              &lt;/xs:sequence&gt;
                              &lt;xs:attribute name="QiD" type="xs:string"/&gt;
                              &lt;xs:attribute name="Service" type="xs:string"/&gt;
                              &lt;xs:attribute name="Version" type="xs:string"/&gt;
                          &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                  &lt;/xs:sequence&gt;
                  &lt;xs:attribute name="TiD" type="xs:string"/&gt;
              &lt;/xs:complexType&gt;
              &lt;xs:element name="Input" type="xs:anyType"/&gt;
              &lt;xs:element name="Output" type="xs:anyType"/&gt;
              &lt;xs:element name="Queries" type="gws:QueryList"/&gt;
              &lt;xs:element name="Results" type="gws:ResultList"/&gt;
          &lt;/xs:schema&gt;
      &lt;/wsdl:types&gt;
      &lt;wsdl:service name="GenericWS.Service"&gt;
          &lt;wsdl:port name="PortTypeEndpoint" binding="tns:PortTypeEndpointBinding"&gt;
              &lt;soap:address location="http://localhost:8101/Generic/GenericWS.Service.serviceagent/PortTypeEndpoint"/&gt;
          &lt;/wsdl:port&gt;
      &lt;/wsdl:service&gt;
      &lt;wsdl:portType name="PortType"&gt;
          &lt;wsdl:operation name="Operation"&gt;
              &lt;wsdl:input message="tns:Request"/&gt;
              &lt;wsdl:output message="tns:Response"/&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:portType&gt;
      &lt;wsdl:binding name="PortTypeEndpointBinding" type="tns:PortType"&gt;
          &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
          &lt;wsdl:operation name="Operation"&gt;
              &lt;soap:operation style="document" soapAction="/Generic/GenericWS.Service.serviceagent/PortTypeEndpoint/Operation"/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use="literal" parts="Input"/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use="literal" parts="Output"/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:binding&gt;
      &lt;wsdl:message name="Request"&gt;
          &lt;wsdl:part name="Input" element="tns:Queries"/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="Response"&gt;
          &lt;wsdl:part name="Output" element="tns:Results"/&gt;
      &lt;/wsdl:message&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>It uses the GetOCR.xsd as you can see :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:spe="http://www.tibco.com/UR/schemas/GetOCR"
       targetNamespace="http://www.tibco.com/UR/schemas/GetOCR"
       elementFormDefault="qualified"
       attributeFormDefault="unqualified"&gt;
      &lt;xs:complexType name="Input"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="CO_EXTREF" type="xs:string"&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name="ValidTodayOnly" type="xs:boolean" minOccurs="0"&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="Output"&gt;
          &lt;xs:annotation&gt;
              &lt;xs:documentation&gt;Specific Output for GetBransh generic service.&lt;/xs:documentation&gt;
          &lt;/xs:annotation&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Store" minOccurs="0" maxOccurs="unbounded"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:complexContent&gt;
                          &lt;xs:extension base="spe:Simple"&gt;
                              &lt;xs:sequence&gt;
                                  &lt;xs:element name="OCR" minOccurs="0" maxOccurs="unbounded"&gt;
                                      &lt;xs:complexType&gt;
                                          &lt;xs:sequence&gt;
                                              &lt;xs:element name="Date" type="spe:YearMonth"/&gt;
                                              &lt;xs:element name="Sales" type="spe:Amount"/&gt;
                                              &lt;xs:element name="Cost" type="spe:Amount"/&gt;
                                          &lt;/xs:sequence&gt;
                                      &lt;/xs:complexType&gt;
                                  &lt;/xs:element&gt;
                              &lt;/xs:sequence&gt;
                          &lt;/xs:extension&gt;
                      &lt;/xs:complexContent&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="Simple"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="ID" type="xs:int"/&gt;
              &lt;xs:element name="Label" type="xs:string"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="YearMonth"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Year" type="xs:integer"/&gt;
              &lt;xs:element name="Month" type="xs:integer"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="Amount"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="VatType" type="xs:string"/&gt;
              &lt;xs:element name="Currency" type="xs:string"/&gt;
              &lt;xs:element name="Amount" type="xs:decimal"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I generated the class files in Maven :</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
      &lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.7.8&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;generate-sources-cxf-Generic&lt;/id&gt;
              &lt;phase&gt;generate-sources&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;wsdlRoot&gt;${basedir}/src/main/resources/wsdl&lt;/wsdlRoot&gt;
                  &lt;sourceRoot&gt;${project.build.directory}/generated/cxf&lt;/sourceRoot&gt;
                  &lt;wsdlOptions&gt;
                      &lt;wsdlOption&gt;
                          &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/GenericWS.wsdl&lt;/wsdl&gt;
                          &lt;extraargs&gt;
                              &lt;extraarg&gt;-client&lt;/extraarg&gt;
                          &lt;/extraargs&gt;
                      &lt;/wsdlOption&gt;
                  &lt;/wsdlOptions&gt;
              &lt;/configuration&gt;
              &lt;goals&gt;
                  &lt;goal&gt;wsdl2java&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>I do call the web service with CXF :</p>
  
  <pre><code>final GenericWSService genericWSService = new GenericWSService();
  final PortType portType = genericWSService.getPortTypeEndpoint();
  ...
  final ResultList resultList = portType.operation(queryList);
  </code></pre>
  
  <p>The returned XML :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns0:Results xmlns:ns0="http://www.tibco.com/UR/schemas/GenericWS"&gt;
              &lt;ns0:Result Service="GetOCR" QiD="ref_89100-00281"
                  Version="00"&gt;
                  &lt;ns0:Status&gt;
                      &lt;ns0:Return&gt;0&lt;/ns0:Return&gt;
                      &lt;ns0:Message&gt;Ok&lt;/ns0:Message&gt;
                  &lt;/ns0:Status&gt;
                  &lt;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"&gt;
                      &lt;tibco_c2s_ns0:CO_EXTREF&gt;89100-00281&lt;/tibco_c2s_ns0:CO_EXTREF&gt;
                      &lt;tibco_c2s_ns0:ValidTodayOnly&gt;false&lt;/tibco_c2s_ns0:ValidTodayOnly&gt;
                  &lt;/ns0:Input&gt;
                  &lt;ns0:Output&gt;
                      &lt;ns1:Store xmlns:ns1="http://www.tibco.com/UR/schemas/GetOCR"&gt;
                          &lt;ns1:ID&gt;4814&lt;/ns1:ID&gt;
                          &lt;ns1:Label&gt;FOOT LOCKER&lt;/ns1:Label&gt;
                          &lt;ns1:OCR&gt;
                              &lt;ns1:Date&gt;
                                  &lt;ns1:Year&gt;2014&lt;/ns1:Year&gt;
                                  &lt;ns1:Month&gt;3&lt;/ns1:Month&gt;
                              &lt;/ns1:Date&gt;
                              &lt;ns1:Sales&gt;
                                  &lt;ns1:VatType&gt;NET&lt;/ns1:VatType&gt;
                                  &lt;ns1:Currency&gt;EUR&lt;/ns1:Currency&gt;
                                  &lt;ns1:Amount&gt;1728832.0&lt;/ns1:Amount&gt;
                              &lt;/ns1:Sales&gt;
  </code></pre>
  
  <p>I can go throught this response until i enter into the xsd part :</p>
  
  <pre><code>final List&lt;ResultList.Result&gt; 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&lt;Object&gt; outputs = result.getOutput();
  
                  for (final Object output : outputs) {
  
                      final Output outputOCR = (Output) output;
  
                      final List&lt;Output.Store&gt; stores = outputOCR.getStore();
  </code></pre>
  
  <p>The last line throws an "java.lang.ClassCastException" (of course) :</p>
  
  <pre><code>java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to com.tibco.ur.schemas.getocr.Output
  </code></pre>
  
  <p>I've tried many things (with ElementNSImpl) but nothing works :-(</p>
  
  <p>Any idea would be welcome...</p>
  
  <p>Th.</p>