JCR Session comes back null in custom Workflow step implementation | Community
Skip to main content
marissaw9851252
Level 3
October 16, 2015
Solved

JCR Session comes back null in custom Workflow step implementation

  • October 16, 2015
  • 11 replies
  • 4208 views

I have created a custom Workflow step for AEM 6.0.  I created a class that implements com.adobe.granite.workflow.exec.WorkflowProcess.  I need to get the jcr session and session.adaptTo(Session.class) is returning null.  session is not null and its type is com.adobe.granite.workflow.WorkflowSession.  The example in the Extending Workflow Functionality documentation uses this call to get the jcr session. http://docs.adobe.com/docs/en/aem/6-0/develop/extending/workflows/wf-extending.html

Below is the class declaration and the first part of the execute method.  This custom Workflow step is set up in place of the Product Asset Upload step at the end of the DAM Update Asset Workflow. 

@Component
@Service(value = WorkflowProcess.class)
@Properties({
 @Property(name = "process.label", value = "Custom Product Assets Upload Process"),
 @Property(name = Constants.SERVICE_DESCRIPTION, value = "Custom Product Assets Upload Process"),
 @Property(name = Constants.SERVICE_VENDOR, value = "Test")
})
public class CustomProductAssetsUploadProcess implements com.adobe.granite.workflow.exec.WorkflowProcess{
 
 private static final String TYPE_JCR_PATH = "JCR_PATH";
    private static final Logger log = LoggerFactory.getLogger(CustomProductAssetsUploadProcess.class);
    public static final String ENABLE_WRITEBACK = "writebackEnable";
 
    @Reference(cardinality= ReferenceCardinality.MANDATORY_UNARY, policy = ReferencePolicy.STATIC)
    private ResourceResolverFactory resourceResolverFactory;
   
    public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {

        try {
           String payloadPath = null;

            if (item.getWorkflowData().getPayloadType().equals(TYPE_JCR_PATH)) {
                payloadPath = item.getWorkflowData().getPayload().toString();
            }
                       
            log.info("payload path :"+payloadPath);
                       
            Session jcrSession = session.adaptTo(Session.class);

...

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by WillMc1

Hmm...

Is there any chance you are embedding a dependency jar inside your bundle?  If you have your own copy of the javax.jcr.Session class file inside your bundle the classloaders could be messed up.  

Sorry again just a guess.

Will

11 replies

Adobe Employee
October 16, 2015

Hi,

Glad that was the issue.  Yes the next problem you're seeing also seems to be the same issue.  Basically you want to make sure that any dependencies you use in your POM don't get embedded (either the jar or jar exploded .class files) in the jar you build.  You can open the jar you build in winzip or another zip tool to see what's in it to verify that you got it right, and then play with your pom.xml file.

Good luck!

Will