Forum Moderators: coopster & phranque

Message Too Old, No Replies

PERL LWP script not able to contact internet

Problem with Tomcat/Catalina settings?

         

pghthompson

10:03 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

;

}

}

upside

9:55 am on Nov 3, 2004 (gmt 0)

10+ Year Member



Make sure that you are printing a proper Content-Type header before any other print statements like this:

print "Content-Type: text/html\n\n";

pghthompson

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

10+ Year Member



Already did that. The problem's something else.