Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

how to debug or log info in bean

Avatar

Level 6

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?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Try this snippet of code.

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

View solution in original post

34 Replies

Avatar

Level 6

then inside JSP  ${ouritem.downloadText}

 

in Java:

 

public class ......Component extends AbstractComponent {

.....

.....

 

public String getDownloadText() {
    //return getStringProperty("jcr:textAsset");
    int fileSize = 0;
    String filePathName = getDownloadUrl();
    String fileType = filePathName.substring(filePathName.indexOf(".") + 1);
    
    filePathName = filePathName.replace(" ", "%20");
    
    try {
        fileSize = getFileSize(new URL(filePathName));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      
      double sizeKb = fileSize;   // 1000;
      
      DecimalFormat df = new DecimalFormat("0.00KB");
      String result = "Download (" + fileType + ", " + df.format(sizeKb) + ")";
      
      return result;
  }

Avatar

Level 6

hi thank you for trying to help me.

All components of this projects have:

<jsp:useBean id="ouritem" scope="page" class="package.components.....Component"></jsp:useBean>
<jsp:setProperty name="ouritem" property="slingRequest" value="<%=slingRequest %>"/>

Avatar

Level 10

its getting some confusion.

Previously you shared getFileSize() method.

and this method dosen't seems to have any logger. Can you try adding few logger in getDownloadText() before getFileSize() gets called.

Thanks

Avatar

Level 6

it is calling a private method  :  getFileSize()

 

Ok i will put before 1 logger

Avatar

Level 10

are you able to see logs which u added?

Avatar

Level 6

It didn't print after URL url =  new URL (filepath);

 

filepath was a path to DAM like /content/project/path/filename.pdf

 

then I added localhost:4502 to it

but now it is  not printing anything....

 

so i stopped and doing another task.

 

seems bad luck, hahaha

Avatar

Level 6

yes exactly dear Edubey

but only that new line before calling the private method getFileSize

 

is it because it is private?

Avatar

Level 10

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.

Avatar

Level 6

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 ?

Avatar

Correct answer by
Level 10

Try this snippet of code.

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

Avatar

Level 6

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

Avatar

Level 6

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.