AEM 6.4 upgrade @reference does not work in a workflow | Community
Skip to main content
Level 9
Jun 15, 2018 5:22 PM UTC
Solved

AEM 6.4 upgrade @reference does not work in a workflow

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.
NitroHazeDevAccepted solution
Level 9
Jul 21, 2018 12:35 AM UTC

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

NitroHazeDevAuthorAccepted solution
Level 9
Jul 21, 2018 12:35 AM UTC

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

Translate
smacdonald2008
Level 10
Jun 21, 2018 1:32 PM UTC

In my example - i did not use that. Simply used an interface and the implementation class that uses @Component.

Let me know if you find a solution when that keyword is used (which seems to be causing an issue). 

Translate
Level 9
Jun 21, 2018 1:29 PM UTC

Yes Scott, that helps, but with the keyword abstract there are issues , so looking into it

Translate
smacdonald2008
Level 10
Jun 21, 2018 12:42 AM UTC

Please watch the video - i show all the code and shows it works in 6.4

Translate
Level 9
Jun 21, 2018 12:02 AM UTC

Thanks Arun, i had that in my workflow, but missed adding it here ..

so here are the updates:

I got a custom workflow to work but the one i was trying didn't work and would not appear in the dropdown in the custom process step

reasons:

1. Class that implements workflow process is marked abstract

Yet to investigate, ..

This worked smooth on 6.2..

Translate
arunpatidar
New Participant
Jun 20, 2018 8:49 PM UTC

Hi,

*you missed @Component annotation in your service implementation.

below is correct code:you can try with this


package com.test.core.workflows.general;
import org.osgi.service.component.annotations.Component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
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;
}
}

Translate
Arun Patidar
smacdonald2008
Level 10
Jun 20, 2018 6:19 PM UTC

See my video - it works

Translate
Level 9
Jun 20, 2018 6:18 PM UTC

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"));

}

}

Translate
smacdonald2008
Level 10
Jun 20, 2018 6:06 PM UTC

I got this to work with Maven Arch 13 and i have also created a nice video. Scott's Digital Community: Learn how to use DS Annotations and Inject a custom AEM Service into a Custom Workflow Step

Translate
smacdonald2008
Level 10
Jun 20, 2018 4:36 PM UTC

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.

Translate