Search in sources :

Example 1 with Service

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

the class ManagerServlet method getConnectorCiphers.

protected Map<String, Set<String>> getConnectorCiphers() {
    Map<String, Set<String>> result = new HashMap<>();
    Engine e = (Engine) host.getParent();
    Service s = e.getService();
    Connector[] connectors = s.findConnectors();
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            SSLHostConfig[] sslHostConfigs = connector.getProtocolHandler().findSslHostConfigs();
            for (SSLHostConfig sslHostConfig : sslHostConfigs) {
                String name = connector.toString() + "-" + sslHostConfig.getHostName();
                Set<String> cipherList = new HashSet<>();
                String[] cipherNames = sslHostConfig.getEnabledCiphers();
                for (String cipherName : cipherNames) {
                    cipherList.add(cipherName);
                }
                result.put(name, cipherList);
            }
        } else {
            Set<String> cipherList = new HashSet<>();
            cipherList.add(sm.getString("managerServlet.notSslConnector"));
            result.put(connector.toString(), cipherList);
        }
    }
    return result;
}
Also used : Connector(org.apache.catalina.connector.Connector) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Service(org.apache.catalina.Service) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Engine(org.apache.catalina.Engine) HashSet(java.util.HashSet)

Example 2 with Service

use of org.apache.catalina.Service in project spring-boot by spring-projects.

the class TomcatWebServer method removeServiceConnectors.

private void removeServiceConnectors() {
    for (Service service : this.tomcat.getServer().findServices()) {
        Connector[] connectors = service.findConnectors().clone();
        this.serviceConnectors.put(service, connectors);
        for (Connector connector : connectors) {
            service.removeConnector(connector);
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service)

Example 3 with Service

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

the class LiveReloadInstaller method install.

public static void install(String path, final int port, final String folder) {
    final Server server = TomcatHelper.getServer();
    if (server == null) {
        throw new IllegalStateException("tomcat not yet starting");
    }
    // checking which one is localhost could be better but should be fine
    final Service service = server.findServices()[0];
    final Engine engine = Engine.class.cast(service.getContainer());
    final Container host = engine.findChild(engine.getDefaultHost());
    if (LifecycleState.STARTED != host.getState()) {
        throw new IllegalStateException("host not started, call LiveReloadInstaller.install() later.");
    }
    // add connector
    final Connector connector = new Connector();
    connector.setPort(port);
    connector.setAttribute("connectionTimeout", "30000");
    service.addConnector(connector);
    // and the endpoint and start the watcher
    final Closeable watch = Instances.get().getWatcher().watch(folder);
    final LiveReloadWebapp liveReloadWebapp = new LiveReloadWebapp(path);
    liveReloadWebapp.addApplicationLifecycleListener(new ServletContextListener() {

        @Override
        public void contextInitialized(final ServletContextEvent servletContextEvent) {
            servletContextEvent.getServletContext().log("Started livereload server on port " + port);
        }

        @Override
        public void contextDestroyed(final ServletContextEvent servletContextEvent) {
            try {
                watch.close();
            } catch (final IOException e) {
            // no-op: not that important, we shutdown anyway
            }
        }
    });
    host.addChild(liveReloadWebapp);
}
Also used : Connector(org.apache.catalina.connector.Connector) Container(org.apache.catalina.Container) Server(org.apache.catalina.Server) ServletContextListener(javax.servlet.ServletContextListener) Closeable(java.io.Closeable) Service(org.apache.catalina.Service) IOException(java.io.IOException) Engine(org.apache.catalina.Engine) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 4 with Service

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

the class WebappDeployer method check.

private void check() {
    final StandardServer server = TomcatHelper.getServer();
    for (final Service service : server.findServices()) {
        if (service.getContainer() instanceof Engine) {
            final Engine engine = (Engine) service.getContainer();
            for (final Container engineChild : engine.findChildren()) {
                if (engineChild instanceof StandardHost) {
                    final StandardHost host = (StandardHost) engineChild;
                    webappBuilder.checkHost(host);
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardServer(org.apache.catalina.core.StandardServer) StandardHost(org.apache.catalina.core.StandardHost) Service(org.apache.catalina.Service) Engine(org.apache.catalina.Engine)

Example 5 with Service

use of org.apache.catalina.Service 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)

Aggregations

Service (org.apache.catalina.Service)62 StandardService (org.apache.catalina.core.StandardService)25 Engine (org.apache.catalina.Engine)20 Connector (org.apache.catalina.connector.Connector)20 StandardEngine (org.apache.catalina.core.StandardEngine)16 ObjectName (javax.management.ObjectName)13 StandardHost (org.apache.catalina.core.StandardHost)12 Container (org.apache.catalina.Container)8 Executor (org.apache.catalina.Executor)8 Server (org.apache.catalina.Server)8 MBeanServer (javax.management.MBeanServer)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MBeanException (javax.management.MBeanException)6 Host (org.apache.catalina.Host)6 File (java.io.File)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 StandardContext (org.apache.catalina.core.StandardContext)5 JarFile (java.util.jar.JarFile)3