Yes, I found that too and added this jira entry https://issues.apache.org/jira/browse/CXF-1562
I finally got cxf working in osgi w/spring-dm. Gosh that was fun, but at least an order of magnitude easier than spring-ws -----Original Message----- From: Peter Gardfjell <[EMAIL PROTECTED]> Sent: Friday, May 2, 2008 1:08pm To: [email protected] Subject: Re: cxf Autowiring in OSGI Hi guys, I have actually packaged CXF (and a subset of its dependencies) as an OSGi bundle and used it from another (service) bundle that is not managed by Spring DM. As far as I can tell, everything works well. I used the Bnd bundling tool to generate the bundle and its OSGi manifest headers. Or, rather, I used the maven-bundle-plugin (which is a Maven plugin that wraps the Bnd tool). Initially, I also experienced problems similar to the one described by Dave. As it turned out, the problems were caused by my bundle not making META-INF/cxf and META-INF/services available to other bundles. Hence, I needed to add META-INF.cxf and META-INF.services to the CXF bundle's Export-Package manifest header. Although I intend to use Spring DM, I have only tested it with a service bundle that was _not_ wired up by Spring DM. That is, I register my web service with the (standard JAX-WS) Endpoint.publish() method. CXF fires up its engine, the service is published, and I can invoke it from client code. Everything seems to be working just fine. However, I haven't tested it extensively yet. For what it's worth, the maven build file (pom.xml) is provided below. As you can see, I have chosen to strip down the CXF bundle by excluding some of its dependencies that I either did not need or chose to provide in separate OSGi bundles. I guess the instructions passed to the maven-bundle-plugin may be of interest. (As a side-note, I looked at the ServiceMix bundling of CXF when I wrote this build file). As I'm a novice, both when it comes to OSGi and maven, I would appreciate if you would care to comment any potential problems you see with the bundling. cheers, Peter ------------------------------- <?xml version="1.0"?> <project> <!-- Generates an OSGi bundle for the Apache CXF implementation of the JAX-WS specification. The build works but generates build errors due to (forced) classpath entries that are not "approved" by the Bnd tool. This error is, however, supressed to make sure that a bundle is created anyway. --> <modelVersion>4.0.0</modelVersion> <groupId>cxf.osgi</groupId> <artifactId>cxf.osgi</artifactId> <name>Apache CXF OSGi bundle</name> <version>2.1</version> <packaging>bundle</packaging> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-bundle</artifactId> <version>2.1</version> <exclusions> <!-- No WS-Security support --> <exclusion> <groupId>bouncycastle</groupId> <artifactId>bcprov-jdk14</artifactId> </exclusion> <exclusion> <groupId>xalan</groupId> <artifactId>xalan</artifactId> </exclusion> <exclusion> <groupId>org.apache.ws.security</groupId> <artifactId>wss4j</artifactId> </exclusion> <exclusion> <groupId>xml-security</groupId> <artifactId>xmlsec</artifactId> </exclusion> <!-- Exclude log4j (provided by Spring DM) --> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> <!-- Exclude spring (provided by platform) --> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <!-- No Aegis support --> <exclusion> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> </exclusion> <exclusion> <groupId>stax-utils</groupId> <artifactId>stax-utils</artifactId> </exclusion> <exclusion> <groupId>jdom</groupId> <artifactId>jdom</artifactId> </exclusion> <!-- No JAX-RS support included --> <exclusion> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> </exclusion> <exclusion> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-extensions-main</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-parser</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-server</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-extensions-html</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-extensions-json</artifactId> </exclusion> <exclusion> <groupId>org.apache.abdera</groupId> <artifactId>abdera-i18n</artifactId> </exclusion> <exclusion> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-api</artifactId> </exclusion> <exclusion> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-impl</artifactId> </exclusion> <!-- Exclude JMS transport support --> <exclusion> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jms_1.1_spec</artifactId> </exclusion> <!-- Exclude CORBA support --> <exclusion> <groupId>antlr</groupId> <artifactId>antlr</artifactId> </exclusion> <!-- Exclude dependencies needed for Java2WSDL and WSDL2Java --> <exclusion> <groupId>velocity</groupId> <artifactId>velocity</artifactId> </exclusion> <exclusion> <groupId>velocity</groupId> <artifactId>velocity-dep</artifactId> </exclusion> <exclusion> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-xjc</artifactId> </exclusion> <!-- Exclude xmlbeans dependency --> <exclusion> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> </exclusion> <!-- Exclude mozilla javascript lib --> <exclusion> <groupId>rhino</groupId> <artifactId>js</artifactId> </exclusion> <!-- Exclude ant lib --> <exclusion> <groupId>ant</groupId> <artifactId>ant</artifactId> </exclusion> <exclusion> <groupId>ant</groupId> <artifactId>ant-nodeps</artifactId> </exclusion> <!-- Exclude commons-logging (provide as a separate target platform bundle) --> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> <!-- Exclude jetty (provide as a target platform bundle instead) --> <exclusion> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty</artifactId> </exclusion> <exclusion> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-util</artifactId> </exclusion> <!-- Exclude asm (provided via Spring DM as a separate bundle in the target platform) --> <exclusion> <groupId>asm</groupId> <artifactId>asm</artifactId> </exclusion> <!-- Exclude aopalliance (provided via Spring DM as a separate bundle in the target platform) --> <exclusion> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <!-- TODO: take a look at what repositories should be used. --> <repositories> <!-- Default repository --> <repository> <id>central</id> <name>Default maven repo</name> <url>http://repo1.maven.org/maven2</url> </repository> <repository> <id>apache.org.snapshot</id> <name>apache.org.snapshot</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> </repository> <repository> <id>apache.org.incubator</id> <name>apache.org.incubator</name> <url>http://people.apache.org/repo/m2-incubating-repository</url> </repository> <repository> <id>java.net</id> <name>java.net Maven Repository</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <!-- To get jsr173.jar and jsr173-ri.jar --> <repository> <id>servicemix.repository</id> <name>servicemix.repository</name> <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url> </repository> </repositories> <properties> <!-- Bundle manifest properties --> <bundle.symbolic.name>${groupId}</bundle.symbolic.name> <bundle.description>Apache CXF OSGi bundle</bundle.description> <!-- Need to export META-INF/cxf directory to make CXF configuration files available. Also, META-INF/services, which contain service provider declarations, needs to be exported. --> <export.package>!1.0*, javax.jws*;version=2.0, *;-split-package:=merge-first, '=META-INF.cxf', '=META-INF.services'</export.package> <import.package>org.apache.commons.logging*, org.xml.*, org.w3c*, org.mortbay*, *;resolution:=optional</import.package> <dynamic.import.package>*</dynamic.import.package> </properties> <build> <plugins> <!-- maven-bundle-plugin configuration --> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>1.4.0</version> <extensions>true</extensions> <configuration> <manifestLocation>META-INF</manifestLocation> <instructions> <Bundle-SymbolicName>${bundle.symbolic.name}</Bundle-SymbolicName> <Bundle-Description>${bundle.description}</Bundle-Description> <Bundle-Activator>${bundle.activator.class}</Bundle-Activator> <Export-Package>${export.package}</Export-Package> <Private-Package>${private.package}</Private-Package> <Import-Package>${import.package}</Import-Package> <DynamicImport-Package>${dynamic.import.package}</DynamicImport-Package> <!-- The bundle plugin does not like us explicitly adding META-INF/cxf and META-INF/services to the bundle's set of exported packages. This instruction prevents the bundling from failing. --> <_failok>true</_failok> </instructions> </configuration> </plugin> <!-- configure manifest generation plugin --> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <executions> <execution> <id>bundle-manifest</id> <phase>process-classes</phase> <goals> <goal>manifest</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> gnodet wrote: > > Here's what we came up with so far: > > http://servicemix.apache.org/SMX4/cxf-examples.html#CXFexamples-Insidetheexample > > if you really want to use the non spring configuration, the best way > to avoid classloader issues may be to embed cxf and its dependencies > inside a single bundle along with your services. > > On Wed, Apr 30, 2008 at 4:06 PM, Daniel Kulp <[EMAIL PROTECTED]> wrote: >> >> Dave, >> >> >> Guillaume Nodet definitely has more experience with the OSGi stuff. In >> generaly, we've seen success using the Spring Dynamic Module stuff with >> OSGi as you can import the cxf stuff you need in the spring module and >> the bus gets wired up correctly. (in 2.0.6/2.1, we even added a >> cxf-all.xml that you can import to grab everything, but thats probably >> more than you need) >> >> I'm not sure if anyone not using spring-dm has gotten anything to work. >> One option MAY be to call SpringBusFactory.createBus() yourself first to >> cause the Bus to be created with spring. Not sure if that works though >> as I'm not sure if it will find all the spring config files or not. >> >> Dan >> >> >> >> >> >> On Tuesday 29 April 2008, Dave Brosius wrote: >> > OK, this code is failing in OSGI >> > >> > BusFactory.getBusFactoryClass >> > >> > specifically, it tries to load the file >> > >> > META-INF/services/org.apache.cxf.bus.factory >> > >> > and fails. >> > >> > [CODE] >> > private static String getBusFactoryClass(ClassLoader classLoader) { >> > >> > String busFactoryClass = null; >> > String busFactoryCondition = null; >> > >> > // next check system properties >> > busFactoryClass = >> > System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME); if >> > (isValidBusFactoryClass(busFactoryClass)) { >> > return busFactoryClass; >> > } >> > >> > try { >> > // next, check for the services stuff in the jar file >> > String serviceId = "META-INF/services/" + >> > BusFactory.BUS_FACTORY_PROPERTY_NAME; InputStream is = null; >> > >> > if (classLoader == null) { >> > classLoader = >> > Thread.currentThread().getContextClassLoader(); } >> > >> > if (classLoader == null) { >> > is = ClassLoader.getSystemResourceAsStream(serviceId); >> > } else { >> > is = classLoader.getResourceAsStream(serviceId); >> > } >> > if (is != null) { >> > BufferedReader rd = new BufferedReader(new >> > InputStreamReader(is, "UTF-8")); busFactoryClass = rd.readLine(); >> > busFactoryCondition = rd.readLine(); >> > rd.close(); >> > } >> > if (isValidBusFactoryClass(busFactoryClass)) { >> > if (busFactoryCondition != null) { >> > try { >> > classLoader.loadClass(busFactoryCondition); >> > return busFactoryClass; >> > } catch (ClassNotFoundException e) { >> > return DEFAULT_BUS_FACTORY; >> > } >> > } else { >> > return busFactoryClass; >> > } >> > } >> > >> > // otherwise use default >> > busFactoryClass = BusFactory.DEFAULT_BUS_FACTORY; >> > return busFactoryClass; >> > } catch (Exception ex) { >> > LogUtils.log(LOG, Level.SEVERE, >> > "FAILED_TO_DETERMINE_BUS_FACTORY_EXC", ex); } >> > return busFactoryClass; >> > } >> > [/CODE] >> > >> > >> > -----Original Message----- >> > From: Dave Brosius <[EMAIL PROTECTED]> >> > Sent: Tuesday, April 29, 2008 6:27pm >> > To: [email protected] >> > Cc: [EMAIL PROTECTED] >> > Subject: RE: cxf Autowiring in OSGI >> > >> > Here's the difference: Can anyone help me with why this is so? >> > >> > In OSGI, createBus creates a CXFBusFactory >> > >> > Thread [SpringOsgiExtenderThread-2] (Suspended) >> > CXFBusFactory.createBus() line: 32 >> > BusFactory.getDefaultBus(boolean) line: 69 >> > BusFactory.getThreadDefaultBus(boolean) line: 106 >> > BusFactory.getThreadDefaultBus() line: 97 >> > JaxWsServerFactoryBean(AbstractEndpointFactory).getBus() line: >> 73 >> > >> JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).initializeSe >> >rviceFactory() line: 143 >> > JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).createEndpoin >> >t() line: 73 JaxWsServerFactoryBean(ServerFactoryBean).create() line: >> > 113 JaxWsServerFactoryBean.create() line: 160 >> > EchoInstaller.init() line: 23 >> > NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: >> not >> > available [native method] NativeMethodAccessorImpl.invoke(Object, >> > Object[]) line: 39 >> > DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 >> > Method.invoke(Object, Object...) line: 585 >> > >> DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).invoke >> >CustomInitMethod(String, Object, String, boolean) line: 1378 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).invokeI >> >nitMethods(String, Object, RootBeanDefinition) line: 1339 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initial >> >izeBean(String, Object, RootBeanDefinition) line: 1299 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreat >> >eBean(String, RootBeanDefinition, Object[]) line: 463 >> > AbstractAutowireCapableBeanFactory$1.run() line: 404 >> > AccessController.doPrivileged(PrivilegedAction<T>) line: not >> > available [native method] >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createB >> >ean(String, RootBeanDefinition, Object[]) line: 375 >> > AbstractBeanFactory$1.getObject() line: 263 >> > >> DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton >> >(String, ObjectFactory) line: 170 >> > DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, >> > Class, Object[], boolean) line: 260 >> > DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class, >> > Object[]) line: 184 >> > DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: >> > 163 DefaultListableBeanFactory.preInstantiateSingletons() line: 430 >> > OsgiBundleXmlApplicationContext(AbstractApplicationContext).finishBean >> >FactoryInitialization(ConfigurableListableBeanFactory) line: 729 >> > OsgiBundleXmlApplicationContext(AbstractDelegatedExecutionApplicationC >> >ontext).completeRefresh() line: 268 >> > DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run() >> > line: 142 >> > DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run() >> > line: 142 Thread.run() line: 595 >> > >> > >> > In standard mode, createBus creates a SpringBusFactory >> > >> > Thread [main] (Suspended (breakpoint at line 54 in SpringBusFactory)) >> > SpringBusFactory.createBus() line: 54 >> > BusFactory.getDefaultBus(boolean) line: 69 >> > BusFactory.getThreadDefaultBus(boolean) line: 106 >> > BusFactory.getThreadDefaultBus() line: 97 >> > JaxWsServerFactoryBean(AbstractEndpointFactory).getBus() line: >> 73 >> > >> JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).initializeSe >> >rviceFactory() line: 143 >> > JaxWsServerFactoryBean(ServerFactoryBean).initializeServiceFactory() >> > line: 149 >> > JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).createEndpoin >> >t() line: 73 JaxWsServerFactoryBean(ServerFactoryBean).create() line: >> > 113 JaxWsServerFactoryBean.create() line: 160 >> > Main.main(String[]) line: 19 >> > >> > >> > >> > >> > -----Original Message----- >> > From: Dave Brosius <[EMAIL PROTECTED]> >> > Sent: Tuesday, April 29, 2008 6:15pm >> > To: [email protected] >> > Cc: [EMAIL PROTECTED] >> > Subject: cxf Autowiring in OSGI >> > >> > I am having trouble getting cxf to work in osgi. The problem is that >> > it appears that there are no factories registered for the various >> > namespaces needed such as http://schemas.xmlsoap.org/soap/http >> > >> > >> > When run in normal mode (not osgi), I see these namespaces being >> > registered (in the below stack trace). In OSGI this isn't happening >> > and so it fails in JaxWsServerFactoryBean.createBindingInfo. Does >> > anyone have any ideas about how to fix this? >> > >> > >> > [CODE] >> > Thread [main] (Suspended (breakpoint at line 79 in >> > DestinationFactoryManagerImpl)) >> > DestinationFactoryManagerImpl.registerDestinationFactory(String, >> > DestinationFactory) line: 79 >> > JettyHTTPTransportFactory.finalizeConfig() line: 68 >> > NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: >> not >> > available [native method] NativeMethodAccessorImpl.invoke(Object, >> > Object[]) line: 39 >> > DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 >> > Method.invoke(Object, Object...) line: 585 >> > ResourceInjector.invokePostConstruct() line: 305 >> > ResourceInjector.construct(Object) line: 86 >> > Jsr250BeanPostProcessor.postProcessAfterInitialization(Object, >> > String) line: 58 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBe >> >anPostProcessorsAfterInitialization(Object, String) line: 357 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initial >> >izeBean(String, Object, RootBeanDefinition) line: 1308 >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreat >> >eBean(String, RootBeanDefinition, Object[]) line: 463 >> > AbstractAutowireCapableBeanFactory$1.run() line: 404 >> > AccessController.doPrivileged(PrivilegedAction<T>) line: not >> > available [native method] >> > DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createB >> >> >ean(String, RootBeanDefinition, Object[]) line: 375 >> > AbstractBeanFactory$1.getObject() line: 263 >> > >> DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton >> >(String, ObjectFactory) line: 170 >> > DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, >> > Class, Object[], boolean) line: 260 >> > DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class, >> > Object[]) line: 184 >> > DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: >> > 163 DefaultListableBeanFactory.preInstantiateSingletons() line: 430 >> > BusApplicationContext(AbstractApplicationContext).finishBeanFactoryIni >> >tialization(ConfigurableListableBeanFactory) line: 729 >> > BusApplicationContext(AbstractApplicationContext).refresh() line: 381 >> > BusApplicationContext.<init>(String[], boolean, ApplicationContext) >> > line: 86 SpringBusFactory.createBus(String[], boolean) line: 93 >> > SpringBusFactory.createBus(String, boolean) line: 87 >> > SpringBusFactory.createBus(String) line: 65 >> > SpringBusFactory.createBus() line: 54 >> > BusFactory.getDefaultBus(boolean) line: 69 >> > BusFactory.getThreadDefaultBus(boolean) line: 106 >> > BusFactory.getThreadDefaultBus() line: 97 >> > JaxWsServerFactoryBean(AbstractEndpointFactory).getBus() line: >> 73 >> > >> JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).initializeSe >> >> >rviceFactory() line: 143 >> > JaxWsServerFactoryBean(ServerFactoryBean).initializeServiceFactory() >> > line: 149 >> > JaxWsServerFactoryBean(AbstractWSDLBasedEndpointFactory).createEndpoin >> >> >> >t() line: 73 JaxWsServerFactoryBean(ServerFactoryBean).create() line: >> > 113 JaxWsServerFactoryBean.create() line: 160 >> > Main.main(String[]) line: 19 >> > [/CODE] >> >> >> >> -- >> J. Daniel Kulp >> Principal Engineer, IONA >> [EMAIL PROTECTED] >> http://www.dankulp.com/blog >> > > > > -- > Cheers, > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > > -- View this message in context: http://www.nabble.com/cxf-Autowiring-in-OSGI-tp16971724p17023794.html Sent from the cxf-user mailing list archive at Nabble.com.
