Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-03-03 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

André,

On 2/27/13 3:59 AM, André Warnier wrote:
 If I understand the original post correctly, the whole point would
 be to know, at the httpd level, which worker (Tomcat) actually
 processed this request, right ? If so, why not have the desired
 response header added at the Tomcat level ? The more or less
 standard workhorsse URLRewriteFilter could be used here for that.

One potential irritant is that requires you to (further?) customize
each of your backend servers. If you could handle this at the mod_jk
level, the app server doesn't have to collude with the web server in
order to perform this logging.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEzYd4ACgkQ9CaO5/Lv0PAkxQCfXaBIxrcDzt2IeYPXCEPgivpx
8MQAn2CmDRb19+P+Gtfj/WUfQW+C9soP
=9a/c
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-03-03 Thread Rainer Jung
On 03.03.2013 15:44, Christopher Schultz wrote:
 André,
 
 On 2/27/13 3:59 AM, André Warnier wrote:
 If I understand the original post correctly, the whole point would
 be to know, at the httpd level, which worker (Tomcat) actually
 processed this request, right ? If so, why not have the desired
 response header added at the Tomcat level ? The more or less
 standard workhorsse URLRewriteFilter could be used here for that.
 
 One potential irritant is that requires you to (further?) customize
 each of your backend servers. If you could handle this at the mod_jk
 level, the app server doesn't have to collude with the web server in
 order to perform this logging.

True, but in the case of load balancing you would have to add an
individual jvmRoute to server.xml n any case. So I typically just set a
system property e.g. -Droute=node1 and use ${route} in server.xml. That
way the file stays consistent. Setting the system property can be done
in setenv.sh, where you could use shell logic to determine on what node
you are running.

Now: the same trick can be used when running without a load balancer. If
the shell script has a way to set the target name you want to be shown,
then just set a dummy system property like -Dworker=node1 and refer to
the system property worker in the filter.

Instead of node! etc. you could e.g. use the result of uname -n on
Linux/Unix.

Regards,

Rainer


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-27 Thread André Warnier

Rainer Jung wrote:

On 26.02.2013 19:41, Jochen Wißmann wrote:

Hello,

i am trying to find an easy way to determine from the http-client side,
which  AJP13-worker handled my request.
So my basic idea is to use mod_header to add mod_jk`s env-variable
JK_WORKER_NAME to the Header of the http-response.
I tried to get something like this working:

httpd.conf:
...
Header add TC-Server %{JK_WORKER_NAME}e
...

All my previous attempts resulted in http-responses looking like this:

 HTTP/1.1 200 OK
 Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
 Date: Tue, 26 Feb 2013 18:25:31 GMT
 Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22
OpenSSL/0.9.8x DAV/2
 Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; Path=/
 Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 18:25:31
GMT; Path=/
 Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31
GMT; Path=/
 Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /
Build 6006 / February 17, 2011)
 ETag: 838b4ae2
 Content-Length: 8043
 X-Server-Ip: 110.160.11.26
 TC-Server: (null)
 Content-Type: text/html;charset=utf-8

Why do i get TC-Server: (null) ?
Using the Variable JK_WORKER_NAME to log the worker's name via
mod_log_config works fine.

Am i missing something? Is it even possible to access the env-variable
JK_WORKER_NAME with module mod_header?
Could anyone please help?
Thanks!


mod_jk respects the environment variable JK_WORKER_NAME when choosing a
target worker, but it does not set it.

mod_jk only sets a note with name JK_WORKER_NAME, which is different
from an env var. The n in your log format means note.

Unfortunately most variable use supported in Apache config is for env
vars, not for notes, so you can't directly set the header from a note.

There are two things you can experiment with:

a) using an undocumented mod_rewrite feature to try to copy the note
into an env var and then using that env var to set the header

or

b) not using the normal JkMount or uriworkermap.properties way of
defining the workers responsible for handling the URIs, but instead
using mod_rewrite via setting the env var JK:WORKER_NAME

Ad a)

Works roughly like that (untested):

RewriteCond %{ENV:JK_WORKER_NAME} (.*)
RewriteRule . - [ENV=WORKER:%1]

Note 1: the undocumented feature of mod_rewrite is, that
%{ENV:JK_WORKER_NAME} first looks for a note named JK_WORKER_NAME and
only if it doesn't find it for an env var.

Note 2: The RewriteRule now sets a new env var WORKER to the captured
value of the note. lease choose a new variable name here, not
JK_WORER_NAME.

Now we add

Header add TC-Server-Ip %{WORKER}e

If you choose another name as WORKER for the new env var in the
RewriteRule, please adjust here as well.

Finally: if it doesn't work, try again by placing the Rewrite lines in a
Directory/Directory block. Don't forget to switch

RewriteEngine On

Ad b)

You can use mod_rewrite to set the env var JK_WORKER_NAME (now it is
important to use that name). mod_jk will then route the request to that
worker and since you had set the env var yourself, you can also copy it
to a header.

RewriteRule ^/c - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/c/.* - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group/.* - [ENV=JK_WORKER_NAME:liferay]

etc.

and then

Header add TC-Server-Ip %{JK_WORKER_NAME}e

Final remarks:

Your config does not really warrant this effort: you only have one
worker name, so what do you expect in the header? I'm asking, because if
you are using a load balancer worker (assumed name lb) in your real
config, and it has sub workers for example node1 and node2 then
JK_WORKER_NAME will always be lb. To actually get the chosen sub
worker, only recipe 1 has a chance to work. You would there replace
JK_WORJER_NAME in the RewriteCond by JK_WORKER_ROUTE. Unfortunately I
think that the route note is not set before the request actually gets
forwarded and that is to late for mod_rewrite to be able to copy it in
an env var.

In that case (load balancer and you want to know the chosen lb sub
worker) we would either need to add something to mod_jk, or allow
mod_headers to also support notes, or write a special small module.

Having written all that, I think the following patch to mod_headers
would be best. It simply adds support for notes to mod_headers (%{xxx}n
notation):

Index: modules/metadata/mod_headers.c
===
--- modules/metadata/mod_headers.c  (revision 1449529)
+++ modules/metadata/mod_headers.c  (working copy)
@@ -200,6 +200,16 @@
 return (null);
 }

+static const char *header_request_note(request_rec *r, char *a)
+{
+const char *s = apr_table_get(r-notes,a);
+
+if (s)
+return unwrap_header(r-pool, s);
+else
+return (null);
+}
+
 static const char *header_request_ssl_var(request_rec *r, char *name)
 {
 if (header_ssl_lookup) {
@@ -853,6 +863,7 @@
 

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-27 Thread Rainer Jung
On 27.02.2013 09:59, André Warnier wrote:

 And from Schwaben too...
 I feel a bit naive after all the sophisticated technical stuff above, in
 suggesting the following, but how about :
 If I understand the original post correctly, the whole point would be to
 know, at the httpd level, which worker (Tomcat) actually processed
 this request, right ?
 If so, why not have the desired response header added at the Tomcat level ?
 The more or less standard workhorsse URLRewriteFilter could be used here
 for that.
 rule
 from.*/from
 set type=response-header name=TC-workername of this
 tomcat/set
 /rule
 and then check this on the way back in Apache..
 That would also overcome Rainer's note about load-balancing above.
 As a matter of fact, I am quite sure that Tomcat itself already adds
 some kind of response header to indicate that it was involved in this,
 so it might just be a matter of proper Tomcat configuration.

Much better :)

Rainer


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-27 Thread Jochen Wißmann

On 27.02.2013 09:59, André Warnier wrote:

Rainer Jung wrote:

On 26.02.2013 19:41, Jochen Wißmann wrote:

Hello,

i am trying to find an easy way to determine from the http-client side,
which  AJP13-worker handled my request.
So my basic idea is to use mod_header to add mod_jk`s env-variable
JK_WORKER_NAME to the Header of the http-response.
I tried to get something like this working:

