Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Applying mod_perl filters to content served from JBOSS

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


rsharma51 at sapient

Jun 26, 2012, 12:46 AM

Post #1 of 5 (428 views)
Permalink
Applying mod_perl filters to content served from JBOSS

Hi All,



I have set up mod_perl filtering as follows:



<Location ~ "/(staticweb|jbossweb)">

SetHandler modperl

PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse

allow from all

</Location>



staticweb is under htdocs and jbossweb is an app-context deployed in jboss .



All I am doing is read the response and replace certain strings and send that to the client making the request.



It is not working for pages being served from jboss (routed to it via the apache web server, using mod_jk) whereas it is working just fine for pages served from Apache's htdocs (being filtered as expected) and access is fine for jboss pages that are not under the filter Location.



Any help is greatly appreciated.



Thank you,

Rommel.


torsten.foertsch at gmx

Jun 26, 2012, 2:02 AM

Post #2 of 5 (402 views)
Permalink
Re: Applying mod_perl filters to content served from JBOSS [In reply to]

On 06/26/2012 09:46 AM, Rommel Sharma wrote:

> <Location ~ "/(staticweb|jbossweb)">
>
> SetHandler modperl

You don't need that. SetHandler declares the response handler. But your
response is generated either by the default handler for static content
or by mod_jk. "SetHandler modperl" should be used only if there is also
a PerlResponseHandler or simpler PerlHandler set for the location.

SetHandler tells the Apache who or which module is responsible for
generating the response. Nothing else.

> PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse
>
> allow from all
>
> </Location>
>

Torsten


aw at ice-sa

Jun 26, 2012, 2:21 AM

Post #3 of 5 (401 views)
Permalink
Re: Applying mod_perl filters to content served from JBOSS [In reply to]

Rommel Sharma wrote:
> Hi All,
>
>
>
> I have set up mod_perl filtering as follows:
>
> <Location ~ "/(staticweb|jbossweb)">
> SetHandler modperl
> PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse
> allow from all
> </Location>
>
> staticweb is under htdocs and jbossweb is an app-context deployed in jboss .
>
> All I am doing is read the response and replace certain strings and send that to the client making the request.
>
> It is not working for pages being served from jboss (routed to it via the apache web server, using mod_jk) whereas it is working just fine for pages served from Apache's htdocs (being filtered as expected) and access is fine for jboss pages that are not under the filter Location.
>

Hi.
I think that your problem here is that by specifying
SetHandler modperl
you are contradicting one of your
JkMount ...
directives, and thus these URLs are no longer being forwarded to Tomcat.

In detail :

Part 1 :

Have a look at this page :

http://tomcat.apache.org/connectors-doc/reference/apache.html

and in particular, the section entitled : Using SetHandler and Environment Variables

What it tells you, is that instead of using directives like this :

