use of org.apache.catalina.Context in project tomcat by apache.
the class StandardContextSF method store.
/**
* Store a Context as Separate file as configFile value from context exists.
* filename can be relative to catalina.base.
*
* @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
* int, java.lang.Object)
*/
@Override
public void store(PrintWriter aWriter, int indent, Object aContext) throws Exception {
if (aContext instanceof StandardContext) {
StoreDescription desc = getRegistry().findDescription(aContext.getClass());
if (desc.isStoreSeparate()) {
URL configFile = ((StandardContext) aContext).getConfigFile();
if (configFile != null) {
if (desc.isExternalAllowed()) {
if (desc.isBackup())
storeWithBackup((StandardContext) aContext);
else
storeContextSeparate(aWriter, indent, (StandardContext) aContext);
return;
}
} else if (desc.isExternalOnly()) {
// Set a configFile so that the configuration is actually saved
Context context = ((StandardContext) aContext);
Host host = (Host) context.getParent();
File configBase = host.getConfigBaseFile();
ContextName cn = new ContextName(context.getName(), false);
String baseName = cn.getBaseName();
File xml = new File(configBase, baseName + ".xml");
context.setConfigFile(xml.toURI().toURL());
if (desc.isBackup())
storeWithBackup((StandardContext) aContext);
else
storeContextSeparate(aWriter, indent, (StandardContext) aContext);
return;
}
}
}
super.store(aWriter, indent, aContext);
}
use of org.apache.catalina.Context in project tomcat by apache.
the class Tomcat method addContext.
/**
* @param host The host in which the context will be deployed
* @param contextPath The context mapping to use, "" for root context.
* @param contextName The context name
* @param dir Base directory for the context, for static files.
* Must exist, relative to the server home
* @return the deployed context
* @see #addContext(String, String)
*/
public Context addContext(Host host, String contextPath, String contextName, String dir) {
silence(host, contextName);
Context ctx = createContext(host, contextPath);
ctx.setName(contextName);
ctx.setPath(contextPath);
ctx.setDocBase(dir);
ctx.addLifecycleListener(new FixContextListener());
if (host == null) {
getHost().addChild(ctx);
} else {
host.addChild(ctx);
}
return ctx;
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestDigestAuthenticator method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Configure a context with digest auth and a single protected resource
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctxt = tomcat.addContext(CONTEXT_PATH, null);
// Add protected servlet
Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet());
ctxt.addServletMappingDecoded(URI, "TesterServlet");
SecurityCollection collection = new SecurityCollection();
collection.addPatternDecoded(URI);
SecurityConstraint sc = new SecurityConstraint();
sc.addAuthRole(ROLE);
sc.addCollection(collection);
ctxt.addConstraint(sc);
// Configure the Realm
TesterMapRealm realm = new TesterMapRealm();
realm.addUser(USER, PWD);
realm.addUserRole(USER, ROLE);
ctxt.setRealm(realm);
// Configure the authenticator
LoginConfig lc = new LoginConfig();
lc.setAuthMethod("DIGEST");
lc.setRealmName(REALM);
ctxt.setLoginConfig(lc);
ctxt.getPipeline().addValve(new DigestAuthenticator());
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestFormAuthenticator method testTimeoutWithoutCookies.
@Test
public void testTimeoutWithoutCookies() throws Exception {
String protectedUri = doTest("GET", "GET", NO_100_CONTINUE, CLIENT_NO_COOKIES, SERVER_USE_COOKIES, SERVER_FREEZE_SESSID);
// Force session to expire one second from now
Context context = (Context) getTomcatInstance().getHost().findChildren()[0];
forceSessionMaxInactiveInterval(context, SHORT_SESSION_TIMEOUT_SECS);
// wait long enough for my session to expire
Thread.sleep(TIMEOUT_DELAY_MSECS);
// then try to continue using the expired session to get the
// protected resource once more.
// should get login challenge or timeout status 408
doTestProtected("GET", protectedUri, NO_100_CONTINUE, FormAuthClient.LOGIN_REQUIRED, 1);
}
use of org.apache.catalina.Context in project tomcat by apache.
the class TestAsyncContextImpl method testCommitOnComplete.
@Test
public void testCommitOnComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStatusServlet asyncStatusServlet = new AsyncStatusServlet(HttpServletResponse.SC_BAD_REQUEST);
Wrapper wrapper = Tomcat.addServlet(ctx, "asyncStatusServlet", asyncStatusServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/asyncStatusServlet", "asyncStatusServlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/asyncStatusServlet");
int rc = getUrl(url.toString(), new ByteChunk(), null);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
// Without this test may complete before access log has a chance to log
// the request
Thread.sleep(REQUEST_TIME);
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0, REQUEST_TIME);
}
Aggregations