Skip to main content
Xena_bcn
Level 5
Oct 16, 2015 2:28 AM UTC
Solved

how to debug or log info in bean

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.
edubey
edubeyAccepted solution
Level 10
Oct 16, 2015 2:28 AM UTC

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
Oct 16, 2015 2:28 AM UTC

it is calling a private method  :  getFileSize()

 

Ok i will put before 1 logger

Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC

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

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

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

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

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

Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC

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}"/>
Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

Hi, thank you for trying to help me

 

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

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

hi

My Java class is working fine

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

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

hellooo

before the calling the private method it is printing it

 

why?

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

all logs in author\crx-quickstart\logs folder

Translate
Adobe Employee
Oct 16, 2015 2:28 AM UTC

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

Translate