Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Tags are not fetching in AEM 6.4 when upgrading from AEM6.2. is there anyone else facing same problems?

Avatar

Level 3

Tags were working properly in AEM 6.2. and we upgraded to AEM 6.4. Now tag manager is unable to resolve tags and throwing null pointer exception.

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

Tag tagObj = tagManager.resolve("/etc/tags/x/abc");

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

Tag tagObj = tagManager.resolve("x:abc");

both of the above-mentioned code snippets are not working and throwing null pointer when try to use tabObj.

"everyone" user has been provided all permissions on /etc/tags folder and sub folders.

please help.

thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

In AEM 6.4 you can get subservice session like below. Similar you can do for TagMAnager. In below code you can replace Session with TagManager.

And check your import also. I am using osgi annotation.

@Reference

  private ResourceResolverFactory resourceFactory;

  ResourceResolver resourceResolver = null;

public Session getSubserviceSession() {

  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);

  }

  return session;

  }

you can check below for imports.

aem63app-repo/HandleSessionsImpl.java at master · arunpatidar02/aem63app-repo · GitHub



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

In AEM 6.4 tags moved to the another location which is /content/cq:tags

Adobe Experience Manager Help | Common Repository Restructuring in AEM 6.4

This could be the issue.

Thanks

Arun



Arun Patidar

Avatar

Level 3

Thanks Arun for your response.

Yes, I have given access to this location too. but as far I was reading that AEM 6.4 supports backward compatibility and works for both locations of tags.

Avatar

Community Advisor

Hi,

I tried same and I can get the tags from /content/cq:tags and from /etc/tags/. Without having /etc/tags/ node I can read the tag from /etc/tags/ in my code but internally it points to tag resides inside /content/cq:tags/. If I create /etc/tags/ and update tags there, it makes no difference because tags are being read from new location that is /content/cq:tags/

e.g. aem63app-repo/GetTags.java at master · arunpatidar02/aem63app-repo · GitHub

Any custom code that explicitly references the path /etc/tags must be updated to /content/cq:tags, or preferably rewritten to leverage the TagManager Java API, in tandem with this migration.

Thanks

Arun



Arun Patidar

Avatar

Level 3

Hi Arun,

thanks a lot for this response.

I still getting issues. The only difference in my code and your code is that in your code, it is getting TagManager from req in servlet while I am writing the tag fetching logic in Controller class in activate method by getting resolving to resource resolver of user account. like this.

public ResourceResolver getUserSystemResourceResolver() {

    ResourceResolverFactory factory = getSlingScriptHelper().

            getService(ResourceResolverFactory.class);

    ResourceResolver resourceResolver = ResourceResolverUtils.

            getResourceResolver(factory,

                    ResourceResolverUtils.TAG_MANAGER_SYSTEM_USER);

    return resourceResolver;

  }

public static ResourceResolver getResourceResolver(ResourceResolverFactory resourceResolverFactory,

          String user) {

    if (resourceResolverFactory != null) {

      Map<String, Object> authInfo = new HashMap<>();

      authInfo.put(ResourceResolverFactory.SUBSERVICE, user);

      try {

        return resourceResolverFactory.getServiceResourceResolver(authInfo);

      } catch (LoginException e) {

        LOGGER.error("Cannot Login user " + user, e);

        return null;

      }

    }

    return null;

  }

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

it is not reading any tags. I have created tags in both locations.

thanks a lot in advance,

Avatar

Correct answer by
Community Advisor

Hi,

In AEM 6.4 you can get subservice session like below. Similar you can do for TagMAnager. In below code you can replace Session with TagManager.

And check your import also. I am using osgi annotation.

@Reference

  private ResourceResolverFactory resourceFactory;

  ResourceResolver resourceResolver = null;

public Session getSubserviceSession() {

  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);

  }

  return session;

  }

you can check below for imports.

aem63app-repo/HandleSessionsImpl.java at master · arunpatidar02/aem63app-repo · GitHub



Arun Patidar