Java 类org.apache.catalina.core.StandardContext 实例源码

项目:tomcat7    文件:TestPersistentManagerIntegration.java   
@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);
    ctx.setDistributable(true);

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

    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    String sessionId = getUrl(
            "http://localhost:" + getPort()
                    + "/dummy?no_create_session=false").toString();
    Assert.assertNotNull("Session is stored", store.load(sessionId));
    Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
    Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
项目:tomcat7    文件:WebappLoader.java   
/**
 * Execute a periodic task, such as reloading, etc. This method will be
 * invoked inside the classloading context of this container. Unexpected
 * throwables will be caught and logged.
 */
@Override
public void backgroundProcess() {
    if (reloadable && modified()) {
        try {
            Thread.currentThread().setContextClassLoader
                (WebappLoader.class.getClassLoader());
            if (container instanceof StandardContext) {
                ((StandardContext) container).reload();
            }
        } finally {
            if (container.getLoader() != null) {
                Thread.currentThread().setContextClassLoader
                    (container.getLoader().getClassLoader());
            }
        }
    } else {
        closeJARs(false);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestGenerator.java   
@Test
public void testBug48701Fail() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null,
            "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug48nnn/bug48701-fail.jsp", new ByteChunk(), null);

    assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
}
项目:tomcat7    文件:TestVirtualWebappLoader.java   
@Test
public void testStartInternal() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0");
    // Must have a real docBase - just use temp
    StandardContext ctx =
        (StandardContext)tomcat.addContext("",  appDir.getAbsolutePath());

    VirtualWebappLoader loader = new VirtualWebappLoader();

    loader.setContainer(ctx);
    ctx.setLoader(loader);
    ctx.setResources(new FileDirContext());
    ctx.resourcesStart();
    File dir = new File("test/webapp-3.0-fragments/WEB-INF/lib");
    loader.setVirtualClasspath(dir.getAbsolutePath() + "/*.jar");
    loader.start();
    String[] repos = loader.getRepositories();
    assertEquals(2,repos.length);
    loader.stop();
    // ToDo: Why doesn't remove repositories?
    repos = loader.getRepositories();
    assertEquals(2, repos.length);

    // no leak
    loader.start();
    repos = loader.getRepositories();
    assertEquals(2,repos.length);

    // clear loader
    ctx.setLoader(null);
    // see tearDown()!
    tomcat.start();
}
项目:lazycat    文件:CatalinaUtil.java   
public void run() {
    while (true) {
        if (true)
            return;
        try {
            Thread.sleep(1000);

            if (null != host) {
                Container[] csa = host.findChildren();
                // System.out.println(host);
                // System.out.println(csa);
                // System.out.println(csa.length);
                for (Container c : csa) {
                    StandardContext sc = (StandardContext) c;
                    System.out.println(sc.getState());
                }
            }
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
项目:uavstack    文件:TomcatPlusIT.java   
/**
 * onAppStarting
 * 
 * @param args
 */
public void onAppStarting(Object... args) {

    // release the left contexts
    StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_INIT);
    StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_CREATE);

    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH,
            ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    iSupport.doIntercept(context);
}
项目:tomcat7    文件:TesterDigestAuthenticatorPerformance.java   
@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();
}
项目:tomcat7    文件:TestNamingContext.java   
@Test
public void testListBindings() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);

    // Create the resource
    ContextResource cr = new ContextResource();
    cr.setName("list/foo");
    cr.setType("org.apache.naming.resources.TesterObject");
    cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
    ctx.getNamingResources().addResource(cr);

    // Map the test Servlet
    Bug23950Servlet bug23950Servlet = new Bug23950Servlet();
    Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet);
    ctx.addServletMapping("/", "bug23950Servlet");

    tomcat.start();

    ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("org.apache.naming.resources.TesterObject", bc.toString());
}
项目:tomcat7    文件:TestNamingContext.java   
@Test
public void testBeanFactory() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);

    // Create the resource
    ContextResource cr = new ContextResource();
    cr.setName("bug50351");
    cr.setType("org.apache.naming.resources.TesterObject");
    cr.setProperty("factory", "org.apache.naming.factory.BeanFactory");
    cr.setProperty("foo", "value");
    ctx.getNamingResources().addResource(cr);

    // Map the test Servlet
    Bug50351Servlet bug50351Servlet = new Bug50351Servlet();
    Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet);
    ctx.addServletMapping("/", "bug50351Servlet");

    tomcat.start();

    ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("value", bc.toString());
}
项目:oryx2    文件:InMemoryRealmTest.java   
@Test
public void testAuthenticate() throws Exception {
  InMemoryRealm realm = new InMemoryRealm();
  StandardContext ctx = new StandardContext();
  ctx.setName("OryxTest");
  realm.setContainer(ctx);
  realm.start();

  realm.addUser("foo", "bar");
  Principal authPrincipal = realm.authenticate("foo", "bar");
  assertNotNull(authPrincipal);
  assertEquals("foo", authPrincipal.getName());
  assertNull(realm.authenticate("foo", "baz"));
  assertNull(realm.authenticate("bar", "foo"));
  assertEquals("bar", realm.getPassword("foo"));
  assertEquals("foo", realm.getPrincipal("foo").getName());
}
项目:tomcat7    文件:TestWarDirContext.java   
/**
 * Additional test following on from SPR-7350 above to check files that
 * contain JNDI reserved characters can be served when caching is disabled.
 */
