Author: rjung
Date: Sat Sep 16 12:28:51 2006
New Revision: 446925

URL: http://svn.apache.org/viewvc?view=rev&rev=446925
Log:
Add a special environment variable to be able to set
target worker names via env variable.
Useful to combine the more powerful regexps of LocationMatch
and mod_rewrite/mod_env/mod_setenvif with mod_jk.
One can now also control mod_jk via
- SetHandler jakarta-servlet (old feature)
- SetEnv JK_HTTP_WORKER name_of_target_worker
The variable name JK_HTTP_WORKER can be changed via
JkWorkerIndicator NEW_VARIABLE_NAME.
This new features makes it easier to define flexible mappings
depending on ":jsessionid" path info and JSESSIONID
(and other) cookies.

Modified:
    tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
    tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c

Modified: tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c?view=diff&rev=446925&r1=446924&r2=446925
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Sat Sep 16 12:28:51 
2006
@@ -60,6 +60,7 @@
 #include "jk_ajp13.h"
 #include "jk_shm.h"
 
+#define JK_ENV_WORKER_NAME          ("JK_WORKER_NAME")
 #define JK_NOTE_WORKER_NAME         ("JK_WORKER_NAME")
 #define JK_NOTE_WORKER_TYPE         ("JK_WORKER_TYPE")
 #define JK_NOTE_REQUEST_DURATION    ("JK_REQUEST_DURATION")
@@ -133,6 +134,11 @@
     array_header *format;
 
     /*
+     * Setting target worker via environment
+     */
+   char *worker_indicator;
+
+    /*
      * SSL Support
      */
     int ssl_enable;
@@ -1393,6 +1399,25 @@
 }
 
 /*
+ * JkWorkerIndicator Directive Handling
+ *
+ * JkWorkerIndicator JkWorker
+ */
+
+static const char *jk_set_worker_indicator(cmd_parms * cmd,
+                                           void *dummy, char *indicator)
+{
+    server_rec *s = cmd->server;
+    jk_server_conf_t *conf =
+        (jk_server_conf_t *) ap_get_module_config(s->module_config,
+                                                  &jk_module);
+
+    conf->worker_indicator = ap_pstrdup(cmd->pool, indicator);
+
+    return NULL;
+}
+
+/*
  * JkExtractSSL Directive Handling
  *
  * JkExtractSSL On/Off
@@ -1699,6 +1724,17 @@
      "The mod_jk module automatic context apache alias directory"},
 
     /*
+     * Enable worker name to be set in an environment variable.
+     * this way one can use LocationMatch together with mod_end,
+     * mod_setenvif and mod_rewrite to set the target worker.
+     * Use this in combination with SetHandler jakarta-servlet to
+     * make mod_jk the handler for the request.
+     *
+     */
+    {"JkWorkerIndicator", jk_set_worker_indicator, NULL, RSRC_CONF, TAKE1,
+     "Name of the Apache environment that contains the worker name"},
+
+    /*
      * Apache has multiple SSL modules (for example apache_ssl, stronghold
      * IHS ...). Each of these can have a different SSL environment names
      * The following properties let the administrator specify the envoiroment
@@ -1759,27 +1795,73 @@
 {
     /* Retrieve the worker name stored by jk_translate() */
     const char *worker_name = ap_table_get(r->notes, JK_NOTE_WORKER_NAME);
+    jk_server_conf_t *conf =
+        (jk_server_conf_t *) ap_get_module_config(r->server->
+                                                  module_config,
+                                                  &jk_module);
+    jk_logger_t *l = conf->log ? conf->log : main_log;
     int rc;
 
+    JK_TRACE_ENTER(l);
+
     if (r->proxyreq) {
+        jk_log(l, JK_LOG_ERROR,
+               "Request has proxyreq flag set in mod_jk handler - aborting.");
+        JK_TRACE_EXIT(l);
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
     /* Set up r->read_chunked flags for chunked encoding, if present */
     if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) {
+        jk_log(l, JK_LOG_ERROR,
+               "Could not setup client_block for chunked encoding - aborting");
+        JK_TRACE_EXIT(l);
         return rc;
     }
 
+    if (worker_name == NULL && r->handler && !strcmp(r->handler, JK_HANDLER)) {
+        /* we may be here because of a manual directive ( that overrides
+         * translate and
+         * sets the handler directly ). We still need to know the worker.
+         */
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG,
+                       "Retrieving environment %s", conf->worker_indicator);
+        worker_name = (char *)ap_table_get(r->subprocess_env, 
conf->worker_indicator);
+        if (worker_name) {
+          /* The JkWorkerIndicator environment variable has
+           * been used to explicitely set the worker without JkMount.
+           * This is useful in combination with LocationMatch or mod_rewrite.
+           */
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG,
+                       "Retrieved worker (%s) from env %s for %s",
+                       worker_name, conf->worker_indicator, r->uri);
+        }
+        else if (worker_env.num_of_workers == 1) {
+          /* We have a single worker ( the common case ).
+           * ( lb is a bit special, it should count as a single worker but
+           * I'm not sure how ). We also have a manual config directive that
+           * explicitely give control to us.
+           */
+            worker_name = worker_env.worker_list[0];
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG,
+                       "Single worker (%s) configuration for %s",
+                       worker_name, r->uri);
+        }
+        else if (worker_env.num_of_workers) {
+            worker_name = worker_env.worker_list[0];
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG,
+                       "Using first worker (%s) from %d workers for %s",
+                       worker_name, worker_env.num_of_workers, r->uri);
+        }
+    }
+
     if (worker_name) {
-        jk_server_conf_t *conf =
-            (jk_server_conf_t *) ap_get_module_config(r->server->
-                                                      module_config,
-                                                      &jk_module);
-        jk_logger_t *l = conf->log ? conf->log : main_log;
         jk_worker_t *worker;
 
-        JK_TRACE_ENTER(l);
-
         worker = wc_get_worker_for_name(worker_name, l);
 
         if (worker) {
@@ -1908,6 +1990,7 @@
         }
     }
 
