You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "allen.lau" <gu...@gmail.com> on 2009/08/31 19:22:13 UTC

Re: Occasional CamelNamespaceHandler exception when running with Spring-DM 1.2

Hi Claus,

Just checked the camel-jaxb code and from looking at the
FallbackTypeConverter and JaxbConverter code, the unmarshaller and
marshaller are always created for each operation.

A helpful comment is also available in the code:
 // must create a new instance of unmarshaller as its not thred safe
 Unmarshaller unmarshaller = context.createUnmarshaller();

So I think the namespace handler should follow the same convention in order
to be thread-safe.

Thanks,
Allen


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Could you take a look at camel-jaxb as its thread safe. And do a
> compare with the namespace handler below.
> Could be that we just need to do a bit more work here to be fully
> thread safe as well.
> 
> 
> On Fri, Aug 28, 2009 at 9:00 PM, allen.lau<gu...@gmail.com> wrote:
>>
>> Hi,
>>
>> Every so often, I would get the following stack trace below when running
>> some integration tests with Spring-DM.    Since it does not happen
>> everytime, I suspect that it is a threading/race issue.
>>
>> The complete environment is Spring-DM 1.2, Spring 2.5.6 and using Camel
>> 2.0.0 running inside of Felix 1.8.0.
>>
>> Looking at the CamelNamespaceHandler's parseUsingJaxb() method, it is
>> coded
>> like so.
>> protected Object parseUsingJaxb(Element element, ParserContext
>> parserContext) {
>>        try {
>>            binder = getJaxbContext().createBinder();
>>            return binder.unmarshal(element);
>>        } catch (JAXBException e) {
>>            throw new BeanDefinitionStoreException("Failed to parse JAXB
>> element: " + e, e);
>>        }
>>    }
>>
>> I wonder if the binder.unmarshal(element) is causing an issue because
>> multiple Spring-DM extender threads may be calling this.   The
>> https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html
>> hints that an unmarshaller should be created for each thread.   I don't
>> know
>> that much about jaxb, so I'm not sure that if that is the cause or not.
>>
>> Thanks,
>> Allen
>>
>> Stacktrace below:
>>
>> org.springframework.beans.factory.BeanDefinitionStoreException:
>> Unexpected
>> exception parsing XML document from URL
>> [bundle://45.0:0/META-INF/spring/osgi-test-context.xml]; nested exception
>> is
>> java.lang.NullPointerException
>> at
>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
>> at
>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
>> at
>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
>> at
>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
>> at
>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
>> at
>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
>> at
>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:176)
>> at
>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:142)
>> at
>> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
>> at
>> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
>> at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)
>> at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)
>> at
>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>> at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:222)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>> at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>> at
>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>> at java.lang.Thread.run(Thread.java:619)
>> Caused by: java.lang.NullPointerException
>> at com.sun.xml.bind.v2.util.QNameMap.getEntry(QNameMap.java:460)
>> at com.sun.xml.bind.v2.util.QNameMap.get(QNameMap.java:158)
>> at
>> com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:198)
>> at
>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
>> at
>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
>> at
>> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
>> at
>> com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
>> at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:100)
>> at
>> com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:156)
>> at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:127)
>> at
>> org.apache.camel.spring.handler.CamelNamespaceHandler.parseUsingJaxb(CamelNamespaceHandler.java:145)
>> at
>> org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:199)
>> at
>> org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:84)
>> at
>> org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
>> at
>> org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
>> at
>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
>> at
>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
>> at
>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
>> at
>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
>> at
>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
>> at
>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
>> ... 18 more
>> Exception in thread "SpringOsgiExtenderThread-8"
>> java.lang.IllegalStateException: BeanFactory not initialized or already
>> closed - call 'refresh' before accessing beans via the ApplicationContext
>> at
>> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
>> at
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>> at
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>> at
>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>> at java.lang.Thread.run(Thread.java:619)
>> --
>> View this message in context:
>> http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25195171.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25227119.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Occasional CamelNamespaceHandler exception when running with Spring-DM 1.2

Posted by "allen.lau" <gu...@gmail.com>.
Hi Williem,

Will do once I get a chance, sometimes this is very hard to reproduce, I see
it more when running integration test inside of CruiseControl.   

