TagManager.getNameSpaces giving null

Avatar

Avatar

sagarv13144480

Avatar

sagarv13144480

sagarv13144480

27-09-2019

Hi Experts,

Whenever I am trying to do TagManager.getNameSpaces()
or TagManager.getTags(resource)

I am getting null pointer Exception.

My Tags are present under /content/cq:tags/

Also I have installed Service Pack 6.4.3

Also  resourceResolver is having readSystem as subservice.

Can you anyone help on this?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

ArpitVarshney

MVP

Avatar

ArpitVarshney

MVP

ArpitVarshney
MVP

09-10-2019

Hi sagarv13144480 ,

As you're using the service user to read the tags.Can you please make sure the below things:

  • After creating the service user , you need to add an entry in the “Apache Sling Service User Mapper Service”. This entry is to allow your bundle to access the permissions of the system user.Go to Configuration Manager in the system console and search for “User Mapper Service”

          <bundle symbolic name>:<any name of service>=<system user id>

         Reference: How to get Service Resource Resolver? – Rahul Mengji

  • Check whether the service user has read permission to appropriate folder(/content/cq:tags).Please verify this on  http://<host>:port/useradmin URL and search for service user and check the permissions

Answers (9)

Answers (9)

Avatar

Avatar

ragulmsd

Avatar

ragulmsd

ragulmsd

09-10-2019

Hi,

I think its because, the sling request is not sent in your servlet.I also faced the same issue.Try using sling request in resource resolver.I Hope it will work.

private static final String tagid = "/content/cq:tags/properties";

TagManager tagManager = slingRequest.getResourceResolver().adaptTo(TagManager.class);

Tag tag = tagManager.resolve(tagid);

Resource resource = slingRequest.getResourceResolver().getResource(tagid);

Tag[] pagetag = tagManager.getTags(resource);

out.print(tag.getNamespace());

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K
Jörg_Hoh
Employee

04-10-2019

A resource can also be adapted to the TagManager.

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K
Jörg_Hoh
Employee

04-10-2019

To see the full list of available adaptions please check [1].

[1] localhost:4502/system/console/adapters

Avatar

Avatar

BrijeshYadav

Avatar

BrijeshYadav

BrijeshYadav

02-10-2019

At line number 3.

adapt TagManager from ResourceResolver instead of Resource.

TagManager tagManager = resourceResolver.adaptTo(TagManager.class);

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K
Jörg_Hoh
Employee

01-10-2019

In which statement do you get the NPE? Please ensure that you check the return value of the adaptTo() call. But also resourceResolver.getResource() can return null if the resource does not exist.

Does your service user have read permission on /content/cq:tags?

Avatar

Avatar

sagarv13144480

Avatar

sagarv13144480

sagarv13144480

29-09-2019

Hi

resourceResolver = resourceResolverFactory.getServiceResourceResolver(Map having readSystem subservice)

Resource resource = resourceResolver.getResource("/content/cq:Tags");

TagManager tagMgr = resource.adaptTo(TagManager.class);

Tag[] Tags = tagMgr.getNamespaces();

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K
Jörg_Hoh
Employee

29-09-2019

How have you acquired the TagManager? What kind of resource resolver are you using?

Avatar

Avatar

sagarv13144480

Avatar

sagarv13144480

sagarv13144480

28-09-2019

Hi Arun,

resourceResolver is not null and I am doing the same as suggested by you hence confused.

Is it a bug?

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

27-09-2019

Hi,

Can you please check if resourceResolver is not null?

If it is not null, then you can do

TagManager tm = resourceResolver.adaptTo(TagManager.class)

tm.getNameSpaces()

TagManager ("The Adobe AEM Quickstart and Web Application.")