set environment variables in tomcat

--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?<br clear=3D"all">
<br>-- <br>Kim<br><br>

--bcaec55401b06e7f5e04a436f465--
Kim Goldov [ Fr, 27 Mai 2011 02:24 ] [ ID #2060143 ]

Re: set environment variables in tomcat

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 <kgoldov [at] 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
>
>
Fred Moyer [ Fr, 27 Mai 2011 04:11 ] [ ID #2060144 ]

Re: set environment variables in tomcat

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).
aw [ Fr, 27 Mai 2011 08:48 ] [ ID #2060145 ]

RE: set environment variables in tomcat

--_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 [at] gmail.com]
Sent: Thursday, May 26, 2011 8:24 PM
To: modperl [at] 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

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
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">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
[at] font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
[at] font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
[at] font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
..MsoChpDefault
{mso-style-type:export-only;}
[at] page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
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,<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri","sans-serif";color:#1F497D"><o:p> </o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri","sans-serif";color:#1F497D">JkEnvVar   =
;   REMOTE_USER   %{REMOTE_USER}<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri","sans-serif";color:#1F497D"><o:p> </o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri","sans-serif";color:#1F497D">-James<o:p></o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri","sans-serif";color:#1F497D"><o:p> </o:p></span><=
/p>
<div style=3D"border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in =
0in 0in">
<p class=3D"MsoNormal"><b><span style=3D"font-size:10.0pt;font-family:"=
;Tahoma","sans-serif"">From:</span></b><span style=3D"font-s=
ize:10.0pt;font-family:"Tahoma","sans-serif""> Kim Gold=
ov [mailto:kgoldov [at] gmail.com]
<br>
<b>Sent:</b> Thursday, May 26, 2011 8:24 PM<br>
<b>To:</b> modperl [at] perl.apache.org<br>
<b>Subject:</b> set environment variables in tomcat<o:p></o:p></span></p>
</div>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt">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?<br clear=3D"all">
<br>
-- <br>
Kim<o:p></o:p></p>
</div>
<br>
<font face=3D"Verdana" color=3D"Black" size=3D"1">IMPORTANT NOTICE REGARDIN=
G THIS ELECTRONIC MESSAGE:<br>
<br>
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.<br>
</font>
</body>
</html>

--_000_527C4914F1B2EA47B38422DE0FA05A65065167F11CDH201DHMCMa st_--
James.B.Muir [ Fr, 27 Mai 2011 14:59 ] [ ID #2060146 ]

Re: set environment variables in tomcat

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.
aw [ Fr, 27 Mai 2011 16:36 ] [ ID #2060147 ]

Re: set environment variables in tomcat

--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.<br><br>In my PerlHeaderParse=
rHandler:<br>=A0<br>=A0 =A0 $r->subprocess_env(AA_MYVAR =3D> 'myv=
alue');<br>=A0=A0=A0 $r->subprocess_env();<br><br>In jk.conf:<br><br=
>=A0=A0=A0 JkEnvVar=A0=A0=A0=A0=A0 AA_MYVAR<br>
<br>In Tomcat:<br><br>=A0=A0=A0=A0=A0 out.println("AA_MYVAR is: "=
+ request.getAttribute("AA_MYVAR") );<br><br>-- <br>Kim<br><br>

--000e0cd1e2a6724ea204a4ae1645--
Kim Goldov [ Do, 02 Juni 2011 00:31 ] [ ID #2060413 ]

Re: set environment variables in tomcat

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).
aw [ Do, 02 Juni 2011 12:47 ] [ ID #2060414 ]
Webserver » gmane.comp.apache.mod-perl » set environment variables in tomcat

Vorheriges Thema: Galbraith, P., 2009, "Developing Web Applications with Apache, MySQL,memcached, and Perl"
Nächstes Thema: Same script with different locations