Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet calling perl script

 
adam braunton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to invoke a simple Perl script using a servlet, but to be honest I don't have a clue where to start. Any thoughts would be much appreciated!
 
Mayer Salzer
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by trying to redirect the servlet-request to your cgi script.
In your "service" method:
response.sendRedirect("/cgi-bin/yourScriptName");
 
adam braunton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i tried the sendRedirect, but the poblem is that this has the same effect as calling the Perl script directly on the server. However, the WebSphere server does not recognise the MIME type of the script, and prompts the user to download the script, rather than running it!

I need a way of calling the script directly from Java, i.e. Acting like a Broker servlet - because I don't fancy rewriting it!
[ June 07, 2002: Message edited by: adam braunton ]
 
Mayer Salzer
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why that's happening. I tried an example like that myself and it works fine.
When you redirect, a message is sent to the client (your browser) telling it to send the request elsewhere. Provided that you redirect to the appropriate path of your cgi-bin (or whatever else runs your script), your websphere server should be out of the loop at that point. . .
For example suppose you have a servlet "TestServlet" invoked with "http://yourhost/webapp/TestServlet". You also have a cgi script named "script.cgi" invoked with "http://yourhost/cgi-bin/script.cgi". In the servlet, if you call response.sendRedirect("http://yourhost/cgi-bin/script.cgi") it will redirect the request to the new url which happens to be your cgi script. The fact that the request was rerouted from a websphere server (or any other) should not matter.
 
adam braunton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, that if i type the URL (http://www....) to the Perl script directly into the browser, i will be promted to download rather than the script executing. But if i type the URL as a location to the server (http://localmachine3/.....) the script executes. So i take it that a sendRedirect basically does the same thing as the former method. I need a way to force the script to execute, if possible. without moving the script from the cgi-bin folder....?
 
Tracey Currier
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I got this to work by setting
res.setContentType("text/plain")
then using the redirect to my url.
My url was to a perl script that was
loaded with parameters, worked ok
behind the firewall
The perl script output an html page
and I sent the html header out in the
perl script
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic