Search in sources :

Example 96 with Wrapper

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

the class TestMapper method createWrapper.

private Wrapper createWrapper(String name) {
    Wrapper wrapper = new StandardWrapper();
    wrapper.setName(name);
    return wrapper;
}
Also used : Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Example 97 with Wrapper

use of org.apache.catalina.Wrapper in project async-http-client by AsyncHttpClient.

the class WebDavBasicTest method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    embedded = new Embedded();
    String path = new File(".").getAbsolutePath();
    embedded.setCatalinaHome(path);
    Engine engine = embedded.createEngine();
    engine.setDefaultHost("localhost");
    Host host = embedded.createHost("localhost", path);
    engine.addChild(host);
    Context c = embedded.createContext("/", path);
    c.setReloadable(false);
    Wrapper w = c.createWrapper();
    w.addMapping("/*");
    w.setServletClass(org.apache.catalina.servlets.WebdavServlet.class.getName());
    w.addInitParameter("readonly", "false");
    w.addInitParameter("listings", "true");
    w.setLoadOnStartup(0);
    c.addChild(w);
    host.addChild(c);
    Connector connector = embedded.createConnector("localhost", 0, Http11NioProtocol.class.getName());
    connector.setContainer(host);
    embedded.addEngine(engine);
    embedded.addConnector(connector);
    embedded.start();
    port1 = connector.getLocalPort();
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Connector(org.apache.catalina.connector.Connector) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) Host(org.apache.catalina.Host) Embedded(org.apache.catalina.startup.Embedded) File(java.io.File) Engine(org.apache.catalina.Engine) BeforeClass(org.testng.annotations.BeforeClass)

Example 98 with Wrapper

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

the class TomcatTest method createServer.

@Override
protected int createServer() throws Exception {
    String baseDir = "target/webapp-runner";
    tomcat = new Tomcat();
    int port = super.getPort();
    tomcat.setPort(port);
    File base = new File(baseDir);
    if (!base.exists()) {
        base.mkdirs();
    }
    tomcat.setBaseDir(baseDir);
    Context ctx = tomcat.addContext("/", base.getAbsolutePath());
    StandardContext standardContext = (StandardContext) ctx;
    standardContext.addApplicationListener(CdiServletContextListener.class.getName());
    Wrapper wrapper = Tomcat.addServlet(ctx, "RequestServlet", RequestServlet.class.getName());
    wrapper.addMapping("/*");
    tomcat.start();
    return port;
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) CdiServletContextListener(org.apache.deltaspike.cdise.servlet.CdiServletContextListener) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File) RequestServlet(org.apache.deltaspike.cdise.servlet.test.content.RequestServlet)

Example 99 with Wrapper

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

the class TomcatWsRegistry method clearWsContainer.

@Override
public void clearWsContainer(final String contextRoot, String virtualHost, final ServletInfo servletInfo, final String moduleId) {
    if (virtualHost == null) {
        virtualHost = engine.getDefaultHost();
    }
    final Container host = engine.findChild(virtualHost);
    if (host == null) {
        throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'.  Do you have a matchiing Host entry in the server.xml?");
    }
    final Context context = (Context) host.findChild("/" + contextRoot);
    if (context == null) {
        throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName());
    }
    final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName);
    if (wrapper == null) {
        throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName());
    }
    // clear the webservice ref in the servlet context
    final String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER);
    if (webServicecontainerId != null) {
        context.getServletContext().removeAttribute(webServicecontainerId);
        wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER);
    }
}
Also used : Context(org.apache.catalina.Context) IgnoredStandardContext(org.apache.tomee.catalina.IgnoredStandardContext) StandardContext(org.apache.catalina.core.StandardContext) Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Container(org.apache.catalina.Container)

Example 100 with Wrapper

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

the class TomcatWsRegistry method addServlet.

private void addServlet(final Container host, final Context context, final String mapping, final HttpListener httpListener, final String path, final List<String> addresses, final boolean fakeDeployment, final String moduleId) {
    // build the servlet
    final Wrapper wrapper = context.createWrapper();
    wrapper.setName("webservice" + path.substring(1));
    wrapper.setServletClass(WsServlet.class.getName());
    // add servlet to context
    context.addChild(wrapper);
    context.addServletMappingDecoded(mapping, wrapper.getName());
    final String webServicecontainerID = wrapper.getName() + WsServlet.WEBSERVICE_CONTAINER + httpListener.hashCode();
    wrapper.addInitParameter(WsServlet.WEBSERVICE_CONTAINER, webServicecontainerID);
    setWsContainer(context, wrapper, httpListener);
    webserviceContexts.put(new Key(path, moduleId), context);
    // register wsdl locations for service-ref resolution
    for (final Connector connector : connectors) {
        final StringBuilder fullContextpath;
        if (!WEBSERVICE_OLDCONTEXT_ACTIVE && !fakeDeployment) {
            String contextPath = context.getPath();
            if (contextPath == null || !contextPath.isEmpty()) {
                if (contextPath != null && !contextPath.startsWith("/")) {
                    contextPath = "/" + contextPath;
                } else if (contextPath == null) {
                    contextPath = "/";
                }
            }
            fullContextpath = new StringBuilder(contextPath);
            if (!WEBSERVICE_SUB_CONTEXT.equals("/")) {
                fullContextpath.append(WEBSERVICE_SUB_CONTEXT);
            }
            fullContextpath.append(path);
        } else {
            fullContextpath = new StringBuilder(context.getPath()).append(path);
        }
        try {
            final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), fullContextpath.toString(), null, null);
            addresses.add(address.toString());
        } catch (final URISyntaxException ignored) {
        // no-op
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Connector(org.apache.catalina.connector.Connector) URISyntaxException(java.net.URISyntaxException) WsServlet(org.apache.openejb.server.webservices.WsServlet) URI(java.net.URI)

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