The fix in the code looks like it should do the trick since the binder is
now passed to all the methods.

Thanks,
Allen


willem.jiang wrote:
> 
> Hi Allen,
> 
> Please feel free to try the latest Camel 2.1-SNAPSHOT[1] to verify the 
> fix :)
> 
> [1]http://cwiki.apache.org/CAMEL/download.html
> 
> Willem
> allen.lau wrote:
>> Thanks for looking into it Willem.
>> 
>> Allen
>> 
>> 
>> willem.jiang wrote:
>>> Hi Allen
>>>
>>> After digging the code of the CamelNamespaceHandler, I found camel store 
>>> the JAXB context Binder as a class number, it will cause the 
>>> multi-thread issue.
>>> So I created a JIRA[1] for it , and will commit a quick fix later.
>>>
>>> Thanks for tracing the issue :)
>>>
>>> [1] https://issues.apache.org/activemq/browse/CAMEL-1966
>>>
>>> Willem
>>>
>>> allen.lau wrote:
>>>> Hi Claus,
>>>>
>>>> Just checked the camel-jaxb code and from looking at the
>>>> FallbackTypeConverter and JaxbConverter code, the unmarshaller and
>>>> marshaller are always created for each operation.
>>>>
>>>> A helpful comment is also available in the code:
>>>>  // must create a new instance of unmarshaller as its not thred safe
>>>>  Unmarshaller unmarshaller = context.createUnmarshaller();
>>>>
>>>> So I think the namespace handler should follow the same convention in
>>>> order
>>>> to be thread-safe.
>>>>
>>>> Thanks,
>>>> Allen
>>>>
>>>>
>>>> Claus Ibsen-2 wrote:
>>>>> Hi
>>>>>
>>>>> Could you take a look at camel-jaxb as its thread safe. And do a
>>>>> compare with the namespace handler below.
>>>>> Could be that we just need to do a bit more work here to be fully
>>>>> thread safe as well.
>>>>>
>>>>>
>>>>> On Fri, Aug 28, 2009 at 9:00 PM, allen.lau<gu...@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Every so often, I would get the following stack trace below when
>>>>>> running
>>>>>> some integration tests with Spring-DM.    Since it does not happen
>>>>>> everytime, I suspect that it is a threading/race issue.
>>>>>>
>>>>>> The complete environment is Spring-DM 1.2, Spring 2.5.6 and using
>>>>>> Camel
>>>>>> 2.0.0 running inside of Felix 1.8.0.
>>>>>>
>>>>>> Looking at the CamelNamespaceHandler's parseUsingJaxb() method, it is
>>>>>> coded
>>>>>> like so.
>>>>>> protected Object parseUsingJaxb(Element element, ParserContext
>>>>>> parserContext) {
>>>>>>        try {
>>>>>>            binder = getJaxbContext().createBinder();
>>>>>>            return binder.unmarshal(element);
>>>>>>        } catch (JAXBException e) {
>>>>>>            throw new BeanDefinitionStoreException("Failed to parse
>>>>>> JAXB
>>>>>> element: " + e, e);
>>>>>>        }
>>>>>>    }
>>>>>>
>>>>>> I wonder if the binder.unmarshal(element) is causing an issue because
>>>>>> multiple Spring-DM extender threads may be calling this.   The
>>>>>> https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html
>>>>>> hints that an unmarshaller should be created for each thread.   I
>>>>>> don't
>>>>>> know
>>>>>> that much about jaxb, so I'm not sure that if that is the cause or
>>>>>> not.
>>>>>>
>>>>>> Thanks,
>>>>>> Allen
>>>>>>
>>>>>> Stacktrace below:
>>>>>>
>>>>>> org.springframework.beans.factory.BeanDefinitionStoreException:
>>>>>> Unexpected
>>>>>> exception parsing XML document from URL
>>>>>> [bundle://45.0:0/META-INF/spring/osgi-test-context.xml]; nested
>>>>>> exception
>>>>>> is
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
>>>>>> at
>>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
>>>>>> at
>>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
>>>>>> at
>>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:176)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:142)
>>>>>> at
>>>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
>>>>>> at
>>>>>> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)
>>>>>> at
>>>>>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:222)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>>> Caused by: java.lang.NullPointerException
>>>>>> at com.sun.xml.bind.v2.util.QNameMap.getEntry(QNameMap.java:460)
>>>>>> at com.sun.xml.bind.v2.util.QNameMap.get(QNameMap.java:158)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:198)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
>>>>>> at
>>>>>> com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
>>>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
>>>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:100)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:156)
>>>>>> at
>>>>>> com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:127)
>>>>>> at
>>>>>> org.apache.camel.spring.handler.CamelNamespaceHandler.parseUsingJaxb(CamelNamespaceHandler.java:145)
>>>>>> at
>>>>>> org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:199)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:84)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
>>>>>> at
>>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
>>>>>> ... 18 more
>>>>>> Exception in thread "SpringOsgiExtenderThread-8"
>>>>>> java.lang.IllegalStateException: BeanFactory not initialized or
>>>>>> already
>>>>>> closed - call 'refresh' before accessing beans via the
>>>>>> ApplicationContext
>>>>>> at
>>>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>>>> at
>>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>>>> at
>>>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25195171.html
>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>
>>>>> -- 
>>>>> Claus Ibsen
>>>>> Apache Camel Committer
>>>>>
>>>>> Open Source Integration: http://fusesource.com
>>>>> Blog: http://davsclaus.blogspot.com/
>>>>> Twitter: http://twitter.com/davsclaus
>>>>>
>>>>>
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25265391.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Occasional CamelNamespaceHandler exception when running with Spring-DM 1.2

