Search in sources :

Example 81 with StandardContext

use of org.apache.catalina.core.StandardContext in project uavstack by uavorg.

the class TomcatPlusIT method onAppStop.

/**
 * 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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 82 with StandardContext

use of org.apache.catalina.core.StandardContext in project uavstack by uavorg.

the class TomcatPlusIT method onAppStarting.

/**
 * 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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 83 with StandardContext

use of org.apache.catalina.core.StandardContext in project uavstack by uavorg.

the class TomcatPlusIT method onAppStart.

/**
 * 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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 84 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat by apache.

the class TestHttpServlet method testBug53454.

@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.addServletMappingDecoded("/", "largeBodyServlet");
    tomcat.start();
    Map<String, List<String>> resHeaders = new HashMap<>();
    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));
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) HashMap(java.util.HashMap) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) List(java.util.List) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 85 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat by apache.

the class TestHttpServlet method testBug57602.

/*
     * Verifies that the same Content-Length is returned for both GET and HEAD
     * operations when a Servlet includes content from another Servlet
     */
@Test
public void testBug57602() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);
    Bug57602ServletOuter outer = new Bug57602ServletOuter();
    Tomcat.addServlet(ctx, "Bug57602ServletOuter", outer);
    ctx.addServletMappingDecoded("/outer", "Bug57602ServletOuter");
    Bug57602ServletInner inner = new Bug57602ServletInner();
    Tomcat.addServlet(ctx, "Bug57602ServletInner", inner);
    ctx.addServletMappingDecoded("/inner", "Bug57602ServletInner");
    tomcat.start();
    Map<String, List<String>> resHeaders = new HashMap<>();
    String path = "http://localhost:" + getPort() + "/outer";
    ByteChunk out = new ByteChunk();
    int rc = getUrl(path, out, resHeaders);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    String length = resHeaders.get("Content-Length").get(0);
    Assert.assertEquals(Long.parseLong(length), out.getLength());
    out.recycle();
    rc = headUrl(path, out, resHeaders);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertEquals(0, out.getLength());
    Assert.assertEquals(length, resHeaders.get("Content-Length").get(0));
    tomcat.stop();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) HashMap(java.util.HashMap) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) List(java.util.List) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

StandardContext (org.apache.catalina.core.StandardContext)181 File (java.io.File)72 Tomcat (org.apache.catalina.startup.Tomcat)64 Test (org.junit.Test)52 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)41 Context (org.apache.catalina.Context)32 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)31 StandardHost (org.apache.catalina.core.StandardHost)25 IOException (java.io.IOException)22 Host (org.apache.catalina.Host)18 MalformedURLException (java.net.MalformedURLException)16 JarFile (java.util.jar.JarFile)16 ServletContext (javax.servlet.ServletContext)16 StandardRoot (org.apache.catalina.webresources.StandardRoot)16 URL (java.net.URL)13 InterceptSupport (com.creditease.monitor.interceptframework.InterceptSupport)12 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Container (org.apache.catalina.Container)12