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
  • 7558 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

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

it is calling a private method  :  getFileSize()

 

Ok i will put before 1 logger

edubey
Level 10
October 16, 2015

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

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

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 %>"/>

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

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;
  }

edubey
Level 10
October 16, 2015

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}"/>
Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

Hi, thank you for trying to help me

 

here is a screenshot [img]logging.png[/img]

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

hi

My Java class is working fine

all other info of this component is shown correctly...

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

hellooo

before the calling the private method it is printing it

 

why?

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

all logs in author\crx-quickstart\logs folder

Adobe Employee
October 16, 2015

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