You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "G. Wade Johnson" <wa...@abbnm.com> on 2003/05/16 23:04:28 UTC
Re: [OFF-TOPIC] Calling a servlet from Perl
The easiest approach I can think of would be:
my $req = new HTTP::Request POST =>
"http://localhost:8080/path/to/servlet";
$req->content( "\%directory=$pwd\%args=$arguments\%" );
my $res = $ua->request( $req );
This assumes, of course, that $pwd and $arguments are set up correctly.
You probably forgot to escape the '%', which caused Perl to interpret
the following string as the name of a hash.
You could also build the string as
'%directory=' . $pwd . '%args=' . $arguments . '%'
(Note the single quotes.)
G. Wade
Alfred von Campe wrote:
>
> I can't even figure out how to pass the parameters to the
> servlet as shown in the sample Java code. All libwww-perl
> examples I found do something like this:
>
> use LWP::UserAgent;
> my $ua = new LWP::UserAgent;
> my $req = new HTTP::Request POST => "http://localhost:8080/path/to/servlet";
> my $res = $ua->request($req);
> if ($res->is_success)
> {
> print "It worked!\n"
> }
> else
> {
> print "Sorry, try again\n";
> }
>
> How do I pass my "%directory=" + pwd + "%args=" + arguments + "%"
> to the servlet? I'm not even sure that I should be using the
> HTTP::Request object.
>
> Alfred
>
> -----Original Message-----
> From: John Turner [mailto:tomcat-user@johnturner.com]
> Sent: Friday, May 16, 2003 4:22 PM
> To: Tomcat Users List
> Subject: Re: Calling a servlet from Perl
>
> What is it, exactly, that isn't working?
>
> John
>
> On Fri, 16 May 2003 16:14:14 -0400, Alfred von Campe <al...@turboworx.com>
> wrote:
>
> > I'm sure someone must have done this already, but I did not get very
> > far with Google searches today. I think what I'm trying to do is pretty
> > straightforward, and although I'm a long time UNIX/Perl user, I'm new to
> > Tomcat and servlets.
> >
> > In a nutshell, I want to invoke a servlet from Perl. This servlet
> > expects
> > some parameters separated by a percent symbol (%) and then runs some
> > program
> > based on the parameters received. It may or may not send the results
> > back to
> > the caller. I have a working Java example that invokes this servlet.
> > Here are
> > the relevant code snippets:
> >
> > String url = new String("http://localhost:8080/path/to/servlet");
> > serviceurl = new URL(url);
> > URLConnection conn = serviceurl.openConnection();
> > conn.setDoOutput(true);
> > PrintWriter out = new PrintWriter(conn.getOutputStream());
> > String appToRun = new String ("%directory=" + pwd + "%args=" + arguments
> > + "%");
> > out.write(appToRun);
> > out.close();
> > InputStream in = conn.getInputStream();
> > InputStreamReader modin = new InputStreamReader(in);
> > result = parseFromReader(modin);
> > modin.close();
> >
> > I have downloaded and installed the latest libwww-perl library (5.69),
> > but
> > I can't figure out how to call this servlet. I'd appreciate any examples
> > that will point me in the right direction. Even the raw protocol
> > exchange
> > would be helpful. If I can understand what's going on between Tomcat and
> > the client, I can implement it in Perl (using straight sockets and
> > avoiding
> > the use of libwww-perl if necessary).
> >
> > Thanks,
> > Alfred
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
> --
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: [OFF-TOPIC] Calling a servlet from Perl
Posted by Alfred von Campe <al...@turboworx.com>.
The problems wasn't with the % at all. It was me not knowing how
to use the libwww-perl library and a typo on my part. I know this
is off topic, but I want to provide the solution I used so that the
next person who asks this same question can find the answers in the
archive.
Here is a simplified version of my Perl script:
# Create user agent object
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
# Create a request
$command = sprintf("%%directory=$ENV{PWD}%%args=%s%%", join(" ", @ARGV));
my $req = new HTTP::Request POST => "http://server:8080/path/to/servlet";
$req->content($command);
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
if ($res->is_success)
{
print "It worked!\n";
}
else
{
print "Try again\n";
}
I actually had this working a lot earlier than I realized. The problem
was that I was calling the wrong servlet (we have two very similarly named
servlets, and I cut & pasted the wrong one into my Perl code). Thanks for
all those who helped (especially for supplying the $req->content() method).
Alfred
-----Original Message-----
From: G. Wade Johnson [mailto:wade.johnson@abbnm.com]
Sent: Monday, May 19, 2003 9:30 AM
To: Tomcat Users List
Subject: Re: [OFF-TOPIC] Calling a servlet from Perl
I did not mean to offend about the escaping, but after over a decade
doing Perl I still mess that up with %.<shrug/>
The only other thing I can think of is URL escaping. Since '%' begins
a URL escape sequence, you may need to encode it as '%25'.
G. Wade
Alfred von Campe wrote:
>
> Thanks for the help, but unfortunately that didn't work either. I
> know about escaping the % in Perl (like I said, I've been using Perl
> for many years), so that wasn't the issue. I've made a little more
> progress. I modified the working Java example to talk to a dumb TCP
> server that just echoes everything back. This is what it sent:
>
> POST /powercloud/servlet/com.computefarm.application.PowerSubmitServlet HTTP/1.1
> User-Agent: Java1.3.1_07
> Host: localhost:8080
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> Connection: keep-alive
> Content-type: application/x-www-form-urlencoded
> Content-length: 91
>
> %directory=....%
>
> My current Perl script produces the following:
>
> POST /powercloud/servlet/com.computefarm.application.PowerCloudServlet HTTP/1.1
> TE: deflate,gzip;q=0.3
> Connection: TE, close
> Host: master:8080
> User-Agent: libwww-perl/5.69
> Content-Length: 91
>
> I think this is close enough. All I need to figure out is how to write the
> %directory...% string to the open connection. I'm reading the LWP::UserAgent
> documentation now, but if anyone has a working example, I would still appreciate
> it.
>
> Alfred
>
> -----Original Message-----
> From: G. Wade Johnson [mailto:wade.johnson@abbnm.com]
> Sent: Friday, May 16, 2003 5:04 PM
> To: Tomcat Users List
> Subject: Re: [OFF-TOPIC] Calling a servlet from Perl
>
> The easiest approach I can think of would be:
>
> my $req = new HTTP::Request POST =>
> "http://localhost:8080/path/to/servlet";
> $req->content( "\%directory=$pwd\%args=$arguments\%" );
> my $res = $ua->request( $req );
>
> This assumes, of course, that $pwd and $arguments are set up correctly.
> You probably forgot to escape the '%', which caused Perl to interpret
> the following string as the name of a hash.
>
> You could also build the string as
>
> '%directory=' . $pwd . '%args=' . $arguments . '%'
>
> (Note the single quotes.)
>
> G. Wade
>
> Alfred von Campe wrote:
> >
> > I can't even figure out how to pass the parameters to the
> > servlet as shown in the sample Java code. All libwww-perl
> > examples I found do something like this:
> >
> > use LWP::UserAgent;
> > my $ua = new LWP::UserAgent;
> > my $req = new HTTP::Request POST => "http://localhost:8080/path/to/servlet";
> > my $res = $ua->request($req);
> > if ($res->is_success)
> > {
> > print "It worked!\n"
> > }
> > else
> > {
> > print "Sorry, try again\n";
> > }
> >
> > How do I pass my "%directory=" + pwd + "%args=" + arguments + "%"
> > to the servlet? I'm not even sure that I should be using the
> > HTTP::Request object.
> >
> > Alfred
> >
> > -----Original Message-----
> > From: John Turner [mailto:tomcat-user@johnturner.com]
> > Sent: Friday, May 16, 2003 4:22 PM
> > To: Tomcat Users List
> > Subject: Re: Calling a servlet from Perl
> >
> > What is it, exactly, that isn't working?
> >
> > John
> >
> > On Fri, 16 May 2003 16:14:14 -0400, Alfred von Campe <al...@turboworx.com>
> > wrote:
> >
> > > I'm sure someone must have done this already, but I did not get very
> > > far with Google searches today. I think what I'm trying to do is pretty
> > > straightforward, and although I'm a long time UNIX/Perl user, I'm new to
> > > Tomcat and servlets.
> > >
> > > In a nutshell, I want to invoke a servlet from Perl. This servlet
> > > expects
> > > some parameters separated by a percent symbol (%) and then runs some
> > > program
> > > based on the parameters received. It may or may not send the results
> > > back to
> > > the caller. I have a working Java example that invokes this servlet.
> > > Here are
> > > the relevant code snippets:
> > >
> > > String url = new String("http://localhost:8080/path/to/servlet");
> > > serviceurl = new URL(url);
> > > URLConnection conn = serviceurl.openConnection();
> > > conn.setDoOutput(true);
> > > PrintWriter out = new PrintWriter(conn.getOutputStream());
> > > String appToRun = new String ("%directory=" + pwd + "%args=" + arguments
> > > + "%");
> > > out.write(appToRun);
> > > out.close();
> > > InputStream in = conn.getInputStream();
> > > InputStreamReader modin = new InputStreamReader(in);
> > > result = parseFromReader(modin);
> > > modin.close();
> > >
> > > I have downloaded and installed the latest libwww-perl library (5.69),
> > > but
> > > I can't figure out how to call this servlet. I'd appreciate any examples
> > > that will point me in the right direction. Even the raw protocol
> > > exchange
> > > would be helpful. If I can understand what's going on between Tomcat and
> > > the client, I can implement it in Perl (using straight sockets and
> > > avoiding
> > > the use of libwww-perl if necessary).
> > >
> > > Thanks,
> > > Alfred
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> >
> > --
> > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: [OFF-TOPIC] Calling a servlet from Perl
Posted by "G. Wade Johnson" <wa...@abbnm.com>.
I did not mean to offend about the escaping, but after over a decade
doing Perl I still mess that up with %.<shrug/>
The only other thing I can think of is URL escaping. Since '%' begins
a URL escape sequence, you may need to encode it as '%25'.
G. Wade
Alfred von Campe wrote:
>
> Thanks for the help, but unfortunately that didn't work either. I
> know about escaping the % in Perl (like I said, I've been using Perl
> for many years), so that wasn't the issue. I've made a little more
> progress. I modified the working Java example to talk to a dumb TCP
> server that just echoes everything back. This is what it sent:
>
> POST /powercloud/servlet/com.computefarm.application.PowerSubmitServlet HTTP/1.1
> User-Agent: Java1.3.1_07
> Host: localhost:8080
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> Connection: keep-alive
> Content-type: application/x-www-form-urlencoded
> Content-length: 91
>
> %directory=....%
>
> My current Perl script produces the following:
>
> POST /powercloud/servlet/com.computefarm.application.PowerCloudServlet HTTP/1.1
> TE: deflate,gzip;q=0.3
> Connection: TE, close
> Host: master:8080
> User-Agent: libwww-perl/5.69
> Content-Length: 91
>
> I think this is close enough. All I need to figure out is how to write the
> %directory...% string to the open connection. I'm reading the LWP::UserAgent
> documentation now, but if anyone has a working example, I would still appreciate
> it.
>
> Alfred
>
> -----Original Message-----
> From: G. Wade Johnson [mailto:wade.johnson@abbnm.com]
> Sent: Friday, May 16, 2003 5:04 PM
> To: Tomcat Users List
> Subject: Re: [OFF-TOPIC] Calling a servlet from Perl
>
> The easiest approach I can think of would be:
>
> my $req = new HTTP::Request POST =>
> "http://localhost:8080/path/to/servlet";
> $req->content( "\%directory=$pwd\%args=$arguments\%" );
> my $res = $ua->request( $req );
>
> This assumes, of course, that $pwd and $arguments are set up correctly.
> You probably forgot to escape the '%', which caused Perl to interpret
> the following string as the name of a hash.
>
> You could also build the string as
>
> '%directory=' . $pwd . '%args=' . $arguments . '%'
>
> (Note the single quotes.)
>
> G. Wade
>
> Alfred von Campe wrote:
> >
> > I can't even figure out how to pass the parameters to the
> > servlet as shown in the sample Java code. All libwww-perl
> > examples I found do something like this:
> >
> > use LWP::UserAgent;
> > my $ua = new LWP::UserAgent;
> > my $req = new HTTP::Request POST => "http://localhost:8080/path/to/servlet";
> > my $res = $ua->request($req);
> > if ($res->is_success)
> > {
> > print "It worked!\n"
> > }
> > else
> > {
> > print "Sorry, try again\n";
> > }
> >
> > How do I pass my "%directory=" + pwd + "%args=" + arguments + "%"
> > to the servlet? I'm not even sure that I should be using the
> > HTTP::Request object.
> >
> > Alfred
> >
> > -----Original Message-----
> > From: John Turner [mailto:tomcat-user@johnturner.com]
> > Sent: Friday, May 16, 2003 4:22 PM
> > To: Tomcat Users List
> > Subject: Re: Calling a servlet from Perl
> >
> > What is it, exactly, that isn't working?
> >
> > John
> >
> > On Fri, 16 May 2003 16:14:14 -0400, Alfred von Campe <al...@turboworx.com>
> > wrote:
> >
> > > I'm sure someone must have done this already, but I did not get very
> > > far with Google searches today. I think what I'm trying to do is pretty
> > > straightforward, and although I'm a long time UNIX/Perl user, I'm new to
> > > Tomcat and servlets.
> > >
> > > In a nutshell, I want to invoke a servlet from Perl. This servlet
> > > expects
> > > some parameters separated by a percent symbol (%) and then runs some
> > > program
> > > based on the parameters received. It may or may not send the results
> > > back to
> > > the caller. I have a working Java example that invokes this servlet.
> > > Here are
> > > the relevant code snippets:
> > >
> > > String url = new String("http://localhost:8080/path/to/servlet");
> > > serviceurl = new URL(url);
> > > URLConnection conn = serviceurl.openConnection();
> > > conn.setDoOutput(true);
> > > PrintWriter out = new PrintWriter(conn.getOutputStream());
> > > String appToRun = new String ("%directory=" + pwd + "%args=" + arguments
> > > + "%");
> > > out.write(appToRun);
> > > out.close();
> > > InputStream in = conn.getInputStream();
> > > InputStreamReader modin = new InputStreamReader(in);
> > > result = parseFromReader(modin);
> > > modin.close();
> > >
> > > I have downloaded and installed the latest libwww-perl library (5.69),
> > > but
> > > I can't figure out how to call this servlet. I'd appreciate any examples
> > > that will point me in the right direction. Even the raw protocol
> > > exchange
> > > would be helpful. If I can understand what's going on between Tomcat and
> > > the client, I can implement it in Perl (using straight sockets and
> > > avoiding
> > > the use of libwww-perl if necessary).
> > >
> > > Thanks,
> > > Alfred
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> >
> > --
> > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: [OFF-TOPIC] Calling a servlet from Perl
Posted by Alfred von Campe <al...@turboworx.com>.
Thanks for the help, but unfortunately that didn't work either. I
know about escaping the % in Perl (like I said, I've been using Perl
for many years), so that wasn't the issue. I've made a little more
progress. I modified the working Java example to talk to a dumb TCP
server that just echoes everything back. This is what it sent:
POST /powercloud/servlet/com.computefarm.application.PowerSubmitServlet HTTP/1.1
User-Agent: Java1.3.1_07
Host: localhost:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-type: application/x-www-form-urlencoded
Content-length: 91
%directory=....%
My current Perl script produces the following:
POST /powercloud/servlet/com.computefarm.application.PowerCloudServlet HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Host: master:8080
User-Agent: libwww-perl/5.69
Content-Length: 91
I think this is close enough. All I need to figure out is how to write the
%directory...% string to the open connection. I'm reading the LWP::UserAgent
documentation now, but if anyone has a working example, I would still appreciate
it.
Alfred
-----Original Message-----
From: G. Wade Johnson [mailto:wade.johnson@abbnm.com]
Sent: Friday, May 16, 2003 5:04 PM
To: Tomcat Users List
Subject: Re: [OFF-TOPIC] Calling a servlet from Perl
The easiest approach I can think of would be:
my $req = new HTTP::Request POST =>
"http://localhost:8080/path/to/servlet";
$req->content( "\%directory=$pwd\%args=$arguments\%" );
my $res = $ua->request( $req );
This assumes, of course, that $pwd and $arguments are set up correctly.
You probably forgot to escape the '%', which caused Perl to interpret
the following string as the name of a hash.
You could also build the string as
'%directory=' . $pwd . '%args=' . $arguments . '%'
(Note the single quotes.)
G. Wade
Alfred von Campe wrote:
>
> I can't even figure out how to pass the parameters to the
> servlet as shown in the sample Java code. All libwww-perl
> examples I found do something like this:
>
> use LWP::UserAgent;
> my $ua = new LWP::UserAgent;
> my $req = new HTTP::Request POST => "http://localhost:8080/path/to/servlet";
> my $res = $ua->request($req);
> if ($res->is_success)
> {
> print "It worked!\n"
> }
> else
> {
> print "Sorry, try again\n";
> }
>
> How do I pass my "%directory=" + pwd + "%args=" + arguments + "%"
> to the servlet? I'm not even sure that I should be using the
> HTTP::Request object.
>
> Alfred
>
> -----Original Message-----
> From: John Turner [mailto:tomcat-user@johnturner.com]
> Sent: Friday, May 16, 2003 4:22 PM
> To: Tomcat Users List
> Subject: Re: Calling a servlet from Perl
>
> What is it, exactly, that isn't working?
>
> John
>
> On Fri, 16 May 2003 16:14:14 -0400, Alfred von Campe <al...@turboworx.com>
> wrote:
>
> > I'm sure someone must have done this already, but I did not get very
> > far with Google searches today. I think what I'm trying to do is pretty
> > straightforward, and although I'm a long time UNIX/Perl user, I'm new to
> > Tomcat and servlets.
> >
> > In a nutshell, I want to invoke a servlet from Perl. This servlet
> > expects
> > some parameters separated by a percent symbol (%) and then runs some
> > program
> > based on the parameters received. It may or may not send the results
> > back to
> > the caller. I have a working Java example that invokes this servlet.
> > Here are
> > the relevant code snippets:
> >
> > String url = new String("http://localhost:8080/path/to/servlet");
> > serviceurl = new URL(url);
> > URLConnection conn = serviceurl.openConnection();
> > conn.setDoOutput(true);
> > PrintWriter out = new PrintWriter(conn.getOutputStream());
> > String appToRun = new String ("%directory=" + pwd + "%args=" + arguments
> > + "%");
> > out.write(appToRun);
> > out.close();
> > InputStream in = conn.getInputStream();
> > InputStreamReader modin = new InputStreamReader(in);
> > result = parseFromReader(modin);
> > modin.close();
> >
> > I have downloaded and installed the latest libwww-perl library (5.69),
> > but
> > I can't figure out how to call this servlet. I'd appreciate any examples
> > that will point me in the right direction. Even the raw protocol
> > exchange
> > would be helpful. If I can understand what's going on between Tomcat and
> > the client, I can implement it in Perl (using straight sockets and
> > avoiding
> > the use of libwww-perl if necessary).
> >
> > Thanks,
> > Alfred
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
> --
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org