@Test
public void testReservedJNDIFileNamesNoCache() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-fragments");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());
    ctxt.setCachingAllowed(false);

    tomcat.start();

    // Should be found in resources.jar
    ByteChunk bc = getUrl("http://localhost:" + getPort() +
            "/test/'singlequote.jsp");
    assertEquals("<p>'singlequote.jsp in resources.jar</p>",
            bc.toString());

    // Should be found in file system
    bc = getUrl("http://localhost:" + getPort() +
            "/test/'singlequote2.jsp");
    assertEquals("<p>'singlequote2.jsp in file system</p>",
            bc.toString());
}
项目:uavstack    文件:TomcatPlusIT.java   
/**
 * onAppInit
 * 
 * @param args
 */
public void onAppInit(Object... args) {

    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    InterceptContext ic2 = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);
    /**
     * NOTE: onAppInit, we put the Context Object into threadlocal, then all other later process for
     * PRE_WEBCONTAINER_INIT, which can get the object, as not everywhere we can get the object
     * 
     * for example, the DataSource related injection
     */
    ic.put(InterceptConstants.CONTEXTOBJ, sc);
    ic2.put(InterceptConstants.CONTEXTOBJ, sc);
}
项目:tomcat7    文件:TestELInJsp.java   
@Test
public void testBug56029() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56029.jspx");

    String result = res.toString();

    Assert.assertTrue(result.contains("[1]:[1]"));
}
项目:tomcat7    文件:TestELInJsp.java   
@Test
public void testBug56147() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctx = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56147.jsp");

    String result = res.toString();
    assertEcho(result, "00-OK");
}
项目:uavstack    文件:TomcatPlusIT.java   
/**
 * onAppStart
 * 
 * @param args
 */
public void onAppStart(Object... args) {

    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STARTED);
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH,
            ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    iSupport.doIntercept(context);
}
项目:tomcat7    文件:TestHttpServlet.java   
@Test
public void testBug53454() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    StandardContext ctx = (StandardContext)
        tomcat.addContext("", null);

    // Map the test Servlet
    LargeBodyServlet largeBodyServlet = new LargeBodyServlet();
    Tomcat.addServlet(ctx, "largeBodyServlet", largeBodyServlet);
    ctx.addServletMapping("/", "largeBodyServlet");

    tomcat.start();

    Map<String,List<String>> resHeaders=
            new HashMap<String, List<String>>();
    int rc = headUrl("http://localhost:" + getPort() + "/", new ByteChunk(),
           resHeaders);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertEquals(LargeBodyServlet.RESPONSE_LENGTH,
            resHeaders.get("Content-Length").get(0));
}
项目:tomcat7    文件:TestCompositeELResolver.java   
@Test
public void testBug50408() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =  new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null,
            "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug50408.jsp", new ByteChunk(), null);

    assertEquals(HttpServletResponse.SC_OK, rc);
}
项目:lazycat    文件:WebappLoader.java   
/**
 * Execute a periodic task, such as reloading, etc. This method will be
 * invoked inside the classloading context of this container. Unexpected
 * throwables will be caught and logged.
 */
@Override
public void backgroundProcess() {
    if (reloadable && modified()) {
        try {
            Thread.currentThread().setContextClassLoader(WebappLoader.class.getClassLoader());
            if (container instanceof StandardContext) {
                ((StandardContext) container).reload();
            }
        } finally {
            if (container.getLoader() != null) {
                Thread.currentThread().setContextClassLoader(container.getLoader().getClassLoader());
            }
        }
    } else {
        closeJARs(false);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestELInJsp.java   
@Test
public void testBug56029() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56029.jspx");

    String result = res.toString();

    Assert.assertTrue(result.contains("[1]:[1]"));
}
项目:lams    文件:Tomcat.java   
public StandardContext addWebapp(StandardHost host, 
                                 String url, String path) 
       throws ServletException {
    silence(url);

    StandardContext ctx = new StandardContext();
    ctx.setPath( url );
    ctx.setDocBase(path);
    if (defaultRealm == null) {
        initSimpleAuth();
    }
    ctx.setRealm(defaultRealm);
    initWebappDefaults(ctx);

    ContextConfig ctxCfg = new ContextConfig();
    ctx.addLifecycleListener( ctxCfg );
    // prevent it from looking ( if it finds one - it'll have dup error )
    ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");

    if (host == null) {
        host = getHost();
    }
    host.addChild(ctx);

    return ctx;
}
项目:lams    文件:ClusterListener.java   
/**
 * Add a new context.
 * 
 * @param context
 */
protected void addContext(Context context, int pos) {
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("clusterListener.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
    }

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("JVMRoute", getJvmRoute(context));
    parameters.put("Context", ("".equals(context.getPath())) ? "/" : context.getPath());
    parameters.put("Alias", getHost(context));

    // Send ENABLE-APP if state is started
    if (context.isStarted()) {
        sendRequest("ENABLE-APP", false, parameters, pos);
    }
}
项目:jerrydog    文件:ContextConfig.java   
/**
 * Process the START event for an associated Context.
 *
 * @param event The lifecycle event that has occurred
 */
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the context we are associated with
    try {
        context = (Context) event.getLifecycle();
        if (context instanceof StandardContext) {
            int contextDebug = ((StandardContext) context).getDebug();
            if (contextDebug > this.debug)
                this.debug = contextDebug;
        }
    } catch (ClassCastException e) {
        log(sm.getString("contextConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
项目:apache-tomcat-7.0.73-with-comment    文件:TestNamingContext.java   
@Test
public void testBeanFactory() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);

    // Create the resource
    ContextResource cr = new ContextResource();
    cr.setName("bug50351");
    cr.setType("org.apache.naming.resources.TesterObject");
    cr.setProperty("factory", "org.apache.naming.factory.BeanFactory");
    cr.setProperty("foo", "value");
    ctx.getNamingResources().addResource(cr);

    // Map the test Servlet
    Bug50351Servlet bug50351Servlet = new Bug50351Servlet();
    Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet);
    ctx.addServletMapping("/", "bug50351Servlet");

    tomcat.start();

    ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("value", bc.toString());
}
项目:apache-tomcat-7.0.73-with-comment    文件:WebappLoader.java   
/**
 * Execute a periodic task, such as reloading, etc. This method will be
 * invoked inside the classloading context of this container. Unexpected
 * throwables will be caught and logged.
 */
@Override
public void backgroundProcess() {
    if (reloadable && modified()) {
        try {
            Thread.currentThread().setContextClassLoader
                (WebappLoader.class.getClassLoader());
            if (container instanceof StandardContext) {
                ((StandardContext) container).reload();
            }
        } finally {
            if (container.getLoader() != null) {
                Thread.currentThread().setContextClassLoader
                    (container.getLoader().getClassLoader());
            }
        }
    } else {
        closeJARs(false);
    }
}
项目:uavstack    文件:SpringBootTomcatPlusIT.java   
@Override
public void onAppInit(Object... args) {

    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    InterceptContext ic2 = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);
    /**
     * NOTE: onAppInit, we put the Context Object into threadlocal, then all other later process for
     * PRE_WEBCONTAINER_INIT, which can get the object, as not everywhere we can get the object
     * 
     * for example, the DataSource related injection
     */
    ic.put(InterceptConstants.CONTEXTOBJ, sc);
    ic2.put(InterceptConstants.CONTEXTOBJ, sc);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfig.java   
private void doTestOverrideDefaultServletWithSCI(String servletName)
        throws Exception{

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    StandardContext ctxt = (StandardContext) tomcat.addContext(null,
            "/test", appDir.getAbsolutePath());
    ctxt.setDefaultWebXml(new File("conf/web.xml").getAbsolutePath());
    ctxt.addLifecycleListener(new ContextConfig());

    ctxt.addServletContainerInitializer(
            new CustomDefaultServletSCI(servletName), null);

    tomcat.start();

    assertPageContains("/test", "OK - Custom default Servlet");
}
项目:uavstack    文件:TomcatPlusIT.java   
/**
 * onAppStop
 * 
 * @param args
 */
public void onAppStop(Object... args) {

    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STOPPED);
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH,
            ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    iSupport.doIntercept(context);
}
项目:tomcat7    文件:ReplicationValve.java   
/**
 * Log the interesting request parameters, invoke the next Valve in the
 * sequence, and log the interesting response parameters.
 *
 * @param request The servlet request to be processed
 * @param response The servlet response to be created
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
@Override
public void invoke(Request request, Response response)
    throws IOException, ServletException
{
    long totalstart = 0;

    //this happens before the request
    if(doStatistics()) {
        totalstart = System.currentTimeMillis();
    }
    if (primaryIndicator) {
        createPrimaryIndicator(request) ;
    }
    Context context = request.getContext();
    boolean isCrossContext = context != null
            && context instanceof StandardContext
            && ((StandardContext) context).getCrossContext();
    try {
        if(isCrossContext) {
            if(log.isDebugEnabled())
                log.debug(sm.getString("ReplicationValve.crossContext.add"));
            //FIXME add Pool of Arraylists
            crossContextSessions.set(new ArrayList<DeltaSession>());
        }
        getNext().invoke(request, response);
        if(context != null && cluster != null
                && context.getManager() instanceof ClusterManager) {
            ClusterManager clusterManager = (ClusterManager) context.getManager();

            // valve cluster can access manager - other cluster handle replication 
            // at host level - hopefully!
            if(cluster.getManager(clusterManager.getName()) == null)
                return ;
            if(cluster.hasMembers()) {
                sendReplicationMessage(request, totalstart, isCrossContext, clusterManager, cluster);
            } else {
                resetReplicationRequest(request,isCrossContext);
            }        
        }
    } finally {
        // Array must be remove: Current master request send endAccess at recycle. 
        // Don't register this request session again!
        if(isCrossContext) {
            if(log.isDebugEnabled())
                log.debug(sm.getString("ReplicationValve.crossContext.remove"));
            // crossContextSessions.remove() only exist at Java 5
            // register ArrayList at a pool
            crossContextSessions.set(null);
        }
    }
}
项目:tomcat7    文件:ContextConfig.java   
/**
 * Process the application classes annotations, if it exists.
 */
