Refine search
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); } } }
private static void configureServer(Server server) { server.addLifecycleListener(new JreMemoryLeakPreventionListener()); server.addLifecycleListener(new ThreadLocalLeakPreventionListener()); }
static String toString(org.apache.catalina.Server server) { requireNonNull(server, "server"); final Service[] services = server.findServices(); final String serviceName; if (services.length == 0) { serviceName = "<unknown>"; } else { serviceName = services[0].getName(); } final StringBuilder buf = new StringBuilder(128); buf.append("(serviceName: "); buf.append(serviceName); if (TomcatVersion.major() >= 8) { buf.append(", catalinaBase: "); buf.append(server.getCatalinaBase()); } buf.append(')'); return buf.toString(); }
static TomcatService forConfig(TomcatServiceConfig config) { final Consumer<Connector> postStopTask = connector -> { final org.apache.catalina.Server server = connector.getService().getServer(); if (server.getState() == LifecycleState.STOPPED) { try { logger.info("Destroying an embedded Tomcat: {}", toString(server)); server.destroy(); } catch (Exception e) { logger.warn("Failed to destroy an embedded Tomcat: {}", toString(server), e); } } }; return new ManagedTomcatService(null, new ManagedConnectorFactory(config), postStopTask); }
void start() throws Exception { assert hostName() != null; started = false; connector = connectorFactory.apply(hostName()); final Service service = connector.getService(); final Engine engine = TomcatUtil.engine(service, hostName()); final String engineName = engine.getName(); if (activeEngines.contains(engineName)) { throw new TomcatServiceException("duplicate engine name: " + engineName); } server = service.getServer(); if (!TOMCAT_START_STATES.contains(server.getState())) { logger.info("Starting an embedded Tomcat: {}", toString(server)); server.start(); started = true; } else { throw new TomcatServiceException("Cannot manage already running server: " + engineName); } activeEngines.add(engineName); this.engineName = engineName; }
log.error("PORT " + this.httpPort + " ALREADY IN USE"); return; this.skipJarsTldConfig); this.tomcat = new Tomcat(); this.tomcat.setBaseDir(this.tempDirectory); this.tomcat.setSilent(true); this.tomcat.getServer().addLifecycleListener(new AprLifecycleListener()); this.tomcat.getEngine().setDefaultHost("localhost"); this.tomcat.getService().addConnector(httpsConnector); this.tomcat.getServer().setPort(this.shutdownPort); this.tomcat.getServer() .addLifecycleListener(new GlobalResourcesLifecycleListener()); Server server = this.tomcat.getServer(); server.addLifecycleListener(new JreMemoryLeakPreventionListener()); server.addLifecycleListener(new ThreadLocalLeakPreventionListener()); this.tomcat.getServer().await(); stop();
if (log.isDebugEnabled()) log.debug("Creating MBean for Server " + server); NamingResources resources = server.getGlobalNamingResources(); if (resources != null) { createMBeans(resources); Service services[] = server.findServices(); for (int i = 0; i < services.length; i++) { if (services[i].getContainer().getClass().getName().equals ("org.apache.catalina.connector.warp.WarpEngine")) { if (log.isDebugEnabled()) { log.debug("Skipping MBean for Service " + services[i]);
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.destroy")); // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) ExpandWar.delete(new File(workDir)); }
digester.parse(is); } catch (Exception e) { log.error("Catalina.stop: ", e); System.exit(1); s.stop(); } catch (LifecycleException e) { log.error("Catalina.stop: ", e); if (s.getPort()>0) { try (Socket socket = new Socket(s.getAddress(), s.getPort()); OutputStream stream = socket.getOutputStream()) { String shutdown = s.getShutdown(); for (int i = 0; i < shutdown.length(); i++) { stream.write(shutdown.charAt(i)); log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(), String.valueOf(s.getPort()))); log.error("Catalina.stop: ", ce); System.exit(1); log.error(sm.getString("catalina.stopServer")); System.exit(1);
tomcat.setBaseDir(args.getWorkingDirectory()); StandardHost host = (StandardHost)tomcat.getHost(); host.setAutoDeploy(false); host.setDeployOnStartup(true); tomcat.getServer().setPort(args.getShutdownPort()); tomcat.getService().addConnector(connector); tomcat.getService().addConnector(connector); tomcat.getService().addConnector(connector);
tomcat.setBaseDir(getSettings().getBaseFolder()); Context context = tomcat.addContext(getSettings().getContextPath(), docBase.getAbsolutePath()); context.setAllowCasualMultipartParsing(true); PippoServlet pippoServlet = new PippoServlet(); tomcat.start(); } catch (LifecycleException e) { log.error("Unable to launch Tomcat", e); tomcat.getServer().await();
/** * Fires the embedded tomcat that is assumed to be fully configured. * * @throws LifecycleException if tomcat failed to start */ private void doStart() throws LifecycleException { tomcat.getServer().addLifecycleListener(new TomcatLifecycleListener()); logger.info("Deploying application to [" + getConfig().getDeployUrl() + "]"); tomcat.start(); // Let's set the port that was used to actually start the application if necessary if (getConfig().getPort() == EmbedVaadinConfig.DEFAULT_PORT) { getConfig().setPort(getTomcat().getConnector().getLocalPort()); } logger.info("Application has been deployed to [" + getConfig().getDeployUrl() + "]"); if (config.shouldOpenBrowser()) { BrowserUtils.openBrowser(getConfig().getOpenBrowserUrl()); } if (isWaiting()) { tomcat.getServer().await(); } }
@Override public void accept(final Tomcat tomcat) { tomcat.getServer().addLifecycleListener(this); }
private void stop(Tomcat tomcat) throws LifecycleException, InterruptedException { tomcat.stop(); long deadline = System.currentTimeMillis() + 10000; do { switch(tomcat.getServer().getState()) { case STOPPED: case DESTROYING: case DESTROYED: case FAILED: return; default : { } } Thread.sleep(10); } while(deadline > System.currentTimeMillis()); }
public void doStart() throws Exception { //Find all the access log valves and add them to the list //Valve could be added on Engine/Host/Context Server server = tomcatServer.getServer(); accessLogValves = new LinkedList<AccessLogValve>(); for(Service service : server.findServices()) { Container container = service.getContainer(); searchAccessLogValves(container); } }
private void addPreviouslyRemovedConnectors() { Service[] services = this.tomcat.getServer().findServices(); for (Service service : services) { Connector[] connectors = this.serviceConnectors.get(service); if (connectors != null) { for (Connector connector : connectors) { service.addConnector(connector); if (!this.autoStart) { stopProtocolHandler(connector); } } this.serviceConnectors.remove(service); } } }
digester.parse(is); } catch (Exception e) { log.error(sm.getString("catalina.stopError"), e); System.exit(1); s.stop(); } catch (LifecycleException e) { log.error(sm.getString("catalina.stopError"), e); if (s.getPortWithOffset() > 0) { try (Socket socket = new Socket(s.getAddress(), s.getPortWithOffset()); OutputStream stream = socket.getOutputStream()) { String shutdown = s.getShutdown(); for (int i = 0; i < shutdown.length(); i++) { stream.write(shutdown.charAt(i)); log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(), String.valueOf(s.getPortWithOffset()), String.valueOf(s.getPort()), String.valueOf(s.getPortOffset()))); log.error(sm.getString("catalina.stopError"), ce); System.exit(1);