Posted by Willem Jiang <wi...@gmail.com>.
Hi Allen,

Please feel free to try the latest Camel 2.1-SNAPSHOT[1] to verify the 
fix :)

[1]http://cwiki.apache.org/CAMEL/download.html

Willem
allen.lau wrote:
> Thanks for looking into it Willem.
> 
> Allen
> 
> 
> willem.jiang wrote:
>> Hi Allen
>>
>> After digging the code of the CamelNamespaceHandler, I found camel store 
>> the JAXB context Binder as a class number, it will cause the 
>> multi-thread issue.
>> So I created a JIRA[1] for it , and will commit a quick fix later.
>>
>> Thanks for tracing the issue :)
>>
>> [1] https://issues.apache.org/activemq/browse/CAMEL-1966
>>
>> Willem
>>
>> allen.lau wrote:
>>> Hi Claus,
>>>
>>> Just checked the camel-jaxb code and from looking at the
>>> FallbackTypeConverter and JaxbConverter code, the unmarshaller and
>>> marshaller are always created for each operation.
>>>
>>> A helpful comment is also available in the code:
>>>  // must create a new instance of unmarshaller as its not thred safe
>>>  Unmarshaller unmarshaller = context.createUnmarshaller();
>>>
>>> So I think the namespace handler should follow the same convention in
>>> order
>>> to be thread-safe.
>>>
>>> Thanks,
>>> Allen
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>> Hi
>>>>
>>>> Could you take a look at camel-jaxb as its thread safe. And do a
>>>> compare with the namespace handler below.
>>>> Could be that we just need to do a bit more work here to be fully
>>>> thread safe as well.
>>>>
>>>>
>>>> On Fri, Aug 28, 2009 at 9:00 PM, allen.lau<gu...@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> Every so often, I would get the following stack trace below when
>>>>> running
>>>>> some integration tests with Spring-DM.    Since it does not happen
>>>>> everytime, I suspect that it is a threading/race issue.
>>>>>
>>>>> The complete environment is Spring-DM 1.2, Spring 2.5.6 and using Camel
>>>>> 2.0.0 running inside of Felix 1.8.0.
>>>>>
>>>>> Looking at the CamelNamespaceHandler's parseUsingJaxb() method, it is
>>>>> coded
>>>>> like so.
>>>>> protected Object parseUsingJaxb(Element element, ParserContext
>>>>> parserContext) {
>>>>>        try {
>>>>>            binder = getJaxbContext().createBinder();
>>>>>            return binder.unmarshal(element);
>>>>>        } catch (JAXBException e) {
>>>>>            throw new BeanDefinitionStoreException("Failed to parse JAXB
>>>>> element: " + e, e);
>>>>>        }
>>>>>    }
>>>>>
>>>>> I wonder if the binder.unmarshal(element) is causing an issue because
>>>>> multiple Spring-DM extender threads may be calling this.   The
>>>>> https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html
>>>>> hints that an unmarshaller should be created for each thread.   I don't
>>>>> know
>>>>> that much about jaxb, so I'm not sure that if that is the cause or not.
>>>>>
>>>>> Thanks,
>>>>> Allen
>>>>>
>>>>> Stacktrace below:
>>>>>
>>>>> org.springframework.beans.factory.BeanDefinitionStoreException:
>>>>> Unexpected
>>>>> exception parsing XML document from URL
>>>>> [bundle://45.0:0/META-INF/spring/osgi-test-context.xml]; nested
>>>>> exception
>>>>> is
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
>>>>> at
>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
>>>>> at
>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
>>>>> at
>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
>>>>> at
>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
>>>>> at
>>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
>>>>> at
>>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:176)
>>>>> at
>>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:142)
>>>>> at
>>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
>>>>> at
>>>>> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
>>>>> at
>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)
>>>>> at
>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)
>>>>> at
>>>>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>>>>> at
>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:222)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>>> at
>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>> Caused by: java.lang.NullPointerException
>>>>> at com.sun.xml.bind.v2.util.QNameMap.getEntry(QNameMap.java:460)
>>>>> at com.sun.xml.bind.v2.util.QNameMap.get(QNameMap.java:158)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:198)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
>>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
>>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
>>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:100)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:156)
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:127)
>>>>> at
>>>>> org.apache.camel.spring.handler.CamelNamespaceHandler.parseUsingJaxb(CamelNamespaceHandler.java:145)
>>>>> at
>>>>> org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:199)
>>>>> at
>>>>> org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:84)
>>>>> at
>>>>> org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
>>>>> at
>>>>> org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
>>>>> at
>>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
>>>>> at
>>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
>>>>> at
>>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
>>>>> at
>>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
>>>>> at
>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
>>>>> at
>>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
>>>>> ... 18 more
>>>>> Exception in thread "SpringOsgiExtenderThread-8"
>>>>> java.lang.IllegalStateException: BeanFactory not initialized or already
>>>>> closed - call 'refresh' before accessing beans via the
>>>>> ApplicationContext
>>>>> at
>>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>>> at
>>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>>> at
>>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>>> at java.lang.Thread.run(Thread.java:619)
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25195171.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> Claus Ibsen
>>>> Apache Camel Committer
>>>>
>>>> Open Source Integration: http://fusesource.com
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Twitter: http://twitter.com/davsclaus
>>>>
>>>>
>>
>>
> 


