Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Adapt WorkflowSession to a ResourceResolver

anireddy
Level 1
Level 1

Adapt WorkflowSession to a ResourceResolver ?

1 Accepted Solution
praveenjain
Correct answer by
Level 4
Level 4

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

View solution in original post

6 Replies
Asutosh_Jena_
Community Advisor
Community Advisor

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

ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
Asutosh_Jena_
Community Advisor
Community Advisor

You can adapt to ResourceResolver from workflowSession. Try this and let me know if this does not work.

Asutosh_Jena_
Community Advisor
Community Advisor
You can adapt to ResourceResolver from workflowSession. Give it it a try 🙂
praveenjain
Correct answer by
Level 4
Level 4

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

View solution in original post