so I have the code below
I have a breakpoint in this line 27 and another one in line 29.
when debugging my code (eclipse user here), the program stops at the first breakpoint. And when I resume (F8), it never stops in the second breakpoint. I suppose something happened to it (fatal error perhaps) and my page loads completely as if nothing happened.
This is how I call the JAVA code:
<sly data-sly-use.protectedflag="${'com.mycompany.core.impl.view.tools.checker' @ path=currentPage.path}"/>
Any ideas what I could be doing wrong? Thanks
package com.mycompany.core.impl.view.tools;
import com.adobe.cq.sightly.WCMUsePojo;
import java.io.IOException;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
public class checker extends WCMUsePojo {
private boolean protectedPage;
@Reference
private ConfigurationAdmin configAdmin;
@Override
public void activate() {
try {
Configuration conf = configAdmin.getConfiguration("org.apache.sling.engine.impl.auth.SlingAuthenticator");
String path = get("path", String.class);
@SuppressWarnings("unchecked")
Dictionary<String, Object> props = conf.getProperties();
protectedPage = false;
} catch (IOException e) {
protectedPage = false;
}
}
public boolean getProtectedPage() {
return protectedPage;
}
}
Solved! Go to Solution.
Both @Reference or @Inject won't work with WCMUsePojo.
To get a Service-reference, you need to use getSlingScriptHelper()
You should use @Inject annotation instead of @Reference to initialize service while extending WCMUsePojo
@Inject
private ConfigurationAdmin configurationAdmin;
/Brijesh Yadav
Views
Replies
Total Likes
Both @Reference or @Inject won't work with WCMUsePojo.
To get a Service-reference, you need to use getSlingScriptHelper()
As Feike suggested you might have to get the service using the below code snippet
To see what Feike suggested in a full example - see this article where we get a reference to another AEM Servicve from a Class that uses WCMUsePojo -- Scott's Digital Community: Creating an AEM HTL component that queries the JCR
Question:
Will the activate() gets called when we update the config?
I believe activate() is only called once when the service gets activated or does it have a different way of working with WCMusePojo?
Views
Replies
Total Likes
Hi,
WcmUsePojos are no services, but -- as already indicated by the name -- simple pojos. Therefor all mechanics which are available for OSGI components are not available. activate() is never called during the rendering by the framework.
Views
Replies
Total Likes
Views
Likes
Replies