jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
castor
  • castor
  • CASTOR-2222 issue with generated castor mapping f...
  • CASTOR-2227

Exception generated when mapping file is not used.

  • Log In
  • Views
    • XML
    • Word
    • Printable

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.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. XML File
    emp.xsd
    11/Dec/07 5:27 AM
    1 kB
    aparajitha

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Werner Guttmann added a comment - 11/Dec/07 5:38 AM

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 - 11/Dec/07 5:38 AM 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
Permalink
aparajitha added a comment - 11/Dec/07 5:59 AM

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 - 11/Dec/07 5:59 AM 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
Permalink
Werner Guttmann added a comment - 13/Dec/07 4:36 AM

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 - 13/Dec/07 4:36 AM 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.
Ralf Joachim made changes - 17/Dec/07 2:04 PM
Field Original Value New Value
Component/s XML code generator [ 11761 ]
Hide
Permalink
Werner Guttmann added a comment - 27/Dec/07 4:56 PM

As per above comments .....

Show
Werner Guttmann added a comment - 27/Dec/07 4:56 PM As per above comments .....
Werner Guttmann made changes - 27/Dec/07 4:56 PM
Resolution Won't Fix [ 2 ]
Fix Version/s 1.2 [ 13559 ]
Status Open [ 1 ] Resolved [ 5 ]
Werner Guttmann made changes - 14/Mar/08 6:41 AM
Status Resolved [ 5 ] Closed [ 6 ]

People

  • Assignee:
    Unassigned
    Reporter:
    aparajitha
Vote (0)
Watch (0)

Dates

  • Created:
    11/Dec/07 5:27 AM
    Updated:
    14/Mar/08 6:41 AM
    Resolved:
    27/Dec/07 4:56 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.