Expand my Community achievements bar.

SOLVED

Adapt WorkflowSession to a ResourceResolver

Avatar

Level 1

Adapt WorkflowSession to a ResourceResolver ?

1 Accepted Solution

Avatar

Correct answer by
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

Avatar

Community Advisor

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

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

Avatar

Level 1
i don't think session adaptTo resourceResolver.

Avatar

Community Advisor

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

Avatar

Community Advisor
You can adapt to ResourceResolver from workflowSession. Give it it a try

Avatar

Correct answer by
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