AEM 6.4 upgrade @reference does not work in a workflow | Community
Skip to main content
Level 9
June 15, 2018
Solved

AEM 6.4 upgrade @reference does not work in a workflow

  • June 15, 2018
  • 16 replies
  • 7817 views

All i have a workflow process step and it references class A that exposes a service, but when i check for the value of A in the process step, it appears to be null,

i am injecting this service A using the @Reference.

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 NitroHazeDev

So Scott, i finally have a response and after consultation and weeks of debugging assuming i was doing something wrong for something that is so simple,

i am asked (by adobe) to avoid using @reference in abstract classes , and this worked on 6.2 and is something that breaks in 6.4, , with bunch of scr annotation errors and components appear to be in satisfied state

Infact abstract keyword for a service at times sets the component to state "16", solution - remove abstract keyword

If you have nested inheritance and a class that is abstract and implement workflowprocess, keep it simple, take off  abstract keyword and avoid inheritance since if  a child class(extending parent class that implements workflow process) is invoked the annotations of the parent class is null, so just keep child class that implements workflowprocess and avoid inheritance where the parent class uses annotation and no abstract keyword.

https://forums.adobe.com/thread/2461255

16 replies

Level 9
June 15, 2018

Anyone?

arunpatidar
Community Advisor
Community Advisor
June 15, 2018

Hi,

Which annotation are you using Felix or Osgi?

How did you created your service? Are you able to see your service at http://localhost:4502/system/console/services

I created a Demo Process and shared with you which include Reference to my custom service HandleSession and I am able to get the Service reference inside workflow process.

Thanks

Arun

Arun Patidar
Level 9
June 16, 2018

I used the OSGI, yes i see the service as well. Sent the code over, its a custom service and not OOTB so i am not sure if that affects anything.

I took off the @Reference annotation and just instantiated the class and it worked fine. i wonder why the annotation would not work within a workflow.

I do see errors as well, could this be related?

[com.adobe.granite.workflow.core.job.ExternalProcessPollingHandler(917)] : Could not get service from ref [com.adobe.granite.workflow.exec.WorkflowProcess]

15.06.2018 20:10:15.785 *WARN* [FelixStartLevel] com.adobe.granite.workflow.core bundle com.adobe.granite.workflow.core:2.0.168 (275)[com.adobe.granite.workflow.core.job.ExternalProcessPollingHandler(917)] : DependencyManager : invokeUnbindMethod : Service not available from service registry for ServiceReference [com.adobe.granite.workflow.exec.WorkflowProcess] for reference WorkflowProcess

15.06.2018 20:10:15.785 *ERROR* [FelixStartLevel] com.test.core bundle com.test.core:1.5.10.SNAPSHOT (1033)[com.test.core.workflows.BaseWorkflowProcess(3632)] :  Error during instantiation of the implementation object: null

15.06.2018 20:10:15.785 *ERROR* [FelixDispatchQueue] com.adobe.granite.workflow.core FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: com.test.core.workflows.BaseWorkflowProcess (3632)))

org.osgi.framework.ServiceException: Service factory returned null. (Component: com.test.core.workflows.BaseWorkflowProcess (3632))

Level 9
June 16, 2018

I also tried @Reference ResourceResolverFactory rrf; and it appears to be null as well, so curious if @reference throws null for some unknown reason>

arunpatidar
Community Advisor
Community Advisor
June 16, 2018

Hi,

Check below article with same kind of issue, something may be wrong with service

Could not get service from ref [javax.servlet.Servlet, javax.servlet.ServletConfig, java.io.Serializable]

Could you please check the sample code to Create Service WorkflowProcess and invoked using @Reference inside Process Step

aem63app-repo/demo at master · arunpatidar02/aem63app-repo · GitHub

Thanks

Arun

Arun Patidar
Level 9
June 20, 2018

Will be logging a ticket with Adobe,

Created classes as you've shared and weird issues were noted

1. With @reference annotation, custom workflow process  (java)step did not appear in the dropdown  for the workflow

2.Without @Reference annotation, the process step java class was visible.

smacdonald2008
June 20, 2018

What Annotations are you using - DS Annotations or Felix Src annotations.

Post some of your code - including your import statements - that will tell us exactly what you are trying to do. I do not believe using @Reference ins a custom workflow step has an issue.

smacdonald2008
June 20, 2018
Level 9
June 20, 2018

Sure thanks i believe i used maven arch 13, but i am attaching the code here

package com.test.core.workflows.general;

public interface DemoWFService {

public String showMessage(String msg);

}

------------------------------------

package com.test.core.workflows.general;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class DemoWFServiceImpl implements DemoWFService {

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

String PrefixMessage = "Service Invoked by Workflow -- ";

@Override

public String showMessage(String msg) {

return PrefixMessage+msg;

}

}

------------------------

package com.test.core.workflows.general;

import org.osgi.framework.Constants;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import com.adobe.granite.workflow.WorkflowException;

import com.adobe.granite.workflow.WorkflowSession;

import com.adobe.granite.workflow.exec.WorkItem;

import com.adobe.granite.workflow.exec.WorkflowProcess;

import com.adobe.granite.workflow.metadata.MetaDataMap;

@Component(immediate = false,service= WorkflowProcess.class, property={

        Constants.SERVICE_DESCRIPTION + "=Test.",

        Constants.SERVICE_VENDOR + "=Test",

        "process.label" + "=Test"

})

public class WFProcessStep implements WorkflowProcess {

@Reference

private DemoWFService ws;

    private static final Logger logger = LoggerFactory.getLogger(WFProcessStep.class);

@Override

public void execute(WorkItem arg0, WorkflowSession arg1, MetaDataMap arg2) throws WorkflowException {

    logger.info("********************* WF");

    logger.info("wfff"+ws.showMessage("text"));

}

}

smacdonald2008
June 20, 2018

See my video - it works