Null Pointer when trying to access TagManager | Community
Skip to main content
October 16, 2015
Solved

Null Pointer when trying to access TagManager

  • October 16, 2015
  • 2 replies
  • 1037 views

I am writing a standalone script in java which is trying to modify some tags on my AEM instance.  I am running into a problem when trying to get an instance of TagManager (com.day.cq.tagging.TagManager).

Here is what I have tried:

Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server"); Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); JcrTagManagerFactoryImpl tagManagerFactory = new JcrTagManagerFactoryImpl(); TagManager tagManager = tagManagerFactory.getTagManager(session);

There is a NullPointerException being thrown on my last line of code there and I am not sure why.  I would like to be clear that since this script is not being installed onto my AEM server (it is not a servlet), I cannot obtain the TagManager from a ResourceResolver.  Also my session object is working correctly (I testing adding nodes through it and it was fine).

Thankyou for any help.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PaulMcMahon

You problem is that the JcrTagManagerFactoryImpl class is not intended to be used in a stand alone application. It is an OSGI service and will only work properly when accessed as and OSGI service. If you look at the service it has OSGI references to the SlingRepository and the Sling JcrResourceResolver. The service won't work in a standalone Java application. You'll either have to use standard JCR interfaces to manipulate the tag nodes, or you have to migrate your standalone script to a JSP or servlet that executes on an AEM instance.  

2 replies

PaulMcMahonAccepted solution
Level 8
October 16, 2015

You problem is that the JcrTagManagerFactoryImpl class is not intended to be used in a stand alone application. It is an OSGI service and will only work properly when accessed as and OSGI service. If you look at the service it has OSGI references to the SlingRepository and the Sling JcrResourceResolver. The service won't work in a standalone Java application. You'll either have to use standard JCR interfaces to manipulate the tag nodes, or you have to migrate your standalone script to a JSP or servlet that executes on an AEM instance.  

droodnickAuthor
October 16, 2015

orotas wrote...

You problem is that the JcrTagManagerFactoryImpl class is not intended to be used in a stand alone application. It is an OSGI service and will only work properly when accessed as and OSGI service. If you look at the service it has OSGI references to the SlingRepository and the Sling JcrResourceResolver. The service won't work in a standalone Java application. You'll either have to use standard JCR interfaces to manipulate the tag nodes, or you have to migrate your standalone script to a JSP or servlet that executes on an AEM instance.  

 

Thankyou very much, very clear answer.