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

📄 status.java

📁 urlrewritefilter-2.6-src.zip
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Copyright (c) 2005, Paul Tuckey
 * All rights reserved.
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.tuckey.web.filters.urlrewrite;

import org.tuckey.web.filters.urlrewrite.utils.Log;
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

/**
 * Outputs information about urlrewritefilter.
 *
 * @author Paul Tuckey
 * @version $Revision: 1.11 $ $Date: 2005/12/07 10:27:04 $
 */
public class Status {

    private static Log log = Log.getLog(Status.class);

    private StringBuffer buffer = new StringBuffer();

    private Conf conf;
    private UrlRewriteFilter urlRewriteFilter;

    public Status(Conf conf) {
        this.conf = conf;
    }

    public Status(Conf conf, UrlRewriteFilter urlRewriteFilter) {
        this.conf = conf;
        this.urlRewriteFilter = urlRewriteFilter;
    }

    public void displayStatusInContainer(final HttpServletRequest hsRequest) {
        showHeader();
        showRunningInfo();
        showConf();
        showRequestInfo(hsRequest);
        showFooter();
    }

    public void displayStatusOffline() {
        showHeader();
        showConf();
        showFooter();
    }


    private void showRequestInfo(final HttpServletRequest hsRequest) {
        // other info
        println("<h2>Request Debug Info</h2>");

        println("<h4>General</h4>");
        println("<pre>");

        println("method: " + hsRequest.getMethod());
        if (hsRequest.getAuthType() != null) println("auth-type: " + hsRequest.getAuthType());
        if (hsRequest.getCharacterEncoding() != null) println("character-encoding: " + hsRequest.getCharacterEncoding());
        println("context-path: " + hsRequest.getContextPath());
        if (hsRequest.getPathInfo() != null) println("path-info: " + hsRequest.getPathInfo());
        if (hsRequest.getPathTranslated() != null) println("path-translated: " + hsRequest.getPathTranslated());
        println("port: " + hsRequest.getServerPort());
        println("protocol: " + hsRequest.getProtocol());
        if (hsRequest.getQueryString() != null) println("query-string: " + hsRequest.getQueryString());
        println("remote-addr: " + hsRequest.getRemoteAddr());
        println("remote-host: " + hsRequest.getRemoteHost());
        if (hsRequest.getRemoteUser() != null) println("remote-user: " + hsRequest.getRemoteUser());
        if (hsRequest.getRequestedSessionId() != null) println("requested-session-id: " + hsRequest.getRequestedSessionId());
        println("request-uri: " + hsRequest.getRequestURI());
        println("request-url: " + hsRequest.getRequestURL());
        println("server-name: " + hsRequest.getServerName());
        println("scheme: " + hsRequest.getScheme());

        println("</pre>");

        HttpSession session = hsRequest.getSession(false);
        if (session != null) {
            println("<h4>Session</h4>");
            println("<br />session-isnew: " + session.isNew());
            Enumeration enumer = session.getAttributeNames();
            while (enumer.hasMoreElements()) {
                String name = (String) enumer.nextElement();
                println("<br />session-attribute " + name + ": " + session.getAttribute(name));
            }
        }

        // show headers from request
        println("<h4>Request Headers</h4>");
        println("<pre>");
        final Enumeration headers = hsRequest.getHeaderNames();
        while (headers.hasMoreElements()) {
            final String headerName = (String) headers.nextElement();
            // ignore cookies as they are handled later
            if ("cookie".equals(headerName)) continue;
            println(headerName + ": " + hsRequest.getHeader(headerName));
        }
        println("</pre>");

        final Cookie[] cookies = hsRequest.getCookies();
        if (cookies != null) {
            if (cookies.length > 0) {
                println("<h4>Cookies</h4>");
                for (int i = 0; i < cookies.length; i++) {
                    println("<h5>Cookie " + i + "</h5>");
                    final Cookie cookie = cookies[i];
                    if (cookie == null) continue;
                    println("<pre>");
                    println("    name     : " + cookie.getName());
                    println("    value    : " + cookie.getValue());
                    println("    path     : " + cookie.getPath());
                    println("    domain   : " + cookie.getDomain());
                    println("    max age  : " + cookie.getMaxAge());
                    println("    is secure: " + cookie.getSecure());
                    println("    version  : " + cookie.getVersion());
                    println("    comment  : " + cookie.getComment());
                    println("</pre>");
                }
            }
        }
        println("</pre>");

        // show headers from request
        println("<h4>Time info</h4>");
        println("<pre>");
        Calendar nowCal = Calendar.getInstance();
        println("time: " + nowCal.getTime().getTime());
        println("year: " + nowCal.get(Calendar.YEAR));
        println("month: " + nowCal.get(Calendar.MONTH));
        println("dayofmonth: " + nowCal.get(Calendar.DAY_OF_MONTH));
        println("dayofweek: " + nowCal.get(Calendar.DAY_OF_WEEK));
        println("ampm: " + nowCal.get(Calendar.AM_PM));
        println("hourofday: " + nowCal.get(Calendar.HOUR_OF_DAY));
        println("minute: " + nowCal.get(Calendar.MINUTE));
        println("second: " + nowCal.get(Calendar.SECOND));
        println("millisecond: " + nowCal.get(Calendar.MILLISECOND));
        println("</pre>");

    }

