Author: rjung
Date: Sun Oct 23 15:31:26 2011
New Revision: 1187906
URL: http://svn.apache.org/viewvc?rev=1187906&view=rev
Log:
Fix BZ 52056: HTTPD: JK request log does not always log
correct response status. Fixed by refactoring JK request
log to use the standard request log hook. (rjung)
Modified:
tomcat/jk/trunk/native/apache-1.3/mod_jk.c
tomcat/jk/trunk/native/apache-2.0/mod_jk.c
tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
Modified: tomcat/jk/trunk/native/apache-1.3/mod_jk.c
URL:
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/apache-1.3/mod_jk.c?rev=1187906&r1=1187905&r2=1187906&view=diff
==============================================================================
--- tomcat/jk/trunk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/jk/trunk/native/apache-1.3/mod_jk.c Sun Oct 23 15:31:26 2011
@@ -214,6 +214,15 @@ typedef struct
/*
+ * Request specific configuration
+ */
+typedef struct
+{
+ rule_extension_t *rule_extensions;
+ int jk_handled;
+} jk_request_conf_t;
+
+/*
* The "private", or subclass portion of the web server service class for
* Apache 1.3. An instance of this class is created for each request
* handled. See jk_service.h for details about the ws_service object in
@@ -729,7 +738,9 @@ static int init_ws_service(apache_privat
if (conf->options & JK_OPT_FLUSHEADER)
s->flush_header = 1;
- e = (rule_extension_t *)ap_get_module_config(r->request_config,
&jk_module);
+ jk_request_conf_t *rconf = (jk_request_conf_t
*)ap_get_module_config(r->request_config,
+
&jk_module);
+ e = rconf->rule_extensions;
if (e) {
s->extension.reply_timeout = e->reply_timeout;
s->extension.sticky_ignore = e->sticky_ignore;
@@ -1431,7 +1442,7 @@ static const char *process_item(request_
return cp ? cp : "-";
}
-static void request_log_transaction(request_rec * r, jk_server_conf_t * conf)
+static int request_log_transaction(request_rec * r)
{
request_log_format_item *items;
char *str, *s;
@@ -1439,7 +1450,21 @@ static void request_log_transaction(requ
int len = 0;
const char **strs;
int *strl;
- array_header *format = conf->format;
+ jk_server_conf_t *conf;
+ jk_request_conf_t *rconf;
+ array_header *format;
+
+ conf = (jk_server_conf_t *) ap_get_module_config(r->server->module_config,
+ &jk_module);
+ format = conf->format;
+ if (format == NULL) {
+ return DECLINED;
+ }
+ rconf = (jk_request_conf_t *)ap_get_module_config(r->request_config,
+ &jk_module);
+ if (rconf == NULL || rconf->jk_handled == JK_FALSE) {
+ return DECLINED;
+ }
strs = ap_palloc(r->pool, sizeof(char *) * (format->nelts));
strl = ap_palloc(r->pool, sizeof(int) * (format->nelts));
@@ -1457,6 +1482,7 @@ static void request_log_transaction(requ
}
*s = 0;
jk_log(conf->log, JK_LOG_REQUEST, "%s", str);
+ return OK;
}
/*****************************************************************
@@ -2332,8 +2358,10 @@ static int jk_handler(request_rec * r)
(jk_server_conf_t *) ap_get_module_config(r->server->
module_config,
&jk_module);
+ jk_request_conf_t *rconf;
+
/* Retrieve the worker name stored by jk_translate() */
- const char *worker_name = ap_table_get(r->notes, JK_NOTE_WORKER_NAME);
+ const char *worker_name;
int rc;
JK_TRACE_ENTER(conf->log);
@@ -2347,20 +2375,7 @@ static int jk_handler(request_rec * r)
return DECLINED;
}
- if (r->proxyreq) {
- jk_log(conf->log, JK_LOG_ERROR,
- "Request has proxyreq flag set in mod_jk handler - aborting.");
- JK_TRACE_EXIT(conf->log);
- 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(conf->log, JK_LOG_ERROR,
- "Could not setup client_block for chunked encoding - aborting");
- JK_TRACE_EXIT(conf->log);
- return rc;
- }
+ worker_name = ap_table_get(r->notes, JK_NOTE_WORKER_NAME);
if (worker_name == NULL && r->handler && !strcmp(r->handler, JK_HANDLER)) {
/* we may be here because of a manual directive ( that overrides
@@ -2402,6 +2417,30 @@ static int jk_handler(request_rec * r)
}
}
+ if (JK_IS_DEBUG_LEVEL(conf->log))
+ jk_log(conf->log, JK_LOG_DEBUG, "Into handler %s worker=%s"
+ " r->proxyreq=%d",
+ r->handler, STRNULL_FOR_NULL(worker_name), r->proxyreq);
+
+ rconf = (jk_request_conf_t *)ap_get_module_config(r->request_config,
+ &jk_module);
+ rconf->jk_handled = JK_TRUE;
+
+ if (r->proxyreq) {
+ jk_log(conf->log, JK_LOG_ERROR,
+ "Request has proxyreq flag set in mod_jk handler - aborting.");
+ JK_TRACE_EXIT(conf->log);
+ 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(conf->log, JK_LOG_ERROR,
+ "Could not setup client_block for chunked encoding - aborting");
+ JK_TRACE_EXIT(conf->log);
+ return rc;
+ }
+
if (worker_name) {
jk_worker_t *worker;
@@ -2471,9 +2510,6 @@ static int jk_handler(request_rec * r)
#endif
if (s.route && *s.route)
ap_table_setn(r->notes, JK_NOTE_WORKER_ROUTE, s.route);
- if (conf->format != NULL) {
- request_log_transaction(r, conf);
- }
}
else {
jk_log(conf->log, JK_LOG_ERROR, "Could not init service"
@@ -3032,7 +3068,10 @@ static void jk_init(server_rec * s, ap_p
*/
static int jk_translate(request_rec * r)
{
- ap_set_module_config(r->request_config, &jk_module, NULL);
+ jk_request_conf_t *rconf = ap_palloc(r->pool, sizeof(jk_request_conf_t));
+ rconf->jk_handled = JK_FALSE;
+ rconf->rule_extensions = NULL;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
if (!r->proxyreq) {
jk_server_conf_t *conf =
@@ -3065,7 +3104,8 @@ static int jk_translate(request_rec * r)
rule_extension_t *e;
worker = map_uri_to_worker_ext(conf->uw_map, clean_uri,
NULL, &e, NULL, conf->log);
- ap_set_module_config(r->request_config, &jk_module, e);
+ rconf->rule_extensions = e;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
}
/* Don't know the worker, ForwardDirectories is set, there is a
@@ -3365,7 +3405,7 @@ module MODULE_VAR_EXPORT jk_module = {
NULL, /* [4] check access by host address */
NULL, /* XXX [7] MIME type checker/setter */
jk_fixups, /* [8] fixups */
- NULL, /* [10] logger */
+ request_log_transaction, /* [10] logger */
NULL, /* [3] header parser */
child_init_handler, /* apache child process initializer */
child_exit_handler, /* apache child process exit/cleanup */
Modified: tomcat/jk/trunk/native/apache-2.0/mod_jk.c
URL:
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/apache-2.0/mod_jk.c?rev=1187906&r1=1187905&r2=1187906&view=diff
==============================================================================
--- tomcat/jk/trunk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/jk/trunk/native/apache-2.0/mod_jk.c Sun Oct 23 15:31:26 2011
@@ -243,6 +243,15 @@ typedef struct
server_rec *s;
} jk_server_conf_t;
+/*
+ * Request specific configuration
+ */
+typedef struct
+{
+ rule_extension_t *rule_extensions;
+ int jk_handled;
+} jk_request_conf_t;
+
struct apache_private_data
{
jk_pool_t p;
@@ -783,7 +792,9 @@ static int init_ws_service(apache_privat
if (conf->options & JK_OPT_FLUSHEADER)
s->flush_header = 1;
- e = (rule_extension_t *)ap_get_module_config(r->request_config,
&jk_module);
+ jk_request_conf_t *rconf = (jk_request_conf_t
*)ap_get_module_config(r->request_config,
+
&jk_module);
+ e = rconf->rule_extensions;
if (e) {
s->extension.reply_timeout = e->reply_timeout;
s->extension.sticky_ignore = e->sticky_ignore;
@@ -1526,7 +1537,7 @@ static const char *process_item(request_
return cp ? cp : "-";
}
-static void request_log_transaction(request_rec * r, jk_server_conf_t * conf)
+static int request_log_transaction(request_rec * r)
{
request_log_format_item *items;
char *str, *s;
@@ -1534,7 +1545,21 @@ static void request_log_transaction(requ
int len = 0;
const char **strs;
int *strl;
- apr_array_header_t *format = conf->format;
+ jk_server_conf_t *conf;
+ jk_request_conf_t *rconf;
+ apr_array_header_t *format;
+
+ conf = (jk_server_conf_t *) ap_get_module_config(r->server->module_config,
+ &jk_module);
+ format = conf->format;
+ if (format == NULL) {
+ return DECLINED;
+ }
+ rconf = (jk_request_conf_t *)ap_get_module_config(r->request_config,
+ &jk_module);
+ if (rconf == NULL || rconf->jk_handled == JK_FALSE) {
+ return DECLINED;
+ }
strs = apr_palloc(r->pool, sizeof(char *) * (format->nelts));
strl = apr_palloc(r->pool, sizeof(int) * (format->nelts));
@@ -1553,6 +1578,7 @@ static void request_log_transaction(requ
*s = 0;
jk_log(conf->log, JK_LOG_REQUEST, "%s", str);
+ return OK;
}
@@ -2473,6 +2499,7 @@ static int jk_handler(request_rec * r)
{
const char *worker_name;
jk_server_conf_t *xconf;
+ jk_request_conf_t *rconf;
int rc, dmt = 1;
/* We do DIR_MAGIC_TYPE here to make sure TC gets all requests, even
@@ -2502,13 +2529,8 @@ static int jk_handler(request_rec * r)
JK_TRACE_EXIT(xconf->log);
return DECLINED;
}
- worker_name = apr_table_get(r->notes, JK_NOTE_WORKER_NAME);
- /* Set up r->read_chunked flags for chunked encoding, if present */
- if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) !=
APR_SUCCESS) {
- JK_TRACE_EXIT(xconf->log);
- return rc;
- }
+ worker_name = apr_table_get(r->notes, JK_NOTE_WORKER_NAME);
if (worker_name == NULL) {
/* we may be here because of a manual directive ( that overrides
@@ -2549,7 +2571,9 @@ static int jk_handler(request_rec * r)
rule_extension_t *e;
worker_name = map_uri_to_worker_ext(xconf->uw_map, r->uri,
NULL, &e, NULL,
xconf->log);
- ap_set_module_config(r->request_config, &jk_module, e);
+ rconf = (jk_request_conf_t
*)ap_get_module_config(r->request_config,
+ &jk_module);
+ rconf->rule_extensions = e;
}
if (worker_name == NULL && worker_env.num_of_workers) {
@@ -2569,6 +2593,10 @@ static int jk_handler(request_rec * r)
" r->proxyreq=%d",
r->handler, STRNULL_FOR_NULL(worker_name), r->proxyreq);
+ rconf = (jk_request_conf_t *)ap_get_module_config(r->request_config,
+ &jk_module);
+ rconf->jk_handled = JK_TRUE;
+
/* If this is a proxy request, we'll notify an error */
if (r->proxyreq) {
jk_log(xconf->log, JK_LOG_INFO, "Proxy request for worker=%s"
@@ -2578,6 +2606,12 @@ static int jk_handler(request_rec * r)
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)) !=
APR_SUCCESS) {
+ JK_TRACE_EXIT(xconf->log);
+ return rc;
+ }
+
if (worker_name) {
jk_worker_t *worker = wc_get_worker_for_name(worker_name, xconf->log);
@@ -2678,10 +2712,6 @@ static int jk_handler(request_rec * r)
if (s.route && *s.route)
apr_table_setn(r->notes, JK_NOTE_WORKER_ROUTE, s.route);
- if (xconf->format != NULL) {
- request_log_transaction(r, xconf);
- }
-
jk_close_pool(&private_data.p);
if (rc > 0) {
@@ -2737,6 +2767,7 @@ static int jk_handler(request_rec * r)
}
}
+ rconf->jk_handled = JK_FALSE;
JK_TRACE_EXIT(xconf->log);
return DECLINED;
}
@@ -3465,7 +3496,10 @@ static int jk_post_config(apr_pool_t * p
*/
static int jk_translate(request_rec * r)
{
- ap_set_module_config(r->request_config, &jk_module, NULL);
+ jk_request_conf_t *rconf = apr_palloc(r->pool, sizeof(jk_request_conf_t));
+ rconf->jk_handled = JK_FALSE;
+ rconf->rule_extensions = NULL;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
if (!r->proxyreq) {
jk_server_conf_t *conf =
@@ -3541,7 +3575,8 @@ static int jk_translate(request_rec * r)
rule_extension_t *e;
worker = map_uri_to_worker_ext(conf->uw_map, r->uri,
NULL, &e, NULL, conf->log);
- ap_set_module_config(r->request_config, &jk_module, e);
+ rconf->rule_extensions = e;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
}
if (worker) {
@@ -3662,6 +3697,14 @@ static int jk_translate(request_rec * r)
static int jk_map_to_storage(request_rec * r)
{
+ jk_request_conf_t *rconf = ap_get_module_config(r->request_config,
&jk_module);
+ if (rconf == NULL) {
+ jk_request_conf_t *rconf = apr_palloc(r->pool,
sizeof(jk_request_conf_t));
+ rconf->jk_handled = JK_FALSE;
+ rconf->rule_extensions = NULL;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
+ }
+
if (!r->proxyreq && !apr_table_get(r->notes, JK_NOTE_WORKER_NAME)) {
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(r->server->
@@ -3700,7 +3743,8 @@ static int jk_map_to_storage(request_rec
rule_extension_t *e;
worker = map_uri_to_worker_ext(conf->uw_map, r->uri,
NULL, &e, NULL, conf->log);
- ap_set_module_config(r->request_config, &jk_module, e);
+ rconf->rule_extensions = e;
+ ap_set_module_config(r->request_config, &jk_module, rconf);
}
if (worker) {
@@ -3776,11 +3820,12 @@ static int jk_map_to_storage(request_rec
static void jk_register_hooks(apr_pool_t * p)
{
- ap_hook_handler(jk_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(jk_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(jk_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_translate_name(jk_translate, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_map_to_storage(jk_map_to_storage, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_handler(jk_handler, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_log_transaction(request_log_transaction, NULL, NULL,
APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA jk_module = {
Modified: tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml?rev=1187906&r1=1187905&r2=1187906&view=diff
==============================================================================
--- tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml Sun Oct 23 15:31:26 2011
@@ -44,6 +44,11 @@
<br />
<subsection name="Native">
<changelog>
+ <fix>
+ <bug>52056</bug>: HTTPD: JK request log does not always log
+ correct response status. Fixed by refactoring JK request
+ log to use the standard request log hook. (rjung)
+ </fix>
<add>
HTTPD: Allow to choose a sticky worker using the environment
variable JK_ROUTE. This can be used if sessions and routes
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]