⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_jk.c

📁 jboss与apache集成的中间件,详情请参看文档说明.
💻 C
📖 第 1 页 / 共 5 页
字号:
    AP_INIT_TAKE1("JkShmSize", jk_set_shm_size, NULL, RSRC_CONF,                  "Size of the shared memory file in KBytes"),    AP_INIT_TAKE1("JkLogLevel", jk_set_log_level, NULL, RSRC_CONF,                  "The Jakarta Tomcat module log level, can be debug, "                  "info, error or emerg"),    AP_INIT_TAKE1("JkLogStampFormat", jk_set_log_fmt, NULL, RSRC_CONF,                  "The Jakarta Tomcat module log format, follow strftime synthax"),    AP_INIT_TAKE1("JkRequestLogFormat", jk_set_request_log_format, NULL,                  RSRC_CONF,                  "The Jakarta mod_jk module request log format string"),    /*     * Automatically Alias webapp context directories into the Apache     * document space.     */    AP_INIT_TAKE1("JkAutoAlias", jk_set_auto_alias, NULL, RSRC_CONF,                  "The Jakarta mod_jk module automatic context apache alias directory"),    /*     * 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     * variables names.     *     * HTTPS - indication for SSL     * CERTS - Base64-Der-encoded client certificates.     * CIPHER - A string specifing the ciphers suite in use.     * KEYSIZE - Size of Key used in dialogue (#bits are secure)     * SESSION - A string specifing the current SSL session.     */    AP_INIT_TAKE1("JkHTTPSIndicator", jk_set_https_indicator, NULL, RSRC_CONF,                  "Name of the Apache environment that contains SSL indication"),    AP_INIT_TAKE1("JkCERTSIndicator", jk_set_certs_indicator, NULL, RSRC_CONF,                  "Name of the Apache environment that contains SSL client certificates"),    AP_INIT_TAKE1("JkCIPHERIndicator", jk_set_cipher_indicator, NULL,                  RSRC_CONF,                  "Name of the Apache environment that contains SSL client cipher"),    AP_INIT_TAKE1("JkSESSIONIndicator", jk_set_session_indicator, NULL,                  RSRC_CONF,                  "Name of the Apache environment that contains SSL session"),    AP_INIT_TAKE1("JkKEYSIZEIndicator", jk_set_key_size_indicator, NULL,                  RSRC_CONF,                  "Name of the Apache environment that contains SSL key size in use"),    AP_INIT_FLAG("JkExtractSSL", jk_set_enable_ssl, NULL, RSRC_CONF,                 "Turns on SSL processing and information gathering by mod_jk"),    /*     * Options to tune mod_jk configuration     * for now we understand :     * +ForwardSSLKeySize        => Forward SSL Key Size, to follow 2.3 specs but may broke old TC 3.2     * -ForwardSSLKeySize        => Don't Forward SSL Key Size, will make mod_jk works with all TC release     *  ForwardURICompat         => Forward URI normally, less spec compliant but mod_rewrite compatible (old TC)     *  ForwardURICompatUnparsed => Forward URI as unparsed, spec compliant but broke mod_rewrite (old TC)     *  ForwardURIEscaped        => Forward URI escaped and Tomcat (3.3 rc2) stuff will do the decoding part     */    AP_INIT_RAW_ARGS("JkOptions", jk_set_options, NULL, RSRC_CONF,                     "Set one of more options to configure the mod_jk module"),    /*     * JkEnvVar let user defines envs var passed from WebServer to     * Servlet Engine     */    AP_INIT_TAKE2("JkEnvVar", jk_add_env_var, NULL, RSRC_CONF,                  "Adds a name of environment variable that should be sent "                  "to servlet-engine"),    AP_INIT_RAW_ARGS("JkWorkerProperty", jk_set_worker_property,                     NULL, RSRC_CONF,                     "Set workers.properties formated directive"),    {NULL}};/* ========================================================================= *//* The JK module handlers                                                    *//* ========================================================================= *//** Util - cleanup shmem. */static apr_status_t jk_cleanup_shmem(void *data){    jk_logger_t *l = data;    jk_shm_close();    if (l && JK_IS_DEBUG_LEVEL(l))       jk_log(l, JK_LOG_DEBUG, "Shmem cleanup");    return 0;}/** Main service method, called to forward a request to tomcat */static int jk_handler(request_rec * r){    const char *worker_name;    jk_server_conf_t *xconf;    int rc, dmt = 1;    /* We do DIR_MAGIC_TYPE here to make sure TC gets all requests, even     * if they are directory requests, in case there are no static files     * visible to Apache and/or DirectoryIndex was not used. This is only     * used when JkOptions has ForwardDirectories set. */    /* Not for me, try next handler */    if (strcmp(r->handler, JK_HANDLER)        && (dmt = strcmp(r->handler, DIR_MAGIC_TYPE)))        return DECLINED;    xconf = (jk_server_conf_t *) ap_get_module_config(r->server->module_config,                                                      &jk_module);    JK_TRACE_ENTER(xconf->log);    if (apr_table_get(r->subprocess_env, "no-jk")) {        jk_log(xconf->log, JK_LOG_DEBUG,               "Into handler no-jk env var detected for uri=%s, declined",               r->uri);        JK_TRACE_EXIT(xconf->log);        return DECLINED;    }    /* Was the option to forward directories to Tomcat set? */    if (!dmt && !(xconf->options & JK_OPT_FWDDIRS)) {        JK_TRACE_EXIT(xconf->log);        return DECLINED;    }    worker_name = apr_table_get(r->notes, JK_WORKER_ID);    /* 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 == NULL) {        /* 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 (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(xconf->log))                jk_log(xconf->log, JK_LOG_DEBUG,                       "Single worker (%s) configuration for %s",                       worker_name, r->uri);        }        else {            worker_name = map_uri_to_worker(xconf->uw_map, r->uri, xconf->log);            if (worker_name == NULL && worker_env.num_of_workers) {                worker_name = worker_env.worker_list[0];                if (JK_IS_DEBUG_LEVEL(xconf->log))                    jk_log(xconf->log, JK_LOG_DEBUG,                           "Using first worker (%s) from %d workers for %s",                           worker_name, worker_env.num_of_workers, r->uri);            }        }        if (worker_name)            apr_table_setn(r->notes, JK_WORKER_ID, worker_name);    }    if (JK_IS_DEBUG_LEVEL(xconf->log))       jk_log(xconf->log, JK_LOG_DEBUG, "Into handler %s worker=%s"              " r->proxyreq=%d",              r->handler, worker_name, r->proxyreq);    /* 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"              " is not allowed",              worker_name);        JK_TRACE_EXIT(xconf->log);        return HTTP_INTERNAL_SERVER_ERROR;    }    if (worker_name) {        jk_worker_t *worker = wc_get_worker_for_name(worker_name, xconf->log);        /* If the remote client has aborted, just ignore the request */        if (r->connection->aborted) {            jk_log(xconf->log, JK_LOG_INFO, "Client connection aborted for"                   " worker=%s",                   worker_name);            JK_TRACE_EXIT(xconf->log);            return OK;        }        if (worker) {#ifndef NO_GETTIMEOFDAY            struct timeval tv_begin, tv_end;#endif            int is_error = HTTP_INTERNAL_SERVER_ERROR;            int rc = JK_FALSE;            apache_private_data_t private_data;            jk_ws_service_t s;            jk_pool_atom_t buf[SMALL_POOL_SIZE];            jk_open_pool(&private_data.p, buf, sizeof(buf));            private_data.response_started = JK_FALSE;            private_data.read_body_started = JK_FALSE;            private_data.r = r;            wc_maintain(xconf->log);            jk_init_ws_service(&s);            /* Update retries for this worker */            s.retries = worker->retries;            s.ws_private = &private_data;            s.pool = &private_data.p;#ifndef NO_GETTIMEOFDAY            if (xconf->format != NULL) {                gettimeofday(&tv_begin, NULL);            }#endif            if (init_ws_service(&private_data, &s, xconf)) {                jk_endpoint_t *end = NULL;                /* Use per/thread pool ( or "context" ) to reuse the                   endpoint. It's a bit faster, but I don't know                   how to deal with load balancing - but it's usefull for JNI                 */                /* worker->get_endpoint might fail if we are out of memory so check */                /* and handle it */                if (worker->get_endpoint(worker, &end, xconf->log)) {                    rc = end->service(end, &s, xconf->log,                                      &is_error);                    end->done(&end, xconf->log);                    if (s.content_read < s.content_length ||                        (s.is_chunked && !s.no_more_chunks)) {                        /*                         * If the servlet engine didn't consume all of the                         * request data, consume and discard all further                         * characters left to read from client                         */                        char *buff = apr_palloc(r->pool, 2048);                        if (buff != NULL) {                            int rd;                            while ((rd =                                    ap_get_client_block(r, buff, 2048)) > 0) {                                s.content_read += rd;                            }                        }                    }                }                else {            /* this means we couldn't get an endpoint */                    jk_log(xconf->log, JK_LOG_ERROR, "Could not get endpoint"                           " for worker=%s",                           worker_name);                    rc = 0;       /* just to make sure that we know we've failed */                }            }            else {                jk_log(xconf->log, JK_LOG_ERROR, "Could not init service"                       " for worker=%s",                       worker_name);                jk_close_pool(&private_data.p);                JK_TRACE_EXIT(xconf->log);                return HTTP_INTERNAL_SERVER_ERROR;            }#ifndef NO_GETTIMEOFDAY            if (xconf->format != NULL) {                char *duration = NULL;                long micro, seconds;                gettimeofday(&tv_end, NULL);                if (tv_end.tv_usec < tv_begin.tv_usec) {                    tv_end.tv_usec += 1000000;                    tv_end.tv_sec--;                }                micro = tv_end.tv_usec - tv_begin.tv_usec;                seconds = tv_end.tv_sec - tv_begin.tv_sec;                duration = apr_psprintf(r->pool, "%.1ld.%.6ld", seconds, micro);                apr_table_setn(r->notes, JK_DURATION, duration);                request_log_transaction(r, xconf);            }#endif            jk_close_pool(&private_data.p);            if (rc > 0) {                /* If tomcat returned no body and the status is not OK,                   let apache handle the error code */                if (!r->sent_bodyct && r->status >= HTTP_BAD_REQUEST) {                    jk_log(xconf->log, JK_LOG_INFO, "No body with status=%d"                           " for worker=%s",                           r->status, worker_name);                    JK_TRACE_EXIT(xconf->log);                    return r->status;                }                if (JK_IS_DEBUG_LEVEL(xconf->log))                    jk_log(xconf->log, JK_LOG_DEBUG, "Service finished"                           " with status=%d for worker=%s",                           r->status, worker_name);                JK_TRACE_EXIT(xconf->log);                return OK;      /* NOT r->status, even if it has changed. */            }            else if (rc == JK_CLIENT_ERROR) {                if (is_error != HTTP_REQUEST_ENTITY_TOO_LARGE)                    r->connection->aborted = 1;                jk_log(xconf->log, JK_LOG_INFO, "Aborting connection"                       " for worker=%s",                       worker_name);                JK_TRACE_EXIT(xconf->log);                return is_error;            }            else {                jk_log(xconf->log, JK_LOG_INFO, "Service error=%d"                       " for worker=%s",                       rc, worker_name);                JK_TRACE_EXIT(xconf->log);                return is_error;            }        }        else {            jk_log(xconf->log, JK_LOG_INFO, "Could not find a worker"                   " for worker name=%s",                   worker_name);            JK_TRACE_EXIT(xconf->log);            return HTTP_INTERNAL_SERVER_ERROR;        }    }    JK_TRACE_EXIT(xconf->log);    return DECLINED;}/** Standard apache hook, cleanup jk */static apr_status_t jk_apr_pool_cleanup(void *data){    server_rec *s = data;    while (NULL != s) {        jk_server_conf_t *conf =            (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                      &jk_module);        if (conf && conf->worker_properties) {            /* On pool cleanup pass NULL for the jk_logger to               prevent segmentation faults on Windows because               we can't guarantee what order pools get cleaned               up between APR implementations. */            if (conf->was_initialized)                wc_close(NULL);            if (conf->worker_properties)                jk_map_free(&conf->worker_properties);            if (conf->uri_to_context)                jk_map_free(&conf->uri_to_context);            if (conf->automount)                jk_map_free(&conf->automount);            if (conf->uw_map)                uri_worker_map_free(&conf->uw_map, NULL);            conf->was_initialized   = JK_FALSE;            conf->worker_properties = NULL;        }        s = s->next;    }    return APR_SUCCESS;}/** Create default jk_config. XXX This is mostly server-independent,    all servers are using something similar - should go to common. */static void *create_jk_config(apr_pool_t * p, server_rec * s){    jk_server_conf_t *c =        (jk_server_conf_t *) apr_pcalloc(p, sizeof(jk_server_conf_t));    c->worker_properties = NULL;    jk_map_alloc(&c->worker_properties);    c->worker_file = NULL;    c->mount_file = NULL;    c->log_file = NULL;    c->log_level = -1;    c->log = NULL;    c->alias_dir = NULL;    c->format_string = NULL;    c->format = NULL;    c->mountcopy = JK_FALSE;    c->was_initialized = JK_FALSE;    c->options = JK_OPT_FWDURIDEFAULT;    /*     * By default we will try to gather SSL info.     * Disable this functionality through JkExtractSSL     */    c->ssl_enable = JK_TRUE;    /*     * The defaults ssl indicators match those in mod_ssl (seems     * to be in more use).     */    c->https_indicator = "HTTPS";    c->certs_indicator = "SSL_CLIENT_CERT";    /*     * The following (comented out) environment variables match apache_ssl!     * If you are using apache_sslapache_ssl uncomment them (or use the     * configuration directives to set them.     *     c->cipher_indicator = "HTTPS_CIPHER";     c->session_indicator = NULL;     */    /*     * The following environment variables match mod_ssl! If you     * are using another module (say apache_ssl) comment them out.     */    c->cipher_indicator = "SSL_CIPHER";    c->session_indicator = "SSL_SESSION_ID

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -