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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to get the New way of ResourceResolver object from Sling Mapper service

Avatar

Avatar
Validate 1
Level 1
sunil_kumarn484
Level 1

Like

1 like

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
sunil_kumarn484
Level 1

Like

1 like

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
sunil_kumarn484
Level 1

06-09-2018

Hi ,

I need some help on where I am making the mistake in getting the ResourceResolver Object using the Apache Sling Service User Mapper Service.

I am trying to get the ResourceResolver Object from the Java service using the mapper service.

I am getting NULL Pointer Exception .

I had pasted the code snippet of the Service class below.

I had pasted the code snippet of the WCMUsePojo class below.

Created the System User with full permission for /content folder.

And mapper the System user with the service name and bundleID in the below format.

1566145_pastedImage_1.png

ServiceMapping= telstrahealth.core:datawrite=datawrite-service

BundleID or SymbolicName of the bundle folder= telstrahealth.core

Subservice Name=datawrite

System User created/mapped=datawrite-service

Please help to identify which step i am missing, as I am getting NULL Pointet Exception.

Any pointers in this regards is much appreciated.

thanks.

Sunil

Code snippet  of my WCMUsePojo class is below:

@Component(service=WCMUsePojo.class)

public class SolutionsComponent extends WCMUsePojo

{

   private final Logger logger = LoggerFactory.getLogger(getClass());

  private final String QUERY_PROP = "_property";
  private final String QUERY_PROP_VAL = "_property.value";

   List<TagCountBean> tagList = null;
   List<ProductTagCountBean> tagList2 = null;
  public void activate()

  {

  TagService tagSrvc= getSlingScriptHelper().getService(TagService.class);
   logger.info("tagSrvctagSrvctagSrvctagSrvctagSrvc"+tagSrvc);
   ResourceResolver resolver=tagSrvc.getResolverObject();

   logger.info("Inside Activate method---->>>");

}

}

I wrote a TagServiceImpl java service class  in the project.

Below is the code snippet:

import com.au.telstrahealth.core.service.TagService;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.osgi.service.component.annotations.*;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.ComponentContext;
import java.util.*;
import javax.jcr.Session;



//This is a component so it can provide or consume services
@Component(service=TagService.class,immediate = true)

public class TagServiceImpl implements TagService {

  @Reference

  ResourceResolverFactory resFactory;
  private Session adminSession;
  private final Logger logger = LoggerFactory.getLogger(getClass());

   //Define a class member named key
   private int key = 0 ;


   ResourceResolver resolver;


  public ResourceResolver getResolverObject(){

   try{

  Map<String, Object> param = new HashMap<String, Object>();
   param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");

   logger.info("ResourceResolver inside TagServiceImpl Just before getting in to try block--");
   resolver = resFactory.getServiceResourceResolver(param);

   logger.info("ResourceResolver in TagServiceImpl class associated System User--"+resolver.getUserID());


   }catch(Exception e){

  logger.info("ERROR" + e + e.getStackTrace().toString());

   e.printStackTrace();

   }

   return resolver;

   }

}

Replies

Avatar

Avatar
Validate 10
Level 3
jetate
Level 3

Likes

12 likes

Total Posts

69 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 10
Level 3
jetate
Level 3

Likes

12 likes

Total Posts

69 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 5
View profile
jetate
Level 3

18-03-2019

Did you ever figure this out?

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

18-03-2019

Hey Guys,

Could you please make sure you followed all 3 steps to get service user session/resource

Step 1: Use in-built system user in OSGI configuration. In OSGI select Apache Sling Service User Mapper Service

e.g. AEM63App.core:readService=training-user

Step 2: Create system user(training-user) and assign that system user the permissions to access the desire folder/paths.

Step 3: In code, do below, as example:

Session session = null;
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put(ResourceResolverFactory.SUBSERVICE, "readService");
try {
resourceResolver = resourceFactory.getServiceResourceResolver(paramMap);
// logger.debug("User id inside {}", resourceResolver.getUserID());
session = resourceResolver.adaptTo(Session.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.debug("getSubserviceSession : Unable to Login : " + e);
}

Adobe Experience Manager Help | Querying Adobe Experience Manager 6 data using the Sling getServiceR...

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

18-03-2019

This is not new - been around since 2014.

We have plenty of docs on this - see this:

Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data using the QueryBuilde...