Accessing Config File from a CXF WebService
mhuisking_michael.c.huisking Sep 8, 2011 12:51 PMHi,
I am using ServiceMix 4.3.1-fuse and am deploying war file containing a CXF web service into ServiceMix using the install war:file:filename method. The war file is a
"plain vanilla" CXF servlet webservice with all parameters specified in the cxf-servlet.xml file and cxf configured in the web.xml file.
Up until now, I had a couple of parameters in a bean definition hard-coded, but I really need to get the values out of a configuration file instead. Since I am deploying in
ServiceMix, I thought I could add osgi-compendium and use a placeholder to get at a config file. Here's a sample of what I'm doing:
cxf-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" xmlns:ctx="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <osgix:cm-properties id="myConfig" persistent-id="com.foo.properties"> <prop key="Server">SNAME</prop> <prop key="Group">GROUP</prop> </osgix:cm-properties> <ctx:property-placeholder properties-ref="myConfig"></ctx:property-placeholder> <jaxws:endpoint xmlns:hpd="http://foo.com/wsdl/FooService/" id="FooService" address="/FooService" serviceName="hpd:FooService" endpointName="hpd:FooServicePort" implementor="#FooServiceImpl"> </jaxws:endpoint> <bean id="fooProxy" class="com.foo.FooAdapter"> <constructor-arg value="${Server}"></constructor-arg> <constructor-arg value="${Group}"></constructor-arg> </bean> <bean id="FooServiceImpl" class="com.foo.FooServiceImpl"> <property name="proxyAdapter" ref="fooProxy"></property> </bean> </beans>
The config file is in the $SMX_HOME/etc/ directory as "com.foo.properties.cfg"
When the properties/place holder are constructed I get a:
Error creating bean with name 'myConfig': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: bundleContext property is required
I think I'm missing a step here -- what else do I need to add to make the servlet aware of the container, or get the bundle context? Is this even possible when deploying a war file in this manner?
Thanks in advance,
Mick