Java Code Examples for org.apache.catalina.Context#setName()

The following examples show how to use org.apache.catalina.Context#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: TesterDigestAuthenticatorPerformance.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    ConcurrentMessageDigest.init("MD5");

    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);

    // Add the Realm to the Context
    Context context = new StandardContext();
    context.setName(CONTEXT_PATH);
    context.setRealm(realm);

    // Configure the Login config
    LoginConfig config = new LoginConfig();
    config.setRealmName(REALM);
    context.setLoginConfig(config);

    // Make the Context and Realm visible to the Authenticator
    authenticator.setContainer(context);
    authenticator.setNonceCountWindowSize(8 * 1024);

    authenticator.start();
}
 
Example 3
Source File: Tomcat.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public Context addContext(Host host, String contextPath, String contextName,
        String dir) {
    silence(host, contextPath);
    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;
}
 
Example 4
Source File: TesterDigestAuthenticatorPerformance.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    ConcurrentMessageDigest.init("MD5");

    // Configure the Realm
    MapRealm realm = new MapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);

    // Add the Realm to the Context
    Context context = new StandardContext();
    context.setName(CONTEXT_PATH);
    context.setRealm(realm);

    // Make the Context and Realm visible to the Authenticator
    authenticator.setContainer(context);
    authenticator.setNonceCountWindowSize(8 * 1024);

    authenticator.start();
}
 
Example 5
Source File: Tomcat.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: TesterDigestAuthenticatorPerformance.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    ConcurrentMessageDigest.init("MD5");

    // Configure the Realm
    MapRealm realm = new MapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);

    // Add the Realm to the Context
    Context context = new StandardContext();
    context.setName(CONTEXT_PATH);
    context.setRealm(realm);

    // Make the Context and Realm visible to the Authenticator
    authenticator.setContainer(context);
    authenticator.setNonceCountWindowSize(8 * 1024);

    authenticator.start();
}
 
Example 7
Source File: RedisStoreTest.java    From session-managers with Apache License 2.0 5 votes vote down vote up
@Before
public void setupManager() {
    Context context = new StandardContext();
    Host host = new StandardHost();

    this.manager.setContext(context);
    context.setName("test-context-name");
    context.setParent(host);
    host.setName("test-host-name");
}
 
Example 8
Source File: TestMapper.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private Context createContext(String name) {
    Context context = new StandardContext();
    context.setName(name);
    return context;
}
 
Example 9
Source File: TestApplicationContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testBug57190() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    Context foo1 = new StandardContext();
    foo1.setName("/foo##1");
    foo1.setPath("/foo");
    foo1.setWebappVersion("1");
    foo1.addLifecycleListener(new FixContextListener());
    foo1.addLifecycleListener(new SetIdListener("foo1"));
    tomcat.getHost().addChild(foo1);

    Context foo2 = new StandardContext();
    foo2.setName("/foo##2");
    foo2.setPath("/foo");
    foo2.setWebappVersion("2");
    foo2.addLifecycleListener(new FixContextListener());
    foo2.addLifecycleListener(new SetIdListener("foo2"));
    tomcat.getHost().addChild(foo2);

    Context bar = tomcat.addContext("/bar", null);
    bar.addLifecycleListener(new SetIdListener("bar"));

    Context ctx = tomcat.addContext("", null);
    ctx.addLifecycleListener(new SetIdListener("ROOT"));
    ctx.setCrossContext(true);

    Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
    ctx.addServletMappingDecoded("/", "Bug57190Servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    String body = res.toString();

    Assert.assertTrue(body, body.contains("01-bar"));
    Assert.assertTrue(body, body.contains("02-foo2"));
    Assert.assertTrue(body, body.contains("03-foo1"));
    Assert.assertTrue(body, body.contains("04-foo2"));
    Assert.assertTrue(body, body.contains("05-foo2"));
    Assert.assertTrue(body, body.contains("06-ROOT"));
    Assert.assertTrue(body, body.contains("07-ROOT"));
    Assert.assertTrue(body, body.contains("08-foo2"));
    Assert.assertTrue(body, body.contains("09-ROOT"));
}
 