protected void applicationAnnotationsConfig() {

    long t1=System.currentTimeMillis();

    WebAnnotationSet.loadApplicationAnnotations(context);

    long t2=System.currentTimeMillis();
    if (context instanceof StandardContext) {
        ((StandardContext) context).setStartupTime(t2-t1+
                ((StandardContext) context).getStartupTime());
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestPersistentManagerIntegration.java   
@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);
    ctx.setDistributable(true);

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

    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    String sessionId = getUrl(
            "http://localhost:" + getPort()
                    + "/dummy?no_create_session=false").toString();
    Assert.assertNotNull("Session is stored", store.load(sessionId));
    Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
    Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
项目:appng-tomcat-session    文件:RedisSessionMangagerIT.java   
@Test
public void test() throws Exception {
    StandardContext context = new StandardContext();
    context.setName("foo");
    WebappLoader loader = new WebappLoader() {
        @Override
        public ClassLoader getClassLoader() {
            return WebappLoader.class.getClassLoader();
        }
    };
    context.setLoader(loader);
    StandardHost host = new StandardHost();
    StandardEngine engine = new StandardEngine();
    engine.setService(new StandardService());
    host.setParent(engine);
    context.setParent(host);
    loader.setContext(context);

    RedisSessionManager manager = new RedisSessionManager();
    manager.setSessionIdGenerator(new StandardSessionIdGenerator());
    manager.setContext(context);
    manager.initializeSerializer();
    manager.initializeDatabaseConnection();
    manager.clear();

    StandardSession session = manager.createSession(null);
    session.setAttribute("foo", "test");

    manager.afterRequest();

    StandardSession loaded = manager.findSession(session.getId());
    Assert.assertEquals(session.getAttribute("foo"), loaded.getAttribute("foo"));

    Assert.assertEquals(1, manager.getSize());
    Assert.assertArrayEquals(new String[] { session.getId() }, manager.keys());

    manager.processExpires();

}
项目:tomcat7    文件:TestWebappClassLoaderExecutorMemoryLeak.java   
@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());
}
项目:tomcat7    文件:TestWebappClassLoaderMemoryLeak.java   
@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");
            }
        }
    }
}
项目:tomcat7    文件:TestTomcat.java   
@Test
public void testBug51526() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appFile = new File("test/deployment/context.war");
    StandardContext context = (StandardContext) tomcat.addWebapp(null, "/test",
            appFile.getAbsolutePath());

    tomcat.start();

    assertEquals("WAR_CONTEXT", context.getSessionCookieName());
}
项目:tomcat7    文件:TestTomcat.java   
@Test
public void testGetDefaultContextPerAddWebapp() {
    Tomcat tomcat = getTomcatInstance();

    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(null,
            "/test", appFile.getAbsolutePath());

    assertEquals(StandardContext.class.getName(), context.getClass()
            .getName());
}
项目:tomcat7    文件:TestWebappServiceLoader.java   
@Test
public void testWebapp() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0-fragments-empty-absolute-ordering");
    StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
    ctxt.addLifecycleListener(new ContextConfig());
    tomcat.start();

    WebappServiceLoader<ServletContainerInitializer> loader =
            new WebappServiceLoader<ServletContainerInitializer>(ctxt);
    @SuppressWarnings("unused")
    Collection<ServletContainerInitializer> initializers = loader.load(ServletContainerInitializer.class);
}
项目:tomcat7    文件:TestPersistentManagerIntegration.java   
@Test
public void noSessionCreate_57637() throws IOException, LifecycleException {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);
    ctx.setDistributable(true);

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

    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    Assert.assertEquals(
            "NO_SESSION",
            getUrl(
                    "http://localhost:" + getPort()
                            + "/dummy?no_create_session=true").toString());
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty());
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestParser.java   
@Test
public void testBug56265() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null,
            "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56265.jsp");

    String result = res.toString();

    Assert.assertTrue(result,
            result.contains("[1: [data-test]: [window.alert('Hello World <&>!')]]"));
    Assert.assertTrue(result,
            result.contains("[2: [data-test]: [window.alert('Hello World <&>!')]]"));
    Assert.assertTrue(result,
            result.contains("[3: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
    Assert.assertTrue(result,
            result.contains("[4: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
}
项目:tomcat7    文件:TestNamingContext.java   
public void doTestLookup(boolean useSingletonResource) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);

    // Create the resource
    ContextResource cr = new ContextResource();
    cr.setName("list/foo");
    cr.setType("org.apache.naming.resources.TesterObject");
    cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
    cr.setSingleton(useSingletonResource);
    ctx.getNamingResources().addResource(cr);

    // Map the test Servlet
    Bug49994Servlet bug49994Servlet = new Bug49994Servlet();
    Tomcat.addServlet(ctx, "bug49994Servlet", bug49994Servlet);
    ctx.addServletMapping("/", "bug49994Servlet");

    tomcat.start();

    ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");

    String expected;
    if (useSingletonResource) {
        expected = "EQUAL";
    } else {
        expected = "NOTEQUAL";
    }
    assertEquals(expected, bc.toString());

}
项目:tomcat7    文件:TestNamingContext.java   
@Test
public void testBug52830() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);

    // Create the resource
    ContextEnvironment env = new ContextEnvironment();
    env.setName("boolean");
    env.setType(Boolean.class.getName());
    env.setValue("true");
    ctx.getNamingResources().addEnvironment(env);

    // Map the test Servlet
    Bug52830Servlet bug52830Servlet = new Bug52830Servlet();
    Tomcat.addServlet(ctx, "bug52830Servlet", bug52830Servlet);
    ctx.addServletMapping("/", "bug52830Servlet");

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/", bc, null);
    assertEquals(200, rc);
    assertTrue(bc.toString().contains("truetrue"));
}