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

📄 testrunobj.java

📁 jsp中 urlRewrite的源代码 很有用的喔
💻 JAVA
字号:
/**
 * 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 javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Paul Tuckey
 * @version $Revision: 1.6 $ $Date: 2005/12/07 10:22:13 $
 */
public class TestRunObj {
    private static boolean runCalled;
    private static boolean destroyCalled;
    private static boolean initCalled;
    private static boolean nonDefaultRunCalled;
    private static ServletConfig servletConfig;

    private static int createdCount = 0;

    public TestRunObj() {
        createdCount++;
    }

    public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        runCalled = true;

        PrintWriter sos = httpServletResponse.getWriter();
        if (sos == null) return;
        sos.print("this is " + TestRunObj.class.getName());
        sos.close();
    }

    public void nonDefaultRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        nonDefaultRunCalled = true;
    }

    public String runThatReturns(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        return "aaabbb";
    }

    public void runNullPointerException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        exceptionGenerator.doNullPointer();
    }

    public void runRuntiumeException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        exceptionGenerator.doRuntime();
    }

    public void runServletException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        exceptionGenerator.doServlet();
    }

    public void runIOException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        exceptionGenerator.doIO();
    }

    public void runCustomException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws TestExceptionGenerator.CustomException {
        exceptionGenerator.doCustom();
    }

    TestExceptionGenerator exceptionGenerator = new TestExceptionGenerator();

    private class TestExceptionGenerator {
        public void doNullPointer() {
            String aaa = null;
            aaa.toLowerCase();
        }
        public void doRuntime() {
            throw new RuntimeException("shit!");
        }
        public void doServlet() throws ServletException {
            throw new ServletException("serv");
        }
        public void doIO() throws IOException {
            throw new IOException("me i.o. has gone crazy");
        }
        public void doCustom() throws CustomException {
            throw new CustomException();
        }
        public class CustomException extends Exception {

        }
    }

    /**
     * Do not delete! used in RunTest.
     */
    private void privateRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        // do nothing
    }

    public void destroy() {
        destroyCalled = true;
    }

    public void init(ServletConfig config) throws ServletException {
        servletConfig = config;
        initCalled = true;
    }

    public static boolean isRunCalled() {
        return runCalled;
    }

    public static int getCreatedCount() {
        return createdCount;
    }

    public static void resetTestFlags() {
        createdCount = 0;
        runCalled = false;
        destroyCalled = false;
        initCalled = false;
        nonDefaultRunCalled = false;
        servletConfig = null;
    }

    public static ServletConfig getTestServletConfig() {
        return servletConfig;
    }

    public static boolean isDestroyCalled() {
        return destroyCalled;
    }

    public static boolean isInitCalled() {
        return initCalled;
    }

    public static boolean isNonDefaultRunCalled() {
        return nonDefaultRunCalled;
    }
}

⌨️ 快捷键说明

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