Expand my Community achievements bar.

AEM 6.3 System user - Resource resolver issue

Avatar

Level 4

On AEM 6.3 we've a custom quick links search where we map keywords to outer links.

We created system user and mapped it using Apache sling Service User Mapper Service. System user is given required permissions in user admin.

We used the following code for sub service

@Activate

protected void activate() throws RepositoryException {

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

        param.put(ResourceResolverFactory.SUBSERVICE, "searchService");

        ResourceResolver resolver = null;

     

        try {

resolver = resolverFactory.getServiceResourceResolver(param);

adminSession = resolver.adaptTo(Session.class);

         

        } catch (Exception e) {

log.error("ERROR" + e + e.getStackTrace().toString());

e.printStackTrace();

}

}

We're seeing the following Null pointer during search

*ERROR* [0:0:0:0:0:0:0:1 [1513035725695] GET /bin/amica/searchServlet HTTP/1.1] com.******.adc.******com.core.search.SearchServlet ERRORjava.lang.NullPointerException[Ljava.lang.StackTraceElement;@3d05a33d

For the custom quick links we are using

public JSONArray performSearch(String queryTerm,

SlingHttpServletRequest request) throws RepositoryException,

JSONException {

String resourcePath = searchConfigurationService.getSearchQuicklinksAdminNodePath();

ResourceResolver resourceResolver = request.getResourceResolver();

        Resource res = resourceResolver.getResource(resourcePath);

We can see the  resourcePath through log info but unable to resolve the resource. No error logs on this.

This search working on author but not on publish, seems to be an authentication issue. Even tried using Ensure Service User​   for creating user and permissions.

3 Replies

Avatar

Level 10

If it works on Author - make sure all of the same users, etc are setup. What works on Author has to work on Pub if everything is setup the same.

Avatar

Level 4

Pub has everything same as author.... We found this isn't working

ResourceResolver resourceResolver = request.getResourceResolver();

Avatar

Level 2

resolverFactory.getServiceResourceResolver(param);

is the correct way of getting resolver. If you are getting Nullpointer exception, check if the system user exists on publish.

Try changing the user like giving 'OAuthUser' in the User Mapper Service if the issue persists.