Details

    • Type: Sub-task Sub-task
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: XML code generator
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Hi,

      This in continuation to my previous question.

      The reason to use mapping file is : Without mapping file , marshalling works but not unmarshalling. While unmarshalling, it searches for the corresponding class for root of the xml. If mapping file is not provided it raises an exception.

      The exception raised is on the server side is:

      Caused by: org.xml.sax.SAXException: The class for the root element 'EmployeeRequest' could not be found.
      at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.
      java:1527)
      at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.
      java:1430)
      at org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.
      java:246)
      at org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.
      java:183)
      at org.exolab.castor.xml.util.DOMEventProducer.start(DOMEventProducer.ja
      va:111)
      at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:617)

      I am using spring webservices. Initially i have generated classes and class descriptors for the xsd. Next i have marshalled the object and send it to server by using webservicetemplate.

      EmployeeResponse response = (EmployeeResponse) webServiceTemplate
      .marshalSendAndReceive(employeeRequest);

      Whereas in config.xml file the configurations are: (Client side configurations)

      <bean id="webServiceTemplate"
      class="org.springframework.ws.client.core.WebServiceTemplate">
      <property name="messageFactory" ref="messageFactory" />
      <property name="defaultUri"
      value="http://localhost:8080/empService/" />
      <property name="messageSender" ref="urlMessageSender" />

      <property name="marshaller" ref="marshaller" />
      <property name="unmarshaller" ref="marshaller" />
      </bean>

      <bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller"/>

      Whereas in service -config.xml file the configurations are: (Service side configurations)

      <bean id="saveEmpEndpoint"
      class="com.hr.ws.SaveEmpEndpoint">
      <property name="marshaller" ref="marshaller" />
      <property name="unmarshaller" ref="marshaller" />
      <property name="saveEmpService" ref="saveEmpService" />
      </bean>

      <bean id="marshaller"
      class="org.springframework.oxm.castor.CastorMarshaller">

      </bean>

      My SaveEmpEndpoint class extends AbstractMarshallingPayloadEndpoint

      I am attaching xsd for your reference.

      Thanks in advance.

        Activity

        Hide
        Werner Guttmann added a comment -

        Hi, looking at the exception in detail, it looks like the Java class for 'EmployeeRequest' is not on your classpath, and thus cannot be found at unmarshalling. Make sure that the classes as generated by the XML code generator (Java classes and descriptor classes) are packaged with your server side application. Then - and only then - will Castor be able to find the class(es) required during unmarshalling.

        In other words, you will never need a mapping file in this scenario, where you started from an XML schema and generated classes for it.

        Show
        Werner Guttmann added a comment - Hi, looking at the exception in detail, it looks like the Java class for 'EmployeeRequest' is not on your classpath, and thus cannot be found at unmarshalling. Make sure that the classes as generated by the XML code generator (Java classes and descriptor classes) are packaged with your server side application. Then - and only then - will Castor be able to find the class(es) required during unmarshalling. In other words, you will never need a mapping file in this scenario, where you started from an XML schema and generated classes for it.
        Hide
        aparajitha added a comment -

        But i have used maven in this case for generating classes and class descriptors. Obviously it would place classes in the classpath

        Attached is the code used in pom.xml
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>castor-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
        <execution>
        <goals>
        <goal>generate</goal>
        </goals>
        <configuration>
        <schema>
        src/main/castor/emp.xsd
        </schema>
        <packaging>
        com.hr.schema
        </packaging>
        </configuration>
        </execution>
        </executions>
        </plugin>

        This will by default generate classes and place in target/generated source and packaged in to war.

        Show
        aparajitha added a comment - But i have used maven in this case for generating classes and class descriptors. Obviously it would place classes in the classpath Attached is the code used in pom.xml <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>castor-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <schema> src/main/castor/emp.xsd </schema> <packaging> com.hr.schema </packaging> </configuration> </execution> </executions> </plugin> This will by default generate classes and place in target/generated source and packaged in to war.
        Hide
        Werner Guttmann added a comment -

        Yes, you are right that this plugin configuration will generate the sources from the XML schema given, and place them into the default output directory (target/generated-source/castor). Problem is that this is not a default location where Maven will look for code artifacts during the compile phase (with standard locations being src/main/java and src/test/java). You'll either have to make this new directory known to Maven so that it will be considered at compilation time, or change the destination directory to be e.g. src/main/java and use a package prefix to acquire uniqueness. Then, and only then, will your classes be packaged with the WAR.

        Have a look at the WAR file, and I am sure you won't find the generated classes in there.

        Show
        Werner Guttmann added a comment - Yes, you are right that this plugin configuration will generate the sources from the XML schema given, and place them into the default output directory (target/generated-source/castor). Problem is that this is not a default location where Maven will look for code artifacts during the compile phase (with standard locations being src/main/java and src/test/java). You'll either have to make this new directory known to Maven so that it will be considered at compilation time, or change the destination directory to be e.g. src/main/java and use a package prefix to acquire uniqueness. Then, and only then, will your classes be packaged with the WAR. Have a look at the WAR file, and I am sure you won't find the generated classes in there.
        Hide
        Werner Guttmann added a comment -

        As per above comments .....

        Show
        Werner Guttmann added a comment - As per above comments .....

          People

          • Assignee:
            Unassigned
            Reporter:
            aparajitha
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: