smg1827 has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am trying to debug my colleague's code.

(1) When I run this on command line

 # java '<XML string>' http://weburl

The output is

<XML string> Result = [OPERATION SUCCESSFUL]

Note: It takes few seconds between the output line-1 and output line-2

(2) The same web service call is coded in Perl CGI as below:

 $java_res = `java '<XML string>' http://weburl 2>/err.dat 1>/out.dat` ;

I have introduced debug logs in the CGI program just before and after this code.

(3) When this CGI program is tested on command line. It works as expected.

err.dat is empty file and

out.dat has

<XML string> Result = [OPERATION SUCCESSFUL]

(4) When this same CGI program is called from web browser and running on web server it doesn't work as expected.

err.dat is empty file and

out.dat has

<XML string>

Note:

err.dat file is empty which is correct and as expected But

out.dat doesn't have the Result = [OPERATION SUCCESSFUL] which is not correct.

Also, the program hangs at this call and I don’t see the log message after this call. It means the program doesn’t continue after this. Log message works while running the same CGI on the command line.

For debugging purpose I did hardcode the java parameters just to make sure they are same in command line and web server.

Only thing I could suspect is there is some delay (max 5 seconds) between the output line-1 and output line-2. Please confirm if that could be the issue.

Please let me know how do I go about and debug this Perl CGI code.

Please let me know if you need more details to help me on this.

Thanks.

Replies are listed 'Best First'.
Re: how to debug CGI when response is slow
by Anonymous Monk on May 12, 2012 at 07:43 UTC

      Thanks to everyone.

      I could figure out the issue.

      This bug http://www-01.ibm.com/support/docview.wss?uid=swg1PK28569 made me to go on infinite loop.

        I noticed that IBM link stopped working from today and it was working yesterday.

        In case if you are interested in knowing the content of that IBM url then see from my cache...

        PK28569: Infinite loop when java.io.tmpdir does not exist, or if the user does not have write access

        Error description The AppServer does not start when the temp directory, specified via -Djava.io.tmpdir, does not exist, or if the user does not write access to the directory. An infinite loop occurrs in the class org.eclipse.hyades.logging.core.Guid, in the 'getUniqueTimeStamp' method. (The loop occurrs because the IOException from 'File.createNewFile' is mis-interpreted, and the loop is allowed to cycle.)
Re: how to debug CGI when response is slow
by Khen1950fx (Canon) on May 12, 2012 at 08:20 UTC
    To call $java_res from a script:
    #!/usr/bin/perl -l use strict; use warnings; use CGI qw/:standard/; my $java_res = `java '<XML string>' http://weburl 2>/err.dat 1>/out.da +t`; open STDERR, '>', '/root/Desktop/err.dat' or die $!; open STDOUT, '>', '/root/Desktop/out.dat' or die $!; binmode STDOUT, ':encoding(UTF-8)'; print Dump $java_res; if ($java_res eq 1) { print "Result = [OPERATION SUCCESSFUL]"; } else { print "Result = [OPERATION UNSUCCESSFUL]"; } close STDERR; close STDOUT;

      To call $java_res from a script:...

      What a bunch of nonsense