    private void showConf() {
        if (conf == null) return;

        println("<h2>Summary of " + conf.getFileName() + "</h2>");

        if (!conf.isOk()) {
            final List errors = conf.getErrors();
            println("<h4 class=\"err\">Errors During Load of " + conf.getFileName() + "</h4>");
            println("<ul>");
            if (errors.size() > 0) {
                for (int i = 0; i < errors.size(); i++) {
                    final String error = (String) errors.get(i);
                    println("<li class=\"err\">" + error + "</li>");
                }
            }
            displayRuleErrors(conf.getRules());
            displayRuleErrors(conf.getOutboundRules());
            println("</ul>");
        }

        int conditionsCount = 0;
        final List rules = conf.getRules();
        for (int i = 0; i < rules.size(); i++) {
            final Rule rule = (Rule) rules.get(i);
            conditionsCount += rule.getConditions().size();
        }
        final List outboundRules = conf.getOutboundRules();
        for (int i = 0; i < outboundRules.size(); i++) {
            final OutboundRule rule = (OutboundRule) outboundRules.get(i);
            conditionsCount += rule.getConditions().size();
        }
        println("<p>In total there " +
                (rules.size() == 1 ? "is 1 rule" : "are " + rules.size() + " rules") + ", " +
                (outboundRules.size() == 1 ? "1 outbound rule" : outboundRules.size() + " outbound rules") +
                (conditionsCount > 0 ? " and " : "") +
                (conditionsCount == 1 ? conditionsCount + " condtion" : "") +
                (conditionsCount > 1 ? conditionsCount + " condtions" : "") +
                " in the configuration file.</code></p>");

        for (int i = 0; i < rules.size(); i++) {
            final Rule rule = (Rule) rules.get(i);
            println("<h3>" + rule.getDisplayName() +
                    (rule.isEnabled() ? "" : " **DISABLED**") + "</h3>");
            if (!StringUtils.isBlank(rule.getNote())) {
                println("<dl><dd><p>" + StringUtils.nl2br(rule.getNote()) + "</p></dd></dl>");
            }
            print("<p>URL's matching <code>" + rule.getFrom() + "</code>");
            if (!StringUtils.isBlank(rule.getTo())) {
                print(" will ");
                if ("forward".equals(rule.getToType()))
                    print("be <code>forwarded</code> to");
                else if ("include".equals(rule.getToType()))
                    print("<code>include</code>");
                else if ("redirect".equals(rule.getToType()))
                    print("be <code>redirected</code> to");
                else
                    print("<code>" + rule.getToType() + "</code> to");
                print(" <code>" + rule.getTo() + "</code>");
            }
            println(".</p>");
            showConditions(rule);
            showSets(rule);
            showRuns(rule);

            if (!rule.isLast()) {
                println("<p>Note, other rules will be proessed after this rule.</p>");
            }
            println("</p>");
        }

        for (int i = 0; i < outboundRules.size(); i++) {

⌨️ 快捷键说明

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