Forum Moderators: phranque

Message Too Old, No Replies

PERL LWP routine does not work on Tomcat

Cannot make http request from PERL script

         

pghthompson

7:50 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



I have a PERL routine that saves a backup copy of a url using the LWP module. It works reliably on Windows servers. I have just set up a machine with the J2EE environment and Tomcat web server, and the routine will not run through the server on this machine (although it will run from the command prompt). I presume this means that the problem is somewhere in the server setup or permissions, but I can’t seem to locate anything that resolves the problem. I need to get this working through the browser because it is part of a web-based system. Any suggestions on what needs tweaked?

Here is an abbreviated copy of the code:

sub CheckSave{

my $id = $_[0]; #passing primary key

my $url = $_[1]; #whether or not to save backup

my $savepath = $_[2];

#check web page header to see if it exists

@dat=head($url);

if (!@dat) {

print <<EOF;

<DIV STYLE="color:red;border:solid 2px red; padding:4px;">

System cannot contact the Internet to save a backup. Please contact the webmaster

or edit the web address entered.<BR>

URL: $url

</DIV>

EOF

;

die;

}

#get extension for saved file from url

$ext=$in{"cec_url"};

if ($ext =~ /\?/ ¦¦ $ext =~ /.com$/) {

#if url contains a query string, use header to return extension

#if .com address, use content_type

$ext=$dat[0];

$ext =~ s/.*\/(.*)/\1/;

} else {

#otherwise, find the file type from the url

$ext =~ s/.*\.([^\/]*)/\1/;

}

#save the new web download

$saveFile = $savepath.$id.".".$ext; #generate archive file name

$status = getstore($in{"cec_url"}, $saveFile); #check url and save copy

if (is_success($status)) {

print qq[<BR><CENTER>Backup copy saved.</CENTER>\n];

} else {

#print warning if website was not valid

print <<EOF;

<DIV STYLE="color:red;border:solid 2px red; ">

Website link not found. Archive file not saved.<BR>

Please edit this record.

</DIV>

EOF

;

}

}

jdMorgan

9:35 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



pghthompson,

Welcome to WebmasterWorld!

There aren't a lot of Tomcat/LWP experts around here, apparently...

Is there any other information you might provide to help clarify the problem?

<bump>

Jim

Birdman

9:57 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Definately going to need the error that gets logged when the script dies.

Have you tried running it from the command line in strict mode?

#!/pathto/perl

use strict;

pghthompson

11:40 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



This appears to be the important part of the server log:

2004-11-04 18:22:42 StandardContext[/arch]cgi: runCGI(envp=[{HTTP_USER_AGENT=Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1), HTTP_ACCEPT_ENCODING=gzip, deflate, REQUEST_METHOD=GET,
AUTH_TYPE=, HTTP_ACCEPT_LANGUAGE=en-us, SERVER_NAME=svr-arch.cecinc.com, SERVER_SOFTWARE=TOMCAT,
HTTP_HOST=svr-arch.cecinc.com, GATEWAY_INTERFACE=CGI/1.1,
X_TOMCAT_SCRIPT_PATH=C:\Program Files\Afm14\Tomcat 5.0\webapps\arch\cgi-bin\cec\msds_save_url.pl,
REMOTE_ADDR=10.100.8.70, SERVER_PROTOCOL=HTTP/1.1, PATH_INFO=, REMOTE_HOST=DTHOMPSON,
QUERY_STRING=, HTTP_CONNECTION=Keep-Alive, SERVER_PORT=80,
HTTP_COOKIE=afm_user_id_per_computer=afm; JSESSIONID=14AD0D44927B3B6A0071B70D52F5547F,
CONTENT_TYPE=, CONTENT_LENGTH=, SCRIPT_NAME=/arch/cgi-bin\cec\msds_save_url.pl, HTTP_ACCEPT=*/*,
REMOTE_USER=, REMOTE_IDENT=}], command=C:\Program Files\Afm14\Tomcat 5.0\webapps\arch\cgi-bin\cec\
msds_save_url.pl)

2004-11-04 18:22:42 StandardContext[/arch]cgi: runCGI (stderr):500
Can't connect to www.theneonweb.com:80 (Bad protocol 'tcp')
<URL:http://www.theneonweb.com/index.html>

pghthompson

7:00 pm on Nov 9, 2004 (gmt 0)

10+ Year Member



For anyone else who has the problem, adding the line

$ENV{"SYSTEMROOT"} = "C:\\windows";

to the code fixed the problem.

kbright

5:42 pm on Dec 1, 2004 (gmt 0)



Thank you, thank you, thank you!

I had to do this on my system: (from a command prompt I did "echo %SYSTEMROOT%")

$ENV{"SYSTEMROOT"} = "C:\\WINNT";

How did you figure out that was the problem?