httpd.conf:
...
Header add TC-Server %{JK_WORKER_NAME}e
...

All my previous attempts resulted in http-responses looking like this:

 HTTP/1.1 200 OK
 Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
 Date: Tue, 26 Feb 2013 18:25:31 GMT
 Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22
OpenSSL/0.9.8x DAV/2
 Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; 
Path=/
 Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 
18:25:31

GMT; Path=/
 Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31
GMT; Path=/
 Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /
Build 6006 / February 17, 2011)
 ETag: 838b4ae2
 Content-Length: 8043
 X-Server-Ip: 110.160.11.26
 TC-Server: (null)
 Content-Type: text/html;charset=utf-8

Why do i get TC-Server: (null) ?
Using the Variable JK_WORKER_NAME to log the worker's name via
mod_log_config works fine.

Am i missing something? Is it even possible to access the env-variable
JK_WORKER_NAME with module mod_header?
Could anyone please help?
Thanks!


mod_jk respects the environment variable JK_WORKER_NAME when choosing a
target worker, but it does not set it.

mod_jk only sets a note with name JK_WORKER_NAME, which is different
from an env var. The n in your log format means note.

Unfortunately most variable use supported in Apache config is for env
vars, not for notes, so you can't directly set the header from a note.

There are two things you can experiment with:

a) using an undocumented mod_rewrite feature to try to copy the note
into an env var and then using that env var to set the header

or

b) not using the normal JkMount or uriworkermap.properties way of
defining the workers responsible for handling the URIs, but instead
using mod_rewrite via setting the env var JK:WORKER_NAME

Ad a)

Works roughly like that (untested):

RewriteCond %{ENV:JK_WORKER_NAME} (.*)
RewriteRule . - [ENV=WORKER:%1]

Note 1: the undocumented feature of mod_rewrite is, that
%{ENV:JK_WORKER_NAME} first looks for a note named JK_WORKER_NAME and
only if it doesn't find it for an env var.

Note 2: The RewriteRule now sets a new env var WORKER to the captured
value of the note. lease choose a new variable name here, not
JK_WORER_NAME.

Now we add

Header add TC-Server-Ip %{WORKER}e

If you choose another name as WORKER for the new env var in the
RewriteRule, please adjust here as well.

Finally: if it doesn't work, try again by placing the Rewrite lines in a
Directory/Directory block. Don't forget to switch

RewriteEngine On

Ad b)

You can use mod_rewrite to set the env var JK_WORKER_NAME (now it is
important to use that name). mod_jk will then route the request to that
worker and since you had set the env var yourself, you can also copy it
to a header.

RewriteRule ^/c - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/c/.* - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group/.* - [ENV=JK_WORKER_NAME:liferay]

etc.

and then

Header add TC-Server-Ip %{JK_WORKER_NAME}e

Final remarks:

Your config does not really warrant this effort: you only have one
worker name, so what do you expect in the header? I'm asking, because if
you are using a load balancer worker (assumed name lb) in your real
config, and it has sub workers for example node1 and node2 then
JK_WORKER_NAME will always be lb. To actually get the chosen sub
worker, only recipe 1 has a chance to work. You would there replace
JK_WORJER_NAME in the RewriteCond by JK_WORKER_ROUTE. Unfortunately I
think that the route note is not set before the request actually gets
forwarded and that is to late for mod_rewrite to be able to copy it in
an env var.

