This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

no tomcat CGI redirect() ??  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my tomcat webapp, I was hoping to do this:

1) SC_INTERNAL_SERVER_ERROR ->
2) deployment-descriptor-defined error-page ->
3) CGI-HANDLER (send me email) ->
4) back to webapp

The CGI-HANDLER would notify me about the problem, then return to the webapp. Seemed like an OK idea, because email is so much easier to do in perl than in java.

The perl script runs, and i get the email. But under tomcat (Tomcat 4.1.31), I cannot redirect from the perl script to any other page, either within the webapp, or anywhere on the site. Generated HTML & tomcat log entry appear below.

On the same webserver, under mod_perl (Apache mod_perl 1.99_12 ), but no tomcat, a busier version of the same perl script works just fine, redirection included.

Anybody know what tomcat's doing with my redirect()?

Thanks!

********************************
CGI-HANDLER ('trouble.cgi'):

#!/usr/bin/perl
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

my $now =`date`;

# notify
open (SENDMAIL, "| /usr/lib/sendmail -oi -t")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From:<me\@me.net>
To:<me\@me.net>
Subject: hohos trouble
------------------
$now
------------------
EOF
close (SENDMAIL) or warn "Unhappy sendmail close\n";

print redirect
('/csci315/servlet/robust.MyRobustServlet?pushed=restart');

#$url = "http://www.me.net/hohos/index.html";
#print "Location: $url\n\n";
#exit;

********************************
CGI-HANDLER invocation from deployment-descriptor-defined error-page:

<form action="/csci315/cgi-bin/trouble.cgi" method="post"
enctype="application/x-www-form-urlencoded">

********************************
CGI generated HTML:

<HTML><HEAD><TITLE>$Name: $</TITLE></HEAD>
<BODY>$Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java,v
1.27 2004/08/26 21:38:13 markt Exp $<p>

********************************
tomcat log entry (CGIServlet 'debug' param-value == 99):

2005-05-05 12:38:27 cgi: findCGI: path=/trouble.cgi, /opt/tomcat4/webapps/csci315/WEB-INF/cgi
2005-05-05 12:38:27 cgi: findCGI: currentLoc=/opt/tomcat4/webapps/csci315/WEB-INF/cgi
2005-05-05 12:38:27 cgi: findCGI: currentLoc=/opt/tomcat4/webapps/csci315/WEB-INF/cgi
2005-05-05 12:38:27 cgi: findCGI: FOUND cgi at /opt/tomcat4/webapps/csci315/WEB-INF/cgi/trouble.cgi
2005-05-05 12:38:27 cgi: findCGI calc: name=trouble.cgi, path=/opt/tomcat4/webapps/csci315/WEB-INF/cgi/trouble.cgi, scriptname=/csci315/cgi-bin/trouble.cgi, cginame=/trouble.cgi
2005-05-05 12:38:27 cgi: runCGI(envp=[{HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1), HTTP_ACCEPT_ENCODING=gzip, deflate, REQUEST_METHOD=POST, AUTH_TYPE=, HTTP_ACCEPT_LANGUAGE=en-us, SERVER_NAME=me.net, SERVER_SOFTWARE=TOMCAT, HTTP_CONTENT_TYPE=application/x-www-form-urlencoded, HTTP_REFERER=http://me.net:8080/csci315/servlet/robust.MyRobustServlet?loginname=&logintype=old&src=LOGIN&pu_m=May&pu_d=5&pu_y=2005&do_m=May&do_d=5&do_y=2005&selcar=Select&pushed=browse&src=MKRES, HTTP_HOST=me.net:8080, GATEWAY_INTERFACE=CGI/1.1, X_TOMCAT_SCRIPT_PATH=/opt/tomcat4/webapps/csci315/WEB-INF/cgi/trouble.cgi, REMOTE_ADDR=207.135.102.195, SERVER_PROTOCOL=HTTP/1.1, HTTP_CACHE_CONTROL=no-cache, PATH_INFO=, REMOTE_HOST=207.135.102.195, QUERY_STRING=, HTTP_CONNECTION=Keep-Alive, SERVER_PORT=8080, HTTP_COOKIE=JSESSIONID=54E1AEE3C232E600079B54D1B9E3C4FD, CONTENT_TYPE=application/x-www-form-urlencoded, CONTENT_LENGTH=14, HTTP_CONTENT_LENGTH=14, SCRIPT_NAME=/csci315/cgi-bin/trouble.cgi, HTTP_ACCEPT=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, application/x-shockwave-flash, */*, REMOTE_USER=, REMOTE_IDENT=}], command=/opt/tomcat4/webapps/csci315/WEB-INF/cgi/trouble.cgi)
2005-05-05 12:38:27 cgi: runCGI: addHeader("Location: /csci315/servlet/robust.MyRobustServlet?pushed=restart")
2005-05-05 12:38:27 cgi: runCGI: 1 lines received on stderr
2005-05-05 12:38:28 StandardWrapperValve[cgi]: Servlet.service() for servlet cgi threw exception
java.lang.ClassCastException: java.lang.Integer
at org.apache.catalina.servlets.CGIServlet$CGIEnvironment.toString(CGIServlet.java:1258)
at org.apache.catalina.servlets.CGIServlet.doGet(CGIServlet.java:613)
at org.apache.catalina.servlets.CGIServlet.doPost(CGIServlet.java:561)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't you use a servlet filter for this? Catch the response on the way out. If it's sending back an internal server error response code, you can inform yourself via JavaMail.
 
Paul Fenerty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it be time to punt, then JavaMail gets the focus. Still curious about what's going on however, and if CGI redirect() is completely not-workable from within the tomcat context. Thanks!
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!