Hi,
I�ve run into some threading issues when I upgrade to Castor 1.1. I have a multi-threaded application where I spawn two threads to retrieve XML from a backend and then un-marshal it based on a supplied mapping file.
The application uses a combination of Castor (castor-xml.jar version 1.1) and JAXB (jaxb-api.jar version 1.0.1) to do the unmarshalling. Sometimes the problem arises when I'm creating the CastorUnmarshaller where it has a problem loading the mappings. The problem seems to arise when the JAXB context tries to access the mapping file through the same InputStream for both unmarshal efforts
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.reflect.InvocationTargetException]
at com.test.CastorUnmarshaller.<init>(CastorUnmarshaller.java:77)
at com.test.CastorJAXBContext.createUnmarshaller(CastorJAXBContext.java:124)
at com.tasks.JAXBBindTask.unmarshallXML(JAXBBindTask.java:207)
... 13 more
Caused by: org.exolab.castor.mapping.MappingException: Nested error: Premature end of file.
at org.castor.mapping.MappingUnmarshaller.loadMappingInternal(MappingUnmarshaller.java:246)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:124)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:99)
at org.exolab.castor.xml.Unmarshaller.setMapping(Unmarshaller.java:526)
at org.exolab.castor.xml.Unmarshaller.<init>(Unmarshaller.java:255)
OR
Caused by: org.exolab.castor.mapping.MappingException: Nested error: Content is not allowed in prolog.{File: [not available]; line: 1; column: 1}
at org.castor.mapping.MappingUnmarshaller.loadMappingInternal(MappingUnmarshaller.java:246)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:124)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:99)
at org.exolab.castor.xml.Unmarshaller.setMapping(Unmarshaller.java:526)
at org.exolab.castor.xml.Unmarshaller.<init>(Unmarshaller.java:255)
Some times it gets past loading the mapping but fails at the unmarshal effort itself
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.reflect.InvocationTargetException]
at com.test.CastorUnmarshaller.unmarshal(CastorUnmarshaller.java:170)
at com.tasks.JAXBBindTask.unmarshallXML(JAXBBindTask.java:239)
... 13 more
used by: org.xml.sax.SAXException: The class for the root element 'QUOTE' could not be found.
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1538)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1373)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:729)
If I revert back to Castor 1.0.1, everything works perfectly. Also if I sleep one of the threads for a period of time, it also works. Does anyone know what has changed in Castor 1.1 that causes this problem.
Any advice/help greatly appreciated.
Thanks,
Michael