Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

CQ5.6.1 osgi bundle no longer running activate method

acequeen08
Level 2
Level 2

I created an osgi bundle using CQ5.5 that would use sling scheduler to add a job to run at midnight everyday.  We recently did an update to CQ5.6.1 which included the scr code and install jar, however the bundle appears to not run the activate method with my code.  I've tried stopping, restart, an uninstalling the bundle with no change.  The log returns warnings but not any errors that prevent it from successfully building.  Once I build in the console I am getting error on the component could not be activated, or SchedulerBind could not be completed.  Before the update the scheduled job did run correctly selecting a page from a folder of terms, but now it is not even printing debug statements in activate method.

import java.io.Serializable;
import java.util.*;
import javax.jcr.*;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.sling.api.resource.*;
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.framework.BundleContext;
import com.day.cq.wcm.api.*;
import com.day.cq.replication.*;
import org.apache.sling.commons.osgi.*;

@Component(immediate=true, label="Term of the Day Scheduler", 
           description="Specify the term of day location.",metatype=true,
           configurationFactory=false,
           policy=ConfigurationPolicy.REQUIRE)
@Service(value=DictionaryScheduledService.class)

public class DictionaryScheduledService {
    @Property(unbounded=PropertyUnbounded.DEFAULT, label="Dictionary Term Location", description="Location of all Dictionary terms (/content/public/dictionary/legal-terms).", value="/content/public/dictionary/legal-terms")
    private static final String TOD_BASE_URL = "tod.baseurl";
    private String todBaseUrl;        // Scheduler's baseurl for dictionary terms

    @Property(unbounded=PropertyUnbounded.DEFAULT, label="Term of Day Location", description="Location to write selected term of day values to (/content/public/dictionary/tod).", value="/content/public/dictionary/tod")
    private static final String TOD_PATH = "tod.path";
    private String todPath;

    /** Default log. */
    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    public String getTodBaseUrl() {
        return todBaseUrl;
    }

    public String getTodPath() {
        return todPath;
    }

    @Reference
    private Replicator replicator;
    @Reference
    private Scheduler scheduler;
    @Reference
    private SlingRepository repository;

    private Session session;
    private PageManager pageManager;

     @Activate
    protected void activate(ComponentContext componentContext) throws Exception {
        
        session = repository.loginAdministrative(repository.getDefaultWorkspace());
        
        BundleContext bundleContext = componentContext.getBundleContext();
        ServiceReference serviceReference = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());               
        ResourceResolverFactory resolverFactory = (ResourceResolverFactory) bundleContext.getService(serviceReference);
        Map authInfo = new HashMap();
        authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);
        ResourceResolver rr = resolverFactory.getResourceResolver(authInfo);  
        pageManager = rr.adaptTo(PageManager.class);   
        
        //config to execute the job every day, 12AM
        //String schedulingExpression = "0 0 0 * * ? *";

        //run every 5 seconds

        String schedulingExpression = "0/5 * * * * * *"
        String jobName1 = "case1";
        Map<String, Serializable> config1 = new HashMap<String, Serializable>();
        boolean canRunConcurrently = true;     
        
        //Scheduled Job
        final Runnable job1 = new Runnable() {
            public void run() {   
                log.info("executing job one");           
            }
        };
        try {
            this.scheduler.addJob(jobName1, job1, config1, schedulingExpression, canRunConcurrently);
        } catch (Exception e) {
            job1.run();
        }                
    }  
      
    @Deactivate
    protected void deactivate(ComponentContext componentContext) {
        log.info("Deactivated, goodbye!");
        this.scheduler.removeJob("case1");
        if (session != null) {
            session.logout();
            log.info("service is deactivated session logged out");
        }          
    } 

}

 

-----ERROR----

04.09.2013 16:35:22.038 *ERROR* [Background Update com.findlaw.util.scheduler (326)] com.findlaw.util.scheduler [com.findlaw.util.DictionaryScheduledService] bind method [bindScheduler] not found; Component will fail

04.09.2013 16:35:22.038 *WARN* [Background Update com.findlaw.util.scheduler (326)] com.findlaw.util.scheduler [com.findlaw.util.DictionaryScheduledService] bindRepository cannot be found (java.lang.VerifyError: Expecting a stackmap frame at branch target 13 in method com.findlaw.util.DictionaryScheduledService.unbindRepository(Lorg/apache/sling/jcr/api/SlingRepository;)V at offset 5) java.lang.VerifyError: Expecting a stackmap frame at branch target 13 in method com.findlaw.util.DictionaryScheduledService.unbindRepository(Lorg/apache/sling/jcr/api/SlingRepository;)V at offset 5

1 Accepted Solution
Sham_HC
Correct answer by
Level 10
Level 10

Assuming you are using JDK1.7

Try with adding [1] to startup parameter and verify.

[1]  -XX:-UseSplitVerifier

View solution in original post

0 Replies
smacdonald2008
Level 10
Level 10

This is strange -- however - one thing to try is to build your OSGi using this new maven plugin - which is used for 5.6:

http://dev.day.com/docs/en/cq/aem-how-tos/development/how-to-build-aem-projects-using-apache-maven.h...

Let us know what happens. 

HTH

acequeen08
Level 2
Level 2

Using @reference to inject services into my code was causing a the error for some reason.  I ended up using   bundleContext.getServiceReference(service name.class) access the replicator and session for my osgi bundle.

Dragosche
Level 1
Level 1

I solved this problem without using the "-XX:UseSplitVerifier" workaround. 

I noticed that SCR is the one that caused problems b/c I was using an older version compiled probably only with 1.6.

My working version as of today uses:

          <dependency>
                <groupId>org.apache.felix</groupId>
                <artifactId>org.apache.felix.scr.annotations</artifactId>
                <version>1.9.8</version>
                <scope>provided</scope>
            </dependency>

 

            <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-scr-plugin</artifactId>
                    <version>1.15.0</version>

           ....

           </plugin>

Sham_HC
Correct answer by
Level 10
Level 10

Assuming you are using JDK1.7

Try with adding [1] to startup parameter and verify.

[1]  -XX:-UseSplitVerifier

View solution in original post

pieterjan_desm1
Level 1
Level 1

Many Thanks Sham!

PS: how did you find this solution?

garth914
Level 2
Level 2

FYI, I'm using JDK1.7, and adding -XX:UseSplitVerifier helped resolve this same issue for me.  Thanks!

acequeen08
Level 2
Level 2

It turned out that the issue was coming from the version of the jdk (1.6 I believe) that I originally built the osgi bundle before upgrading to CQ v5.6.1 (jdk 1.7).