Search in sources :

Example 36 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestTagHandlerPoolPerformance method testConcurrency.

@Test
public void testConcurrency() throws Exception {
    // Create a working TagHandlerPool
    Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
    Wrapper w = (Wrapper) tomcat.getHost().findChildren()[0].findChild("jsp");
    TagHandlerPool tagHandlerPool = new TagHandlerPool();
    tagHandlerPool.init(w.getServlet().getServletConfig());
    for (int i = 1; i < 9; i++) {
        doTestConcurrency(tagHandlerPool, i);
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 37 with Wrapper

use of org.apache.catalina.Wrapper in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method addServlets.

private static void addServlets(Context ctx, JSONObject jaggeryConfig) {
    if (jaggeryConfig != null) {
        JSONArray arrServlets = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS);
        JSONArray arrServletMappings = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS);
        if (arrServlets != null) {
            for (Object servletObj : arrServlets) {
                JSONObject servlet = (JSONObject) servletObj;
                String name = (String) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_NAME);
                String clazz = (String) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_CLASS);
                Wrapper servletWrapper = Tomcat.addServlet(ctx, name, clazz);
                JSONArray arrParams = (JSONArray) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS);
                if (arrParams != null) {
                    for (Object paramObj : arrParams) {
                        JSONObject param = (JSONObject) paramObj;
                        String paramName = (String) param.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS_NAME);
                        String paramValue = (String) param.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS_VALUE);
                        servletWrapper.addInitParameter(paramName, paramValue);
                    }
                }
            }
        }
        if (arrServletMappings != null) {
            for (Object servletMappingObj : arrServletMappings) {
                JSONObject mapping = (JSONObject) servletMappingObj;
                String name = (String) mapping.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS_NAME);
                String url = (String) mapping.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS_URL);
                ctx.addServletMapping(url, name);
            }
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Example 38 with Wrapper

use of org.apache.catalina.Wrapper in project tomee by apache.

the class TomcatWebAppBuilder method ensureMyFacesDontLooseFacesContext.

private void ensureMyFacesDontLooseFacesContext(final StandardContext standardContext) {
    for (final Container w : standardContext.findChildren()) {
        if (!Wrapper.class.isInstance(w)) {
            continue;
        }
        final Wrapper wrapper = Wrapper.class.cast(w);
        if ("FacesServlet".equals(wrapper.getName()) && "javax.faces.webapp.FacesServlet".equals(wrapper.getServletClass())) {
            final ClassLoader loader = standardContext.getLoader().getClassLoader();
            try {
                if (Files.toFile(loader.getResource("javax/faces/webapp/FacesServlet.class")).getName().startsWith("myfaces")) {
                    loader.loadClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
                    wrapper.setServletClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
                    break;
                }
            } catch (final Throwable t) {
            // not there, not a big deal in most of cases
            }
        }
    }
}
Also used : StandardWrapper(org.apache.catalina.core.StandardWrapper) Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container)

Example 39 with Wrapper

use of org.apache.catalina.Wrapper in project tomee by apache.

the class TomEERemoteWebapp method initInternal.

@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    final Wrapper servlet = createWrapper();
    servlet.setName(ServerServlet.class.getSimpleName());
    servlet.setServletClass(ServerServlet.class.getName());
    addChild(servlet);
    addServletMappingDecoded(MAPPING, ServerServlet.class.getSimpleName());
}
Also used : Wrapper(org.apache.catalina.Wrapper) ServerServlet(org.apache.openejb.server.httpd.ServerServlet)

Example 40 with Wrapper

use of org.apache.catalina.Wrapper in project tomee by apache.

the class TomEEMyFacesContainerInitializer method isFacesServletPresent.

private boolean isFacesServletPresent(final ServletContext ctx) {
    if (ctx instanceof ApplicationContextFacade) {
        try {
            final ApplicationContext appCtx = (ApplicationContext) get(ApplicationContextFacade.class, ctx);
            final Context tomcatCtx = (Context) get(ApplicationContext.class, appCtx);
            if (tomcatCtx instanceof StandardContext) {
                final Container[] servlets = tomcatCtx.findChildren();
                if (servlets != null) {
                    for (final Container s : servlets) {
                        if (s instanceof Wrapper) {
                            if ("javax.faces.webapp.FacesServlet".equals(((Wrapper) s).getServletClass()) || "Faces Servlet".equals(s.getName())) {
                                return true;
                            }
                        }
                    }
                }
            }
        } catch (final Exception e) {
        // no-op
        }
    }
    return false;
}
Also used : ApplicationContext(org.apache.catalina.core.ApplicationContext) Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Wrapper(org.apache.catalina.Wrapper) ApplicationContext(org.apache.catalina.core.ApplicationContext) Container(org.apache.catalina.Container) ApplicationContextFacade(org.apache.catalina.core.ApplicationContextFacade) StandardContext(org.apache.catalina.core.StandardContext) ServletException(javax.servlet.ServletException)

Aggregations

Wrapper (org.apache.catalina.Wrapper)109 Context (org.apache.catalina.Context)57 Tomcat (org.apache.catalina.startup.Tomcat)48 AsyncContext (javax.servlet.AsyncContext)33 Test (org.junit.Test)31 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)28 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)24 ServletResponseWrapper (javax.servlet.ServletResponseWrapper)24 TesterContext (org.apache.tomcat.unittest.TesterContext)24 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)22 IOException (java.io.IOException)18 StandardWrapper (org.apache.catalina.core.StandardWrapper)16 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)14 File (java.io.File)13 Container (org.apache.catalina.Container)13 ServletException (javax.servlet.ServletException)9 HashMap (java.util.HashMap)7 StandardContext (org.apache.catalina.core.StandardContext)7 Servlet (javax.servlet.Servlet)6 ArrayList (java.util.ArrayList)5