cancel
Showing results for 
Search instead for 
Did you mean: 

Nullpointer exception when running custom code in eclipse

Former Member
0 Kudos

Hi All,

I am trying to create custom code for sending reminder Emails for pending contract approvals.

Code is as below, but when I try to run this in Eclipse, I get null pointer exception for session object.

Please guide me to remove this error.

//Sample custom code

package com.frictionless.custom;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.frictionless.api.common.exception.ApplicationException;
import com.frictionless.api.common.platform.IapiDbHandleIfc;
import com.frictionless.api.common.platform.IapiSessionContextIfc;
import com.frictionless.api.common.platform.IapiTaskIfc;
import com.frictionless.common.platform.SessionContextIfc;

public class ReminderEmail implements IapiTaskIfc {


public ReminderEmail(IapiSessionContextIfc session)
    {
        this.session = session;
    }
public IapiSessionContextIfc getSessionContext()
    {
        return session;
    }

    public String getDescription()
    {
        return "This scheduled task is responsible for sending reminder emails.";
    }

// comment below method when creating jar
public static void main(String[] args) {
  ReminderEmail re = new ReminderEmail(session);
  try {
   boolean b = re.execute();
   System.out.println("Executed = " + b);
  } catch (ApplicationException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
}
    public boolean execute()throws ApplicationException
    { 
        String sql;
        IapiDbHandleIfc dbHandle;
        sql = "SELECT * FROM DUAL";
        dbHandle = null;
        String result;
        result = null;
        System.out.println("Session is = "+session); //prints Session is = null
        dbHandle = session.getDbHandle();   //Null pointer exception here
        try{
         dbHandle.beginTransaction();
         dbHandle.executeQuery(sql);
         if(dbHandle.next())
          result = dbHandle.getString(1);
         System.out.println("The value of result is = "+result);
         dbHandle.endTransaction();
        }
        catch(Exception e){           
           if(dbHandle != null && dbHandle.isInsideTransaction())
               dbHandle.abortTransaction();        
           ApplicationException ae = new ApplicationException(session, e);
           ae.setMessageString("Unable to query database for extension table name: [" + e.getMessage() + "]");
           throw ae; 
        }

return true;
    }

  private static IapiSessionContextIfc session; 

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Saloni,

 

As far my knowledge goes, you will not be able to test an
IapiTask outside CLM system.

To test your code do the following:

   1. Remove the main method from your code

   2. Build build the code into a jar and deploy it on server.

   3. Once deployed, create a schedule task in CLM

        Setup -> Schedule Tak -> create new -> Select a document type: IAPI Task Execution

 

Hope this helps.

Regards,

Bindu

isaac_ariza_cruz
Participant
0 Kudos

Hello Saloni,

I have similar requirements and I would also need some support.

Did you solve this problem? I've so, could you please let me now how it was solved?

Thanks and best regards,

Isaac