Rob, thanks for pointing me in the right direction. Your advise
helped me find a solution that works for my situation.
I'm working on an API that sits between an Oracle DB and bunch of web
application programmers. Unfortunately, the programmers run their
apps under a variety of perl-handlers (Apache::Registry, Apache::RegistryNG,
Apache::RegistryFilter, etc). None of the programmers follow any
sort of standard method for handling exceptions, so I can't assume
that 'return OK;' will ever be called (in fact I'm pretty sure, it
will never be called). What I've been trying to do is kind of 'take
over' the request, whenever a programmer fails to connect to the DB and
redirect the browser to a handler that can put up a custom 503 page
for each application.
I finally settled on putting the following in conf file for the web
sites:
ErrorDocument 503 "<HTML><HEAD><META http-equiv="refresh"
content="0;URL=/DBConnectError.cgi"></HEAD></HTML>
<Files DBConnectError.cgi>
SetHandler perl-script
PerlHandler Tec::Api::DBConnectError
</Files>
It seems to work for just about every perl handler the programmers are
using, as long as they doesn't use Carp::fatalsToBrowser, which raises a whole
new set of problems.
If you see any issues with my solution, please chime in.
Thanks again for you help.
-Jim
Rob Bloodgood muttered:
> > I'm trying to handle an exception using an internal_redirect. I
> > can get it to work by redirecting to a static page, but when I try to
> > redirect to a modperl handler, I'm run into problems.
> >
> > Here are the two versions of code (BTW, the handler works fine when I
> > access it directly via the browser).
> >
> > ## ver. 1
> > print STDERR "$@";
> > require Apache;
> > my $r = Apache->request;
> > $r->internal_redirect("/DBConnectError.cgi");
> >
> > ## ver. 2
> > print STDERR "$@";
> > require Apache;
> > my $r = Apache->request;
> > $r->internal_redirect("/errordocs/503.html");
> >
> > When I run the modperl handler, the browser prompts me and asks if I
> > want to save the output of the cgi script that raised the error, but
> > it never displays the content from the handler. The static file
> > version works great and the browser displays it's content.
>
> Hmm... First of all, the Guide (and experience :-) sez that IMMEDIATELY
> after running
>
> $r->internal_redirect(blah);
>
> one should
>
> return OK;
>
> Secondly, I would suggest doing it differently:
> tell the request object that the handler returned code 503, and in
> httpd.conf:
>
> ErrorDocument 503 /DBConnectError.cgi
>
> I just wrote this handler in 2 minutes, that demonstrates:
>
> =========
> package Stat::Testfail;
>
> use strict;
>
> sub handler {
> my $r = shift;
>
> $r->status(503);
> return 503;
> }
>
> 1;
> =========
>
> with the following httpd.conf entry:
> <Location /testonly>
> SetHandler perl-script
> PerlHandler +Stat::Testfail
> </Location>
>
> and it works like I've described:
>
> # telnet localhost 80
> GET /testonly HTTP/1.0
>
> HTTP/1.1 503 Service Temporarily Unavailable
> Date: Tue, 03 Apr 2001 18:01:28 GMT
> Server: Apache/1.3.9 (Unix) (Red Hat/Linux) mod_perl/1.25
> Connection: close
> Content-Type: text/html
>
> <HTML>
> <HEAD><TITLE>An Error Occurred</TITLE></HEAD>
> <BODY>
> <H1>An Error Occurred</h1>
> 503 Service Temporarily Unavailable
> </BODY>
> </HTML>
>
> (Naturally this would have been different if i'd set an ErrorDocument 503).
>
> HTH!
>
> L8r,
> Rob
>
--
<[EMAIL PROTECTED]> (Replace Z's with E's to reply)
Okay, I got Linux installed. So where's the free beer.
-Anonymous
PGP signature