You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Shiv <sh...@gmail.com> on 2014/05/13 09:43:35 UTC

ClassCastException in XML Parsing - JBoss Fuse ESB 6.0

Hi,
I am using a bean in my camel route to load an XML file and do further
processing. When I deploy the bundle, I am getting below error. If I run the
same code snippet in a standalone Java class, it works fine.
Do I need to change my XML parsing logic? Seems like XPath.evaluate() is
causing issue in bean initialization.

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'messageTransformer' defined in URL
[bundle://258.5:0/META-INF/spring/bundle-context.xml]: Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.test.MessageTransformer]: Constructor threw exception;
nested exception is java.lang.RuntimeException:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to
org.w3c.dom.NodeList
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)[105:org.springframework.beans:3.1.3.RELEASE]
	at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)[106:org.springframework.context:3.1.3.RELEASE]
	at
org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)[133:org.springframework.osgi.core:1.2.1]
	at
org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)[133:org.springframework.osgi.core:1.2.1]
	at
org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[133:org.springframework.osgi.core:1.2.1]
	at
org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[133:org.springframework.osgi.core:1.2.1]
	at
org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[132:org.springframework.osgi.extender:1.2.1]
	at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]

Thanks
Shiv



--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-in-XML-Parsing-JBoss-Fuse-ESB-6-0-tp5751062.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException in XML Parsing - JBoss Fuse ESB 6.0

Posted by Shiv <sh...@gmail.com>.
In order to fix the issue, I have changed the logic of bean which parses the
XML and it is working fine.

But it will be nice to know the root cause of such exception.

Thanks
Shiv



--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-in-XML-Parsing-JBoss-Fuse-ESB-6-0-tp5751062p5751151.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException in XML Parsing - JBoss Fuse ESB 6.0

Posted by Shiv <sh...@gmail.com>.
Route details - whenever any message is sent to test.* queue, it is
intercepted and xslt transformation is done.
-------------------------------------------------------------------------------------------------------
<bean id="messageTransformer" class="com.test.MessageTransformer" />

<interceptSendToEndpoint uri="activemq:queue:test.*">
   <doTry>
      <process ref="messageTransformer" />				
      <doCatch>					
         <exception>java.lang.RuntimeException</exception>
	<handled>
	  <constant>true</constant>
	</handled>
	<setHeader headerName="Exception">
	   <simple>${exception.message}</simple>
	</setHeader>
	<to uri="activemq:queue:SYSTEM.ERROR.MONITOR" />					
     </doCatch>
   </doTry>
</interceptSendToEndpoint>

Bean details - this bean load an xml to find out which XSLT has to be
applied based on certain conditions and then applies the matching XSLT.
-----------------------------------------------------------------------------------------------------
private static void loadXmlConfig() throws Exception {
    XPath xpath;
    String xpathExpression;
    NodeList nodes;
    InputSource inputSource;

    // Load the transformer.xml
    xpath = XPathFactory.newInstance().newXPath();
    xpathExpression = "/Endpoint/transform";
    inputSource = new InputSource(<path to transformer.xml>);

   nodes = (NodeList) xpath.evaluate(xpathExpression,
inputSource,XPathConstants.NODESET); --->*Seems   this cast is generating
exception.*
   ...........
   ...........
}
   



--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-in-XML-Parsing-JBoss-Fuse-ESB-6-0-tp5751062p5751103.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException in XML Parsing - JBoss Fuse ESB 6.0

Posted by Willem Jiang <wi...@gmail.com>.
It could be easier for us to trace the issue if you can provide more information about your bean and the camel route.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 14, 2014 at 5:10:41 AM, Shiv (shiv.dixit.bgp@gmail.com) wrote:
> Hi,
> I am using a bean in my camel route to load an XML file and do further
> processing. When I deploy the bundle, I am getting below error. If I run the
> same code snippet in a standalone Java class, it works fine.
> Do I need to change my XML parsing logic? Seems like XPath.evaluate() is
> causing issue in bean initialization.
>  
> org.springframework.beans.factory.BeanCreationException: Error creating bean  
> with name 'messageTransformer' defined in URL
> [bundle://258.5:0/META-INF/spring/bundle-context.xml]: Instantiation of bean  
> failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Could not instantiate  
> bean class [com.test.MessageTransformer]: Constructor threw exception;
> nested exception is java.lang.RuntimeException:
> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
> org.w3c.dom.NodeList
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)[105:org.springframework.beans:3.1.3.RELEASE]  
> at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)[106:org.springframework.context:3.1.3.RELEASE]  
> at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)[133:org.springframework.osgi.core:1.2.1]  
> at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)[133:org.springframework.osgi.core:1.2.1]  
> at
> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[133:org.springframework.osgi.core:1.2.1]  
> at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[133:org.springframework.osgi.core:1.2.1]  
> at
> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[132:org.springframework.osgi.extender:1.2.1]  
> at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]
>  
> Thanks
> Shiv
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-in-XML-Parsing-JBoss-Fuse-ESB-6-0-tp5751062.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>