Search in sources :

Example 1 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project bamboobsc by billchen198318.

the class HostUtils method getHttpPort.

public static int getHttpPort() {
    int port = 8080;
    MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
    ObjectName name;
    try {
        name = new ObjectName("Catalina", "type", "Server");
        try {
            Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
            Service[] services = server.findServices();
            for (Service service : services) {
                for (Connector connector : service.findConnectors()) {
                    ProtocolHandler protocolHandler = connector.getProtocolHandler();
                    if (protocolHandler instanceof Http11Protocol || protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                        port = connector.getPort();
                    }
                }
            }
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    return port;
}
Also used : Connector(org.apache.catalina.connector.Connector) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) InstanceNotFoundException(javax.management.InstanceNotFoundException) Service(org.apache.catalina.Service) Http11AprProtocol(org.apache.coyote.http11.Http11AprProtocol) ObjectName(javax.management.ObjectName) ProtocolHandler(org.apache.coyote.ProtocolHandler) Http11Protocol(org.apache.coyote.http11.Http11Protocol) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer)

Example 2 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project nuxeo-filesystem-connectors by nuxeo.

the class WebDavServerFeature method setUpTomcat.

protected void setUpTomcat() throws Exception {
    tomcat = new Tomcat();
    // for tmp dir
    tomcat.setBaseDir(".");
    tomcat.setHostname(HOST);
    tomcat.setPort(PORT);
    ProtocolHandler p = tomcat.getConnector().getProtocolHandler();
    AbstractEndpoint<?> endpoint = (AbstractEndpoint<?>) getFieldValue(p, "endpoint");
    // vital for clean shutdown
    endpoint.setMaxKeepAliveRequests(1);
    File docBase = new File(".");
    Context context = tomcat.addContext(CONTEXT, docBase.getAbsolutePath());
    Application app = new org.nuxeo.ecm.webdav.Application();
    ApplicationAdapter conf = new ApplicationAdapter(app);
    conf.getFeatures().put(ResourceConfig.FEATURE_MATCH_MATRIX_PARAMS, Boolean.TRUE);
    String servletName = "testServlet";
    Servlet servlet = new ServletContainer(conf);
    tomcat.addServlet(CONTEXT, servletName, servlet);
    context.addServletMappingDecoded("/*", servletName);
    addFilter(context, servletName, "RequestContextFilter", new RequestContextFilter());
    addFilter(context, servletName, "SessionCleanupFilter", new SessionCleanupFilter());
    addFilter(context, servletName, "NuxeoAuthenticationFilter", new NuxeoAuthenticationFilter());
    addFilter(context, servletName, "WebEngineFilter", new WebEngineFilter());
    tomcat.start();
}
Also used : Context(org.apache.catalina.Context) AbstractEndpoint(org.apache.tomcat.util.net.AbstractEndpoint) Tomcat(org.apache.catalina.startup.Tomcat) RequestContextFilter(org.nuxeo.ecm.webengine.jaxrs.context.RequestContextFilter) SessionCleanupFilter(org.nuxeo.ecm.webengine.jaxrs.session.SessionCleanupFilter) WebEngineFilter(org.nuxeo.ecm.webengine.app.WebEngineFilter) ProtocolHandler(org.apache.coyote.ProtocolHandler) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) Servlet(javax.servlet.Servlet) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter) NuxeoAuthenticationFilter(org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter) File(java.io.File) Application(javax.ws.rs.core.Application)

Example 3 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.

the class MBeanUtils method destroyMBean.

/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service) throws Exception {
    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol) handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol) handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol) handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol) handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol) handler).getName();
    }
    ObjectName query = new ObjectName(domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for (ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AjpProtocol(org.apache.coyote.ajp.AjpProtocol) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) Http11Protocol(org.apache.coyote.http11.Http11Protocol) Http11AprProtocol(org.apache.coyote.http11.Http11AprProtocol) AjpAprProtocol(org.apache.coyote.ajp.AjpAprProtocol) ObjectName(javax.management.ObjectName)

Example 4 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.

the class ThreadLocalLeakPreventionListener method stopIdleThreads.

/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 *
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping)
        return;
    if (!(context instanceof StandardContext) || !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. " + "It is not configured to do it.");
        return;
    }
    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }
            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor = (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }
        }
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Service(org.apache.catalina.Service) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Engine(org.apache.catalina.Engine)

Example 5 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.

the class TestCustomSsl method doTestCustomTrustManager.

private void doTestCustomTrustManager(boolean serverTrustAll) throws Exception {
    if (!TesterSupport.RFC_5746_SUPPORTED) {
        // Make sure SSL renegotiation is not disabled in the JVM
        System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
    }
    Tomcat tomcat = getTomcatInstance();
    Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isRenegotiationSupported(getTomcatInstance()));
    TesterSupport.configureClientCertContext(tomcat);
    // Override the defaults
    ProtocolHandler handler = tomcat.getConnector().getProtocolHandler();
    if (handler instanceof AbstractHttp11JsseProtocol) {
        ((AbstractHttp11JsseProtocol<?>) handler).setTruststoreFile(null);
    } else {
        // Unexpected
        Assert.fail("Unexpected handler type");
    }
    if (serverTrustAll) {
        tomcat.getConnector().setAttribute("trustManagerClassName", "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
    }
    // Start Tomcat
    tomcat.start();
    TesterSupport.configureClientSsl();
    // Unprotected resource
    ByteChunk res = getUrl("https://localhost:" + getPort() + "/unprotected");
    Assert.assertEquals("OK", res.toString());
    // Protected resource
    res.recycle();
    int rc = -1;
    try {
        rc = getUrl("https://localhost:" + getPort() + "/protected", res, null, null);
    } catch (SocketException se) {
        if (serverTrustAll) {
            Assert.fail(se.getMessage());
            se.printStackTrace();
        }
    } catch (SSLException he) {
        if (serverTrustAll) {
            Assert.fail(he.getMessage());
            he.printStackTrace();
        }
    }
    if (serverTrustAll) {
        Assert.assertEquals(200, rc);
        Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());
    } else {
        Assert.assertTrue(rc != 200);
        Assert.assertEquals("", res.toString());
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) SocketException(java.net.SocketException) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) SSLException(javax.net.ssl.SSLException)

Aggregations

ProtocolHandler (org.apache.coyote.ProtocolHandler)28 AbstractProtocol (org.apache.coyote.AbstractProtocol)8 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)8 Connector (org.apache.catalina.connector.Connector)7 Tomcat (org.apache.catalina.startup.Tomcat)5 AbstractHttp11JsseProtocol (org.apache.coyote.http11.AbstractHttp11JsseProtocol)5 SocketException (java.net.SocketException)4 Service (org.apache.catalina.Service)4 SSLException (javax.net.ssl.SSLException)3 File (java.io.File)2 Executor (java.util.concurrent.Executor)2 ObjectName (javax.management.ObjectName)2 Context (org.apache.catalina.Context)2 Engine (org.apache.catalina.Engine)2 Http11AprProtocol (org.apache.coyote.http11.Http11AprProtocol)2 Http11NioProtocol (org.apache.coyote.http11.Http11NioProtocol)2 Http11Protocol (org.apache.coyote.http11.Http11Protocol)2 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)2 ThreadPoolExecutor (org.apache.tomcat.util.threads.ThreadPoolExecutor)2 Test (org.junit.jupiter.api.Test)2