Adapt WorkflowSession to a ResourceResolver

Avatar

Avatar

anireddy

Avatar

anireddy

anireddy

20-12-2020

Adapt WorkflowSession to a ResourceResolver ?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

praveenjain

Avatar

praveenjain

praveenjain

24-12-2020

As mentioned by Ashutosh, you can get resource resolver from workflow session.

 

Another way of good practice is to get serivce resource resolver, and you can write this reusable mention in one utils class and call it in your workflow

 

Example:

public static ResourceResolver getServiceResolver() throws LoginException {
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "my-custom-service");
BundleContext bundleContext = FrameworkUtil.getBundle(MyUtils.class).getBundleContext();
ServiceReference resourceResolverFactoryRef = bundleContext
.getServiceReference(ResourceResolverFactory.class.getName());
ResourceResolverFactory resFactory = (ResourceResolverFactory) bundleContext
.getService(resourceResolverFactoryRef);
return resFactory.getServiceResourceResolver(param);
}

 

Refer more details in : https://aemhub.blogspot.com/2020/12/how-to-get-service-resource-resolver.html

 

Regards

Praveen

Answers (2)

Answers (2)

Avatar

Avatar

Umesh_Thakur

MVP

Avatar

Umesh_Thakur

MVP

Umesh_Thakur
MVP

23-12-2020

@anireddy , can you please have a look the below community article on the same

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/adapt-workflowsession-to-a...

hope this will help.

umesh thakur

Avatar

Avatar

asutosh_jena

Avatar

asutosh_jena

asutosh_jena

20-12-2020

@anireddy You can adapt to the ResourceResolver interface from workflowSession to get the Resource Resolver object.

ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);