Search in sources :

Example 86 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)

Example 87 with Wrapper

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

the class TomcatWsRegistry method setWsContainer.

@Override
public List<String> setWsContainer(final HttpListener httpListener, final ClassLoader classLoader, String contextRoot, String virtualHost, final ServletInfo servletInfo, final String realmName, final String transportGuarantee, final String authMethod, final String moduleId) throws Exception {
    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?");
    }
    if ("ROOT".equals(contextRoot)) {
        // doesn't happen in tomee itself but with all our tooling around
        contextRoot = "";
    }
    if (!contextRoot.startsWith("/") && !contextRoot.isEmpty()) {
        contextRoot = "/" + contextRoot;
    }
    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());
    }
    // for Pojo web services, we need to change the servlet class which is the service implementation
    // by the WsServler class
    wrapper.setServletClass(WsServlet.class.getName());
    if (wrapper.getServlet() != null) {
        // deallocate previous one
        wrapper.unload();
        // reload this one withuot unloading it to keep the instance - unload is called during stop()
        wrapper.load();
        // boolean controlling this method call can't be set to false through API so let do it ourself
        // or Reflections.set(wrapper, "instanceInitialized", false);
        wrapper.getServlet().init(StandardWrapper.class.cast(wrapper));
    }
    setWsContainer(context, wrapper, httpListener);
    // add service locations
    final List<String> addresses = new ArrayList<>();
    for (final Connector connector : connectors) {
        for (final String mapping : wrapper.findMappings()) {
            final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), (contextRoot.startsWith("/") ? "" : "/") + contextRoot + mapping, null, null);
            addresses.add(address.toString());
        }
    }
    return addresses;
}
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) Connector(org.apache.catalina.connector.Connector) Container(org.apache.catalina.Container) ArrayList(java.util.ArrayList) WsServlet(org.apache.openejb.server.webservices.WsServlet) URI(java.net.URI) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Aggregations

Wrapper (org.apache.catalina.Wrapper)87 Context (org.apache.catalina.Context)53 Tomcat (org.apache.catalina.startup.Tomcat)46 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)14 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)14 File (java.io.File)11 Container (org.apache.catalina.Container)11 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 StandardContext (org.apache.catalina.core.StandardContext)6 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)6 ServletException (javax.servlet.ServletException)5 ArrayList (java.util.ArrayList)4 ServletContext (javax.servlet.ServletContext)4