Help with PerlTransHandler

[prev] [thread] [next] [Date index for 2005/05/22]

From: Johnny Shz
Subject: Help with PerlTransHandler
Date: 22:28 on 22 May 2005
This is a multi-part message in MIME format.

------=_NextPart_000_004D_01C55EE2.E6346360
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi, I'm trying to write my own translation handler. The problem is that =
I'd like to map something like:

    /foo.html to /bar/servlet/test

where /bar/ is supposed to be handled by mod_jk with something like:
    <Location "/bar">
        JkUriSet worker ajp13:localhost:8009
    </Location>

When I tried to use mod_rewrite, the mapping took effect, but then =
apache tried to find the file: "/bar/servlet/test"=20
rather than applying the <Location/> to send to mod_jk.

I thought a mod_perl's PerlTransHandler will solve this problem, with a =
simple:

package Urlmap;
use strict;
use Apache2::Const -compile =3D> qw(DECLINED);
use Apache2::RequestRec;

sub handler{
    my $r =3D shift;
    my $uri =3D $r->uri;
    my $target =3D "";
    if($uri =3D~ m|^/foo.html|i){
        $r->uri("/bar/servlet/test");
    }
    return Apache2::Const::DECLINED;
}

But it is giving me the same error, it returns a 404 file not found for =
"/bar/servlet/test".

So how can I change the URL, and still apply the <Location/> directive =
afterwards?

Thanks.

Z.




------=_NextPart_000_004D_01C55EE2.E6346360
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hi, I'm trying to write my own =
translation handler.=20
The problem is that I'd like to map something like:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; /foo.html to=20
/bar/servlet/test</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>where /bar/ is supposed to be handled =
by mod_jk=20
with something like:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;Location=20
"/bar"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JkUriSet worker =

ajp13:localhost:8009<BR>&nbsp;&nbsp;&nbsp; =
&lt;/Location&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>When I tried to use mod_rewrite, the =
mapping took=20
effect, but then apache tried to find the file: "/bar/servlet/test"=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>rather than applying the =
&lt;Location/&gt; to send=20
to mod_jk.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I thought a mod_perl's PerlTransHandler =
will solve=20
this problem, with a simple:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>package Urlmap;<BR>use strict;<BR>use=20
Apache2::Const -compile =3D&gt; qw(DECLINED);<BR>use=20
Apache2::RequestRec;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>sub handler{<BR>&nbsp;&nbsp;&nbsp; my =
$r =3D=20
shift;<BR>&nbsp;&nbsp;&nbsp; my $uri =3D =
$r-&gt;uri;<BR>&nbsp;&nbsp;&nbsp; my=20
$target =3D "";<BR>&nbsp;&nbsp;&nbsp; if($uri =3D~=20
m|^/foo.html|i){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$r-&gt;uri("/bar/servlet/test");<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return=20
Apache2::Const::DECLINED;<BR>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But it is giving me the same error, it =
returns a=20
404 file not found for "/bar/servlet/test".</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So how can I change the URL, and still =
apply the=20
&lt;Location/&gt; directive afterwards?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Z.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV>
<DIV><BR></DIV></FONT></FONT></DIV></BODY></HTML>

------=_NextPart_000_004D_01C55EE2.E6346360--

Help with PerlTransHandler
Johnny Shz 22:28 on 22 May 2005

Re: Help with PerlTransHandler
Torsten Foertsch 06:17 on 23 May 2005

Generated at 15:53 on 25 May 2005 by mariachi v0.52