In that case (load balancer and you want to know the chosen lb sub
worker) we would either need to add something to mod_jk, or allow
mod_headers to also support notes, or write a special small module.

Having written all that, I think the following patch to mod_headers
would be best. It simply adds support for notes to mod_headers (%{xxx}n
notation):

Index: modules/metadata/mod_headers.c
===
--- modules/metadata/mod_headers.c  (revision 1449529)
+++ modules/metadata/mod_headers.c  (working copy)
@@ -200,6 +200,16 @@
 return (null);
 }

+static const char *header_request_note(request_rec *r, char *a)
+{
+const char *s = apr_table_get(r-notes,a);
+
+if (s)
+return unwrap_header(r-pool, s);
+else
+return (null);
+}
+
 static const char *header_request_ssl_var(request_rec *r, char *name)
 {
 if 

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-27 Thread André Warnier

Jochen Wißmann wrote:

On 27.02.2013 09:59, André Warnier wrote:

Rainer Jung wrote:

On 26.02.2013 19:41, Jochen Wißmann wrote:

Hello,

i am trying to find an easy way to determine from the http-client side,
which  AJP13-worker handled my request.
So my basic idea is to use mod_header to add mod_jk`s env-variable
JK_WORKER_NAME to the Header of the http-response.
I tried to get something like this working:

httpd.conf:
...
Header add TC-Server %{JK_WORKER_NAME}e
...

All my previous attempts resulted in http-responses looking like this:

 HTTP/1.1 200 OK
 Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
 Date: Tue, 26 Feb 2013 18:25:31 GMT
 Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22
OpenSSL/0.9.8x DAV/2
 Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; 
Path=/
 Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 
18:25:31

GMT; Path=/
 Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31
GMT; Path=/
 Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /
Build 6006 / February 17, 2011)
 ETag: 838b4ae2
 Content-Length: 8043
 X-Server-Ip: 110.160.11.26
 TC-Server: (null)
 Content-Type: text/html;charset=utf-8

Why do i get TC-Server: (null) ?
Using the Variable JK_WORKER_NAME to log the worker's name via
mod_log_config works fine.

Am i missing something? Is it even possible to access the env-variable
JK_WORKER_NAME with module mod_header?
Could anyone please help?
Thanks!


mod_jk respects the environment variable JK_WORKER_NAME when choosing a
target worker, but it does not set it.

mod_jk only sets a note with name JK_WORKER_NAME, which is different
from an env var. The n in your log format means note.

Unfortunately most variable use supported in Apache config is for env
vars, not for notes, so you can't directly set the header from a note.

There are two things you can experiment with:

a) using an undocumented mod_rewrite feature to try to copy the note
into an env var and then using that env var to set the header

or

b) not using the normal JkMount or uriworkermap.properties way of
defining the workers responsible for handling the URIs, but instead
using mod_rewrite via setting the env var JK:WORKER_NAME

Ad a)

Works roughly like that (untested):

RewriteCond %{ENV:JK_WORKER_NAME} (.*)
RewriteRule . - [ENV=WORKER:%1]

Note 1: the undocumented feature of mod_rewrite is, that
%{ENV:JK_WORKER_NAME} first looks for a note named JK_WORKER_NAME and
only if it doesn't find it for an env var.

Note 2: The RewriteRule now sets a new env var WORKER to the captured
value of the note. lease choose a new variable name here, not
JK_WORER_NAME.

Now we add

Header add TC-Server-Ip %{WORKER}e

If you choose another name as WORKER for the new env var in the
RewriteRule, please adjust here as well.

Finally: if it doesn't work, try again by placing the Rewrite lines in a
Directory/Directory block. Don't forget to switch

RewriteEngine On

Ad b)

You can use mod_rewrite to set the env var JK_WORKER_NAME (now it is
important to use that name). mod_jk will then route the request to that
worker and since you had set the env var yourself, you can also copy it
to a header.

RewriteRule ^/c - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/c/.* - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group/.* - [ENV=JK_WORKER_NAME:liferay]

etc.

and then

Header add TC-Server-Ip %{JK_WORKER_NAME}e

Final remarks:

Your config does not really warrant this effort: you only have one
worker name, so what do you expect in the header? I'm asking, because if
you are using a load balancer worker (assumed name lb) in your real
config, and it has sub workers for example node1 and node2 then
JK_WORKER_NAME will always be lb. To actually get the chosen sub
worker, only recipe 1 has a chance to work. You would there replace
JK_WORJER_NAME in the RewriteCond by JK_WORKER_ROUTE. Unfortunately I
think that the route note is not set before the request actually gets
forwarded and that is to late for mod_rewrite to be able to copy it in
an env var.

In that case (load balancer and you want to know the chosen lb sub
worker) we would either need to add something to mod_jk, or allow
mod_headers to also support notes, or write a special small module.

Having written all that, I think the following patch to mod_headers
would be best. It simply adds support for notes to mod_headers (%{xxx}n
notation):

Index: modules/metadata/mod_headers.c
===
--- modules/metadata/mod_headers.c  (revision 1449529)
+++ modules/metadata/mod_headers.c  (working copy)
@@ -200,6 +200,16 @@
 return (null);
 }

+static const char *header_request_note(request_rec *r, char *a)
+{
+const char *s = apr_table_get(r-notes,a);
+
+if (s)
+return unwrap_header(r-pool, s);
+else
+return (null);
+}
+
 static const char *header_request_ssl_var(request_rec *r, char *name)

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-27 Thread Rainer Jung
On 27.02.2013 12:16, André Warnier wrote:
 Hi. Before you do that, you may want to have another look at this page :
 http://tomcat.apache.org/connectors-doc/reference/apache.html
 and in particular the section at the end labeled : Using SetHandler and
 Environment Variables
 
 I use this way of configuring the proxy-ing of requests via mod_jk,
 rather than the JkMount and uriworkermap style, for some (purely
 personal) reasons :
 - it keeps things in one place (the httpd config file)
 - I believe that it fits better in the Apache httpd configuration
 style, allowing you to use the classical Apache Location,
 LocationMatch etc.. to decide which URLs are being proxied
 - I find it easier that way, to mentally see where and when what happens
 at the Apache level when you use mod_jk + Tomcat, as in fact an Apache
 response handler.
 
 For example, in your case, you could set up the following section in
 Apache, to replace your external uri map :
 
 LocationMatch ^\/(c|group|html|image|language|layouttpl|...)\/
   # in principle, for all those, pass them on to Tomcat..
   SetHandler jakarta-servlet
   SetEnv JK_WORKER_NAME liferay-1
 
   # but for some subset, do not pass them on, and let Apache itself
 handle them
   SetEnvIf REQUEST_URI (some condition) no-jk
   ...
   (set other filters, variables, headers, whatever)
   ...
 /LocationMatch
 
 Just so that you would know about it.

Thanks Andre, in my second recipe I forgot the SetHandler jakarta-servlet.

Rainer

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Jochen Wißmann

Hello,

i am trying to find an easy way to determine from the http-client side, 
which  AJP13-worker handled my request.
So my basic idea is to use mod_header to add mod_jk`s env-variable 
JK_WORKER_NAME to the Header of the http-response.

I tried to get something like this working:

httpd.conf:
...
Header add TC-Server %{JK_WORKER_NAME}e
...

All my previous attempts resulted in http-responses looking like this:

 HTTP/1.1 200 OK
 Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
 Date: Tue, 26 Feb 2013 18:25:31 GMT
 Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22 
OpenSSL/0.9.8x DAV/2

 Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; Path=/
 Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 18:25:31 
GMT; Path=/
 Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31 
GMT; Path=/
 Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan / 
Build 6006 / February 17, 2011)

 ETag: 838b4ae2
 Content-Length: 8043
 X-Server-Ip: 110.160.11.26
 TC-Server: (null)
 Content-Type: text/html;charset=utf-8

