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; }
@Override public Connector apply(String hostname) { // Create the connector with our protocol handler. Tomcat will call ProtocolHandler.setAdapter() // on its startup with the Coyote Adapter which gives an access to Tomcat's HTTP service pipeline. final Class<?> protocolType = TomcatService.PROTOCOL_HANDLER_CLASS; final Connector connector = new Connector(protocolType.getName()); // We do not really open a port - just trying to stop the Connector from complaining. connector.setPort(0); final StandardServer server = newServer(hostname, connector, config); // Retrieve the components configured by newServer(), so we can use it in checkConfiguration(). final Service service = server.findServices()[0]; final Engine engine = TomcatUtil.engine(service, hostname); final StandardHost host = (StandardHost) engine.findChildren()[0]; final Context context = (Context) host.findChildren()[0]; // Apply custom configurators set via TomcatServiceBuilder.configurator() try { config.configurators().forEach(c -> c.accept(server)); } catch (Throwable t) { throw new TomcatServiceException("failed to configure an embedded Tomcat", t); } // Make sure the configurators did not ruin what we have configured in this method. checkConfiguration(server, service, connector, engine, host, context); assert connector.getService().getServer() != null; return connector; }
public void init() throws Exception { if( this.getService() != null ) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Already configured"); } return; } }
public void destroy() throws Exception { if( oname!=null && controller==oname ) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Unregister itself " + oname ); } } if( getService() == null) return; getService().removeConnector(this); }
@Override protected String getDomainInternal() { Service s = getService(); if (s == null) { return null; } else { return service.getDomain(); } }
public void init() throws Exception { if( this.getService() != null ) { if(log.isDebugEnabled()) log.debug( "Already configured" ); return; } if( container==null ) { findContainer(); } }
@Override protected String getDomainInternal() { Service s = getService(); if (s == null) { return null; } else { return service.getDomain(); } }
@Override protected String getDomainInternal() { Service s = getService(); if (s == null) { return null; } else { return service.getDomain(); } }
@Override protected String getDomainInternal() { return MBeanUtils.getDomain(getService()); }
@Override protected String getDomainInternal() { return MBeanUtils.getDomain(getService()); }
@Override protected String getDomainInternal() { return MBeanUtils.getDomain(getService()); }
@Override protected String getDomainInternal() { return MBeanUtils.getDomain(getService()); }
@Override protected String getDomainInternal() { return MBeanUtils.getDomain(getService()); }
public void destroy() throws Exception { if( oname!=null && controller==oname ) { if(log.isDebugEnabled()) log.debug("Unregister itself " + oname ); Registry.getRegistry(null, null).unregisterComponent(oname); } if( getService() == null) return; getService().removeConnector(this); }
public void destroy() throws Exception { if (org.apache.tomcat.util.Constants.ENABLE_MODELER) { if( oname!=null && controller==oname ) { Registry.getRegistry(null, null).unregisterComponent(oname); } } if( getService() == null) return; getService().removeConnector(this); }
public void init() throws Exception { if( this.getService() != null ) { if(log.isDebugEnabled()) log.debug( "Already configured" ); return; } if( container==null ) { findContainer(); } }
public void destroy() throws Exception { if( oname!=null && controller==oname ) { if(log.isDebugEnabled()) log.debug("Unregister itself " + oname ); Registry.getRegistry(null, null).unregisterComponent(oname); } if( getService() == null) return; getService().removeConnector(this); }
@Override protected void destroyInternal() throws LifecycleException { try { if (protocolHandler != null) { protocolHandler.destroy(); } } catch (Exception e) { throw new LifecycleException( sm.getString("coyoteConnector.protocolHandlerDestroyFailed"), e); } if (getService() != null) { getService().removeConnector(this); } super.destroyInternal(); }
@Override protected void destroyInternal() throws LifecycleException { try { protocolHandler.destroy(); } catch (Exception e) { throw new LifecycleException (sm.getString ("coyoteConnector.protocolHandlerDestroyFailed"), e); } if (getService() != null) { getService().removeConnector(this); } super.destroyInternal(); }