You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Kim Goldov <kg...@gmail.com> on 2011/05/27 02:24:02 UTC

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

Re: set environment variables in tomcat

Posted by André Warnier <aw...@ice-sa.com>.
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).



Re: set environment variables in tomcat

Posted by André Warnier <aw...@ice-sa.com>.
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).


Re: set environment variables in tomcat

Posted by Kim Goldov <kg...@gmail.com>.
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

Re: set environment variables in tomcat

Posted by André Warnier <aw...@ice-sa.com>.
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.


RE: set environment variables in tomcat

Posted by "James B. Muir" <Ja...@hitchcock.org>.
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@gmail.com]
Sent: Thursday, May 26, 2011 8:24 PM
To: modperl@perl.apache.org
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.

Re: set environment variables in tomcat

Posted by Fred Moyer <fr...@redhotpenguin.com>.
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 <kg...@gmail.com> 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
>
>