set environment variables in tomcat

set environment variables in tomcat

am 27.05.2011 02:24:02 von Kim Goldov

--bcaec55401b06e7f5e04a436f465
Content-Type: text/plain; charset=ISO-8859-1

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

--bcaec55401b06e7f5e04a436f465
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I'm connecting to a tomcat server from our web server using mod_jk. I&#=
39;m setting environment variables with each request in the PerlAuthenHandl=
er 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



--bcaec55401b06e7f5e04a436f465--

Re: set environment variables in tomcat

am 27.05.2011 04:11:06 von Fred Moyer

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

On Thu, May 26, 2011 at 5:24 PM, 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?
>
> --
> Kim
>
>

Re: set environment variables in tomcat

am 27.05.2011 08:48:19 von aw

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

am 27.05.2011 14:59:48 von James.B.Muir

--_000_527C4914F1B2EA47B38422DE0FA05A65065167F11CDH201DHMCMa st_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

In order to pass an environment variable via mod_jk to tomcat you need to s=
et 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 set=
ting environment variables with each request in the PerlAuthenHandler and P=
erlHeaderParserHandler. I'm able to read the variables in PHP, perl fcgi, a=
nd wsgi, however they are not being passed to tomcat. Is there a way to pas=
s 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 recipien=
t, your use of this message for any purpose is strictly prohibited. If you =
have received this communication in error, please delete the message and no=
tify the sender so that we may correct our records.

--_000_527C4914F1B2EA47B38422DE0FA05A65065167F11CDH201DHMCMa st_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">

>





libri","sans-serif";color:#1F497D">In order to pass an envir=
onment variable via mod_jk to tomcat you need to set the “JkEnvVar=
221; in your jk.conf file.  For example,


libri","sans-serif";color:#1F497D"> <=
/p>

libri","sans-serif";color:#1F497D">JkEnvVar   =
;   REMOTE_USER   %{REMOTE_USER}


libri","sans-serif";color:#1F497D"> <=
/p>

libri","sans-serif";color:#1F497D">-James<=
/p>

libri","sans-serif";color:#1F497D"> <=
/p>

0in 0in">

;Tahoma","sans-serif"">From: ize:10.0pt;font-family:"Tahoma","sans-serif""> Kim Gold=
ov [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 t=
omcat server from our web server using mod_jk. I'm setting environment vari=
ables with each request in the PerlAuthenHandler and PerlHeaderParserHandle=
r. 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 REGARDIN=
G 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 recipien=
t, your use of this message for
any purpose is strictly prohibited. If you have received this communicatio=
n in error, please delete the message and notify the sender so that we may =
correct our records.





--_000_527C4914F1B2EA47B38422DE0FA05A65065167F11CDH201DHMCMa st_--

Re: set environment variables in tomcat

am 27.05.2011 16:36:00 von aw

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

am 02.06.2011 00:31:54 von Kim Goldov

--000e0cd1e2a6724ea204a4ae1645
Content-Type: text/plain; charset=ISO-8859-1

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

--000e0cd1e2a6724ea204a4ae1645
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Thanks everyone. Here is what I ended up with.

In my PerlHeaderParse=
rHandler:
=A0
=A0 =A0 $r->subprocess_env(AA_MYVAR =3D> 'myv=
alue');
  =A0 $r->subprocess_env();

In jk.conf:
>  =A0 JkEnvVar    =A0 AA_MYVAR


In Tomcat:

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

--
Kim



--000e0cd1e2a6724ea204a4ae1645--

Re: set environment variables in tomcat

am 02.06.2011 12:47:00 von aw

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).