+    JK_TRACE_EXIT(l);
     return HTTP_INTERNAL_SERVER_ERROR;
 }
 
@@ -1933,6 +2016,8 @@
     c->mountcopy = JK_FALSE;
     c->options = JK_OPT_FWDURIDEFAULT;
 
+    c->worker_indicator = JK_ENV_WORKER_NAME;
+
     /*
      * By default we will try to gather SSL info.
      * Disable this functionality through JkExtractSSL
@@ -2003,6 +2088,8 @@
 {
     jk_server_conf_t *base = (jk_server_conf_t *) basev;
     jk_server_conf_t *overrides = (jk_server_conf_t *) overridesv;
+
+    overrides->worker_indicator = base->worker_indicator;
 
     if (base->ssl_enable) {
         overrides->ssl_enable = base->ssl_enable;

Modified: tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c?view=diff&rev=446925&r1=446924&r2=446925
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Sat Sep 16 12:28:51 
2006
@@ -108,6 +108,7 @@
 #include "jk_worker.h"
 #include "jk_shm.h"
 
+#define JK_ENV_WORKER_NAME          ("JK_WORKER_NAME")
 #define JK_NOTE_WORKER_NAME         ("JK_WORKER_NAME")
 #define JK_NOTE_WORKER_TYPE         ("JK_WORKER_TYPE")
 #define JK_NOTE_REQUEST_DURATION    ("JK_REQUEST_DURATION")
@@ -167,6 +168,11 @@
     apr_array_header_t *format;
 
     /*
+     * Setting target worker via environment
+     */
+    char *worker_indicator;
+
+    /*
      * SSL Support
      */
     int ssl_enable;
@@ -1410,6 +1416,25 @@
 
 
 /*
+ * JkWorkerIndicator Directive Handling
+ *
+ * JkWorkerIndicator JkWorker
+ */
+
+static const char *jk_set_worker_indicator(cmd_parms * cmd,
+                                           void *dummy, const char *indicator)
+{
+    server_rec *s = cmd->server;
+    jk_server_conf_t *conf =
+        (jk_server_conf_t *) ap_get_module_config(s->module_config,
+                                                  &jk_module);
+
+    conf->worker_indicator = apr_pstrdup(cmd->pool, indicator);
+
+    return NULL;
+}
+
+/*
  * JkExtractSSL Directive Handling
  *
  * JkExtractSSL On/Off
@@ -1730,6 +1755,17 @@
                   "The mod_jk module automatic context apache alias 
directory"),
 
     /*
+     * Enable worker name to be set in an environment variable.
+     * this way one can use LocationMatch together with mod_end,
+     * mod_setenvif and mod_rewrite to set the target worker.
+     * Use this in combination with SetHandler jakarta-servlet to
+     * make mod_jk the handler for the request.
+     *
+     */
+    AP_INIT_TAKE1("JkWorkerIndicator", jk_set_worker_indicator, NULL, 
RSRC_CONF,
+                  "Name of the Apache environment that contains the worker 
name"),
+
+    /*
      * Apache has multiple SSL modules (for example apache_ssl, stronghold
      * IHS ...). Each of these can have a different SSL environment names
      * The following properties let the administrator specify the envoiroment
@@ -1843,7 +1879,17 @@
            translate and
            sets the handler directly ). We still need to know the worker.
          */
-        if (worker_env.num_of_workers == 1) {
+        if (worker_name = apr_table_get(r->subprocess_env, 
xconf->worker_indicator)) {
+          /* The JkWorkerIndicator environment variable has
+           * been used to explicitely set the worker without JkMount.
+           * This is useful in combination with LocationMatch or mod_rewrite.
+           */
+            if (JK_IS_DEBUG_LEVEL(xconf->log))
+                jk_log(xconf->log, JK_LOG_DEBUG,
+                       "Retrieved worker (%s) from env %s for %s",
+                       worker_name, xconf->worker_indicator, r->uri);
+        }
+        else if (worker_env.num_of_workers == 1) {
           /** We have a single worker ( the common case ).
               ( lb is a bit special, it should count as a single worker but
               I'm not sure how ). We also have a manual config directive that
@@ -2088,6 +2134,8 @@
     c->was_initialized = JK_FALSE;
     c->options = JK_OPT_FWDURIDEFAULT;
 
+    c->worker_indicator = JK_ENV_WORKER_NAME;
+
     /*
      * By default we will try to gather SSL info.
      * Disable this functionality through JkExtractSSL
@@ -2163,6 +2211,8 @@
 {
     jk_server_conf_t *base = (jk_server_conf_t *) basev;
     jk_server_conf_t *overrides = (jk_server_conf_t *) overridesv;
+
+    overrides->worker_indicator = base->worker_indicator;
 
     if (base->ssl_enable) {
         overrides->ssl_enable = base->ssl_enable;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to