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
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Likes
Replies