Why do i get TC-Server: (null) ?
Using the Variable JK_WORKER_NAME to log the worker's name via 
mod_log_config works fine.


Am i missing something? Is it even possible to access the env-variable 
JK_WORKER_NAME with module mod_header?

Could anyone please help?
Thanks!

Jochen


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Jochen,

On 2/26/13 10:41 AM, Jochen Wißmann wrote:
 I tried to get something like this working:
 
 httpd.conf: ... Header add TC-Server %{JK_WORKER_NAME}e

This looks like it should work from my brief review of the documentation.

  TC-Server: (null)
 
 Why do i get TC-Server: (null) ? Using the Variable
 JK_WORKER_NAME to log the worker's name via mod_log_config works
 fine.
 
 Am i missing something? Is it even possible to access the
 env-variable JK_WORKER_NAME with module mod_header?

The httpd documentation says so.

Can you give us more of your httpd.conf? Perhaps the Header
directive isn't in a place where the environment variable has been
set, goes out of scope, etc.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEtK1AACgkQ9CaO5/Lv0PAdmwCgvDx2p5ZNdLAU6E7xXIg4uuu6
tCcAoLWtF78/eXNDXvmV2FeR6TIOq0qj
=f/sj
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Igor Cicimov
On 27/02/2013 5:42 AM, Jochen Wißmann jochen.wissm...@kepol.com wrote:

 Hello,

 i am trying to find an easy way to determine from the http-client side,
which  AJP13-worker handled my request.
 So my basic idea is to use mod_header to add mod_jk`s env-variable
JK_WORKER_NAME to the Header of the http-response.
 I tried to get something like this working:

 httpd.conf:
 ...
 Header add TC-Server %{JK_WORKER_NAME}e

I think this should be

Header add TC-Server %{JK_WORKER_NAME}n

Please paste here the worker.properties file too.

 ...

 All my previous attempts resulted in http-responses looking like this:

  HTTP/1.1 200 OK
  Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
  Date: Tue, 26 Feb 2013 18:25:31 GMT
  Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22
OpenSSL/0.9.8x DAV/2
  Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; Path=/
  Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 18:25:31
GMT; Path=/
  Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31 GMT;
Path=/
  Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /
Build 6006 / February 17, 2011)
  ETag: 838b4ae2
  Content-Length: 8043
  X-Server-Ip: 110.160.11.26
  TC-Server: (null)
  Content-Type: text/html;charset=utf-8

 Why do i get TC-Server: (null) ?
 Using the Variable JK_WORKER_NAME to log the worker's name via
mod_log_config works fine.

 Am i missing something? Is it even possible to access the env-variable
JK_WORKER_NAME with module mod_header?
 Could anyone please help?
 Thanks!

 Jochen


 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Jochen Wißmann

On 26.02.2013 23:52, Igor Cicimov wrote:

On 27/02/2013 5:42 AM, Jochen Wißmann jochen.wissm...@kepol.com wrote:

Hello,

i am trying to find an easy way to determine from the http-client side,

which  AJP13-worker handled my request.

So my basic idea is to use mod_header to add mod_jk`s env-variable

JK_WORKER_NAME to the Header of the http-response.

I tried to get something like this working:

httpd.conf:
...
Header add TC-Server %{JK_WORKER_NAME}e

I think this should be

Header add TC-Server %{JK_WORKER_NAME}n

Please paste here the worker.properties file too.


...

All my previous attempts resulted in http-responses looking like this:

 HTTP/1.1 200 OK
 Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
 Date: Tue, 26 Feb 2013 18:25:31 GMT
 Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22

OpenSSL/0.9.8x DAV/2

 Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; Path=/
 Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 18:25:31

GMT; Path=/

 Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31 GMT;

Path=/

 Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /

Build 6006 / February 17, 2011)

 ETag: 838b4ae2
 Content-Length: 8043
 X-Server-Ip: 110.160.11.26
 TC-Server: (null)
 Content-Type: text/html;charset=utf-8

Why do i get TC-Server: (null) ?
Using the Variable JK_WORKER_NAME to log the worker's name via

mod_log_config works fine.

Am i missing something? Is it even possible to access the env-variable

JK_WORKER_NAME with module mod_header?

Could anyone please help?
Thanks!

Jochen


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


Hi Igor,

thanks for the tip, but using Header add TC-Server 
%{JK_WORKER_NAME}n as you suggested appears to be an invalid 
configuration:


# apachectl configtest

...
Syntax error on line 43 of /etc/apache2/sites-enabled/000-default:
Unrecognized header format %n
Action 'restart' failed.
...

Regards
Jochen

--
Jochen Wißmann
Head of operations

KEBA GmbH Automation
Vertretung der KEBA AG Linz
Adenauerallee 73
D-53113 Bonn, Germany

Phone +49/228/1848698014
Fax   +49/228/1848698015
Mailto: jochen.wissm...@agimatec.de
www.keba.com
Geschäftsführer:
Franz Berger, Thomas Linde, Michael Spatz Amtsgericht Ulm HRB 725943


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Jochen Wißmann

On 26.02.2013 22:38, Christopher Schultz wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Jochen,

On 2/26/13 10:41 AM, Jochen Wißmann wrote:

I tried to get something like this working:

httpd.conf: ... Header add TC-Server %{JK_WORKER_NAME}e

This looks like it should work from my brief review of the documentation.


 TC-Server: (null)

Why do i get TC-Server: (null) ? Using the Variable
JK_WORKER_NAME to log the worker's name via mod_log_config works
fine.

Am i missing something? Is it even possible to access the
env-variable JK_WORKER_NAME with module mod_header?

The httpd documentation says so.

Can you give us more of your httpd.conf? Perhaps the Header
directive isn't in a place where the environment variable has been
set, goes out of scope, etc.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEtK1AACgkQ9CaO5/Lv0PAdmwCgvDx2p5ZNdLAU6E7xXIg4uuu6
tCcAoLWtF78/eXNDXvmV2FeR6TIOq0qj
=f/sj
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


Hi Christopher,

my setup looks like this.
* os: ubuntu, running apache  2.2 with mod_jk 1.2.36
* AJP13-Worker: Liferay Portal Community Edition 6.0.6 CE (Bunyan / 
Build 6006 / February 17, 2011) , which is based on tomcat-6.0.29


000-default:

# Load mod_jk configuration
Include mod-jk.conf

VirtualHost *:80
ServerAdmin webmaster@localhost
DocumentRoot /var/www
Directory /
Options FollowSymLinks
AllowOverride None
/Directory
Directory /var/www/
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
/Directory

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Directory /usr/lib/cgi-bin
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
/Directory

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ /usr/share/doc/
Directory /usr/share/doc/
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
/Directory
Header add X-Server-Ip %{SERVER_ADDR}e
Header merge TC-Server-Ip %{JK_WORKER_NAME}e
/VirtualHost

mod_jk.conf:
-
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile workers.properties

# Where to put jk logs
JkLogFile ${APACHE_LOG_DIR}/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# LogFormat
LogFormat %h %l %u %t \%r\ %s %b %{JK_WORKER_NAME}n 
%{JK_LB_FIRST_NAME}n \
 %{JK_LB_FIRST_BUSY}n %{JK_LB_LAST_NAME}n 
%{JK_LB_LAST_BUSY}n JkLogFile

# Select the log format
JkLogStampFormat  %Y-%m-%d %H:%M:%S,%Q 
#SetEnv JK_WORKER_NAME {JK_WORKER_NAME}n
Header add TC-Server-Ip %{JK_NOTE_WORKER_NAME}e
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat  %w %V %U %T %s %R

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile uriworkermap.properties

JkMountCopy all

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile /var/log/apache2/jk.shm

worker.properties:

# Define list of workers that will be used
# for mapping requests
worker.list=status,liferay
# Status worker for managing load balancer
worker.status.type=status

# Liferay-Load-balancer
worker.liferay.port=8009
worker.liferay.host=127.0.0.1
worker.liferay.type=ajp13

uriworkermap.properties:
--
# Mount the Servlet context to the ajp13 worker
/jkstatus/*=status

# Liferay
/c=liferay
/c/*=liferay
/group=liferay
/group/*=liferay
/html/*=liferay
/image/*=liferay
/language/*=liferay
/layouttpl/*=liferay
/user=liferay
/user/*=liferay
/web=liferay
/web/*=liferay
/kepol=liferay
/kepol/*=liferay

# Liferay Languages
/da=liferay
/da/*=liferay
/de=liferay
/de/*=liferay
/en=liferay
/en/*=liferay
/ru=liferay
/ru/*=liferay
/tr=liferay
/tr/*=liferay

Using these config-files allows me to use JK_WORKER_NAME for logging, 
but not for header-manipulation, strange 

Any ideas?

Thanks!

Jochen

--
Jochen Wißmann
Head of operations

KEBA GmbH Automation
Vertretung der KEBA AG 

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Igor Cicimov
On 27/02/2013 10:47 AM, Jochen Wißmann jochen.wissm...@kepol.com wrote:

 On 26.02.2013 22:38, Christopher Schultz wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA256

 Jochen,

 On 2/26/13 10:41 AM, Jochen Wißmann wrote:

 I tried to get something like this working:

 httpd.conf: ... Header add TC-Server %{JK_WORKER_NAME}e

 This looks like it should work from my brief review of the documentation.

  TC-Server: (null)

 Why do i get TC-Server: (null) ? Using the Variable
 JK_WORKER_NAME to log the worker's name via mod_log_config works
 fine.

 Am i missing something? Is it even possible to access the
 env-variable JK_WORKER_NAME with module mod_header?

 The httpd documentation says so.

 Can you give us more of your httpd.conf? Perhaps the Header
 directive isn't in a place where the environment variable has been
 set, goes out of scope, etc.

 - -chris
 -BEGIN PGP SIGNATURE-
 Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
 Comment: GPGTools - http://gpgtools.org
 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

 iEYEAREIAAYFAlEtK1AACgkQ9CaO5/Lv0PAdmwCgvDx2p5ZNdLAU6E7xXIg4uuu6
 tCcAoLWtF78/eXNDXvmV2FeR6TIOq0qj
 =f/sj
 -END PGP SIGNATURE-

 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org

 Hi Christopher,

 my setup looks like this.
 * os: ubuntu, running apache  2.2 with mod_jk 1.2.36
 * AJP13-Worker: Liferay Portal Community Edition 6.0.6 CE (Bunyan / Build
6006 / February 17, 2011) , which is based on tomcat-6.0.29

 000-default:
 
 # Load mod_jk configuration
 Include mod-jk.conf

 VirtualHost *:80
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www
 Directory /
 Options FollowSymLinks
 AllowOverride None
 /Directory
 Directory /var/www/
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
 /Directory

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 Directory /usr/lib/cgi-bin
 AllowOverride None
 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
 Order allow,deny
 Allow from all
 /Directory

 ErrorLog ${APACHE_LOG_DIR}/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog ${APACHE_LOG_DIR}/access.log combined

 Alias /doc/ /usr/share/doc/
 Directory /usr/share/doc/
 Options Indexes MultiViews FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
 Allow from 127.0.0.0/255.0.0.0 ::1/128
 /Directory
 Header add X-Server-Ip %{SERVER_ADDR}e
 Header merge TC-Server-Ip %{JK_WORKER_NAME}e
 /VirtualHost

 mod_jk.conf:
 -
 # Load mod_jk module
 # Specify the filename of the mod_jk lib
 LoadModule jk_module modules/mod_jk.so

 # Where to find workers.properties
 JkWorkersFile workers.properties

 # Where to put jk logs
 JkLogFile ${APACHE_LOG_DIR}/mod_jk.log

 # Set the jk log level [debug/error/info]
 JkLogLevel info

 # LogFormat
 LogFormat %h %l %u %t \%r\ %s %b %{JK_WORKER_NAME}n
%{JK_LB_FIRST_NAME}n \
  %{JK_LB_FIRST_BUSY}n %{JK_LB_LAST_NAME}n
%{JK_LB_LAST_BUSY}n JkLogFile
 # Select the log format
 JkLogStampFormat  %Y-%m-%d %H:%M:%S,%Q 
 #SetEnv JK_WORKER_NAME {JK_WORKER_NAME}n
 Header add TC-Server-Ip %{JK_NOTE_WORKER_NAME}e
 # JkOptions indicates to send SSK KEY SIZE
 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

 # JkRequestLogFormat
 JkRequestLogFormat  %w %V %U %T %s %R

 # You can use external file for mount points.
 # It will be checked for updates each 60 seconds.
 # The format of the file is: /url=worker
 # /examples/*=loadbalancer
 JkMountFile uriworkermap.properties

 JkMountCopy all

 # Add shared memory.
 # This directive is present with 1.2.10 and
 # later versions of mod_jk, and is needed for
 # for load balancing to work properly
 JkShmFile /var/log/apache2/jk.shm

 worker.properties:
 
 # Define list of workers that will be used
 # for mapping requests
 worker.list=status,liferay
 # Status worker for managing load balancer
 worker.status.type=status

 # Liferay-Load-balancer
 worker.liferay.port=8009
 worker.liferay.host=127.0.0.1
 worker.liferay.type=ajp13

 uriworkermap.properties:
 --
 # Mount the Servlet context to the ajp13 worker
 /jkstatus/*=status

 # Liferay
 /c=liferay
 /c/*=liferay
 /group=liferay
 /group/*=liferay
 /html/*=liferay
 /image/*=liferay
 /language/*=liferay
 /layouttpl/*=liferay
 /user=liferay
 /user/*=liferay
 /web=liferay
 /web/*=liferay
 /kepol=liferay
 /kepol/*=liferay

 # Liferay Languages
 /da=liferay
 /da/*=liferay
 /de=liferay
 /de/*=liferay
 /en=liferay
 /en/*=liferay
 /ru=liferay
 /ru/*=liferay
 /tr=liferay
 /tr/*=liferay

 Using these 

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Igor Cicimov
On 27/02/2013 10:47 AM, Jochen Wißmann jochen.wissm...@kepol.com wrote:

 On 26.02.2013 22:38, Christopher Schultz wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA256

 Jochen,

 On 2/26/13 10:41 AM, Jochen Wißmann wrote:

 I tried to get something like this working:

 httpd.conf: ... Header add TC-Server %{JK_WORKER_NAME}e

 This looks like it should work from my brief review of the documentation.

  TC-Server: (null)

 Why do i get TC-Server: (null) ? Using the Variable
 JK_WORKER_NAME to log the worker's name via mod_log_config works
 fine.

 Am i missing something? Is it even possible to access the
 env-variable JK_WORKER_NAME with module mod_header?

 The httpd documentation says so.

 Can you give us more of your httpd.conf? Perhaps the Header
 directive isn't in a place where the environment variable has been
 set, goes out of scope, etc.

 - -chris
 -BEGIN PGP SIGNATURE-
 Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
 Comment: GPGTools - http://gpgtools.org
 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

 iEYEAREIAAYFAlEtK1AACgkQ9CaO5/Lv0PAdmwCgvDx2p5ZNdLAU6E7xXIg4uuu6
 tCcAoLWtF78/eXNDXvmV2FeR6TIOq0qj
 =f/sj
 -END PGP SIGNATURE-

 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org

 Hi Christopher,

 my setup looks like this.
 * os: ubuntu, running apache  2.2 with mod_jk 1.2.36
 * AJP13-Worker: Liferay Portal Community Edition 6.0.6 CE (Bunyan / Build
6006 / February 17, 2011) , which is based on tomcat-6.0.29

 000-default:
 
 # Load mod_jk configuration
 Include mod-jk.conf

 VirtualHost *:80
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www
 Directory /
 Options FollowSymLinks
 AllowOverride None
 /Directory
 Directory /var/www/
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
 /Directory

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 Directory /usr/lib/cgi-bin
 AllowOverride None
 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
 Order allow,deny
 Allow from all
 /Directory

 ErrorLog ${APACHE_LOG_DIR}/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog ${APACHE_LOG_DIR}/access.log combined

 Alias /doc/ /usr/share/doc/
 Directory /usr/share/doc/
 Options Indexes MultiViews FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
 Allow from 127.0.0.0/255.0.0.0 ::1/128
 /Directory
 Header add X-Server-Ip %{SERVER_ADDR}e
 Header merge TC-Server-Ip %{JK_WORKER_NAME}e
 /VirtualHost

 mod_jk.conf:
 -
 # Load mod_jk module
 # Specify the filename of the mod_jk lib
 LoadModule jk_module modules/mod_jk.so

 # Where to find workers.properties
 JkWorkersFile workers.properties

 # Where to put jk logs
 JkLogFile ${APACHE_LOG_DIR}/mod_jk.log

 # Set the jk log level [debug/error/info]
 JkLogLevel info

 # LogFormat
 LogFormat %h %l %u %t \%r\ %s %b %{JK_WORKER_NAME}n
%{JK_LB_FIRST_NAME}n \
  %{JK_LB_FIRST_BUSY}n %{JK_LB_LAST_NAME}n
%{JK_LB_LAST_BUSY}n JkLogFile
 # Select the log format
 JkLogStampFormat  %Y-%m-%d %H:%M:%S,%Q 
 #SetEnv JK_WORKER_NAME {JK_WORKER_NAME}n
 Header add TC-Server-Ip %{JK_NOTE_WORKER_NAME}e
 # JkOptions indicates to send SSK KEY SIZE
 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

 # JkRequestLogFormat
 JkRequestLogFormat  %w %V %U %T %s %R

 # You can use external file for mount points.
 # It will be checked for updates each 60 seconds.
 # The format of the file is: /url=worker
 # /examples/*=loadbalancer
 JkMountFile uriworkermap.properties

 JkMountCopy all

 # Add shared memory.
 # This directive is present with 1.2.10 and
 # later versions of mod_jk, and is needed for
 # for load balancing to work properly
 JkShmFile /var/log/apache2/jk.shm

 worker.properties:
 
 # Define list of workers that will be used
 # for mapping requests
 worker.list=status,liferay
 # Status worker for managing load balancer
 worker.status.type=status

 # Liferay-Load-balancer
 worker.liferay.port=8009
 worker.liferay.host=127.0.0.1
 worker.liferay.type=ajp13

 uriworkermap.properties:
 --
 # Mount the Servlet context to the ajp13 worker
 /jkstatus/*=status

 # Liferay
 /c=liferay
 /c/*=liferay
 /group=liferay
 /group/*=liferay
 /html/*=liferay
 /image/*=liferay
 /language/*=liferay
 /layouttpl/*=liferay
 /user=liferay
 /user/*=liferay
 /web=liferay
 /web/*=liferay
 /kepol=liferay
 /kepol/*=liferay

 # Liferay Languages
 /da=liferay
 /da/*=liferay
 /de=liferay
 /de/*=liferay
 /en=liferay
 /en/*=liferay
 /ru=liferay
 /ru/*=liferay
 /tr=liferay
 /tr/*=liferay


Another 

Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Igor,

On 2/26/13 2:52 PM, Igor Cicimov wrote:
 On 27/02/2013 5:42 AM, Jochen Wißmann jochen.wissm...@kepol.com
 wrote:
 Header add TC-Server %{JK_WORKER_NAME}e
 
 I think this should be
 
 Header add TC-Server %{JK_WORKER_NAME}n

??! ${FOOBAR}n isn't defined only %{...}e and %{...}s.

 Please paste here the worker.properties file too.

This should have no effect on things.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEtnUIACgkQ9CaO5/Lv0PBTswCdFDxSNRPn5oxZLqPAkuH8IJqy
cUwAnjFcoojJ0IYGdtdQuNQw1oHvpYg+
=PLoS
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: mod_jk how to add JK_WORKER_NAME to http-header

2013-02-26 Thread Rainer Jung
On 26.02.2013 19:41, Jochen Wißmann wrote:
 Hello,
 
 i am trying to find an easy way to determine from the http-client side,
 which  AJP13-worker handled my request.
 So my basic idea is to use mod_header to add mod_jk`s env-variable
 JK_WORKER_NAME to the Header of the http-response.
 I tried to get something like this working:
 
 httpd.conf:
 ...
 Header add TC-Server %{JK_WORKER_NAME}e
 ...
 
 All my previous attempts resulted in http-responses looking like this:
 
  HTTP/1.1 200 OK
  Set-Cookie: ARPT=LRWQXVS110.160.11.26CKMLQ; path=/
  Date: Tue, 26 Feb 2013 18:25:31 GMT
  Server: Apache/2.2.22 (Unix) mod_jk/1.2.36 mod_ssl/2.2.22
 OpenSSL/0.9.8x DAV/2
  Set-Cookie: JSESSIONID=A4052BF60BA2007F0B0F47E2699AFDE.liferay0; Path=/
  Set-Cookie: GUEST_LANGUAGE_ID=en_US; Expires=Wed, 26-Feb-2014 18:25:31
 GMT; Path=/
  Set-Cookie: COOKIE_SUPPORT=true; Expires=Wed, 26-Feb-2014 18:25:31
 GMT; Path=/
  Liferay-Portal: Liferay Portal Community Edition 6.0.6 CE (Bunyan /
 Build 6006 / February 17, 2011)
  ETag: 838b4ae2
  Content-Length: 8043
  X-Server-Ip: 110.160.11.26
  TC-Server: (null)
  Content-Type: text/html;charset=utf-8
 
 Why do i get TC-Server: (null) ?
 Using the Variable JK_WORKER_NAME to log the worker's name via
 mod_log_config works fine.
 
 Am i missing something? Is it even possible to access the env-variable
 JK_WORKER_NAME with module mod_header?
 Could anyone please help?
 Thanks!

mod_jk respects the environment variable JK_WORKER_NAME when choosing a
target worker, but it does not set it.

mod_jk only sets a note with name JK_WORKER_NAME, which is different
from an env var. The n in your log format means note.

Unfortunately most variable use supported in Apache config is for env
vars, not for notes, so you can't directly set the header from a note.

There are two things you can experiment with:

a) using an undocumented mod_rewrite feature to try to copy the note
into an env var and then using that env var to set the header

or

b) not using the normal JkMount or uriworkermap.properties way of
defining the workers responsible for handling the URIs, but instead
using mod_rewrite via setting the env var JK:WORKER_NAME

Ad a)

Works roughly like that (untested):

RewriteCond %{ENV:JK_WORKER_NAME} (.*)
RewriteRule . - [ENV=WORKER:%1]

Note 1: the undocumented feature of mod_rewrite is, that
%{ENV:JK_WORKER_NAME} first looks for a note named JK_WORKER_NAME and
only if it doesn't find it for an env var.

Note 2: The RewriteRule now sets a new env var WORKER to the captured
value of the note. lease choose a new variable name here, not
JK_WORER_NAME.

Now we add

Header add TC-Server-Ip %{WORKER}e

If you choose another name as WORKER for the new env var in the
RewriteRule, please adjust here as well.

Finally: if it doesn't work, try again by placing the Rewrite lines in a
Directory/Directory block. Don't forget to switch

RewriteEngine On

Ad b)

You can use mod_rewrite to set the env var JK_WORKER_NAME (now it is
important to use that name). mod_jk will then route the request to that
worker and since you had set the env var yourself, you can also copy it
to a header.

RewriteRule ^/c - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/c/.* - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group - [ENV=JK_WORKER_NAME:liferay]
RewriteRule ^/group/.* - [ENV=JK_WORKER_NAME:liferay]

etc.

and then

Header add TC-Server-Ip %{JK_WORKER_NAME}e

Final remarks:

Your config does not really warrant this effort: you only have one
worker name, so what do you expect in the header? I'm asking, because if
you are using a load balancer worker (assumed name lb) in your real
config, and it has sub workers for example node1 and node2 then
JK_WORKER_NAME will always be lb. To actually get the chosen sub
worker, only recipe 1 has a chance to work. You would there replace
JK_WORJER_NAME in the RewriteCond by JK_WORKER_ROUTE. Unfortunately I
think that the route note is not set before the request actually gets
forwarded and that is to late for mod_rewrite to be able to copy it in
an env var.

In that case (load balancer and you want to know the chosen lb sub
worker) we would either need to add something to mod_jk, or allow
mod_headers to also support notes, or write a special small module.

Having written all that, I think the following patch to mod_headers
would be best. It simply adds support for notes to mod_headers (%{xxx}n
notation):

Index: modules/metadata/mod_headers.c
===
--- modules/metadata/mod_headers.c  (revision 1449529)
+++ modules/metadata/mod_headers.c  (working copy)
@@ -200,6 +200,16 @@
 return (null);
 }

+static const char *header_request_note(request_rec *r, char *a)
+{
+const char *s = apr_table_get(r-notes,a);
+
+if (s)
+return unwrap_header(r-pool, s);
+else
+return (null);
+}
+
 static const char *header_request_ssl_var(request_rec *r, char *name)
 {
 if (header_ssl_lookup) {
@@ -853,6 +863,7