Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0

    Error Calling Java Object


    Im trying to call the method below on java.

    public static byte[] getPDFBytesArray(String account, String billdate, String source) throws Exception
    {
    byte[] array = null;
    Date strstartdate = null;
    Date strenddate = null;
    System.out.println(" Callinng the <<< getPDFBytesArray >>>");
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    StringBuffer sb = new StringBuffer();
    sb.append(" Callinng the <<< getPDFBytesArray >>>");


    //validate date
    try
    {
    if (billdate != null)
    strstartdate = formatter.parse(billdate);
    }
    catch(Exception _exx)
    {
    _exx.printStackTrace();
    throw _exx;
    }
    System.out.println(" <<< Start date and end date verified>>");
    try
    {
    //String datemft = formatter.format(date);

    Document document = DocumentHelper.createDocument();
    Element root = document.addElement( "BILLPrint" );
    root.addElement("account").addText(account == null?"":account);
    root.addElement("startdate").addText(billdate == null?"":billdate);
    root.addElement("enddate").addText(billdate == null?"":billdate);
    root.addElement("billsource").addText(source == null?"":source);
    sb.append("calling locator = new KubraBillPrintProxyServiceLocator()");

    System.out.println(" <<< locator = new KubraBillPrintProxyServiceLocator() \nInbound XML created ....>>");
    locator = new KubraBillPrintProxyServiceLocator();
    sb.append(" <<<Calling locator.getKubraBillPrintProxy(new URL(ADDRESS) ....>>");
    System.out.println(" <<<Calling locator.getKubraBillPrintProxy(new URL(ADDRESS) ....>>");
    soap = locator.getKubraBillPrintProxy(new URL(ADDRESS)); // from configuration

    sb.append("<<< SOAP object found .. about to call the getKubraPDF ....>>");

    System.out.println(" <<< SOAP object found .. about to call the getKubraPDF ....>>");

    String base64 = soap.getKubraPDF(document.asXML());
    array = base64Decode(base64);
    sb.append("<<< getKubraPDF function Executed... and Back!!! ....>>");
    System.out.println(" <<< getKubraPDF function Executed... and Back!!! ....>>");

    }
    catch (Exception _exx) {
    // TODO Auto-generated catch block
    _exx.printStackTrace();
    System.out.println("<<<< OOOPPS Got Error " + _exx.getMessage() + " >>>>>>");
    sb.append(_exx.getMessage());
    return sb.toString().getBytes();
    //throw _exx;
    }
    sb.append("<<<< Returning the object array .... >>>>>>");
    System.out.println("<<<< Returning the object array .... >>>>>>");

    return array;
    }
    private static byte[] base64Decode(String base64)
    {
    return Base64.decode(base64);
    }
    private static String base64Encode(byte[] array)
    {
    return Base64.encode(array);
    }

    }

    Im using to the tag below to call the object

    [IGREP]<!---cfset myObject = createObject( "java", "com.washgas.kubra.client.KubraAPI" )--->

    <cfset BillDate = DateFormat(Date, "short")>

    <cfset result = myObj.getPDFBytesArray("0063062087",#BillDate#,"")>[/IGREP]

    But i always this Null Null error. Not sure where is this coming from. I tried different approach creating object and java casting but always come up with the null null error. Any idea why?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    I'd check a few things. First, your CreateObject() call is commented out. Second, you're not calling init() on the Java object, which you need to do in order to properly construct the object. And last, you're passing an empty string for the third parameter, but the Java code is only checking if it is null, not if it is an empty string.

    It probably wouldn't hurt to run this directly within Eclipse, IDEA, or some other Java IDE to confirm that the Java side of it actually works correctly.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0
    Originally Posted by kiteless
    I'd check a few things. First, your CreateObject() call is commented out. Second, you're not calling init() on the Java object, which you need to do in order to properly construct the object. And last, you're passing an empty string for the third parameter, but the Java code is only checking if it is null, not if it is an empty string.

    It probably wouldn't hurt to run this directly within Eclipse, IDEA, or some other Java IDE to confirm that the Java side of it actually works correctly.
    Comment is being removed whenever i try to run it.
    Java code was tested succesfully and confirmed wokring.
    Can you please give me how to create object with INIT?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Second, you're not calling init() on the Java object, which you need to do in order to properly construct the object.
    Actually you don't need to do that w/a static method.

    bozzpaw - As I mentioned in your other thread, did you check the logs for more details about the "null null" error?
  8. #5
  9. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    Yep, I didn't notice that it is a static method, so no init() call needed.

    My first guess is that the JAR isn't on the CF classpath. Or it could be the param types. Might be worth using an actual string rather than a date, and to make sure you're passing something in for the third param ("source"), since right now you're not passing anything for that.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by kiteless
    Or it could be the param types.
    Yeah, that would be my guess. (If the jar were not in the class path, I'd expect a ClassNotFoundException). Either way the logs should provide more information. At the very least what line in the class is causing the problem.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0
    Originally Posted by cfSearching
    Yeah, that would be my guess. (If the jar were not in the class path, I'd expect a ClassNotFoundException). Either way the logs should provide more information. At the very least what line in the class is causing the problem.
    Looks like the JAR is in the correct classpath. I've created a method that will only display a message and I've successfully displyed it in CF.

    For the logs - logs is not updating for my error for some reason. It has a latest log but not for what I am testing. Do I need to put some tag for logs?

    Sorry guy, im very new with CF.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0
    Originally Posted by kiteless
    Yep, I didn't notice that it is a static method, so no init() call needed.

    My first guess is that the JAR isn't on the CF classpath. Or it could be the param types. Might be worth using an actual string rather than a date, and to make sure you're passing something in for the third param ("source"), since right now you're not passing anything for that.
    How am I going to check the classpath CF6 is using? Is there anyway? Though I already tested some of the methods from the Jar file, I'd still wanna know if my CF is pointing in the right direction..
  16. #9
  17. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    Like I said earlier, I always took the easy route and just put any JARs I needed into the CF server's /lib folder. It should have a lot of JARs in it already and it HAS to be on CF's classpath or the whole server wouldn't work at all. But it will require a restart of CF I believe, for it to pick up the new JAR.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0
    Originally Posted by kiteless
    Like I said earlier, I always took the easy route and just put any JARs I needed into the CF server's /lib folder. It should have a lot of JARs in it already and it HAS to be on CF's classpath or the whole server wouldn't work at all. But it will require a restart of CF I believe, for it to pick up the new JAR.
    Yeah. I put my JAR files there. Just wanna know if theres a way to check where is my CF pointing its classpath. Like a command to type in CMD, then will show you where CF is getting its classpath. Something like that.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by bozzpaw
    For the logs - logs is not updating for my error for some reason. It has a latest log but not for what I am testing. Do I need to put some tag for logs?
    It is possible, but .. unlikely. Severe errors should be logged automatically by CF courtesy of log4j. Are you sure you checked both log directories? Just sort the files by date and check the ones updated recently.

    Originally Posted by bozzpaw
    Though I already tested some of the methods from the Jar file, I'd still wanna know if my CF is pointing in the right direction..
    If you are able to run any methods, then it is in the right place. So there is no issue unless you added multiple versions of that jar to the CF class path.

    However, IIRC you can check the class path by dumping the system properties. I *think* coldfusion.classPath and cfdump exist in MX6.

    <cfset prop = createObject("java", "java.lang.System").getProperties()>
    <cfdump var="#prop#">

    See also Debugging Tip: Identifying Which Jar file a class was loaded from in ColdFusion MX
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    17
    Rep Power
    0
    Originally Posted by cfSearching
    It is possible, but .. unlikely. Severe errors should be logged automatically by CF courtesy of log4j. Are you sure you checked both log directories? Just sort the files by date and check the ones updated recently.



    If you are able to run any methods, then it is in the right place. So there is no issue unless you added multiple versions of that jar to the CF class path.

    However, IIRC you can check the class path by dumping the system properties. I *think* coldfusion.classPath and cfdump exist in MX6.

    <cfset prop = createObject("java", "java.lang.System").getProperties()>
    <cfdump var="#prop#">

    See also Debugging Tip: Identifying Which Jar file a class was loaded from in ColdFusion MX
    Yeah, some of the simple methods I call is working. No other version of my JAR file there. Look all for the logs. Just showing system.output from the Java I am calling (for reference to know where the code stopped). But no errors related with I am encountering.

    I am really frustrated. Been working on this for the past 2 weeks.
  24. #13
  25. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    Originally Posted by bozzpaw
    Yeah. I put my JAR files there. Just wanna know if theres a way to check where is my CF pointing its classpath. Like a command to type in CMD, then will show you where CF is getting its classpath. Something like that.
    In the CF admin there should be a page for System Information which will list a ton of info, including the configured classpath. That said, I can't remember where that is in the CF 6 admin UI, or if it is even there. It's probably been 10 years since I used CF 6.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by bozzpaw
    But no errors related with I am encountering.
    Again, it is possible .. but unlikely. I find it very hard to believe it's not outputting something .. somewhere. Is it possible you're just overlooking the messages. (Not trying to be insulting. I just do not know how familiar you are w/java stack traces).

    What are the actual files you checked? What is the actual message content of the logs?
  28. #15
  29. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    Originally Posted by bozzpaw
    Yeah, some of the simple methods I call is working. No other version of my JAR file there. Look all for the logs. Just showing system.output from the Java I am calling (for reference to know where the code stopped). But no errors related with I am encountering.

    I am really frustrated. Been working on this for the past 2 weeks.
    It could even be an issue with CF 6 itself (being so old), or the version of the JRE it uses (probably Java 1.4). They're up to Java 7 now, and I wouldn't be shocked at all if a Java 1.4 JRE couldn't run code compiled under Java 5, 6, or 7.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo