本文整理汇总了Java中org.apache.catalina.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于org.apache.catalina包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setContainer
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Set the Container with which this Manager has been associated. If it is a
* Context (the usual case), listen for changes to the session timeout
* property.
*
* @param container
* The associated Container
*/
public void setContainer(Container container) {
// De-register from the old Container (if any)
if ((this.container != null) && (this.container instanceof Context))
((Context) this.container).removePropertyChangeListener(this);
// Default processing provided by our superclass
super.setContainer(container);
// Register with the new Container (if any)
if ((this.container != null) && (this.container instanceof Context)) {
setMaxInactiveInterval
( ((Context) this.container).getSessionTimeout()*60 );
((Context) this.container).addPropertyChangeListener(this);
}
}
示例2: testConnectToRootEndpoint
import org.apache.catalina.Context; //导入依赖的package包/类
@Test
public void testConnectToRootEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
Context ctx2 = tomcat.addContext("/foo", null);
ctx2.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx2, "default", new DefaultServlet());
ctx2.addServletMapping("/", "default");
tomcat.start();
echoTester("");
echoTester("/");
// FIXME: The ws client doesn't handle any response other than the upgrade,
// which may or may not be allowed. In that case, the server will return
// a redirect to the root of the webapp to avoid possible broken relative
// paths.
// echoTester("/foo");
echoTester("/foo/");
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:26,代码来源:TestWebSocketFrameClient.java
示例3: sessionEvent
import org.apache.catalina.Context; //导入依赖的package包/类
@Override
public void sessionEvent(SessionEvent event) {
if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) {
return;
}
Session session = event.getSession();
Manager manager = session.getManager();
if (manager == null) {
return;
}
Context context = (Context) manager.getContainer();
Authenticator authenticator = context.getAuthenticator();
if (!(authenticator instanceof AuthenticatorBase)) {
return;
}
SingleSignOn sso = ((AuthenticatorBase) authenticator).sso;
if (sso == null) {
return;
}
sso.sessionDestroyed(ssoId, session);
}
示例4: setContainer
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Set the Container with which this Logger has been associated.
*
* @param container The associated Container
*/
@Override
public void setContainer(Container container) {
// Deregister from the old Container (if any)
if ((this.container != null) && (this.container instanceof Context))
((Context) this.container).removePropertyChangeListener(this);
// Process this property change
Container oldContainer = this.container;
this.container = container;
support.firePropertyChange("container", oldContainer, this.container);
// Register with the new Container (if any)
if ((this.container != null) && (this.container instanceof Context)) {
setReloadable( ((Context) this.container).getReloadable() );
((Context) this.container).addPropertyChangeListener(this);
}
}
示例5: threadStart
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Start the background thread that will periodically check for
* session timeouts.
*
* @exception IllegalStateException if we should not be starting
* a background thread now
*/
private void threadStart() {
// Has the background thread already been started?
if (thread != null)
return;
// Validate our current state
if (!reloadable)
throw new IllegalStateException
(sm.getString("webappLoader.notReloadable"));
if (!(container instanceof Context))
throw new IllegalStateException
(sm.getString("webappLoader.notContext"));
// Start the background thread
if (debug >= 1)
log(" Starting background thread");
threadDone = false;
threadName = "WebappLoader[" + container.getName() + "]";
thread = new Thread(this, threadName);
thread.setDaemon(true);
thread.start();
}
示例6: super
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Construct a new instance of this class, configured according to the
* specified parameters. If both servletPath and pathInfo are
* <code>null</code>, it will be assumed that this RequestDispatcher
* was acquired by name, rather than by path.
*
* @param wrapper The Wrapper associated with the resource that will
* be forwarded to or included (required)
* @param requestURI The request URI to this resource (if any)
* @param servletPath The revised servlet path to this resource (if any)
* @param pathInfo The revised extra path information to this resource
* (if any)
* @param queryString Query string parameters included with this request
* (if any)
* @param name Servlet name (if a named dispatcher was created)
* else <code>null</code>
*/
public ApplicationDispatcher
(Wrapper wrapper, String requestURI, String servletPath,
String pathInfo, String queryString, String name) {
super();
// Save all of our configuration parameters
this.wrapper = wrapper;
this.context = (Context) wrapper.getParent();
this.requestURI = requestURI;
this.servletPath = servletPath;
this.pathInfo = pathInfo;
this.queryString = queryString;
this.name = name;
if (wrapper instanceof StandardWrapper)
this.support = ((StandardWrapper) wrapper).getInstanceSupport();
else
this.support = new InstanceSupport(wrapper);
}
示例7: unregisterWrapper
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Unregister wrapper.
*/
private void unregisterWrapper(Wrapper wrapper) {
Context context = (Context) wrapper.getParent();
String contextPath = context.getPath();
String wrapperName = wrapper.getName();
if ("/".equals(contextPath)) {
contextPath = "";
}
String version = context.getWebappVersion();
String hostName = context.getParent().getName();
String[] mappings = wrapper.findMappings();
for (String mapping : mappings) {
mapper.removeWrapper(hostName, contextPath, version, mapping);
}
if (log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.unregisterWrapper", wrapperName, contextPath, connector));
}
}
示例8: pathParamExtenionTest
import org.apache.catalina.Context; //导入依赖的package包/类
private void pathParamExtenionTest(String path, String expected)
throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("/testapp", null);
Tomcat.addServlet(ctx, "servlet", new PathParamServlet());
ctx.addServletMapping("*.txt", "servlet");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + path);
Assert.assertEquals(expected, res.toString());
}
示例9: 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"));
}
示例10: removeContext
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Remove an existing Context.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeContext(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
String serviceName = oname.getKeyProperty("service");
String hostName = oname.getKeyProperty("host");
String contextName = getPathStr(oname.getKeyProperty("path"));
Server server = ServerFactory.getServer();
Service service = server.findService(serviceName);
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(hostName);
Context context = (Context) host.findChild(contextName);
// Remove this component from its parent component
host.removeChild(context);
}
示例11: testUtf8Body
import org.apache.catalina.Context; //导入依赖的package包/类
@Test
public void testUtf8Body() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context root = tomcat.addContext("", null);
Tomcat.addServlet(root, "Echo", new Utf8Echo());
root.addServletMapping("/test", "Echo");
tomcat.getConnector().setProperty("soTimeout", "300000");
tomcat.start();
for (Utf8TestCase testCase : TestUtf8.TEST_CASES) {
String expected = null;
if (testCase.invalidIndex == -1) {
expected = testCase.outputReplaced;
}
doUtf8BodyTest(testCase.description, testCase.input, expected);
}
}
示例12: testTimeoutDispatchCustomErrorPage
import org.apache.catalina.Context; //导入依赖的package包/类
@Test
public void testTimeoutDispatchCustomErrorPage() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context context = tomcat.addContext("", null);
tomcat.addServlet("", "timeout", Bug58751AsyncServlet.class.getName())
.setAsyncSupported(true);
CustomErrorServlet customErrorServlet = new CustomErrorServlet();
Tomcat.addServlet(context, "customErrorServlet", customErrorServlet);
context.addServletMapping("/timeout", "timeout");
context.addServletMapping("/error", "customErrorServlet");
ErrorPage errorPage = new ErrorPage();
errorPage.setLocation("/error");
context.addErrorPage(errorPage);
tomcat.start();
ByteChunk responseBody = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/timeout", responseBody, null);
Assert.assertEquals(503, rc);
Assert.assertEquals(CustomErrorServlet.ERROR_MESSAGE, responseBody.toString());
}
示例13: getSessionsForPath
import org.apache.catalina.Context; //导入依赖的package包/类
protected Session[] getSessionsForPath(String path) {
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
throw new IllegalArgumentException(sm.getString("managerServlet.invalidPath",
RequestUtil.filter(path)));
}
String displayPath = path;
if( path.equals("/") )
path = "";
Context context = (Context) host.findChild(path);
if (null == context) {
throw new IllegalArgumentException(sm.getString("managerServlet.noContext",
RequestUtil.filter(displayPath)));
}
Session[] sessions = context.getManager().findSessions();
return sessions;
}
示例14: testGetResource
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Test for https://bz.apache.org/bugzilla/show_bug.cgi?id=47866
*/
@Test
public void testGetResource() throws Exception {
Tomcat tomcat = getTomcatInstance();
String contextPath = "/examples";
File appDir = new File(getBuildDirectory(), "webapps" + contextPath);
// app dir is relative to server home
Context ctx =
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
Tomcat.addServlet(ctx, "testGetResource", new GetResource());
ctx.addServletMapping("/testGetResource", "testGetResource");
tomcat.start();
ByteChunk res = new ByteChunk();
int rc =getUrl("http://localhost:" + getPort() + contextPath +
"/testGetResource", res, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertTrue(res.toString().contains("<?xml version=\"1.0\" "));
}
示例15: if
import org.apache.catalina.Context; //导入依赖的package包/类
/**
* Find and return the ErrorPage instance for the specified exception's
* class, or an ErrorPage instance for the closest superclass for which
* there is such a definition. If no associated ErrorPage instance is
* found, return <code>null</code>.
*
* @param context The Context in which to search
* @param exception The exception for which to find an ErrorPage
*/
private static ErrorPage findErrorPage
(Context context, Throwable exception) {
if (exception == null)
return (null);
Class<?> clazz = exception.getClass();
String name = clazz.getName();
while (!Object.class.equals(clazz)) {
ErrorPage errorPage = context.findErrorPage(name);
if (errorPage != null)
return (errorPage);
clazz = clazz.getSuperclass();
if (clazz == null)
break;
name = clazz.getName();
}
return (null);
}