webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

java.lang.NullPointerException in Java Service

  • 1.  java.lang.NullPointerException in Java Service

    Posted Fri June 11, 2010 01:29 PM

    Hi All,

    I am getting java.lang.NullPointerException while invoking my java service from flow service.
    I am having records in database and using jdbc adaptor I am reading those records and passing fields values as input for my java service.
    This database may have null values in some columns. My service is checking whether its null or blank and accordingly its setting default values to those variables.

    But when null values will get mapped, it throws java.lang.NullPointerException. Allow Null property of all variable is set to True. I have checked the inputs an all possible causes that i can think.
    In my case it is necessary to pass null value to my java service. Can you please help me, how to pass null values to java service.

    Sample of my code :
    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String DocTitle = IDataUtil.getString( pipelineCursor, “DocTitle” );
    Object InTime = null; //IDataUtil.get( pipelineCursor, “InTime” );
    String Author = null; //IDataUtil.getString( pipelineCursor, “Author” );
    String Account =null; // IDataUtil.getString( pipelineCursor, “Account” );
    String primaryFile = IDataUtil.getString( pipelineCursor, “primaryFile” );
    pipelineCursor.destroy();

    //FileMetaData is HashMap static object of HashMap declared in source part of Shared tab
    if (FileMetaData==null)
    FileMetaData = new HashMap(); // Stores the Key Value pair for the File
    else
    FileMetaData.clear();

    FileMetaData.put(“DocTitle”, DocTitle.trim());

    DateFormat dateFormat = new SimpleDateFormat(“MM/dd/yyyy hh:mm a”);
    if (InTime!= null )
    {
    Date date=(Date)InTime;
    FileMetaData.put(“InTime”, dateFormat.format(date));
    }
    else
    {
    Date date = new Date();
    FileMetaData.put(“InTime”, dateFormat.format(date));
    }

    if (Author==null)
    FileMetaData.put(“Author”, “sysadmin”);
    else if (Author.trim().equals(“”))
    FileMetaData.put(“Author”, “sysadmin”);
    else
    FileMetaData.put(“Author”, Author.trim());

    if (Account==null)
    FileMetaData.put(“Account”,“”);
    else
    FileMetaData.put(“Account”, Account.trim());

    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    IDataUtil.put( pipelineCursor_1, “DocTitle”, FileMetaData.get(“DocTitle” ).toString());
    IDataUtil.put( pipelineCursor_1, “InTime”, FileMetaData.get(“InTime” ).toString());
    IDataUtil.put( pipelineCursor_1, “Author”, FileMetaData.get(“Author” ).toString());
    IDataUtil.put( pipelineCursor_1, “Account”, FileMetaData.get(“Account” ).toString());
    pipelineCursor_1.destroy();


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 2.  RE: java.lang.NullPointerException in Java Service

    Posted Fri June 11, 2010 07:09 PM

    DocTitle could be null. I don’t see a null check before the call to DocTitle.trim()

    If this does not solve your problem ,you may want to try debugging the issue by adding some sysout statements to your java service.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 3.  RE: java.lang.NullPointerException in Java Service

    Posted Mon June 14, 2010 11:06 AM

    Thank you agrawal, thanks for your quick reply.
    I found the root cause of problem. Actually mapping was wrong. I was having variable with name Intime as well as InTime. And I have mapped Intime variable instead of InTime.

    My problem is solved after changing mapping.

    Thanks and Regards,
    mayur


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services