3 Replies Latest reply on Aug 26, 2009 12:44 PM by Ulhas Bhole

    Problem with an OSGi bundle with CXF SOAP web services

    Oren Livne Novice

      Dear All,

       

      I have a bundle that contains some cxf soap (and rest) services. Unfortunately, it fails to start because it does not find the annotation javax.jws.WebService (the error below is in one of my spring beans declared in the dts-ws-context-services.xml that tries to add it as a property). I added javax.jws and javax.jws.soap to my import packages, but that doesn't help. I am using JDK 1.6.0_10 to run the fuse esb, and javax.jws should be part of the JVM's rt.jar. How can I let my bundle see the WebService annotation class?

       

      Thanks so much in advance.

       

                                        ? | BundleEvent STARTED

      20:33:40,421 | ERROR | tenderThread-152 | OsgiBundleXmlApplicationContext  | gatedExecutionApplicationContext  366 | Post refresh error

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapClasses' defined in URL bundle://242.0:0/META-INF/spring/dts-ws-context-services.xml: Cannot create inner bean 'edu.utah.further.core.util.io.AnnotatedClassResourceMatcher#405782' of type while setting bean property 'resourceMatcher'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edu.utah.further.core.util.io.AnnotatedClassResourceMatcher#405782' defined in URL bundle://242.0:0/META-INF/spring/dts-ws-context-services.xml: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class : Constructor threw exception; nested exception is org.springframework.beans.FatalBeanException: Could not add annotation class javax.jws.WebService to the list of annotations in the annotatedClasses property of the sessionFactory declaration: java.lang.ClassNotFoundException: javax.jws.WebService

           at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)

           at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:117)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

           at java.security.AccessController.doPrivileged(Native Method)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)

           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)

           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)

           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)

           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)

           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)

           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)

           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:68)

           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:343)

           at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:308)

           at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:138)

           at java.lang.Thread.run(Thread.java:619)

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edu.utah.further.core.util.io.AnnotatedClassResourceMatcher#405782' defined in URL bundle://242.0:0/META-INF/spring/dts-ws-context-services.xml: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class : Constructor threw exception; nested exception is org.springframework.beans.FatalBeanException: Could not add annotation class javax.jws.WebService to the list of annotations in the annotatedClasses property of the sessionFactory declaration: java.lang.ClassNotFoundException: javax.jws.WebService

           at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

           at java.security.AccessController.doPrivileged(Native Method)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)

           at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)

           ... 20 more

      Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class : Constructor threw exception; nested exception is org.springframework.beans.FatalBeanException: Could not add annotation class javax.jws.WebService to the list of annotations in the annotatedClasses property of the sessionFactory declaration: java.lang.ClassNotFoundException: javax.jws.WebService

           at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)

           at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)

           at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)

           ... 27 more

      Caused by: org.springframework.beans.FatalBeanException: Could not add annotation class javax.jws.WebService to the list of annotations in the annotatedClasses property of the sessionFactory declaration: java.lang.ClassNotFoundException: javax.jws.WebService

           at edu.utah.further.core.util.io.ClasspathUtil.loadClassWithDetailedExceptions(ClasspathUtil.java:153)

           at edu.utah.further.core.util.io.AnnotatedClassResourceMatcher.toAnnotationClassSet(AnnotatedClassResourceMatcher.java:109)

           at edu.utah.further.core.util.io.AnnotatedClassResourceMatcher.(AnnotatedClassResourceMatcher.java:58)

           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

           at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

           at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)

           ... 29 more

        • 1. Re: Problem with an OSGi bundle with CXF SOAP web services
          Oren Livne Novice

          The problem might be that I am trying to load a class via Class.forName(), and I know it is risky to load a class with classloaders in an osgi bundle. The code below throws the ClassNotFoundException on the bus, but works just fine in stand-alone tests (say, in a maven build). What is the proper way to load a class by name in an osgi bundle?

           

          Thanks so much in advance!

           

           

               /**

                 

          • Load an annotation class by name.

                *

                 

          • @param <T>

                 

          •            class type

                 

          • @param className

                 

          •            class' fully qualified name

                 

          • @return class class, if found

                 

          • @throws FatalBeanException

                 

          •             if class is not found

                */

               @SuppressWarnings("unchecked")

               public static ) Class.forName(cleanContextFileString(className));

                    }

                    catch (final NoClassDefFoundError ignore)

                    {

                         throw new FatalBeanException(

                                   "The class "

                                             + className

                                             + " in the annotatedClasses property of the sessionFactory declaration is not an annotation type.");

                    }

                    catch (final ClassCastException e)

                    {

                         throw new FatalBeanException(

                                   "Could not find annotation class "

                                             + className

                                             + " in the annotatedClasses property of the sessionFactory declaration.");

                    }

                    catch (final Throwable throwable)

                    {

                         throw new FatalBeanException(

                                   "Could not add annotation class "

                                             + className

                                             + " to the list of annotations in the annotatedClasses property of the sessionFactory declaration: "

                                             + throwable);

                    }

               }

          • 2. Re: Problem with an OSGi bundle with CXF SOAP web services
            Oren Livne Novice

            Using Thread.currentThread().getContextClassLoader().loadClass(name) solved it.

            • 3. Re: Problem with an OSGi bundle with CXF SOAP web services
              Ulhas Bhole Novice

              In OSGI environment you should really avoid/replace any kind of Class.forName() stuff. It is generally a good candidate for another service provided by separate bundle.

               

              Ulhas Bhole