Not able to inject ResouceResolverFactory

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

27-05-2017

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

02-06-2017

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 getServiceResour...

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

Answers (17)

Answers (17)

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

28-05-2017

The way you get the resourceResolver is fine, however you must close it. The golden rule is "you create, you close".

Normally you can do this in a finally{} clause, or if you use 6.2 or above you can benefit from the AutoCloseable implementation.

Example here: https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/examples/htl/c...

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

04-06-2017

In /system/console/componenets

What i observed that:-

ccom.adobe.ClassName  and its status is Satisfied

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

01-06-2017

1221127_pastedImage_0.png

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

where connect is serviceuser.

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

30-05-2017

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

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

30-05-2017

What do you see here? 

/system/console/components

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

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

30-05-2017

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

Avatar

Avatar

antoniom5495929

Avatar

antoniom5495929

antoniom5495929

29-05-2017

        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..

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

29-05-2017

Actually,

At this line, 

  1. rr = resourceFactory.getServiceResourceResolver(paramMap);

It throws java.lang.NullPointerException.

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

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

29-05-2017

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

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

28-05-2017

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){ } }

Avatar

Avatar

antoniom5495929

Avatar

antoniom5495929

antoniom5495929

28-05-2017

        It seems that you are trying to use a system user to retrive you resource resolver.. have you configured the user mapping configuration in system console? And also.. this is a service where you reference it? Inside a model?

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

28-05-2017

This looks a non-related error

Avatar

Avatar

Rajeev_Kumar

Avatar

Rajeev_Kumar

Rajeev_Kumar

28-05-2017

        Thank you for clarification.

Avatar

Avatar

umeshj24393

Avatar

umeshj24393

umeshj24393

28-05-2017

In error.log :-

 

28.05.2017 08:49:37.850 *WARN* [qtp1248549286-25322] com.adobe.connect.osgi.cq.auth.ConnectUserManager Error creating/updating user
java.lang.NullPointerException: null
    at com.adobe.connect.osgi.cq.auth.ConnectUserManager.createOrUpdateUser(ConnectUserManager.java:695)
    at com.adobe.connect.osgi.cq.auth.ConnectAuthenticationHandler.extractCredentials(ConnectAuthenticationHandler.java:175)
    at org.apache.sling.auth.core.impl.AuthenticationHandlerHolder.doExtractCredentials(AuthenticationHandlerHolder.java:75)
    at org.apache.sling.auth.core.impl.AbstractAuthenticationHandlerHolder.extractCredentials(AbstractAuthenticationHandlerHolder.java:60)
    at org.apache.sling.auth.core.impl.SlingAuthenticator.getAuthenticationInfo(SlingAuthenticator.java:718)
    at org.apache.sling.auth.core.impl.SlingAuthenticator.doHandleSecurity(SlingAuthenticator.java:466)
    at org.apache.sling.auth.core.impl.SlingAuthenticator.handleSecurity(SlingAuthenticator.java:451)
    at org.apache.sling.engine.impl.SlingHttpContext.handleSecurity(SlingHttpContext.java:121)
    at org.apache.felix.http.base.internal.service.ServletContextImpl.handleSecurity(ServletContextImpl.java:421)
    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:57)
    at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:124)
    at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:61)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)

Avatar

Avatar

Rajeev_Kumar

Avatar

Rajeev_Kumar

Rajeev_Kumar

28-05-2017

Hi Feike, I am using the same way to get resource resolver in my code. If this way of getting resource resolver is not advised, would you please suggest any other way to get resource resolver with admin rights.

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

27-05-2017

Also do realize that this code creates hanging sessions that you want to avoid

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

27-05-2017

Do you see anything related in the error.log?