Gentlemen,
Thank you for helping me with some of my questions.
I am facing a technical issue
a) I am calling a java class from the sling scheduler which runs at regular interval.
b) This java class has code which will delete nodes from specific path in the jcr and recreates them based on the data given by other service.
In the scheduler
run method (using the below code)
AspectServiceImpl objAspectServiceImpl = new AspectServiceImpl();
try {
Boolean result = objAspectServiceImpl.InjectAlertData(alertList);
}
In the AspectServiceImpl (I have a method InjectAlertData, i have datawrite configured in OSGI configuration, this will open connection and insert data into specified node)
@Override
public boolean InjectAlertData(List<AlertModel> alertList) throws Exception
{
log.info("into injectalertdata " + alertList.size());
try
{
Map<String, Object> param = new HashMap<String, Object>();
log.info("into map");
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
log.info("after datawrite");
ResourceResolver resolver = null;
log.info("into injectalertdata try");
resolver = resolverFactory.getServiceResourceResolver(param); (this is throwing error not much description , just says null)
log.info("after resolver");
session = resolver.adaptTo(Session.class);
did any one of you face this issue? If yes can you please guide me to resolve this.
Why do you instantiate the service in your code yourself? - AspectServiceImpl objAspectServiceImpl = new AspectServiceImpl();
Can you confirm that your scheduler is annotated with SCR/OSGI annotations?
Refer code samples here -
https://adobe-consulting-services.github.io/acs-aem-samples/
Thanks for the reply Gaurav,
I do not know any other way to instantiate a class at this point (AspectSerivceImpl). If there is any other way, please share.
I am using the archtype19 project which comes with sample code(simpleScheduledTask), I am using that.
Can you please elaborate more on SCR/OSGI annotation please...
The links shared above has reference implementations
For OSGI annotations refer -
https://medium.com/adobetech/aem-6-4-creating-a-scheduler-using-osgi-r6-annotations-4ad0b8c6fce7
https://medium.com/adobetech/using-the-osgi-declarative-service-in-aem-6-4-21102f649d54
Using OSGi R7 annotations in AEM - Experience Delivers
AEM Developer Learning : Migration of SCR annotations to OSGi R6 annotations in AEM 6.3
Hi,
Just to check do you have system user and mapping in place to get subservice sesison
resolver = resolverFactory.getServiceResourceResolver(param); (this is throwing error not much description , just says null)
Services should not be instantiated, but just referenced. Therefor it's best they are stateless, in case multiple invocations can happen at the same time.
Jörg
Thanks all for your support.
AspectServiceImpl objAspectServiceImpl = new AspectServiceImpl(); (this should be just referenced using the OSGI).
You should be using @Reference to create service objects.
Views
Likes
Replies