1 Reply Latest reply on Sep 26, 2012 8:24 PM by Sham HC

    Problems while getting the Datasource from a Utill class

    chamila.fernando Level 1

      Hi all,

       

      I faced a problem when following below instructions.

       

      http://dev.day.com/content/kb/home/cq5/Development/HowToConfigureSlingDatasource.html

       

      It would not return from the getDataSource(dataSourceName); call. No exceptions.

       

      public DataSource getDataSource(String dataSourceName) {

              DataSource dataSource = null;

              try {

       

               log.info("Reaches here ! ");

       

                  dataSource = (DataSource) dataSourceService

                          .getDataSource(dataSourceName);

       

              log.info("Never Reaches here ! ");

       

              } catch (DataSourceNotFoundException e) {

                  log.error("Unable to find datasource {}.", dataSourceName, e);

              }       

              return dataSource;

      }

       

      I can connect to db directly from post.POST.jsp so DB is correctly mapped.

       

      I had to remove below annotation since while compiling the bundle, it says that it is deprecated.

           @scr.component immediate="true" metatype="no"

       

      Log is as follows...

       

      com.day.cqwebsite.impl.DatasourceUtilImpl -------------------------------------------- Using DataSourcePool service lookup to get connection pool mynewdsname

      26.09.2012 17:49:30.197 *INFO* [0:0:0:0:0:0:0:1 [1348661970143] POST /content/mywebsite_cq/en/toolbar/login.html HTTP/1.1] com.day.cqwebsite.impl.DatasourceUtilImpl Reaches here !

      26.09.2012 17:50:17.770 *INFO* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.impl.AgentManagerImpl Processing job for agent publish

      26.09.2012 17:50:17.770 *INFO* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish Sending POST request to http://localhost:4503/bin/receive?sling:authRequestLogin=1

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish Error while sending request: java.net.ConnectException: Connection refused: connect

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish Replication (ACTIVATE) of /etc/designs/mywebsite/images not successful: java.net.ConnectException: Connection refused: connect Conversation follows

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish ------------------------------------------------

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish Sending message to localhost:4503

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish >> POST /bin/receive HTTP/1.0

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish >> Action: Activate

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish >> Path: /etc/designs/mywebsite/images

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish >> Handle: /etc/designs/mywebsite/images

      26.09.2012 17:50:18.983 *ERROR* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.Agent.publish >> ...spooling 744 bytes...

      26.09.2012 17:50:18.983 *INFO* [pool-6-thread-32-com/day/cq/replication/job/publish(com/day/cq/replication/job/publish)] com.day.cq.replication.impl.AgentManagerImpl Job for agent publish processed in 1213ms. Failed.


       

      Any help will be great !

       

      Tx

        • 1. Re: Problems while getting the Datasource from a Utill class
          Sham HC Level 7

          Could you please use [1], verify & confirm. If does not work let me know cq version & jdbc jar you are using.

           

          [1]

           

          import org.apache.felix.scr.annotations.Component;

          import org.apache.felix.scr.annotations.Properties;

          import org.apache.felix.scr.annotations.Property;

          import org.apache.felix.scr.annotations.Service;

           

           

          @Component(immediate = true)

          @Service(value = DatasourceUtil.class)

          @Properties({

                  @Property(name = "service.description", value = "Data Source lookup example"),

                  @Property(name = "service.vendor", value = "Day Management AG")

          })

          1 person found this helpful