Topic
  • 4 replies
  • Latest Post - ‏2012-11-06T09:48:49Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic How to debug Java Class called by adapter

‏2012-10-30T09:57:07Z |
Hello,
I'm using an adapter to call a JavaClass (like var myObj = com.package.MyClass.getString();)

Everything works good, but if i put a System.out or a System.err they won't print on the Worklight Console and i don't know where i could read their output. So i cannot debug if i encounter any error.

Where i could read these values?
Or How i have to debug correctly?

Thank you.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: How to debug Java Class called by adapter

    ‏2012-10-30T21:43:10Z  
    This is a good question...And I don't know if I have an adequate answer for you.

    I would first note that since you are calling a java class from an adapter, it means that you are already able to run the java class as either a standalone project or from some other java class that uses it.

    If you are passing parameters to the java classes that you are calling through your adapter (which I'm assuming you are) then I would log the parameters through the Worklight logger before passing them to your Java object. That way when there is an error, you can run the java classes as a standalone project and pass the parameters manually to see what went wrong.
    Another solution is instead of using System.out.println, create a function that writes any of your messages to a string and then create a function that returns this string. For example:

    
    String logger = 
    ""; 
    
    int a = 5; logger = 
    "Got to this part"; someFunctionCall(a);   ...   
    
    public String getLogger()
    { 
    
    return logger; 
    }
    


    And then in your adapter, call the "getLogger()" function to get everything that happened during the time you used that object and output it using your Worklight logger.

    The above solutions are sort of hacky, but I do not know if Worklight has a built in solution for debugging java that is being run through adapters.
  • eabe
    eabe
    13 Posts

    Re: How to debug Java Class called by adapter

    ‏2012-10-31T22:54:04Z  
    Hello,

    Jetty will not show up System.out / System.err messages into its console. In order to debug your Java code you need to use Log4J to log your messages.
    Please refer to the Getting Started module 22 (Custom Login Module) - its Java class "MyCustomAuthenticator" illustrates how to use the Logger.

    
    
    
    private 
    
    static 
    
    final Logger logger = Logger.getLogger(MyCustomAuthenticator.class); 
    
    public 
    
    void init(Map<String, String> options) 
    
    throws MissingConfigurationOptionException 
    { logger.info(
    "MyCustomAuthenticator initialized"); 
    }
    


    I hope this helps.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: How to debug Java Class called by adapter

    ‏2012-11-05T07:55:33Z  
    • eabe
    • ‏2012-10-31T22:54:04Z
    Hello,

    Jetty will not show up System.out / System.err messages into its console. In order to debug your Java code you need to use Log4J to log your messages.
    Please refer to the Getting Started module 22 (Custom Login Module) - its Java class "MyCustomAuthenticator" illustrates how to use the Logger.

    <pre class="jive-pre"> private static final Logger logger = Logger.getLogger(MyCustomAuthenticator.class); public void init(Map<String, String> options) throws MissingConfigurationOptionException { logger.info( "MyCustomAuthenticator initialized"); } </pre>

    I hope this helps.
    Thank you all.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: How to debug Java Class called by adapter

    ‏2012-11-06T09:48:49Z  
    hi,

    there is a debug method, add below-mentioned java debug parameter to end of -vmargs section of eclipse.ini, then you can create a Remote Java Application launching configuration from debug category of Eclipse, and give connection type 'Socket Attach' and Connection Properties (host localhost, port 5050), then launch it and debug it as a normal java program.

    -agentlib:jdwp=transport=dt_socket,server=y,address=localhost:5050,suspend=n