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. It seems like one thread reads
the mapping file from the stream and when the other thread tries to do
the same, I get the following errors.


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(MappingUnmars
haller.java:246)
        at
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshal
ler.java:124)
        at
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshal
ler.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(MappingUnmars
haller.java:246)
        at
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshal
ler.java:124)
        at
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshal
ler.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.jav
a:1538)
        at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.jav
a: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(U
nknown Source)
        at
org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRoot
ElementHook(Unknown Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDis
patcher.dispatch(Unknown Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
wn 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




Reply via email to