Not able to inject ResouceResolverFactory | Community
Skip to main content
Level 4
May 27, 2017 7:51 PM UTC
Solved

Not able to inject ResouceResolverFactory

Hi,

Not able to inject resouceresolverfactory in following code.

I created an interface

public interface WriteService{

    public void getSession();

{

And a class which implemented an interface

@Component(immediate=true) @Service(value = WriteSerive.class) public class WriteServiceImp  implements WriteService { @Reference private ResourceResolverFactory resourceFactory; @Override public void getSession(){ try{ Map<String,Object> paramMap = new HashMap<String,Object>(); paramMap.put(ResourceResolverFactory.SUBSERVICE, "connectSession"); ResourceResolver rr = null; rr = resourceFactory.getServiceResourceResolver(paramMap); Sessionsession = rr.adaptTo(Session.class); } catch(Exception e){ } }

 

Any Suggestion?

Thanks in advance

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 2, 2017 1:45 PM UTC

Watch the video here - we do a step by step of everything you need:

Scott's Digital Community: Querying Adobe Experience Manager 6 data using the Sling getServiceResourceResolver method

You need to reference the system user and make sure you specify the symbolic bundle name as mentioned in the video

18 replies

Level 4
Jun 5, 2017 6:58 AM UTC

In /system/console/componenets

What i observed that:-

ccom.adobe.ClassName  and its status is Satisfied

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 2, 2017 1:45 PM UTC

Watch the video here - we do a step by step of everything you need:

Scott's Digital Community: Querying Adobe Experience Manager 6 data using the Sling getServiceResourceResolver method

You need to reference the system user and make sure you specify the symbolic bundle name as mentioned in the video

Translate
Level 4
Jun 2, 2017 6:39 AM UTC

com.adobe.connect.osgi.service.connect-osgi-service:connectSession=connect

where connect is serviceuser.

Translate
smacdonald2008
Level 10
May 30, 2017 5:50 PM UTC

Post a Screen shot of your OSGI SLING MAPPING - i suspect issue is there. 

Translate
Feike_Visser1
Employee
May 30, 2017 10:57 AM UTC

What do you see here? 

/system/console/components

There should be a reason why the dependency can't be injected

Translate
Level 4
May 30, 2017 10:37 AM UTC

Yes,I tried to debug and resourceResolverFactory is null throw java.lang.NullPointerException: null

Translate
antoniom5495929
Level 7
May 30, 2017 6:20 AM UTC
        Have you tried to debug? Are you sure that resourceResolverFactory is null? I suggest you to debug or insert a log in order to be sure that this is not related to wrong configuration of user mapper or user amendement service..
Translate
Level 4
May 29, 2017 6:14 PM UTC

Actually,

At this line, 

  1. rr = resourceFactory.getServiceResourceResolver(paramMap);

It throws java.lang.NullPointerException.

I think resourceFactory variable is not injected in osgi bundles..

Translate
Feike_Visser1
Employee
May 29, 2017 10:57 AM UTC

But what is the issue you are having? That is not clear to me now.

Translate
Level 4
May 29, 2017 6:08 AM UTC

Yes, I have configured the user mapping configuration in system console. 

In osgi bundles, wherever the .loginAdministrstive(null) is called , i have replaced by below written codes:-

  1. @Component(immediate=true) @Service(value = WriteSerive.class) public class WriteServiceImp implements WriteService { @Reference private ResourceResolverFactory resourceFactory; @Override public void getSession(){ try{ Map<String,Object> paramMap = new HashMap<String,Object>(); paramMap.put(ResourceResolverFactory.SUBSERVICE, "connectSession"); ResourceResolver rr = null; rr = resourceFactory.getServiceResourceResolver(paramMap); Sessionsession = rr.adaptTo(Session.class); } catch(Exception e){ } }
Translate