本文整理匯總了Java中org.apache.catalina.Context.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.stop方法的具體用法?Java Context.stop怎麽用?Java Context.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.catalina.Context
的用法示例。
在下文中一共展示了Context.stop方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stopConext
import org.apache.catalina.Context; //導入方法依賴的package包/類
public void stopConext() {
int port = this.getTomcat().getPort();
Bootstrap b = BootstrapManager.getBoostrap(port);
if (null == b) {
return;
}
List<Context> cs = b.listContexts();
Context matchedContext = null;
for (Context c : cs) {
if (this.nameMatch(c)) {
try {
c.stop();
matchedContext = c;
} catch (LifecycleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
if (matchedContext != null)
cs.remove(matchedContext);
}
示例2: doTestBug51376
import org.apache.catalina.Context; //導入方法依賴的package包/類
private void doTestBug51376(boolean loadOnStartUp) throws Exception {
// Test that for a servlet that was added programmatically its
// loadOnStartup property is honored and its init() and destroy()
// methods are called.
// Set up a container
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add ServletContainerInitializer
Bug51376SCI sci = new Bug51376SCI(loadOnStartUp);
ctx.addServletContainerInitializer(sci, null);
// Start the context
tomcat.start();
// Stop the context
ctx.stop();
// Make sure that init() and destroy() were called correctly
assertTrue(sci.getServlet().isOk());
assertTrue(loadOnStartUp == sci.getServlet().isInitCalled());
}
示例3: testTldListener
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testTldListener() throws Exception {
// Set up a container
Tomcat tomcat = getTomcatInstance();
File docBase = new File("test/webapp-3.0");
Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
// Start the context
tomcat.start();
// Stop the context
ctx.stop();
String log = TesterTldListener.getLog();
Assert.assertTrue(log, log.contains("PASS-01"));
Assert.assertTrue(log, log.contains("PASS-02"));
Assert.assertFalse(log, log.contains("FAIL"));
}
示例4: remove
import org.apache.catalina.Context; //導入方法依賴的package包/類
/**
* Invoke the remove method on the deployer.
*/
protected void remove(String contextName) throws Exception {
// TODO Handle remove also work dir content !
// Stop the context first to be nicer
Context context = (Context) host.findChild(contextName);
if (context != null) {
if(log.isDebugEnabled())
log.debug(sm.getString("farmWarDeployer.undeployLocal",
contextName));
context.stop();
String baseName = context.getBaseName();
File war = new File(getAppBase(), baseName + ".war");
File dir = new File(getAppBase(), baseName);
File xml = new File(configBase, baseName + ".xml");
if (war.exists()) {
if (!war.delete()) {
log.error(sm.getString("farmWarDeployer.deleteFail", war));
}
} else if (dir.exists()) {
undeployDir(dir);
} else {
if (!xml.delete()) {
log.error(sm.getString("farmWarDeployer.deleteFail", xml));
}
}
// Perform new deployment and remove internal HostConfig state
check(contextName);
}
}
示例5: stop
import org.apache.catalina.Context; //導入方法依賴的package包/類
/**
* Stop the web application at the specified context path.
*
* @param writer Writer to render to
* @param cn Name of the application to be stopped
*/
protected void stop(PrintWriter writer, ContextName cn,
StringManager smClient) {
if (debug >= 1)
log("stop: Stopping 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;
}
// It isn't possible for the manager to stop itself
if (context.getName().equals(this.context.getName())) {
writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.stop();
writer.println(smClient.getString(
"managerServlet.stopped", displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.stop[" + displayPath + "]", t);
writer.println(smClient.getString("managerServlet.exception",
t.toString()));
}
}
示例6: testTimerThreadLeak
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testTimerThreadLeak() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
if (ctx instanceof StandardContext) {
((StandardContext) ctx).setClearReferencesStopThreads(true);
}
ExecutorServlet executorServlet = new ExecutorServlet();
Tomcat.addServlet(ctx, "taskServlet", executorServlet);
ctx.addServletMapping("/", "taskServlet");
tomcat.start();
// This will trigger the timer & thread creation
getUrl("http://localhost:" + getPort() + "/");
// Stop the context
ctx.stop();
// If the thread still exists, we have a thread/memory leak
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
// ignore
}
Assert.assertTrue(executorServlet.tpe.isShutdown());
Assert.assertTrue(executorServlet.tpe.isTerminated());
}
示例7: testTimerThreadLeak
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testTimerThreadLeak() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
if (ctx instanceof StandardContext) {
((StandardContext) ctx).setClearReferencesStopTimerThreads(true);
}
Tomcat.addServlet(ctx, "taskServlet", new TaskServlet());
ctx.addServletMapping("/", "taskServlet");
tomcat.start();
// This will trigger the timer & thread creation
getUrl("http://localhost:" + getPort() + "/");
// Stop the context
ctx.stop();
Thread[] threads = getThreads();
for (Thread thread : threads) {
if (thread != null && thread.isAlive() &&
TaskServlet.TIMER_THREAD_NAME.equals(thread.getName())) {
thread.join(5000);
if (thread.isAlive()) {
fail("Timer thread still running");
}
}
}
}
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:34,代碼來源:TestWebappClassLoaderMemoryLeak.java
示例8: remove
import org.apache.catalina.Context; //導入方法依賴的package包/類
/**
* Invoke the remove method on the deployer.
*/
protected void remove(String contextName) throws Exception {
// TODO Handle remove also work dir content !
// Stop the context first to be nicer
Context context = (Context) host.findChild(contextName);
if (context != null) {
if (log.isDebugEnabled())
log.debug(sm.getString("farmWarDeployer.undeployLocal", contextName));
context.stop();
String baseName = context.getBaseName();
File war = new File(getAppBase(), baseName + ".war");
File dir = new File(getAppBase(), baseName);
File xml = new File(configBase, baseName + ".xml");
if (war.exists()) {
if (!war.delete()) {
log.error(sm.getString("farmWarDeployer.deleteFail", war));
}
} else if (dir.exists()) {
undeployDir(dir);
} else {
if (!xml.delete()) {
log.error(sm.getString("farmWarDeployer.deleteFail", xml));
}
}
// Perform new deployment and remove internal HostConfig state
check(contextName);
}
}
示例9: stop
import org.apache.catalina.Context; //導入方法依賴的package包/類
/**
* Stop the web application at the specified context path.
*
* @param writer
* Writer to render to
* @param cn
* Name of the application to be stopped
*/
protected void stop(PrintWriter writer, ContextName cn, StringManager smClient) {
if (debug >= 1)
log("stop: Stopping 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;
}
// It isn't possible for the manager to stop itself
if (context.getName().equals(this.context.getName())) {
writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.stop();
writer.println(smClient.getString("managerServlet.stopped", displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.stop[" + displayPath + "]", t);
writer.println(smClient.getString("managerServlet.exception", t.toString()));
}
}
示例10: testThreadLocalLeak1
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testThreadLocalLeak1() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Need to make sure we see a leak for the right reasons
tomcat.getServer().addLifecycleListener(
new JreMemoryLeakPreventionListener());
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "leakServlet1",
"org.apache.tomcat.unittest.TesterLeakingServlet1");
ctx.addServletMapping("/leak1", "leakServlet1");
tomcat.start();
Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
// Configure logging filter to check leak message appears
LogValidationFilter f = new LogValidationFilter(
"The web application [] created a ThreadLocal with key of");
LogManager.getLogManager().getLogger(
"org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);
// Need to force loading of all web application classes via the web
// application class loader
loadClass("TesterCounter",
(WebappClassLoaderBase) ctx.getLoader().getClassLoader());
loadClass("TesterLeakingServlet1",
(WebappClassLoaderBase) ctx.getLoader().getClassLoader());
// This will trigger the ThreadLocal creation
int rc = getUrl("http://localhost:" + getPort() + "/leak1",
new ByteChunk(), null);
// Make sure request is OK
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Destroy the context
ctx.stop();
tomcat.getHost().removeChild(ctx);
ctx = null;
// Make sure we have a memory leak
String[] leaks = ((StandardHost) tomcat.getHost())
.findReloadedContextMemoryLeaks();
Assert.assertNotNull(leaks);
Assert.assertTrue(leaks.length > 0);
// Make sure the message was logged
Assert.assertEquals(1, f.getMessageCount());
}
示例11: testThreadLocalLeak2
import org.apache.catalina.Context; //導入方法依賴的package包/類
@Test
public void testThreadLocalLeak2() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Need to make sure we see a leak for the right reasons
tomcat.getServer().addLifecycleListener(
new JreMemoryLeakPreventionListener());
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "leakServlet2",
"org.apache.tomcat.unittest.TesterLeakingServlet2");
ctx.addServletMapping("/leak2", "leakServlet2");
tomcat.start();
Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
// Configure logging filter to check leak message appears
LogValidationFilter f = new LogValidationFilter(
"The web application [] created a ThreadLocal with key of");
LogManager.getLogManager().getLogger(
"org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);
// Need to force loading of all web application classes via the web
// application class loader
loadClass("TesterCounter",
(WebappClassLoaderBase) ctx.getLoader().getClassLoader());
loadClass("TesterThreadScopedHolder",
(WebappClassLoaderBase) ctx.getLoader().getClassLoader());
loadClass("TesterLeakingServlet2",
(WebappClassLoaderBase) ctx.getLoader().getClassLoader());
// This will trigger the ThreadLocal creation
int rc = getUrl("http://localhost:" + getPort() + "/leak2",
new ByteChunk(), null);
// Make sure request is OK
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Destroy the context
ctx.stop();
tomcat.getHost().removeChild(ctx);
ctx = null;
// Make sure we have a memory leak
String[] leaks = ((StandardHost) tomcat.getHost())
.findReloadedContextMemoryLeaks();
Assert.assertNotNull(leaks);
Assert.assertTrue(leaks.length > 0);
// Make sure the message was logged
Assert.assertEquals(1, f.getMessageCount());
}
示例12: 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);
}