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.
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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,
Views
Replies
Total Likes
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
Views
Replies
Total Likes