当前位置: 首页>>代码示例>>Java>>正文


Java Context.start方法代码示例

本文整理汇总了Java中org.apache.catalina.Context.start方法的典型用法代码示例。如果您正苦于以下问题:Java Context.start方法的具体用法?Java Context.start怎么用?Java Context.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Context的用法示例。


在下文中一共展示了Context.start方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reload

import org.apache.catalina.Context; //导入方法依赖的package包/类
private void reload(DeployedApplication app, File fileToRemove, String newDocBase) {
    if(log.isInfoEnabled())
        log.info(sm.getString("hostConfig.reload", app.name));
    Context context = (Context) host.findChild(app.name);
    if (context.getState().isAvailable()) {
        if (fileToRemove != null && newDocBase != null) {
            context.addLifecycleListener(
                    new ExpandedDirectoryRemovalListener(fileToRemove, newDocBase));
        }
        // Reload catches and logs exceptions
        context.reload();
    } else {
        // If the context was not started (for example an error
        // in web.xml) we'll still get to try to start
        if (fileToRemove != null && newDocBase != null) {
            ExpandWar.delete(fileToRemove);
            context.setDocBase(newDocBase);
        }
        try {
            context.start();
        } catch (Exception e) {
            log.warn(sm.getString
                     ("hostConfig.context.restart", app.name), e);
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:HostConfig.java

示例2: reload

import org.apache.catalina.Context; //导入方法依赖的package包/类
private void reload(DeployedApplication app, File fileToRemove, String newDocBase) {
	if (log.isInfoEnabled())
		log.info(sm.getString("hostConfig.reload", app.name));
	Context context = (Context) host.findChild(app.name);
	if (context.getState().isAvailable()) {
		if (fileToRemove != null && newDocBase != null) {
			context.addLifecycleListener(new ExpandedDirectoryRemovalListener(fileToRemove, newDocBase));
		}
		// Reload catches and logs exceptions
		context.reload();
	} else {
		// If the context was not started (for example an error
		// in web.xml) we'll still get to try to start
		if (fileToRemove != null && newDocBase != null) {
			ExpandWar.delete(fileToRemove);
			context.setDocBase(newDocBase);
		}
		try {
			context.start();
		} catch (Exception e) {
			log.warn(sm.getString("hostConfig.context.restart", app.name), e);
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:25,代码来源:HostConfig.java

示例3: start

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Start the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be started
 */
protected void start(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("start: Starting web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext", 
                    RequestUtil.filter(displayPath)));
            return;
        }
        context.start();
        if (context.getState().isAvailable())
            writer.println(smClient.getString("managerServlet.started",
                    displayPath));
        else
            writer.println(smClient.getString("managerServlet.startFailed",
                    displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log(sm.getString("managerServlet.startFailed",
                displayPath), t);
        writer.println(smClient.getString("managerServlet.startFailed",
                displayPath));
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:44,代码来源:ManagerServlet.java

示例4: testWebappLoaderStartFail

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testWebappLoaderStartFail() throws Exception {
    // Test that if WebappLoader start() fails and if the cause of
    // the failure is gone, the context can be started without
    // a need to redeploy it.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();
    tomcat.start();
    // To not start Context automatically, as we have to configure it first
    ((ContainerBase) tomcat.getHost()).setStartChildren(false);

    FailingWebappLoader loader = new FailingWebappLoader();
    File root = new File("test/webapp-3.0");
    Context context = tomcat.addWebapp("", root.getAbsolutePath());
    context.setLoader(loader);

    try {
        context.start();
        fail();
    } catch (LifecycleException ex) {
        // As expected
    }
    assertEquals(LifecycleState.FAILED, context.getState());

    // The second attempt
    loader.setFail(false);
    context.start();
    assertEquals(LifecycleState.STARTED, context.getState());

    // Using a test from testBug49922() to check that the webapp is running
    ByteChunk result = getUrl("http://localhost:" + getPort() +
            "/bug49922/target");
    assertEquals("Target", result.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestStandardContext.java

示例5: testWebappListenerConfigureFail

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testWebappListenerConfigureFail() throws Exception {
    // Test that if LifecycleListener on webapp fails during
    // configure_start event and if the cause of the failure is gone,
    // the context can be started without a need to redeploy it.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();
    tomcat.start();
    // To not start Context automatically, as we have to configure it first
    ((ContainerBase) tomcat.getHost()).setStartChildren(false);

    FailingLifecycleListener listener = new FailingLifecycleListener();
    File root = new File("test/webapp-3.0");
    Context context = tomcat.addWebapp("", root.getAbsolutePath());
    context.addLifecycleListener(listener);

    try {
        context.start();
        fail();
    } catch (LifecycleException ex) {
        // As expected
    }
    assertEquals(LifecycleState.FAILED, context.getState());

    // The second attempt
    listener.setFail(false);
    context.start();
    assertEquals(LifecycleState.STARTED, context.getState());

    // Using a test from testBug49922() to check that the webapp is running
    ByteChunk result = getUrl("http://localhost:" + getPort() +
            "/bug49922/target");
    assertEquals("Target", result.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestStandardContext.java

示例6: start

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Start the web application at the specified context path.
 *
 * @param writer
 *            Writer to render to
 * @param cn
 *            Name of the application to be started
 */
protected void start(PrintWriter writer, ContextName cn, StringManager smClient) {

	if (debug >= 1)
		log("start: Starting web application '" + cn + "'");

	if (!validateContextName(cn, writer, smClient)) {
		return;
	}

	String displayPath = cn.getDisplayName();

	try {
		Context context = (Context) host.findChild(cn.getName());
		if (context == null) {
			writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath)));
			return;
		}
		context.start();
		if (context.getState().isAvailable())
			writer.println(smClient.getString("managerServlet.started", displayPath));
		else
			writer.println(smClient.getString("managerServlet.startFailed", displayPath));
	} catch (Throwable t) {
		ExceptionUtils.handleThrowable(t);
		getServletContext().log(sm.getString("managerServlet.startFailed", displayPath), t);
		writer.println(smClient.getString("managerServlet.startFailed", displayPath));
		writer.println(smClient.getString("managerServlet.exception", t.toString()));
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:39,代码来源:ManagerServlet.java

示例7: testBug46243

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug46243() throws Exception {
    // This tests that if a Filter init() fails then the web application
    // is not put into service. (BZ 46243)
    // This also tests that if the cause of the failure is gone,
    // the context can be started without a need to redeploy it.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();

    File docBase = new File(tomcat.getHost().getAppBase(), "ROOT");
    if (!docBase.mkdirs() && !docBase.isDirectory()) {
        fail("Unable to create docBase");
    }

    Context root = tomcat.addContext("", "ROOT");
    configureTest46243Context(root, true);
    tomcat.start();

    // Configure the client
    Bug46243Client client =
            new Bug46243Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] { REQUEST });

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse404());

    // Context failed to start. This checks that automatic transition
    // from FAILED to STOPPED state was successful.
    assertEquals(LifecycleState.STOPPED, root.getState());

    // Prepare context for the second attempt
    // Configuration was cleared on stop() thanks to
    // StandardContext.resetContext(), so we need to configure it again
    // from scratch.
    configureTest46243Context(root, false);
    root.start();
    // The same request is processed successfully
    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    assertEquals(Bug46243Filter.class.getName()
            + HelloWorldServlet.RESPONSE_TEXT, client.getResponseBody());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:TestStandardContext.java

示例8: testBug54239

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug54239() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    tomcat.start();

    ServletContext context = ctx.getServletContext();

    ELInterpreter interpreter =
            ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof DefaultELInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    context.setAttribute(ELInterpreter.class.getName(),
            SimpleELInterpreter.class.getName());
    interpreter = ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter();
    context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter);
    interpreter = ELInterpreterFactory.getELInterpreter(context);
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
    Assert.assertTrue(interpreter == simpleInterpreter);

    context.removeAttribute(ELInterpreter.class.getName());

    ctx.stop();
    ctx.addApplicationListener(Bug54239Listener.class.getName());
    ctx.start();

    interpreter = ELInterpreterFactory.getELInterpreter(ctx.getServletContext());
    Assert.assertNotNull(interpreter);
    Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:43,代码来源:TestELInterpreterFactory.java


注:本文中的org.apache.catalina.Context.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。