hello here.
So one of my component java bean functions is not returning result I am expecting.
I added log.info to trace , doesn't print anything.
Then used debug from Eclipse , doesn't stop on breakpoints.
Where and what I should do?
Solved! Go to Solution.
Views
Replies
Total Likes
Try this snippet of code.
Resource r = resourceResolver.getResource(path); Asset a = r.adaptTo(Asset.class); Rendition rnd = a.getOriginal(); long size = rnd.getSize();
Views
Replies
Total Likes
You can log information in the AEM log using code like:
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
private Session session;
private java.util.Iterator<Authorizable> users = null ;
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
@Override
public String getCQUsers() {
try
{
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
//Create a UserManager instance from the session object
UserManager userManager = ((JackrabbitSession) session).getUserManager();
users= userManager.findAuthorizables("jcr:primaryType", "rep:User");
while (users.hasNext()) {
Authorizable auth = users.next();
if (!auth.isGroup()) {
//Get the ID of the user
String id = auth.getID();
log.info("Retrieved USER "+id) ;
}
}
// Log out
session.logout();
return "All AEM Users are written to the log file" ;
}
catch(Exception e)
{
log.info("CQ ERROR: "+e.getMessage()) ;
}
return null;
}
}
See https://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html
Views
Replies
Total Likes
Hi,
for debugging, did you use the approach defined here: https://helpx.adobe.com/experience-manager/kb/CQ5HowToSetupRemoteDebuggingWithEclipse.html
When creating the debugging configuration, did you define where the source code is located?
Regards,
Opkar
Views
Replies
Total Likes
I am assuming this is component in OSGI.
I prefer using this library for logging, its very helpful, can you try to integrate this. Its simple
hi...
yes i am using it. but it is not printing to adobe error.log
and this java class is in <package>.components
what do you mean by component in OSGI?
In OSGI,
Can you open logger configuration and find out whether there is a separate log file configured for your class in which this code is present.
Also please check what is the log level setup.
Are you able to see logs of other classes ?
Can you please share snippet of your code?
Can you ensure that JAR files required are present in you OSGI.
as far as I can see the core bundle is present in
http://localhost:4502/system/console/bundles
http://localhost:4502/system/console/osgi-installer
I need to show a DAM asset file size in 1 of my components.
So I pass here URL as for example /content/dam/project_name/<path>/filename.pdf
private int getFileSize(URL url) {
HttpURLConnection conn = null;
try {
log.info(" URL : " + url.toString());
conn = (HttpURLConnection) url.openConnection();
log.info(" connected");
conn.setRequestMethod("HEAD");
conn.getInputStream();
log.info(" input streem");
return conn.getContentLength();
} catch (IOException e) {
e.printStackTrace();
return -1;
} finally {
conn.disconnect();
}
}
Did you properly declare the logger:
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
the information is written to the aem log file too.
Hi,
can you explain how the the URL you are calling will lead to your code being invoked? Are you calling the URL directly?
What kind of Java class is it?
It sounds as if you code is simply not being called. Doing things crudely, you should be able to see "System.out.println("");" statements if your code was being called.
Regards,
Opkar
What file are you looking in?
So the bundle that contains your java code is empty?
Did you follow the guide[1] for adding Java classes to your OSGI bundle? It seems like your maven file has not been configured correctly to include the java class. After building you bundle, you should be able to unpack the jar file and see your class file.
Regards,
Opkar
[1] https://helpx.adobe.com/experience-manager/using/creating-osgi-bundles-digital-marketing.html
oh not mine was:
private final Logger log = LoggerFactory.getLogger(getClass());
I added this, compiled and deployed. but it is still not writing log.
should i restart?
Hi,
It is one of components Java bean class.
I access to the web page via WCM in localhost:4502 and I see the component, but the file size is shown as 0.00kb
ButI don't see any log.
I've used System.out.println("") too.
Hi,
unless I have missed it, you haven't explained how you are expecting your code to be called? Is it called by a JSP, is it called by another Java OSGI Service?
Regards,
Opkar
all logs in author\crx-quickstart\logs folder
hellooo
before the calling the private method it is printing it
why?
hi
My Java class is working fine
all other info of this component is shown correctly...
Hi, thank you for trying to help me
here is a screenshot [img]logging.png[/img]
This doesn't look like you are calling the method, its just creating a bean object and setting the property.
Here's what I think, you are using getter setter method in you bean class.
Getter method should only return the value, where as to set value to some instance object you should use setter method. but in this case you are passing arguments to getter method which doesn't seems to be a good one. Please have a setter method to set the value of URL instance variable and then use below code
<c:set var="filesize" value="${ouritem.fileSize}"/> <c:out value="${filesize}"/>
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies