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

Mailing List Archive: ModPerl: ModPerl

set environment variables in tomcat

 

 

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


kgoldov at gmail

May 26, 2011, 5:24 PM

Post #1 of 7 (1362 views)
Permalink
set environment variables in tomcat

I'm connecting to a tomcat server from our web server using mod_jk. I'm
setting environment variables with each request in the PerlAuthenHandler and
PerlHeaderParserHandler. I'm able to read the variables in PHP, perl fcgi,
and wsgi, however they are not being passed to tomcat. Is there a way to
pass these environment variables through?

--
Kim


fred at redhotpenguin

May 26, 2011, 7:11 PM

Post #2 of 7 (1318 views)
Permalink
Re: set environment variables in tomcat [In reply to]

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_
might be what you are looking for.

On Thu, May 26, 2011 at 5:24 PM, Kim Goldov <kgoldov [at] gmail> wrote:
> I'm connecting to a tomcat server from our web server using mod_jk. I'm
> setting environment variables with each request in the PerlAuthenHandler and
> PerlHeaderParserHandler. I'm able to read the variables in PHP, perl fcgi,
> and wsgi, however they are not being passed to tomcat. Is there a way to
> pass these environment variables through?
>
> --
> Kim
>
>


aw at ice-sa

May 26, 2011, 11:48 PM

Post #3 of 7 (1320 views)
Permalink
Re: set environment variables in tomcat [In reply to]

Kim Goldov wrote:
> I'm connecting to a tomcat server from our web server using mod_jk. I'm
> setting environment variables with each request in the PerlAuthenHandler and
> PerlHeaderParserHandler. I'm able to read the variables in PHP, perl fcgi,
> and wsgi, however they are not being passed to tomcat. Is there a way to
> pass these environment variables through?
>
How exactly are you setting these "environment variables" before the request is proxied to
Tomcat ? And how are you trying to read these values at the Tomcat level ?

mod_jk uses the AJP protocol to communicate with Tomcat. This is not exactly the same as
HTTP and it does not really pass "environment values" in the shell sense.
Also, what is named "environment variables" at the Apache level is somewhat ambiguous.
Most of what is called "Apache environment variables" is passed my mod_jk to Tomcat as
"request attributes", and you have to use the appropriate method in Java on the Tomcat
side to retrieve them.

In a general sense, I have found that the easiest way to pass values from Apache to Tomcat
through mod_jk, is to add a (non-standard) HTTP header to the request before it it is
forwarded, and retrieve this HTTP header in the Tomcat application.
This will work no matter how the proxying from Apache to Tomcat is done (e.g. also with
HTTP proxying).


James.B.Muir at hitchcock

May 27, 2011, 5:59 AM

Post #4 of 7 (1316 views)
Permalink
RE: set environment variables in tomcat [In reply to]

In order to pass an environment variable via mod_jk to tomcat you need to set the "JkEnvVar" in your jk.conf file. For example,

JkEnvVar REMOTE_USER %{REMOTE_USER}

-James

From: Kim Goldov [mailto:kgoldov [at] gmail]
Sent: Thursday, May 26, 2011 8:24 PM
To: modperl [at] perl
Subject: set environment variables in tomcat

I'm connecting to a tomcat server from our web server using mod_jk. I'm setting environment variables with each request in the PerlAuthenHandler and PerlHeaderParserHandler. I'm able to read the variables in PHP, perl fcgi, and wsgi, however they are not being passed to tomcat. Is there a way to pass these environment variables through?

--
Kim

IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE:

This message is intended for the use of the person to whom it is addressed and may contain information that is privileged, confidential, and protected from disclosure under applicable law. If you are not the intended recipient, your use of this message for any purpose is strictly prohibited. If you have received this communication in error, please delete the message and notify the sender so that we may correct our records.


aw at ice-sa

May 27, 2011, 7:36 AM

Post #5 of 7 (1315 views)
Permalink
Re: set environment variables in tomcat [In reply to]

James B. Muir wrote:
> In order to pass an environment variable via mod_jk to tomcat you need to set the "JkEnvVar" in your jk.conf file. For example,
>
> JkEnvVar REMOTE_USER %{REMOTE_USER}
>
The problem here being that the environment variable should be set in a Perl handler, if I
understood the original post.


kgoldov at gmail

Jun 1, 2011, 3:31 PM

Post #6 of 7 (1262 views)
Permalink
Re: set environment variables in tomcat [In reply to]

Thanks everyone. Here is what I ended up with.

In my PerlHeaderParserHandler:

$r->subprocess_env(AA_MYVAR => 'myvalue');
$r->subprocess_env();

In jk.conf:

JkEnvVar AA_MYVAR

In Tomcat:

out.println("AA_MYVAR is: " + request.getAttribute("AA_MYVAR") );

--
Kim


aw at ice-sa

Jun 2, 2011, 3:47 AM

Post #7 of 7 (1265 views)
Permalink
Re: set environment variables in tomcat [In reply to]

Kim Goldov wrote:
> Thanks everyone. Here is what I ended up with.
>
> In my PerlHeaderParserHandler:
>
> $r->subprocess_env(AA_MYVAR => 'myvalue');
> $r->subprocess_env();
>
> In jk.conf:
>
> JkEnvVar AA_MYVAR
>
> In Tomcat:
>
> out.println("AA_MYVAR is: " + request.getAttribute("AA_MYVAR") );
>

Right.
But don't forget that this is very Apache/mod_jk/Tomcat specific.
A more generic way of doing this would be to set an additional header in the request at
the Apache level, and get this header at the Tomcat level with request.getHeader().
That would work with any proxying scheme between Apache and a back-end servlet engine
(mod_jk, but also mod_proxy_http and mod_proxy_ajp).

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.