tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <christopher.d.schu...@comcast.net>
Subject Re: Apache http / mod_rewrite / mod_jk [hacked SOLUTION]
Date Thu, 08 Apr 2004 14:17:33 GMT
All,
Here is my solution to the jsessionid issue discussed in this thread.

The problem is that when Tomcat encodes URLs without knowing if the 
browser supports cookies, it adds ";jsessionid=BLAHBLAH" to each encoded 
URL. This is perfectly normal behavior.

However, when using Apache httpd, Apache does not properly handle the 
addition of the ";jsessionid" information, and fails to serve up the 
proper file.

One of the simplest solutions is to simply pass requests including the 
jsessionid information to Tomcat and let Tomcat handle them.

mod_jk does not support this type of behavior, since it only does simple 
context matches (like /context/*", suffix-based context matches 
(/context/*.suffix) or exact matches (/context/j_security_check).

I have modified mod_jk to allow URIs of this special form:

/context/*;jsessionid*

So you can actually do this in your configuration file:

JkMount /context/*;jsessionid* my_worker

The syntax matches what I figured was the most natural way to write this 
in a configuration file. Note that this fix does not actually let you 
use wildcards as flexibly as the config directive would lead you to 
believe. It only works with the specific string "*;jsessionid*" after 
the context and slash character.

Below is the diff for jk_uri_worker_map.c. It works on my configuration. 
I hope it may help others. I would love to receive any constructive 
criticism of this patch. Feel free to email me directly.

All the best,
-chris

=================================================================
[chris@chadis common]$ diff -bc jk_uri_worker_map.c jk_uri_worker_map.c.new
*** jk_uri_worker_map.c 2003-09-06 11:37:21.000000000 -0400
--- jk_uri_worker_map.c.new     2004-04-08 10:07:36.000000000 -0400
***************
*** 80,85 ****
--- 80,86 ----
   #define MATCH_TYPE_GENERAL_SUFFIX (3) /* match all URIs of the form 
*ext */
   /* match all context path URIs with a path component suffix */
   #define MATCH_TYPE_CONTEXT_PATH (4)
+ #define MATCH_TYPE_JSESSIONID (5) /* match all URLs that contains a 
jsessionid */

   struct uri_worker_record {
       /* Original uri for logging */
***************
*** 300,305 ****
--- 301,316 ----
                              "Into 
jk_uri_worker_map_t::uri_worker_map_open, "
                            "suffix rule %s.%s=%s was added\n",
                               uri, asterisk + 3, worker);
+               } else if(0 == strncmp("/*" JK_PATH_SESSION_IDENTIFIER 
"*",asterisk,14) ) {
+                 /* jsessionid interceptor */
+                 asterisk[1] = '\0';
+                   uwr->worker_name = worker;
+                   uwr->context = uri;
+                   uwr->match_type = MATCH_TYPE_JSESSIONID;
+                   jk_log(l, JK_LOG_DEBUG,
+                          "Into jk_uri_worker_map_t::uri_worker_map_open, "
+                          "jsessionid rule %s*;jsessionid*=%s was added\n",
+                          uri, worker);
                 } else if ('\0' != asterisk[2]) {
                     /* general suffix rule */
                     asterisk[1] = '\0';
***************
*** 478,483 ****
--- 489,522 ----
       *d = '\0';
   }

+ uri_worker_record_t *check_jsessionid_matches(char *uri,
+                                             jk_uri_worker_map_t *uw_map,
+                                             jk_logger_t *l)
+ {
+   unsigned i;
+   uri_worker_record_t *match = NULL;
+
+   for(i = 0 ; i < uw_map->size ; i++) {
+     uri_worker_record_t *uwr = uw_map->maps[i];
+
+     if(MATCH_TYPE_JSESSIONID == uwr->match_type) {
+       /* Check context match */
+
+       if(0 == strncmp(uwr->context,
+                     uri,
+                     uwr->ctxt_len)) {
+       /* Looks like a match: URI contains ";jsessionid", context 
matches */
+
+       jk_log(l, JK_LOG_DEBUG, "check_jsessionid_matches: Found context 
match: %s\n", uwr->context);
+
+       match = uwr;
+       break;
+       }
+     } /* MATCH_TYPE_JSESSIONID */
+   } /* foreach mapping */
+
+   return match;
+ }

   char *map_uri_to_worker(jk_uri_worker_map_t *uw_map,
                           char *uri,
***************
*** 493,498 ****
--- 532,544 ----
           char *url_rewrite = strstr(uri, JK_PATH_SESSION_IDENTIFIER);

           if(url_rewrite) {
+         uri_worker_record_t *match = check_jsessionid_matches(uri, 
uw_map, l);
+         if(NULL != match) {
+           jk_log(l, JK_LOG_DEBUG, "Mapped URI %s to context %s using 
jsessionid match\n", uri, match->context);
+
+           return match->worker_name;
+         }
+
           *url_rewrite = '\0';
           }
           jk_no2slash(uri);

Mime
View raw message