2 Replies Latest reply on Sep 8, 2011 9:45 PM by Michael Huisking

    Accessing Config File from a CXF WebService

    Michael Huisking Newbie

      Hi,

      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

        • 1. Re: Accessing Config File from a CXF WebService
          Willem Jiang Master

          You are deploying the war, not the OSGi bundle.

          You may consider to put the configure file into the war and using spring property holder to load the configure.

           

          Willem

          • 2. Re: Accessing Config File from a CXF WebService
            Michael Huisking Newbie

            Thanks for your response Willem.  I am looking for a way to not "bake" the config variables into the war file (so that they can be modified without rebuilding or manipulating the war) 

             

            Another thing I was playing around with (and not that elegant) was to add $SMX_HOME/etc to the system classpath and then specifying this:

             

            <ctx:property-placeholder location="classpath:com.foo.properties.cfg" />

             

            Since the etc directory is now on the classpath, the variables can be loaded with the Spring property-placeholder.

             

            On a side note, I made a little test program to run as one of these wrapped war files and found out that you can't cast a org.eclipse.osgi.internal.baseadaptor.defaultclassloader to a urlclassloader... I thought I could use the trick of casting the classloader and getting the current classpath by iterating through the urls. 

             

            I'll mark this as "answered" and hopefully it can help someone else.