本文整理匯總了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);
}
}
}
示例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);
}
}
}
示例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()));
}
}
示例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());
}
示例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());
}
示例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()));
}
}
示例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());
}
示例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);
}