Folks:

 

I had numerous requests about the actual solution to our problem.  So, I've
posted the problem and solution here for future reference.

 

Here's the original problem:

 

I have Web Services running on a remote server.  There are two (2) calls
that are made to those Web Services.  The first call establishes the
connection and provide basic authentication.  This call always seems to
work.  The second call returns a string variable or "token".  Plain and
simple.  However, for whatever reason, I cannot get the code to run reliably
to return the token each and every time I call the Web Services.  In other
words, if I execute the CF code ten (10) times, I may or may not get the
desired token.  For whatever reason, the calls from CF to the Web Services
are unreliable and flaky at best.

 

So, I had a Java developer create a JAR file that performs the same calls to
the Web Services.  The JAR file actually has two methods.  When instantiated
from CF using the createObject function, the test method of helloWorld()
returns the string "Hello World" just as expected.  But, when I try to
access the generateToken() method, I get the following error: "The system
has attempted to use an undefined value, which usually indicates a
programming error, either in your code or some system code.  Null Pointers
are another name for undefined values."  When I look in the CF logs, I see,
amongst other things, "java.lang.NullPointerException".  In other words, I
can access the helloWorld() test method just fine, but the generateToken()
method doesn't work.  BUT here's the kicker - the JAR file works just fine
when called from a Command Prompt using the "java -jar fileName.jar"
command.

 

To sum this up, I'm seeing unpredictable, flaky behavior when calling Web
Services from ColdFusion as well as invoking a method that calls these same
Web Services from ColdFusion.  When I invoke the JAR file from a Command

Prompt, everything works perfectly.

 

The solution was actually quite simple - it came down to one line of code
that was missing - we forgot to initialize the Java object before accessing
it from CF:

 

myObject = createObject("java", "theJavaJARFile");

theTokenGenerator = myObject.init();

 

(The second line, calling the init() method, was missing from our original
CF code.)

 

So, apparently, when calling the JAR file from the command prompt, the JRE
automatically calls the init() method, or the call is not needed.  However,
then calling the JAR file from a CF object, you MUST call the init() method
first.  Talk about a one-line-of-code-headache!  :-)

 

I hope this solution helps out anyone in a similar situation.  (And Michael,
please forgive the semi-OT post!)  :-)

 

Cheers, All!

 

~Christian N. Abad

 

 

 




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: http://www.houseoffusion.com/groups/cf-jobs/message.cfm/messageid:8254
Subscription: http://www.houseoffusion.com/groups/cf-jobs/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-jobs/unsubscribe.cfm

Reply via email to