You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jcuk <ja...@hotmail.com> on 2014/08/19 14:19:17 UTC
java.lang.ClassCastException: Not instanceof
org.apache.camel.TypeConverter value:
org.apache.camel.converter.jaxb.FallbackTypeConverter
Hello
I'm currently experiencing a problem initializing the TypeConverters in
Camel in a Spring WebApp.
As soon as the first exchange is created and the type converters are loaded
(or type converters are loaded explicitly with
camleContext.getTypeConverterRegistry() ) then I get the following
exception:
org.apache.camel.RuntimeCamelException: java.lang.ClassCastException: Not
instanceof org.apache.camel.TypeConverter value:
org.apache.camel.converter.jaxb.FallbackTypeConverter@35f3198f:
java.lang.ClassCastException: Not instanceof org.apache.camel.TypeConverter
value: org.apache.camel.converter.jaxb.FallbackTypeConverter@35f3198f
at
org.apache.camel.impl.DefaultFactoryFinder.newInstance(DefaultFactoryFinder.java:109)
at
org.apache.camel.impl.DefaultFactoryFinder.newInstance(DefaultFactoryFinder.java:99)
at
org.apache.camel.impl.DefaultFactoryFinder.newInstances(DefaultFactoryFinder.java:65)
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.loadFallbackTypeConverters(BaseTypeConverterRegistry.java:542)
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.loadTypeConverters(BaseTypeConverterRegistry.java:535)
at
org.apache.camel.impl.converter.DefaultTypeConverter.doStart(DefaultTypeConverter.java:47)
at
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1888)
at
org.apache.camel.impl.DefaultCamelContext.doAddService(DefaultCamelContext.java:979)
at
org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:940)
at
org.apache.camel.impl.DefaultCamelContext.getTypeConverter(DefaultCamelContext.java:1148)
at
org.apache.camel.impl.DefaultCamelContext.getTypeConverterRegistry(DefaultCamelContext.java:1165)
However, org.apache.camel.converter.jaxb.FallbackTypeConverter implements
TypeConverter so how can this be the case? I'm not doing anything with
custom type converters. I have found this on
http://camel.apache.org/type-converter.html:
---
Exposed the TypeConverterRegistry from CamelContext so end users more easily
will be able to add type converters at runtime. This is also usable in
situations where the default discovering of type converters fails on
platforms with classloading issues.
To access the registry, you get it from the CamelContext
CamelContext context = ...
context.getTypeConverterRegistry()
---
but there is no indication of exactly how this could be used if there are
class loading issues, and also simply calling getTypeConverterRegistry()
triggers the problem, so I can't see how this would be of any use.
I initially thought it may be caused by multiple versions of camel being
included in the deployment, but I've checked and only one version of camel
is used in the deployment war. Also the version of camel-core and
camel-spring are matching.
I'm currently using spring 3.2.1 and camel version 2.12.1, but I've also
tried 2.12.4 and 2.13.2 with the same result. It occurs consistently on my
local machine where I use the maven-jetty plugin (6.1.26) under cygwyn,
however when deployed to a Tomcat server (v5.5.20 running on CentOS 5.1),
the problem is only intermittent.
Any pointers to what could be the problem would be much appreciated
thanks in advance
Jason
--
View this message in context: http://camel.465427.n5.nabble.com/java-lang-ClassCastException-Not-instanceof-org-apache-camel-TypeConverter-value-org-apache-camel-cor-tp5755390.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: java.lang.ClassCastException: Not instanceof
org.apache.camel.TypeConverter value:
org.apache.camel.converter.jaxb.FallbackTypeConverter
Posted by jcuk <ja...@hotmail.com>.
Yes, this is definitely a class loader issue. In DefaultfactoryFinder:
private <T> T newInstance(String key, Injector injector, String
propertyPrefix, Class<T> expectedType)
throws IOException, ClassNotFoundException {
Class<?> type = findClass(key, propertyPrefix);
Object value = injector.newInstance(type);
if (expectedType.isInstance(value)) {
return expectedType.cast(value);
} else {
throw new ClassCastException("Not instanceof " +
expectedType.getName() + " value: " + value);
}
}
Stepping through the code, the Object 'value' created by the injector has
the classloader from the Maven Jetty plugin, whereas the 'expectedType'
classloader is null (the bootstrap class loader I assume), so isInstance is
always going to be false.
I'll look more closely at the web app and see why this is the case.
--
View this message in context: http://camel.465427.n5.nabble.com/java-lang-ClassCastException-Not-instanceof-org-apache-camel-TypeConverter-value-org-apache-camel-cor-tp5755390p5755432.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: java.lang.ClassCastException: Not instanceof
org.apache.camel.TypeConverter value:
org.apache.camel.converter.jaxb.FallbackTypeConverter
Posted by jcuk <ja...@hotmail.com>.
Yes, its jars in a war file, and no shared libraries.
I agree it looks very like the interface and the object are coming from two
different class loaders - I'll see if I can confirm that this is the case
--
View this message in context: http://camel.465427.n5.nabble.com/java-lang-ClassCastException-Not-instanceof-org-apache-camel-TypeConverter-value-org-apache-camel-cor-tp5755390p5755401.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: java.lang.ClassCastException: Not instanceof org.apache.camel.TypeConverter
value: org.apache.camel.converter.jaxb.FallbackTypeConverter
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
How do you deploy your Camel application? Do you put all the JARs in a
WAR? Or do you have some shared JARs in the Tomcat shared lib
directory or something?
It does sound like a classpath issue due the latter.
If all JARs are in the WAR then it ought to use same classloader and just work.
On Tue, Aug 19, 2014 at 2:19 PM, jcuk <ja...@hotmail.com> wrote:
> Hello
>
> I'm currently experiencing a problem initializing the TypeConverters in
> Camel in a Spring WebApp.
>
> As soon as the first exchange is created and the type converters are loaded
> (or type converters are loaded explicitly with
> camleContext.getTypeConverterRegistry() ) then I get the following
> exception:
>
> org.apache.camel.RuntimeCamelException: java.lang.ClassCastException: Not
> instanceof org.apache.camel.TypeConverter value:
> org.apache.camel.converter.jaxb.FallbackTypeConverter@35f3198f:
> java.lang.ClassCastException: Not instanceof org.apache.camel.TypeConverter
> value: org.apache.camel.converter.jaxb.FallbackTypeConverter@35f3198f
> at
> org.apache.camel.impl.DefaultFactoryFinder.newInstance(DefaultFactoryFinder.java:109)
> at
> org.apache.camel.impl.DefaultFactoryFinder.newInstance(DefaultFactoryFinder.java:99)
> at
> org.apache.camel.impl.DefaultFactoryFinder.newInstances(DefaultFactoryFinder.java:65)
> at
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.loadFallbackTypeConverters(BaseTypeConverterRegistry.java:542)
> at
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.loadTypeConverters(BaseTypeConverterRegistry.java:535)
> at
> org.apache.camel.impl.converter.DefaultTypeConverter.doStart(DefaultTypeConverter.java:47)
> at
> org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
> at
> org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1888)
> at
> org.apache.camel.impl.DefaultCamelContext.doAddService(DefaultCamelContext.java:979)
> at
> org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:940)
> at
> org.apache.camel.impl.DefaultCamelContext.getTypeConverter(DefaultCamelContext.java:1148)
> at
> org.apache.camel.impl.DefaultCamelContext.getTypeConverterRegistry(DefaultCamelContext.java:1165)
>
> However, org.apache.camel.converter.jaxb.FallbackTypeConverter implements
> TypeConverter so how can this be the case? I'm not doing anything with
> custom type converters. I have found this on
> http://camel.apache.org/type-converter.html:
>
> ---
> Exposed the TypeConverterRegistry from CamelContext so end users more easily
> will be able to add type converters at runtime. This is also usable in
> situations where the default discovering of type converters fails on
> platforms with classloading issues.
>
> To access the registry, you get it from the CamelContext
> CamelContext context = ...
> context.getTypeConverterRegistry()
> ---
>
> but there is no indication of exactly how this could be used if there are
> class loading issues, and also simply calling getTypeConverterRegistry()
> triggers the problem, so I can't see how this would be of any use.
>
> I initially thought it may be caused by multiple versions of camel being
> included in the deployment, but I've checked and only one version of camel
> is used in the deployment war. Also the version of camel-core and
> camel-spring are matching.
>
> I'm currently using spring 3.2.1 and camel version 2.12.1, but I've also
> tried 2.12.4 and 2.13.2 with the same result. It occurs consistently on my
> local machine where I use the maven-jetty plugin (6.1.26) under cygwyn,
> however when deployed to a Tomcat server (v5.5.20 running on CentOS 5.1),
> the problem is only intermittent.
>
> Any pointers to what could be the problem would be much appreciated
>
> thanks in advance
>
> Jason
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/java-lang-ClassCastException-Not-instanceof-org-apache-camel-TypeConverter-value-org-apache-camel-cor-tp5755390.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/