how to debug or log info in bean | Community
Skip to main content
Xena_bcn
Level 5
October 16, 2015
Solved

how to debug or log info in bean

  • October 16, 2015
  • 34 replies
  • 7521 views

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?

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 edubey

Try this snippet of code.

Resource r = resourceResolver.getResource(path); Asset a = r.adaptTo(Asset.class); Rendition rnd = a.getOriginal(); long size = rnd.getSize();

34 replies

edubey
Level 10
October 16, 2015

Methods, Variables and Constructors that are declared private can only be accessed within the declared class itself.

So as long as its in same class it should not be a problem.

Do one things , flood your getDownloadText() method with logger so that you can see where its getting break.

edubey
Level 10
October 16, 2015

Did it worked?

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

HI

Today it is working...

I can see an error:

HEAD /content/dam/project/path/filename.pdf HTTP/1.1] org.apache.sling.auth.core.impl.SlingAuthenticator getAnonymousResolver: Anonymous access not allowed by configuration - requesting credentials

How can  I get DAM file size ?

edubey
edubeyAccepted solution
Level 10
October 16, 2015

Try this snippet of code.

Resource r = resourceResolver.getResource(path); Asset a = r.adaptTo(Asset.class); Rendition rnd = a.getOriginal(); long size = rnd.getSize();
Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

I did as u said. it is not printing anything from the private method

 

anyway i can move all the commands to the public method it was called. without using a function

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

Hello @edubey

Thank you a lot

it worked !

I didn't reply till now because I got engaged with another task before I tried your solution just now.

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

thank you I will try it now.

Adobe Employee
October 16, 2015

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

smacdonald2008
Level 10
October 16, 2015

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

Adobe Employee
October 16, 2015

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