Re: Occasional CamelNamespaceHandler exception when running with Spring-DM 1.2

Posted by "allen.lau" <gu...@gmail.com>.
Thanks for looking into it Willem.

Allen


willem.jiang wrote:
> 
> Hi Allen
> 
> After digging the code of the CamelNamespaceHandler, I found camel store 
> the JAXB context Binder as a class number, it will cause the 
> multi-thread issue.
> So I created a JIRA[1] for it , and will commit a quick fix later.
> 
> Thanks for tracing the issue :)
> 
> [1] https://issues.apache.org/activemq/browse/CAMEL-1966
> 
> Willem
> 
> allen.lau wrote:
>> Hi Claus,
>> 
>> Just checked the camel-jaxb code and from looking at the
>> FallbackTypeConverter and JaxbConverter code, the unmarshaller and
>> marshaller are always created for each operation.
>> 
>> A helpful comment is also available in the code:
>>  // must create a new instance of unmarshaller as its not thred safe
>>  Unmarshaller unmarshaller = context.createUnmarshaller();
>> 
>> So I think the namespace handler should follow the same convention in
>> order
>> to be thread-safe.
>> 
>> Thanks,
>> Allen
>> 
>> 
>> Claus Ibsen-2 wrote:
>>> Hi
>>>
>>> Could you take a look at camel-jaxb as its thread safe. And do a
>>> compare with the namespace handler below.
>>> Could be that we just need to do a bit more work here to be fully
>>> thread safe as well.
>>>
>>>
>>> On Fri, Aug 28, 2009 at 9:00 PM, allen.lau<gu...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Every so often, I would get the following stack trace below when
>>>> running
>>>> some integration tests with Spring-DM.    Since it does not happen
>>>> everytime, I suspect that it is a threading/race issue.
>>>>
>>>> The complete environment is Spring-DM 1.2, Spring 2.5.6 and using Camel
>>>> 2.0.0 running inside of Felix 1.8.0.
>>>>
>>>> Looking at the CamelNamespaceHandler's parseUsingJaxb() method, it is
>>>> coded
>>>> like so.
>>>> protected Object parseUsingJaxb(Element element, ParserContext
>>>> parserContext) {
>>>>        try {
>>>>            binder = getJaxbContext().createBinder();
>>>>            return binder.unmarshal(element);
>>>>        } catch (JAXBException e) {
>>>>            throw new BeanDefinitionStoreException("Failed to parse JAXB
>>>> element: " + e, e);
>>>>        }
>>>>    }
>>>>
>>>> I wonder if the binder.unmarshal(element) is causing an issue because
>>>> multiple Spring-DM extender threads may be calling this.   The
>>>> https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html
>>>> hints that an unmarshaller should be created for each thread.   I don't
>>>> know
>>>> that much about jaxb, so I'm not sure that if that is the cause or not.
>>>>
>>>> Thanks,
>>>> Allen
>>>>
>>>> Stacktrace below:
>>>>
>>>> org.springframework.beans.factory.BeanDefinitionStoreException:
>>>> Unexpected
>>>> exception parsing XML document from URL
>>>> [bundle://45.0:0/META-INF/spring/osgi-test-context.xml]; nested
>>>> exception
>>>> is
>>>> java.lang.NullPointerException
>>>> at
>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
>>>> at
>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
>>>> at
>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
>>>> at
>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
>>>> at
>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
>>>> at
>>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
>>>> at
>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:176)
>>>> at
>>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:142)
>>>> at
>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
>>>> at
>>>> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
>>>> at
>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)
>>>> at
>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)
>>>> at
>>>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>>>> at
>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:222)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>> at
>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>> at
>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>> at java.lang.Thread.run(Thread.java:619)
>>>> Caused by: java.lang.NullPointerException
>>>> at com.sun.xml.bind.v2.util.QNameMap.getEntry(QNameMap.java:460)
>>>> at com.sun.xml.bind.v2.util.QNameMap.get(QNameMap.java:158)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:198)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
>>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:100)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:156)
>>>> at
>>>> com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:127)
>>>> at
>>>> org.apache.camel.spring.handler.CamelNamespaceHandler.parseUsingJaxb(CamelNamespaceHandler.java:145)
>>>> at
>>>> org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:199)
>>>> at
>>>> org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:84)
>>>> at
>>>> org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
>>>> at
>>>> org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
>>>> at
>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
>>>> at
>>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
>>>> at
>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
>>>> at
>>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
>>>> at
>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
>>>> at
>>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
>>>> ... 18 more
>>>> Exception in thread "SpringOsgiExtenderThread-8"
>>>> java.lang.IllegalStateException: BeanFactory not initialized or already
>>>> closed - call 'refresh' before accessing beans via the
>>>> ApplicationContext
>>>> at
>>>> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
>>>> at
>>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>>> at
>>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>>> at
>>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>>> at java.lang.Thread.run(Thread.java:619)
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25195171.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>> -- 
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25243913.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Occasional CamelNamespaceHandler exception when running with Spring-DM 1.2

