15 Replies Latest reply on May 11, 2013 5:50 AM by Avinashtan

    QueryBuilder  builder getting null

    ravindrareddydr Level 1

      Hi

       

      I was tried

       

      ......................................................

       

      /**

      * This class is an example ,Create selected users under a group

      ***/

      @Component

      @Service

      @Properties({

              @Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample workflow to sync image b/w servers."),

              @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),

              @Property(name = "process.label", value = "DAM Image SYNC with Image Server")})

       

      public class ImageSync implements WorkflowProcess {

       

           @Reference

                 private QueryBuilder builder;

       

                 private static final Logger log = LoggerFactory.getLogger(ImageSync.class);

       

                public void execute(WorkItem item, WorkflowSession wsession, MetaDataMap metaData)

                                    throws WorkflowException {

                          try{

                          // TODO Auto-generated method stub

       

                                    //QueryBuilder builder = resource.getResourceResolver().adaptTo(QueryBuilder.class);

                                    Session session = wsession.getSession();

                                    Map<String, String> map = new HashMap<String,String>();

       

                  map.put("path", "/content/dam/geometrixx");

                        map.put("type", "dam:Asset");

       

                        Query query = builder.createQuery(PredicateGroup.create(map), session);

       

                        //query.setStart(0);

                        //query.setHitsPerPage(20);

       

       

                        SearchResult result = query.getResult();

       

                        Iterator<Node> itr = result.getNodes();

       

                        while(itr.hasNext()){

                                  Node node = itr.next();

                                  log.info("Node Name : "+node.getName() +"- Path :"+node.getPath());

                        }

                        wsession.complete(item, wsession.getRoutes(item).get(0));

       

                          }catch (Exception e) {

                                    // TODO: handle exception

                                    log.error("Exceptions @@@ "+e.getMessage());

                          }

                }

       

       

      }

       

       

      Issue 1 :

       

      If i use 

       

          @Reference

           private QueryBuilder builder;

      Exceptions :

       

      com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.test.ImageSync

       

      Issue 2 :

       

      If i use

       

           /**@scr.reference*/

           private QueryBuilder builder;

       

      Exception :

      [JobHandler: /etc/workflow/instances/2012-11-16/model_12901374305856:/content/fr] com.test.ImageSync Exceptions @@@ null

       

       

      Can any one help , How can i use annotations for the Query Builder

        • 1. Re: QueryBuilder  builder getting null
          rush_pawan Level 4

          I dont see any problem in referencing using

          @Reference

                        private QueryBuilder builder;

           

          Not sure why you are getting this issue. I can suggest one thing to cross check whether QueryBuilder service is runnning or not. just write below line in your jsp

           

          sling.getService(QueryBuilder.class); and check whethe it returns proper instance or not. All the best.

          • 2. Re: QueryBuilder  builder getting null
            Jörg Hoh Adobe Employee

            It doesn't matter, if you use the annotations or javadoc-style, the difference is only in the build process. The result should be the same. And in any case, your service shouldn't be active if the dependencies are not met. The availability of the QueryBuilder service is therefor required.

             

            Regarding the NPE: at what line/statement does it occur?

            • 3. Re: QueryBuilder  builder getting null
              justin_at_adobe Adobe Employee

              One minor clarification to Joerg's comment - you cannot mix annotations and javadoc-style in the same source file. Only one type will be processed.

              • 4. Re: QueryBuilder  builder getting null
                aklimets Adobe Employee

                As mentioned, you need to be consistent with the annotations, so the java annotations (1st) case is right. The error you get is unrelated to the querybuilder service here:

                 

                Process implementation not found: com.test.ImageSync

                 

                This looks like another problem that makes your service not properly exposed as WorkflowProcess or not even started at all.

                 

                Cheers,

                Alex


                • 5. Re: QueryBuilder  builder getting null
                  ravindrareddydr Level 1

                  Still fighting with annoations

                   

                  I am using CQ 5.5

                   

                  I tried simple class

                   

                  ..........................

                   

                   

                  import javax.jcr.Node;

                  import org.osgi.framework.Constants;

                  import org.slf4j.Logger;

                  import org.slf4j.LoggerFactory;

                  import com.day.cq.wcm.api.Page;

                  import com.day.cq.wcm.api.PageManager;

                  import com.day.cq.workflow.WorkflowException;

                  import com.day.cq.workflow.WorkflowSession;

                  import com.day.cq.workflow.exec.WorkItem;

                  import com.day.cq.workflow.exec.WorkflowProcess;

                  import com.day.cq.workflow.metadata.MetaDataMap;

                   

                  import org.apache.sling.api.resource.ResourceResolver;

                  import org.apache.sling.jcr.resource.JcrResourceUtil;

                  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.Reference;

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

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

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

                   

                   

                  /**

                  * This class is an example ,Create selected users under a group

                  ***/

                  @Component

                  @Service

                  @Properties({

                          @Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample workflow to copy users to group."),

                          @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),

                          @Property(name = "process.label", value = "Page Translation")})

                   

                   

                  public class PublishTranslation implements WorkflowProcess{

                   

                      private static final Logger log = LoggerFactory.getLogger(PublishTranslation.class);

                   

                      @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)

                            private ResourceResolver resourceResolver;

                   

                      public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap metadata)

                              throws WorkflowException {

                   

                  try{

                   

                            // Get workflow current instance path

                   

                            String instancePath = item.getWorkflow().getId();

                            String currentPage = (String)item.getWorkflowData().getPayload();

                     Node instanceNode = JcrResourceUtil.createPath(instancePath+"/data/metaData", "nt:resource","nt:resource", wfsession.getSession(), false);

                     instanceNode.getProperty("translation");

                     PageManager pageManager = resourceResolver.adaptTo(PageManager.class);

                     Page page = pageManager.getPage(currentPage);

                   

                     log.info("Page Title"+page.getTitle());

                     log.info("Page Path"+page.getPath());

                     log.info("Page Template"+page.getTemplate());

                   

                   

                     log.info("Jackrabbit Sessions Saved and workflow completed");

                   

                     wfsession.complete(item, wfsession.getRoutes(item).get(0));

                   

                  }catch (Exception e) {

                   

                      log.error("Exceptions Block @@@@"+e.getMessage());

                  }  

                  }

                   

                   

                  }

                   

                  ...............................................................

                   

                  error Log

                   

                  .........................

                   

                  20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.htr1.com.PublishTranslation

                  20.11.2012 23:08:00.928 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.htr1.com.PublishTranslation

                  20.11.2012 23:08:00.928 *INFO* [JobHandler: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Finished processing: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp(Complete execution took: 0ms)

                  20.11.2012 23:08:02.952 *INFO* [JobHandler: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Start processing: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp

                  20.11.2012 23:08:02.953 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.htr1.com.PublishTranslation

                  20.11.2012 23:08:02.953 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-20/model_22634159245011:/content/esp] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.htr1.com.PublishTranslation

                   

                  NO Process.png

                   

                   

                   

                  Bundle is deployed and active Apache console , No complie issues , all are good

                   

                  1. When i use  "@References" i am getting this issue

                   

                  Please any one help me

                   

                  Thanks

                  • 6. Re: QueryBuilder  builder getting null
                    ravindrareddydr Level 1

                    Bundle is deployed and active Apache console , No complie issues , all are good

                     

                    1. When i use  "@References" i am getting this issue

                     

                    Please any one help me

                    • 7. Re: QueryBuilder  builder getting null
                      justin_at_adobe Adobe Employee

                      You can only refer to OSGi Services. You can use the Services tab in the Web Console to see what services are available.

                      • 8. Re: QueryBuilder  builder getting null
                        ravindrareddydr Level 1

                        These are services running

                        Services.png

                        • 9. Re: QueryBuilder  builder getting null
                          justin_at_adobe Adobe Employee

                          Sorry, perhaps I didn't understand your question. My point is that annotating a ResourceResolver instance variable with @Reference is invalid because there's no service of that type.

                           

                          In other words, if you have


                              @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)

                                    private ResourceResolver resourceResolver;

                           

                          resourceResolver will never be injected.

                           

                          However, since you have the policy as Dynamic, this won't stop your component from being activated.

                          • 10. Re: QueryBuilder  builder getting null
                            ravindrareddydr Level 1

                            Thanks Edelson,

                             

                            How can i get Resource Resolver in my Java class.

                            • 11. Re: QueryBuilder  builder getting null
                              ravindrareddydr Level 1

                              Edelson ,

                               

                              I was tried with "ResourceResolverFactory", which service is running

                               

                              Service.png

                               

                              But i am still getting

                               

                              Code :

                               

                              ..........................

                              private static final Logger log = LoggerFactory.getLogger(PublishTranslation.class);

                               

                                  @Reference

                                        private ResourceResolverFactory resourceResolverFactory;

                               

                                  @Reference

                                        private PageManagerFactory pageManagerFactory;

                               

                                  public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap metadata)

                                          throws WorkflowException {

                                            ResourceResolver resolver; 

                              try{

                               

                                        // Get workflow current instance path

                               

                                        String instancePath = item.getWorkflow().getId();

                                        String currentPage = (String)item.getWorkflowData().getPayload();

                                 Node instanceNode = JcrResourceUtil.createPath(instancePath+"/data/metaData", "nt:resource","nt:resource", wfsession.getSession(), false);

                                 instanceNode.getProperty("translation");

                               

                                 resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

                                 PageManager pageManager = pageManagerFactory.getPageManager(resolver);

                                 Page page = pageManager.getPage(currentPage);

                               

                              ..........................................

                              Error

                               

                              .....................

                              21.11.2012 00:21:32.568 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-21/model_26908334200070:/content/test] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.hrtz1.com.PublishTranslation

                              21.11.2012 00:21:32.568 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-21/model_26908334200070:/content/test] com.day.cq.workflow.impl.job.JobHandler Process implementation not found: com.hrtz1.com.PublishTranslation

                               

                               

                               

                              Cloud you please help me, where i am wrong

                              • 12. Re: QueryBuilder  builder getting null
                                ravindrareddydr Level 1

                                When i use  code as, getting Null Pointer Exception

                                 

                                /** @scr.reference */

                                          private ResourceResolverFactory resourceResolverFactory;

                                 

                                           /** @scr.reference */

                                          private PageManagerFactory pageManagerFactory;

                                 

                                 

                                ...log

                                 

                                21.11.2012 01:17:26.742 *INFO* [JobHandler: /etc/workflow/instances/2012-11-21/model_30390418366990:/content/test] com.hertz1.com.PublishTranslation -------------/content/Hertz/test

                                21.11.2012 01:17:26.742 *ERROR* [JobHandler: /etc/workflow/instances/2012-11-21/model_30390418366990:/content/test] com.hrt1.com.PublishTranslation Exceptions Block @@@@java.lang.NullPointerException

                                 

                                can any one help me ?

                                • 13. Re: QueryBuilder  builder getting null
                                  justin_at_adobe Adobe Employee

                                  As previously discussed, if you mix annotation styles, you will run into problems.

                                   

                                  I don't know why your component isn't activating properly with the @Reference annotation. You will find more information in the log and/or the Components tab in the web console.

                                  • 14. Re: QueryBuilder  builder getting null
                                    Panasaki Level 1

                                    Good morning,

                                     

                                    I have had the same problem that ravindrareddydr I received null in a QueryBuilder Reference element.

                                     

                                    In error.log in the develop of the bundle saw this error:

                                    22.02.2013 10:33:47.328 *ERROR* [OsgiInstallerImpl] com.mycompany.cq.shared-core [com.mycompany..shared.utils.SubscribersManager] The bindQueryBuilder method has thrown an exception (java.lang.IllegalArgumentException: argument type mismatch) java.lang.IllegalArgumentException: argument type mismatch

                                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                                        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                                        at java.lang.reflect.Method.invoke(Unknown Source)

                                        at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:227)

                                        at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:38)

                                        at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:591)

                                        at org.apache.felix.scr.impl.helper.BaseMethod$NotResolved.invoke(BaseMethod.java:548)

                                        at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:472)

                                        at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.ja va:1028)

                                        at org.apache.felix.scr.impl.manager.DependencyManager.bind(DependencyManager.java:944)

                                        at org.apache.felix.scr.impl.manager.DependencyManager.open(DependencyManager.java:868)

                                        at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplementationObject(Im mediateComponentManager.java:200)

                                        at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createComponent(ImmediateComp onentManager.java:118)

                                        at org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.activate(AbstractC omponentManager.java:1140)

                                        at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractCompo nentManager.java:334)

                                        at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManage r.java:158)

                                        at org.apache.felix.scr.impl.config.ImmediateComponentHolder.enableComponents(ImmediateCompo nentHolder.java:313)

                                        at org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivato r.java:241)

                                        at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.ja va:147)

                                        at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:1 11)

                                        at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:274)

                                        at org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:192)

                                        at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatc her.java:807)

                                        at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java :729)

                                        at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)

                                        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3754)

                                        at org.apache.felix.framework.Felix.startBundle(Felix.java:1780)

                                        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)

                                        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:909)

                                        at org.apache.sling.installer.core.impl.tasks.BundleStartTask.execute(BundleStartTask.java:9 7)

                                        at org.apache.sling.installer.core.impl.OsgiInstallerImpl.executeTasks(OsgiInstallerImpl.jav a:621)

                                        at org.apache.sling.installer.core.impl.OsgiInstallerImpl.run(OsgiInstallerImpl.java:196)

                                     

                                    I had declared the reference:

                                    @Reference

                                        private QueryBuilder queryBuilder;

                                     

                                    My problem came for not use in maven the correct definition of the dependency with cq-search artifact, I had different version that is used in the CQ5.5 instance and I have needed to put the scope provided, in that way my Component worked and recovered the QueryBuilder. The dependency was defined in that way.

                                     

                                         <dependency>

                                                <groupId>com.day.cq</groupId>

                                                <artifactId>cq-search</artifactId>

                                                <version>5.5.4</version>

                                                <scope>provided</scope>

                                            </dependency>

                                     

                                    I hope this will be useful for some that would have the same problem.

                                    • 15. Re: QueryBuilder  builder getting null
                                      Avinashtan

                                      one of the workaround is by adding -XX:-UseSplitVerifier option to the JVM .This issue seems to be an with CQ 5.6 and java 7

                                      This issue seems to with @Reference in cq 5.6 and java 7

                                      Please use the above solution and let us know if it works