JkMount /jbossweb myworker
JkMount /jbossweb/* myworker

you can use

<Location /jbossweb>
SetHandler jakarta_servlet
...
</Location>

to the same effect. They are equivalent.


Personally, I prefer the <Location> syntax, rather than the JkMount/JkUnMount, because :
- if "fits" better with the usual Apache configuration style
- it is clearer in terms of the "precedence" aspect of JkMount over other Apache directives
- it is easier to combine with other Apache-based things, just like you are trying to do
here, to combine it with a mod_perl filter

But as a side-effect, you can see how specifying

SetHandler jakarta_servlet

or

SetHandler modperl

are mutually exclusive.

By saying "SetHandler xxx", you are telling Apache that, to generate the *response* to
this HTTP request, it should call the module "xxx".
So, it can be *either* jakarta_servlet (forward this request to Tomcat through mod_jk and
have Tomcat generate the response) *or* modperl (let the embedded perl interpreter
generate the response, by running whatever perl module is configured as the
PerlResponseHandler)

Part 2 :

In your case, you probably do not need to specify
SetHandler modperl
in order to run you filter.
As far as I know, you need "SetHandler modperl" only, if the response itself is generated
by a perl module. Which is not the case here, as you want Tomcat/jboss to generate it.

So what I would do in your case is :

a) remove any "JkMount /jbossweb ..." that you may have
b) add a section as follows :

<Location ~ "^/jbossweb">

SetHandler jakarta_servlet

PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse

allow from all

</Location>

If you have any "JkUnmount" related to that same area, then replace them by lines like
SetEnvIf REQUEST_URI ^/jbossweb/([^/]*)/static no-jk
as indicated in that same Tomcat Connector documentation page

What you are doing above is telling Apache :
- for any request URL that looks like "^/jbossweb" ..
- pass this request to Tomcat, via mod_jk, to generate the response page
- and when the Tomcat response page comes back (from mod_jk), and before sending it back
to the browser, pass it through my filter module

mod_perl advocacy section :

You are touching here one of the really interesting aspects of using mod_perl with Apache
: you can precisely (like with a surgical scalpel) insert your own module in exactly the
appropriate point of the Apache request handling cycle, and combine it with other things
which are not mod_perl based.
Similarly, you could have inserted other mod_perl things in the request cycle, like

<Location ~ "^/jbossweb">
Order allow,deny
Allow from 1.2.3.4
PerlAuthenHandler MyHandlers::MyAAAHandler->authenticate
PerlAuthzHandler MyHandlers::MyAAAHandler->authorize
require valid-user

SetHandler jakarta_servlet

PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse

allow from all

</Location>

and done the access control by Apache, then the user authentication and authorization
using your own modules, then let the response be generated by tomcat/jboss, and filter the
response when it comes back.


rsharma51 at sapient

Jun 26, 2012, 6:47 AM

Post #4 of 5 (397 views)
Permalink
RE: Applying mod_perl filters to content served from JBOSS [In reply to]

Hi Torsten,

removing
> SetHandler mod_perl

worked! Both jboss and apache htdocs data are being filtered as expected. Thanks again, for all the time and inputs!!!

Thanks,
Rommel.

-----Original Message-----
From: Torsten Förtsch [mailto:torsten.foertsch [at] gmx]
Sent: Tuesday, June 26, 2012 2:32 PM
To: Rommel Sharma
Cc: modperl [at] perl
Subject: Re: Applying mod_perl filters to content served from JBOSS

On 06/26/2012 09:46 AM, Rommel Sharma wrote:

> <Location ~ "/(staticweb|jbossweb)">
>
> SetHandler modperl

You don't need that. SetHandler declares the response handler. But your
response is generated either by the default handler for static content
or by mod_jk. "SetHandler modperl" should be used only if there is also
a PerlResponseHandler or simpler PerlHandler set for the location.

SetHandler tells the Apache who or which module is responsible for
generating the response. Nothing else.

> PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse
>
> allow from all
>
> </Location>
>

Torsten


rsharma51 at sapient

Jun 26, 2012, 6:50 AM

Post #5 of 5 (398 views)
Permalink
RE: Applying mod_perl filters to content served from JBOSS [In reply to]

Hi André,

Many thanks for the useful information below that helps me in understanding the working of the filters and the modules.

Realized the mod jk conflict with mod_perl and removed the SetHandler mod_perl and it worked.

Huge thanks to all the experts on this group for sharing the knowledge!!!

Rommel.



-----Original Message-----
From: André Warnier [mailto:aw [at] ice-sa]
Sent: Tuesday, June 26, 2012 2:51 PM
To: mod_perl list
Subject: Re: Applying mod_perl filters to content served from JBOSS

Rommel Sharma wrote:
> Hi All,
>
>
>
> I have set up mod_perl filtering as follows:
>
> <Location ~ "/(staticweb|jbossweb)">
> SetHandler modperl
> PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse
> allow from all
> </Location>
>
> staticweb is under htdocs and jbossweb is an app-context deployed in jboss .
>
> All I am doing is read the response and replace certain strings and send that to the client making the request.
>
> It is not working for pages being served from jboss (routed to it via the apache web server, using mod_jk) whereas it is working just fine for pages served from Apache's htdocs (being filtered as expected) and access is fine for jboss pages that are not under the filter Location.
>

Hi.
I think that your problem here is that by specifying
SetHandler modperl
you are contradicting one of your
JkMount ...
directives, and thus these URLs are no longer being forwarded to Tomcat.

In detail :

Part 1 :

Have a look at this page :

http://tomcat.apache.org/connectors-doc/reference/apache.html

and in particular, the section entitled : Using SetHandler and Environment Variables

What it tells you, is that instead of using directives like this :

JkMount /jbossweb myworker
JkMount /jbossweb/* myworker

you can use

<Location /jbossweb>
SetHandler jakarta_servlet
...
</Location>

to the same effect. They are equivalent.


Personally, I prefer the <Location> syntax, rather than the JkMount/JkUnMount, because :
- if "fits" better with the usual Apache configuration style
- it is clearer in terms of the "precedence" aspect of JkMount over other Apache directives
- it is easier to combine with other Apache-based things, just like you are trying to do
here, to combine it with a mod_perl filter

But as a side-effect, you can see how specifying

SetHandler jakarta_servlet

or

SetHandler modperl

are mutually exclusive.

By saying "SetHandler xxx", you are telling Apache that, to generate the *response* to
this HTTP request, it should call the module "xxx".
So, it can be *either* jakarta_servlet (forward this request to Tomcat through mod_jk and
have Tomcat generate the response) *or* modperl (let the embedded perl interpreter
generate the response, by running whatever perl module is configured as the
PerlResponseHandler)

Part 2 :

In your case, you probably do not need to specify
SetHandler modperl
in order to run you filter.
As far as I know, you need "SetHandler modperl" only, if the response itself is generated
by a perl module. Which is not the case here, as you want Tomcat/jboss to generate it.

So what I would do in your case is :

a) remove any "JkMount /jbossweb ..." that you may have
b) add a section as follows :

<Location ~ "^/jbossweb">

SetHandler jakarta_servlet

PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse

allow from all

</Location>

If you have any "JkUnmount" related to that same area, then replace them by lines like
SetEnvIf REQUEST_URI ^/jbossweb/([^/]*)/static no-jk
as indicated in that same Tomcat Connector documentation page

What you are doing above is telling Apache :
- for any request URL that looks like "^/jbossweb" ..
- pass this request to Tomcat, via mod_jk, to generate the response page
- and when the Tomcat response page comes back (from mod_jk), and before sending it back
to the browser, pass it through my filter module

mod_perl advocacy section :

You are touching here one of the really interesting aspects of using mod_perl with Apache
: you can precisely (like with a surgical scalpel) insert your own module in exactly the
appropriate point of the Apache request handling cycle, and combine it with other things
which are not mod_perl based.
Similarly, you could have inserted other mod_perl things in the request cycle, like

<Location ~ "^/jbossweb">
Order allow,deny
Allow from 1.2.3.4
PerlAuthenHandler MyHandlers::MyAAAHandler->authenticate
PerlAuthzHandler MyHandlers::MyAAAHandler->authorize
require valid-user

SetHandler jakarta_servlet

PerlOutputFilterHandler MyOutputHandlers::CustomFilterResponse

allow from all

</Location>

and done the access control by Apache, then the user authentication and authorization
using your own modules, then let the response be generated by tomcat/jboss, and filter the
response when it comes back.

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.