Hi,

I had the same problem and the solution is easy. Just create a class
that implements PackageScanClassResolver and define it as bean [1].
Camel will find it during startup of the context and use this bean
instead of creating the DefaultPackageScanClassResolver that scans the
classpath. Maybe you have to register some core TypeConverters manually
(this has been changed in 2.8-SNAPSHOT).

See my sample class below. Hope this helps.

Cheers Andi

/**
 * The DoNothingPackageScanClassResolver is a replacement for the
DefaultPackageScanClassResolver
 * to solve the problems with starting the client from webstart cache.
 * You just have to define a bean of this class and camel will replace
the 
 * DefaultPackageScanClassResolver during startup with this bean.  
 *
 */
public class DoNothingPackageScanClassResolver implements
PackageScanClassResolver {

        public void setClassLoaders(Set<ClassLoader> classLoaders) {
                // do nothing here
        }

        public Set<ClassLoader> getClassLoaders() {
        // return a new set to avoid any concurrency issues in other
runtimes such as OSGi
        return Collections.unmodifiableSet(new
LinkedHashSet<ClassLoader>());
        }

        public void addClassLoader(ClassLoader classLoader) {
                // do nothing here
        }

        public Set<Class<?>> findAnnotated(Class<? extends Annotation>
annotation,
                        String... packageNames) {
                return new LinkedHashSet<Class<?>>();
        }

        public Set<Class<?>> findAnnotated(
                        Set<Class<? extends Annotation>> annotations,
                        String... packageNames) {
                return new LinkedHashSet<Class<?>>();
        }

        public Set<Class<?>> findImplementations(Class<?> parent,
                        String... packageNames) {
                return new LinkedHashSet<Class<?>>();
        }

        public Set<Class<?>> findByFilter(PackageScanFilter filter,
                        String... packageNames) {
                return new LinkedHashSet<Class<?>>();
        }

        public void addFilter(PackageScanFilter filter) {
                // do nothing here
        }

        public void removeFilter(PackageScanFilter filter) {
                // do nothing here
        }

}

[1]
http://camel.apache.org/advanced-configuration-of-camelcontext-using-spr
ing.html

-----Original Message-----
From: Jim Newsham [mailto:jnews...@referentia.com] 
Sent: Freitag, 27. Mai 2011 04:55
To: users@camel.apache.org
Subject: TypeConverterLoaderException in webstart


We've come across a problem in Camel 2.7.1 where Camel fails to start up

due to a TypeConverterLoaderException.  This is a regression, as we've 
had no such problem in Camel 2.5.0.  Is this a known issue?  Googling 
around, I've found [1], which states:

>  My second problem is that it's currently not possible to start camel
>  without the AnnotationTypeConverterLoader added. In case of a
webstart
>  based client application this causes startup errors that prevents
using
>  camel.
>  I added an attribute to suppress the usage of
>  AnnotationTypeConverterLoader in my local sources and I've prepared a
>  patch for this problem and the problem described above with test
case.
>
>  Should I create a JIRA issue?

I can't say that I understand his description of the problem or his 
fix.  Has a jira issue been created?

My reproduction is simple:

   public static void main(String... args) {
     try {
       CamelContext context = new DefaultCamelContext();
       context.getTypeConverterRegistry();

       LOGGER.info("Success");
     }
     catch(Exception e) {
       LOGGER.error("Failed", e);
     }
   }

This runs fine in my ide and fails with [2] when deployed via webstart.

Thanks,
Jim

[1] 
http://mail-archives.apache.org/mod_mbox/camel-users/201104.mbox/%3C1302
240811211-4290078.p...@n5.nabble.com%3E

[2] exception:

2011-05-26 16:52:57,550 [javawsApplicationMain] ERROR 
test.TestCamelContext - Failed
org.apache.camel.RuntimeCamelException: 
org.apache.camel.TypeConverterLoaderException: Failed to load type 
converters because of: Cannot find any type converter classes from the 
following packages: [org.apache.camel.component.file, 
org.apache.camel.component.bean, org.apache.camel.converter]
     at 
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelpe
r.java:1139)
     at 
org.apache.camel.impl.DefaultCamelContext.getTypeConverter(DefaultCamelC
ontext.java:986)
     at 
org.apache.camel.impl.DefaultCamelContext.getTypeConverterRegistry(Defau
ltCamelContext.java:1001)
     at test.TestCamelContext.test(TestCamelContext.java:54)
     at test.TestCamelContext.main(TestCamelContext.java:48)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at com.sun.javaws.Launcher.executeApplication(Unknown Source)
     at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
     at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
     at com.sun.javaws.Launcher.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.camel.TypeConverterLoaderException: Failed to load

type converters because of: Cannot find any type converter classes from 
the following packages: [org.apache.camel.component.file, 
org.apache.camel.component.bean, org.apache.camel.converter]
     at 
org.apache.camel.impl.converter.AnnotationTypeConverterLoader.load(Annot
ationTypeConverterLoader.java:79)
     at 
org.apache.camel.impl.converter.BaseTypeConverterRegistry.loadTypeConver
ters(BaseTypeConverterRegistry.java:395)
     at 
org.apache.camel.impl.converter.DefaultTypeConverter.doStart(DefaultType
Converter.java:41)
     at
org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
     at
org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
     at 
org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:60)
     at 
org.apache.camel.impl.DefaultCamelContext.startServices(DefaultCamelCont
ext.java:1613)
     at 
org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext
.java:899)
     at 
org.apache.camel.impl.DefaultCamelContext.getTypeConverter(DefaultCamelC
ontext.java:984)
     ... 12 more

Reply via email to