Example 10
Source File: TestApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBug57190() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    Context foo1 = new StandardContext();
    foo1.setName("/foo##1");
    foo1.setPath("/foo");
    foo1.setWebappVersion("1");
    foo1.setDocBase(System.getProperty("java.io.tmpdir"));
    foo1.addLifecycleListener(new FixContextListener());
    foo1.addLifecycleListener(new SetIdListener("foo1"));
    tomcat.getHost().addChild(foo1);

    Context foo2 = new StandardContext();
    foo2.setName("/foo##2");
    foo2.setPath("/foo");
    foo2.setWebappVersion("2");
    foo2.setDocBase(System.getProperty("java.io.tmpdir"));
    foo2.addLifecycleListener(new FixContextListener());
    foo2.addLifecycleListener(new SetIdListener("foo2"));
    tomcat.getHost().addChild(foo2);

    // No file system docBase required
    Context bar = tomcat.addContext("/bar", null);
    bar.addLifecycleListener(new SetIdListener("bar"));

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addLifecycleListener(new SetIdListener("ROOT"));
    ctx.setCrossContext(true);

    Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
    ctx.addServletMapping("/", "Bug57190Servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    String body = res.toString();

    Assert.assertTrue(body, body.contains("01-bar"));
    Assert.assertTrue(body, body.contains("02-foo2"));
    Assert.assertTrue(body, body.contains("03-foo1"));
    Assert.assertTrue(body, body.contains("04-foo2"));
    Assert.assertTrue(body, body.contains("05-foo2"));
    Assert.assertTrue(body, body.contains("06-ROOT"));
    Assert.assertTrue(body, body.contains("07-ROOT"));
    Assert.assertTrue(body, body.contains("08-foo2"));
    Assert.assertTrue(body, body.contains("09-ROOT"));
}
 
Example 11
Source File: TestApplicationContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Test
public void testBug57190() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    Context foo1 = new StandardContext();
    foo1.setName("/foo##1");
    foo1.setPath("/foo");
    foo1.setWebappVersion("1");
    foo1.setDocBase(System.getProperty("java.io.tmpdir"));
    foo1.addLifecycleListener(new FixContextListener());
    foo1.addLifecycleListener(new SetIdListener("foo1"));
    tomcat.getHost().addChild(foo1);

    Context foo2 = new StandardContext();
    foo2.setName("/foo##2");
    foo2.setPath("/foo");
    foo2.setWebappVersion("2");
    foo2.setDocBase(System.getProperty("java.io.tmpdir"));
    foo2.addLifecycleListener(new FixContextListener());
    foo2.addLifecycleListener(new SetIdListener("foo2"));
    tomcat.getHost().addChild(foo2);

    // No file system docBase required
    Context bar = tomcat.addContext("/bar", null);
    bar.addLifecycleListener(new SetIdListener("bar"));

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addLifecycleListener(new SetIdListener("ROOT"));
    ctx.setCrossContext(true);

    Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
    ctx.addServletMapping("/", "Bug57190Servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    String body = res.toString();

    Assert.assertTrue(body, body.contains("01-bar"));
    Assert.assertTrue(body, body.contains("02-foo2"));
    Assert.assertTrue(body, body.contains("03-foo1"));
    Assert.assertTrue(body, body.contains("04-foo2"));
    Assert.assertTrue(body, body.contains("05-foo2"));
    Assert.assertTrue(body, body.contains("06-ROOT"));
    Assert.assertTrue(body, body.contains("07-ROOT"));
    Assert.assertTrue(body, body.contains("08-foo2"));
    Assert.assertTrue(body, body.contains("09-ROOT"));
}