Posted by Willem Jiang <wi...@gmail.com>.
Hi Allen

After digging the code of the CamelNamespaceHandler, I found camel store 
the JAXB context Binder as a class number, it will cause the 
multi-thread issue.
So I created a JIRA[1] for it , and will commit a quick fix later.

Thanks for tracing the issue :)

[1] https://issues.apache.org/activemq/browse/CAMEL-1966

Willem

allen.lau wrote:
> Hi Claus,
> 
> Just checked the camel-jaxb code and from looking at the
> FallbackTypeConverter and JaxbConverter code, the unmarshaller and
> marshaller are always created for each operation.
> 
> A helpful comment is also available in the code:
>  // must create a new instance of unmarshaller as its not thred safe
>  Unmarshaller unmarshaller = context.createUnmarshaller();
> 
> So I think the namespace handler should follow the same convention in order
> to be thread-safe.
> 
> Thanks,
> Allen
> 
> 
> Claus Ibsen-2 wrote:
>> Hi
>>
>> Could you take a look at camel-jaxb as its thread safe. And do a
>> compare with the namespace handler below.
>> Could be that we just need to do a bit more work here to be fully
>> thread safe as well.
>>
>>
>> On Fri, Aug 28, 2009 at 9:00 PM, allen.lau<gu...@gmail.com> wrote:
>>> Hi,
>>>
>>> Every so often, I would get the following stack trace below when running
>>> some integration tests with Spring-DM.    Since it does not happen
>>> everytime, I suspect that it is a threading/race issue.
>>>
>>> The complete environment is Spring-DM 1.2, Spring 2.5.6 and using Camel
>>> 2.0.0 running inside of Felix 1.8.0.
>>>
>>> Looking at the CamelNamespaceHandler's parseUsingJaxb() method, it is
>>> coded
>>> like so.
>>> protected Object parseUsingJaxb(Element element, ParserContext
>>> parserContext) {
>>>        try {
>>>            binder = getJaxbContext().createBinder();
>>>            return binder.unmarshal(element);
>>>        } catch (JAXBException e) {
>>>            throw new BeanDefinitionStoreException("Failed to parse JAXB
>>> element: " + e, e);
>>>        }
>>>    }
>>>
>>> I wonder if the binder.unmarshal(element) is causing an issue because
>>> multiple Spring-DM extender threads may be calling this.   The
>>> https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html
>>> hints that an unmarshaller should be created for each thread.   I don't
>>> know
>>> that much about jaxb, so I'm not sure that if that is the cause or not.
>>>
>>> Thanks,
>>> Allen
>>>
>>> Stacktrace below:
>>>
>>> org.springframework.beans.factory.BeanDefinitionStoreException:
>>> Unexpected
>>> exception parsing XML document from URL
>>> [bundle://45.0:0/META-INF/spring/osgi-test-context.xml]; nested exception
>>> is
>>> java.lang.NullPointerException
>>> at
>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
>>> at
>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
>>> at
>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
>>> at
>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
>>> at
>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
>>> at
>>> org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
>>> at
>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:176)
>>> at
>>> org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:142)
>>> at
>>> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
>>> at
>>> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
>>> at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)
>>> at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)
>>> at
>>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>>> at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:222)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>> at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>> at
>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>> at java.lang.Thread.run(Thread.java:619)
>>> Caused by: java.lang.NullPointerException
>>> at com.sun.xml.bind.v2.util.QNameMap.getEntry(QNameMap.java:460)
>>> at com.sun.xml.bind.v2.util.QNameMap.get(QNameMap.java:158)
>>> at
>>> com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:198)
>>> at
>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
>>> at
>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
>>> at
>>> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
>>> at
>>> com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
>>> at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
>>> at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:100)
>>> at
>>> com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:156)
>>> at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:127)
>>> at
>>> org.apache.camel.spring.handler.CamelNamespaceHandler.parseUsingJaxb(CamelNamespaceHandler.java:145)
>>> at
>>> org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:199)
>>> at
>>> org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:84)
>>> at
>>> org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
>>> at
>>> org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
>>> at
>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
>>> at
>>> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
>>> at
>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
>>> at
>>> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
>>> at
>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
>>> at
>>> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
>>> ... 18 more
>>> Exception in thread "SpringOsgiExtenderThread-8"
>>> java.lang.IllegalStateException: BeanFactory not initialized or already
>>> closed - call 'refresh' before accessing beans via the ApplicationContext
>>> at
>>> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
>>> at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
>>> at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
>>> at
>>> org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
>>> at java.lang.Thread.run(Thread.java:619)
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Occasional-CamelNamespaceHandler-exception-when-running-with-Spring-DM-1.2-tp25195171p25195171.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>> -- 
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>