/** * Handle a request. */ static int caucho_request(request_rec *r, config_t *config, resin_host_t *host, unsigned int now) { stream_t s; int retval; int code = -1; int session_index; int backup_index = 0; char *ip; srun_t *srun; if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) return retval; session_index = get_session_index(config, r, &backup_index); ip = r->connection->REMOTE_IP; if (host) { } else if (config->manual_host) { host = config->manual_host; } else { host = cse_match_host(config, ap_get_server_name(r), ap_get_server_port(r), now); } LOG(("%s:%d:caucho_request(): session index: %d\n", __FILE__, __LINE__, session_index)); if (! host) { ERR(("%s:%d:caucho_request(): no host: %p\n", __FILE__, __LINE__, host)); return HTTP_SERVICE_UNAVAILABLE; } else if (! cse_open_connection(&s, &host->cluster, session_index, backup_index, now, r->pool)) { ERR(("%s:%d:caucho_request(): no connection: cluster(%p)\n", __FILE__, __LINE__, &host->cluster)); return HTTP_SERVICE_UNAVAILABLE; } srun = s.cluster_srun->srun; apr_thread_mutex_lock(srun->lock); srun->active_sockets++; apr_thread_mutex_unlock(srun->lock); code = write_request(&s, r, config, session_index, backup_index); apr_thread_mutex_lock(srun->lock); srun->active_sockets--; apr_thread_mutex_unlock(srun->lock); /* on failure, do not failover but simply fail */ if (code == HMUX_QUIT) cse_free_idle(&s, now); else cse_close(&s, "no reuse"); if (code != HMUX_QUIT && code != HMUX_EXIT) { ERR(("%s:%d:caucho_request(): protocol failure code:%d\n", __FILE__, __LINE__, code)); return HTTP_SERVICE_UNAVAILABLE; } else if (r->status == HTTP_SERVICE_UNAVAILABLE) { cse_close(&s, "close from 503"); cse_srun_unavail(srun, now); return HTTP_SERVICE_UNAVAILABLE; } else { /* * See pages like jms/index.xtp int status = r->status; r->status = HTTP_OK; return status; */ return OK; } }
/** * Handle a request. */ static int caucho_request(request_rec *r) { config_t *config = cse_get_module_config(r); resin_host_t *host = 0; stream_t s; int retval; int keepalive = 0; int reuse; int session_index; int backup_index; char *ip; time_t now = r->request_time; char *session_id = 0; if (! config) return HTTP_SERVICE_UNAVAILABLE; if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) return retval; /* ap_soft_timeout("servlet request", r); */ if (r->request_config && ! *config->alt_session_url_prefix && ((session_id = ap_get_module_config(r->request_config, &caucho_module)) || r->prev && (session_id = ap_get_module_config(r->prev->request_config, &caucho_module)))) { /* *session_id = *config->session_url_prefix; */ } session_index = get_session_index(config, r, &backup_index); ip = r->connection->remote_ip; if (host) { } else if (config->manual_host) host = config->manual_host; else { host = cse_match_host(config, ap_get_server_name(r), ap_get_server_port(r), now); } if (! host || ! cse_open_connection(&s, &host->cluster, session_index, backup_index, now, r->pool)) { return HTTP_SERVICE_UNAVAILABLE; } reuse = write_request(&s, r, config, &host->cluster, &keepalive, session_index, backup_index, ip, session_id); /* ap_kill_timeout(r); */ ap_rflush(r); if (reuse == HMUX_QUIT) cse_recycle(&s, now); else cse_close(&s, "no reuse"); if (reuse == HTTP_SERVICE_UNAVAILABLE) return reuse; else return OK; }
static void caucho_host_status(request_rec *r, config_t *config, resin_host_t *host) { web_app_t *app; location_t *loc; unsigned int now = time(0); /* check updates as appropriate */ cse_match_host(config, host->name, host->port, now); if (host->canonical == host) ap_rprintf(r, "<h2>"); else ap_rprintf(r, "<h3>"); if (! host->has_data) ap_rprintf(r, "Unconfigured "); if (host->canonical != host) ap_rprintf(r, "Alias "); if (! *host->name) ap_rprintf(r, "Default Virtual Host"); else if (host->port) ap_rprintf(r, "Virtual Host: %s:%d", host->name, host->port); else ap_rprintf(r, "Virtual Host: %s", host->name); if (host->canonical == host) { } else if (! host->canonical) ap_rprintf(r, " -> <font color='red'>null</font>"); else if (host->canonical->port) ap_rprintf(r, " -> %s:%d", host->canonical->name, host->canonical->port); else if (! host->canonical->name[0]) ap_rprintf(r, " -> default"); else ap_rprintf(r, " -> %s", host->canonical->name); if (host->canonical == host) ap_rprintf(r, "</h2>"); else ap_rprintf(r, "</h3>"); if (host->error_message[0]) ap_rprintf(r, "<h3 color='red'>Error: %s</h3>\n", host->error_message); ap_rprintf(r, "<p style='margin-left:2em'>"); if (host->config_source[0]) { ap_rprintf(r, "<b>Source:</b> %s<br />\n", host->config_source); } ap_rprintf(r, "<b>Last-Update:</b> %s</p><br />\n", ctime(&host->last_update_time)); ap_rprintf(r, "</p>\n"); if (host->canonical == host) { jvm_status(&host->cluster, r); ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r); ap_rputs("<tr><th width=\"50%\">web-app\n", r); ap_rputs(" <th>url-pattern\n", r); app = host->applications; for (; app; app = app->next) { if (! app->has_data) { ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>unconfigured</tr>\n", *app->context_path ? app->context_path : "/"); } for (loc = app->locations; loc; loc = loc->next) { if (! strcasecmp(loc->prefix, "/META-INF") || ! strcasecmp(loc->prefix, "/WEB-INF")) continue; ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s%s</tr>\n", *app->context_path ? app->context_path : "/", loc->prefix, ! loc->is_exact && ! loc->suffix ? "/*" : loc->suffix && loc->prefix[0] ? "/" : "", loc->suffix ? "*" : "", loc->suffix ? loc->suffix : "", loc->ignore ? " (ignore)" : ""); } } ap_rputs("</table></center>\n", r); } }
/** * Print a summary of the configuration so users can understand what's * going on. Ping the server to check that it's up. */ static int caucho_status(request_rec *r) { resin_host_t *host; web_app_t *app; location_t *loc; unsigned int now = r->request_time; config_t *config = cse_get_module_config(r); r->content_type = "text/html"; /* ap_soft_timeout("caucho status", r); */ if (r->header_only) { /* ap_kill_timeout(r); */ return OK; } ap_send_http_header(r); ap_rputs("<html><title>Status : Caucho Servlet Engine</title>\n", r); ap_rputs("<body bgcolor=white>\n", r); ap_rputs("<h1>Status : Caucho Servlet Engine</h1>\n", r); if (config->error) { char buf[BUF_LENGTH]; escape_html(buf, config->error); ap_rprintf(r, "<h2 color='red'>Error : %s</h2>\n", buf); } ap_rprintf(r, "<h2>Configuration Cluster</h2>\n"); jvm_status(&config->config_cluster, r); host = config ? config->hosts : 0; for (; host; host = host->next) { if (host != host->canonical) continue; /* check updates as appropriate */ cse_match_host(config, host->name, host->port, now); if (! *host->name) ap_rprintf(r, "<h2>Default Virtual Host</h2>\n"); else if (host->port) ap_rprintf(r, "<h2>Virtual Host: %s:%d</h2>\n", host->name, host->port); else ap_rprintf(r, "<h2>Virtual Host: %s</h2>\n", host->name); jvm_status(&host->cluster, r); ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r); ap_rputs("<tr><th width=\"50%\">web-app\n", r); ap_rputs(" <th>url-pattern\n", r); app = host->applications; for (; app; app = app->next) { for (loc = app->locations; loc; loc = loc->next) { if (! strcasecmp(loc->prefix, "/META-INF") || ! strcasecmp(loc->prefix, "/WEB-INF")) continue; ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s%s</tr>\n", *app->context_path ? app->context_path : "/", loc->prefix, ! loc->is_exact && ! loc->suffix ? "/*" : loc->suffix && loc->prefix[0] ? "/" : "", loc->suffix ? "*" : "", loc->suffix ? loc->suffix : "", loc->ignore ? " (ignore)" : ""); } } ap_rputs("</table></center>\n", r); } ap_rputs("<hr>", r); ap_rprintf(r, "<em>%s<em>", VERSION); ap_rputs("</body></html>\n", r); /* ap_kill_timeout(r); */ return OK; }