resourceResolver null | Community
Skip to main content
New Participant
November 4, 2015
Solved

resourceResolver null

  • November 4, 2015
  • 4 replies
  • 2975 views

Hi,

Anyone can explain me why inside the bundle the reference of resourceResolver is always null?

Is there anybody that i can do to activate this reference?

Jsp side seems to work fine but i'm not able to access the variable inside java code

Thanks

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 smacdonald2008

IN AEM - create a dedicated user account to set up a successful  ResourceResolverFactory instance. See this code:

@Service
public class CustomerServiceImpl implements CustomerService {
   
   
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
       
private Session session;
           
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
       
  
  
//Queries the AEM JCR for customer data and returns
//the data within an XML schema   
public String getCustomerData(String filter) {
  
Customer cust = null;
  
List<Customer> custList = new ArrayList<Customer>();
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
 
try {
            
    //Invoke the adaptTo method to create a Session used to create a QueryManager
    resolver = resolverFactory.getServiceResourceResolver(param);
    session = resolver.adaptTo(Session.class);

NOTE: In AEM 6.1, service users must be system users, which effectively means that their node in the JCR is of type rep:SystemUser. These users cannot be used to log in normally, only by background processes. The admin user is not a system user, so you cannot use the admin user in a service user mapping like this. You have to create a new system user and assign them the appropriate permissions.If you would like to read more of the background on this change, take a look at https://issues.apache.org/jira/browse/SLING-3854.

 

This is explained in this AEM community article: 

https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html

4 replies

New Participant
August 2, 2017

Hey

I am getting null after this line of code:

ResourceResolver rr = resolverFactory.getServiceResourceResolver(paramMap);

my function :-

public void writeToDam(InputStream is, String fileName)

{

try {

//Inject a ResourceResolver

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

//Mention the subServiceName you had used in the User Mapping

paramMap.put(ResourceResolverFactory.SUBSERVICE,"SampleUser");

ResourceResolver rr = resolverFactory.getServiceResourceResolver(paramMap);

//Use AssetManager to place the file into the AEM DAM

AssetManager assetMgr = rr.adaptTo(AssetManager.class);

String newFile = "/content/dam/wda/"+fileName ;

assetMgr.createAsset(newFile, is,"Attachment/xlsx", true);

}

catch (Exception e) {

log.error("error in.... write to DAM function >>"+e.getMessage());

}

}

user mapper Service config:

com.aem.mongodbProject-bundle:SampleUser=mongoDBUser

system user " mongoDBUser " given all permissions

Employee
November 4, 2015

Hi Samuele,

Can you attach your full java file? Without seeing the code it's hard to help with what's going wrong.

Regards,

Opkar

Lokesh_Shivalingaiah
New Participant
November 4, 2015

If you have any other references in your service, remove all of them and try simple with resourceResolver and it should work. I have seen this if there are some other reference which cannot be resolved is there in the service. 

If that works, then later you can add the other references gradually and see what is causing an issue.

smacdonald2008
smacdonald2008Accepted solution
New Participant
November 4, 2015

IN AEM - create a dedicated user account to set up a successful  ResourceResolverFactory instance. See this code:

@Service
public class CustomerServiceImpl implements CustomerService {
   
   
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
       
private Session session;
           
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
       
  
  
//Queries the AEM JCR for customer data and returns
//the data within an XML schema   
public String getCustomerData(String filter) {
  
Customer cust = null;
  
List<Customer> custList = new ArrayList<Customer>();
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
 
try {
            
    //Invoke the adaptTo method to create a Session used to create a QueryManager
    resolver = resolverFactory.getServiceResourceResolver(param);
    session = resolver.adaptTo(Session.class);

NOTE: In AEM 6.1, service users must be system users, which effectively means that their node in the JCR is of type rep:SystemUser. These users cannot be used to log in normally, only by background processes. The admin user is not a system user, so you cannot use the admin user in a service user mapping like this. You have to create a new system user and assign them the appropriate permissions.If you would like to read more of the background on this change, take a look at https://issues.apache.org/jira/browse/SLING-3854.

 

This is explained in this AEM community article: 

https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html