4 Replies Latest reply on Dec 1, 2004 3:58 AM by Alon Agmon

    Problem with Deserialzing Arrays by Axis

    sidhartha Newbie

      Hello,

      I am getting the following error:

      " org.xml.sax.SAXException: SimpleDeserializer encountered a
      child element, which is NOT expected, in something it was trying
      to deserialize
      "

      I am using AXIS 1.1,Jboss4.0 and JbossWs with doc/lit Style.

      I have written a small HelloWorld application that has one method 'printMessage' that takes an array of 'Message'(user defined class) as an argument.

      Without using the array everything works fine .
      However when I add my customized type's Array I get the above error.

      Below is a summary of what was done:

      STEP - 1 :- Created a impl class and Client class
      =========
      -----------------------------------------------------------------------------------
      HelloWorld_Impl.java
      -----------------------------------------------------------------------------------
      package com.myapp;

      import java.rmi.RemoteException;
      import javax.xml.rpc.*;
      import javax.xml.rpc.server.ServiceLifecycle;

      public class HelloWorld_Impl implements HelloWorld, ServiceLifecycle
      {
      public String printMessage(ArrayOfMessage arrayOfMessage)
      {
      System.out.println("In printMessage...");
      return arrayOfMessage.toString();
      }
      }

      -----------------------------------------------------------------------------------
      HelloWorldClient.java
      -----------------------------------------------------------------------------------
      package com.myapp;

      public class HelloWorldClient
      {
      public static void main(String args[]) throws Exception
      {
      HelloWorldServiceLocator locator = new HelloWorldServiceLocator();
      Message message = new Message();
      message.setMessage("HelloWorld");
      Message array[] = { message };
      ArrayOfMessage arrayOfMessage = new ArrayOfMessage();
      arrayOfMessage.setMessages(array);
      locator.getHelloWorld().printMessage(arrayOfMessage);
      }
      }


      STEP - 2 :- configured jaxrpc-mapping.xml,webservices.xml,web.xml
      ==========
      -----------------------------------------------------------------------------------
      jaxrpc-mapping.xml
      -----------------------------------------------------------------------------------

      <?xml version='1.0' encoding='UTF-8' ?>
      <java-wsdl-mapping
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:ns1="http://ekta.com"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
      http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mapping_1_1.xsd"
      version="1.1">
      <package-mapping>
      <package-type>com.myapp</package-type>
      http://ekta.com/HelloWorld
      </package-mapping>
      <package-mapping>
      <package-type>com.myapp</package-type>
      http://ekta.com
      </package-mapping>
      <java-xml-type-mapping>
      <java-type>com.myapp.ArrayOfMessage</java-type>
      <root-type-qname>ns1:in0</root-type-qname>
      <qname-scope>element</qname-scope>
      </java-xml-type-mapping>
      <java-xml-type-mapping>
      <java-type>java.lang.String</java-type>
      <root-type-qname>ns1:printMessageReturn</root-type-qname>
      <qname-scope>element</qname-scope>
      </java-xml-type-mapping>
      </java-wsdl-mapping>


      -----------------------------------------------------------------------------------
      webservices.xml
      -----------------------------------------------------------------------------------

      <?xml version='1.0' encoding='UTF-8' ?>
      <webservices
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:impl="http://com.myapp/simple-ws4ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
      http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
      version="1.1">

      <webservice-description>
      <webservice-description-name>HelloWorldService</webservice-description-name>
      <wsdl-file>WEB-INF/wsdl/hello.wsdl</wsdl-file>
      <jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
      <port-component>
      <port-component-name>HelloWorld</port-component-name>
      <wsdl-port>HelloWorld</wsdl-port>
      <service-endpoint-interface>com.myapp.HelloWorld</service-endpoint-interface>
      <service-impl-bean>
      <servlet-link>HelloWorld</servlet-link>
      </service-impl-bean>
      </port-component>
      </webservice-description>


      -----------------------------------------------------------------------------------
      web.xml
      -----------------------------------------------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4">

      <servlet-name>HelloWorld</servlet-name>
      <servlet-class>com.myapp.HelloWorld_Impl</servlet-class>

      <servlet-mapping>
      <servlet-name>HelloWorld</servlet-name>
      <url-pattern>/services/HelloWorld</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      </welcome-file-list>
      </web-app>


      STEP 3 :- after running java2wsdl tool hello.wsdl file is created.
      =======
      -----------------------------------------------------------------------------------
      hello.wsdl
      -----------------------------------------------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <wsdl:definitions targetNamespace="http://ekta.com" xmlns:impl="http://ekta.com" xmlns:intf="http://ekta.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
      <wsdl:types>
      </wsdl:types>
      <wsdl:message name="printMessageRequest">
      <wsdl:part name="in0" element="impl:in0"/>
      </wsdl:message>
      <wsdl:message name="printMessageResponse">
      <wsdl:part name="printMessageReturn" element="impl:printMessageReturn"/>
      </wsdl:message>
      <wsdl:portType name="HelloWorld">
      <wsdl:operation name="printMessage" parameterOrder="in0">
      <wsdl:input name="printMessageRequest" message="impl:printMessageRequest"/>
      <wsdl:output name="printMessageResponse" message="impl:printMessageResponse"/>
      </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="printMessage">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="printMessageRequest">
      <wsdlsoap:body use="literal" namespace="http://ekta.com"/>
      </wsdl:input>
      <wsdl:output name="printMessageResponse">
      <wsdlsoap:body use="literal" namespace="http://ekta.com"/>
      </wsdl:output>
      </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="HelloWorldService">
      <wsdl:port name="HelloWorld" binding="impl:HelloWorldSoapBinding">
      <wsdlsoap:address location="http://localhost:8080/simple-ws4ee/services/HelloWorld"/>
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>

      -----------------------------------------------------------------------------------
      Problems
      ========
      1) after deployment when i run HelloWorldClient.class i get the following error.


      [java] javax.xml.rpc.JAXRPCException: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is
      NOT expected, in something it was trying to deserialize.
      [java] at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:304)
      [java] at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:143)
      [java] at org.apache.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:1250)
      [java] at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1712)
      [java] at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
      [java] at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
      [java] at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
      [java] at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
      [java] at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
      [java] at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
      [java] at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
      [java] at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
      [java] at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:257)
      [java] at org.apache.axis.MessagePart.getAsSOAPEnvelope(MessagePart.java:655)
      [java] at org.apache.axis.Message.getSOAPEnvelope(Message.java:432)
      [java] at org.apache.axis.client.Call.invokeEngine(Call.java:3062)
      [java] at org.apache.axis.client.Call.invoke(Call.java:3024)
      [java] at org.apache.axis.client.Call.invoke(Call.java:2619)
      [java] at org.apache.axis.client.Call.invoke(Call.java:2524)
      [java] at org.apache.axis.client.Call.invokeInternal(Call.java:1976)
      [java] at org.apache.axis.client.Call.invoke(Call.java:1917)
      [java] at com.myapp.HelloWorldSoapBindingStub.printMessage(Unknown Source)
      [java] at com.myapp.HelloWorldClient.main(HelloWorldClient.java:17)
      [java] Exception in thread "main"
      [java] Java Result: 1