3 Replies Latest reply on Jul 17, 2009 2:07 PM by Roger Cracel

    DBCP Datasource in FUSE ESB 4

    Roger Cracel Newbie

      I have deployed two bundles in FUSE ESB 4, a DataSource and a DAO, and configured my DataSource's bean as follows:

       

             <bean id="commonDatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                  <property name="driverClassName" value="${driver}"></property>
                  <property name="url" value="${url}"></property>
                  <property name="username" value="${user}"></property>
                  <property name="password" value="${password}"></property>
                  <property name="initialSize" value="${initialConnections}"></property>
             </bean>
      

       

      and exported it like so...

       

           <osgi:service auto-export="all-classes" ref="commonDatasource">
                <osgi:interfaces>
                     <value>javax.sql.DataSource</value>
                </osgi:interfaces>
           </osgi:service>
      

       

      -


       

      Now, on my DAO I have imported the datasource:

       

      <osgi:reference id="commonDatasource" interface="javax.sql.DataSource" />

       

      and using spring jdbc I initialize my dao object:

       

           <bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
                <constructor-arg>
                     <ref bean="commonDatasource"></ref>
                </constructor-arg>
           </bean>
      
           <bean id="myDAO" class="com.mycompany.MyDAOImpl">
                <property name="jdbcTemplate" ref="jdbcTemplate"></property>
           </bean>
      

       

      all works well until I try to use my datasource, that is when I get a NullPointerException I have been having a really hard time tracking down:

       

      smx@root:></![CDATA[> Exception in thread "SpringOsgiExtenderThread-82" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDAO' defined in URL [bundle://160.3:0/META-INF/spring/bundle-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
      PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NullPointerException
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
              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 'myDAO' defined in URL [bundle://160.3:0/META-INF/spring/bundle-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
      PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NullPointerException
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
              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.osgi.service.exporter.support.OsgiServiceFactoryBean.afterPropertiesSet(OsgiServiceFactoryBean.java:167)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
              ... 17 more
      Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
      PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NullPointerException
              at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104)
              at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
              ... 30 more
      

       

       

      I have tried tracking down the culprit of the problem, has anyone been able to succesfully deploy a datasource in the ESB as an OSGi bundle?

       

      Here are the support bundles I have installed:

       

      [ 156] [Active     ] [       ] [   60] PostgreSQL JDBC4 Driver (8.3.604)
      
      [ 157] [Active     ] [       ] [   60] Spring JDBC (2.5.6)
      
      [ 158] [Active     ] [       ] [   60] Apache Commons Database Connection Pool (1.2.2.osgi)
      
      [ 160] [Active     ] [Failed ] [   60] MyDAO (0.0.1.SNAPSHOT)
      

       

      I have a cxf bundle that uses the DAO and, as soon as I invoke a method that uses the DAO (and therefore the datasource) I get that exceptions.

       

      Also, I've tried to acquire a connection on the setter of the jdbc template on my DAO, just to eliminate the cxf bundle from the equation, and still get the same problem. Not sure what else to try at this point, any help would be pretty much appreciated.

       

      thank you

        • 1. Re: DBCP Datasource in FUSE ESB 4
          Sean O'Callaghan Newbie

          Hi,

           

          I haven't seen this problem before but given the exception is there a setter for the property "datasource" that should be having a value passed to it?

           

          If you have a simple testcase we can try and reproduce the issue and do some further debugging.

           

          Regards,

           

          Seán.

          • 2. Re: DBCP Datasource in FUSE ESB 4
            Roger Cracel Newbie

            Hello Sean,

             

            thank you for your response.

             

            I think I have been able to pinpoint the exact source of the problem, and hope you can offer some advice on how to proceed.

             

            The actual structure of my bundles is as follows:

             

            WebService (uses cxf-osgi) -> API -> DAO ->DataSource

             

            All this worked well until recently, and just this morning I was able to figure out what caused it to stop working.

             

            Over the last couple of days I decided to use SpringAOP and created a new aspect around the API implementation class, as follows:

             

                 <aop:config>
                 
                      <aop:pointcut id="apiCalls" expression="execution(* com.mycompany.myapp.api.*.*(..))"></aop:pointcut>
                      
                      <aop:aspect id="loggerAspect" ref="loggingInterceptor">
                           <aop:around method="methodAuditor" pointcut-ref="apiCalls" arg-names="pjp"></aop:around>
                      </aop:aspect>
                      
                 </aop:config>
            

             

            The advice works fine and I log a before and after message (catching all exceptions), however the execution of the DAO fails with the exception I mentioned above.

             

            Roger

            • 3. Re: DBCP Datasource in FUSE ESB 4
              Roger Cracel Newbie

              I think I solved the problem, although I am not entirely clear on why.

               

              By default, spring will create Java Proxies instead of CGLIB proxies. So I changed the aop tag to the following:

               

              <aop:config proxy-target-class="true">
              ....
              </aop:config>

               

              and now it appears to be working again.

               

              Roger