Refine search
if (!Objects.equals(server.getCatalinaBase(), expectedBaseDir) || !Objects.equals(server.getCatalinaHome(), expectedBaseDir)) { throw new TomcatServiceException("A configurator should never change the Catalina base and home."); if (server.getPort() != EMBEDDED_TOMCAT_PORT) { throw new TomcatServiceException("A configurator should never change the port of the server."); final Service[] services = server.findServices(); if (services == null || services.length != 1 || services[0] != expectedService) { throw new TomcatServiceException( if (!config.serviceName().equals(expectedService.getName())) { throw new TomcatServiceException( "A configurator should never change the name of the default service."); final Connector[] connectors = expectedService.findConnectors(); if (connectors == null || Arrays.stream(connectors).noneMatch(c -> c == expectedConnector)) { throw new TomcatServiceException("A configurator should never remove the default connector.");
final StandardServer server = new StandardServer(); server.setCatalinaBase(baseDir); server.setCatalinaHome(baseDir); server.setPort(EMBEDDED_TOMCAT_PORT); server.addService(service);
public TomcatWsRegistry() { StandardServer standardServer = (StandardServer) ServerFactory.getServer(); for (Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); engine = (Engine) service.getContainer(); break; } } }
/** * Stop nested components ({@link Service}s) and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error * that needs to be reported */ @Override protected void stopInternal() throws LifecycleException { setState(LifecycleState.STOPPING); fireLifecycleEvent(CONFIGURE_STOP_EVENT, null); // Stop our defined Services for (int i = 0; i < services.length; i++) { services[i].stop(); } stopAwait(); }
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); } } } } }
/** * Starts operation. */ public void start() { // hook the hosts so we get notified before contexts are started standardServer.addPropertyChangeListener(this); standardServer.addLifecycleListener(this); for (final Service service : standardServer.findServices()) { serviceAdded(service); } }
((StandardServer) server).addPropertyChangeListener(this); for (int i = 0; i < services.length; i++) { if (services[i].getContainer().getClass().getName().equals ("org.apache.catalina.connector.warp.WarpEngine")) { if (log.isDebugEnabled()) {
/** * Construct a default instance of this class. */ public StandardServer() { super(); globalNamingResources = new NamingResourcesImpl(); globalNamingResources.setContainer(this); if (isUseNaming()) { namingContextListener = new NamingContextListener(); addLifecycleListener(namingContextListener); } else { namingContextListener = null; } }
/** * Get the server object. You can add listeners and few more * customizations. JNDI is disabled by default. */ public Server getServer() { if (server != null) { return server; } System.setProperty("catalina.useNaming", "false"); server = new StandardServer(); initBaseDir(); server.setPort( -1 ); service = new StandardService(); service.setName("Tomcat"); server.addService( service ); return server; }
private Connector findConnector() { final StandardServer server = TomcatHelper.getServer(); final Service[] services = server.findServices(); for (final Service s : services) { for (final Connector connector : s.findConnectors()) { if (connector.getProtocol().toLowerCase(Locale.ENGLISH).contains("http")) { // TODO: enhance, should not be secured ATM return connector; } } } return null; }
@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; }
private String getServiceName() { if (serviceName == null) { final StandardServer server = TomcatHelper.getServer(); serviceName = server == null ? null : server.findServices()[0].getName(); } return serviceName; }
OpenEJBNamingContextListener namingContextListener = new OpenEJBNamingContextListener(standardServer); if (standardServer.getGlobalNamingContext() != null) { namingContextListener.start(); standardServer.addLifecycleListener(namingContextListener); standardServer.addLifecycleListener(new LifecycleListener() { public void lifecycleEvent(LifecycleEvent event) { String type = event.getType();
public List<ContextInfo> list() { final StandardServer server = getServer(); return Arrays.stream(server.findServices()) .filter(service -> service.getContainer() instanceof Engine) .map(service -> (Engine)service.getContainer()) .flatMap(engine -> Arrays.stream(engine.findChildren())) .filter(possibleHost -> possibleHost instanceof Host) .map(possibleHost -> (Host)possibleHost) .flatMap(host -> Arrays.stream(host.findChildren())) .filter(possibleContext -> possibleContext instanceof Context) .map(possibleContext -> (Context)possibleContext) .map(context -> { // copy to another object -- not the important part final ContextInfo info = new ContextInfo(context.getPath()); info.setThisPart(context.getThisPart()); info.setNotImportant(context.getNotImportant()); return info; }) .collect(Collectors.toList()); }
private Tomcat prepareTomcatServer(ContainerConfig.Configuration cc, ContainerConfig.Configuration.Property engineConfig) throws ContainerException { System.setProperty(Globals.CATALINA_HOME_PROP, System.getProperty("ofbiz.home") + "/" + ContainerConfig.getPropertyValue(cc, "catalina-runtime-home", "runtime/catalina")); System.setProperty(Globals.CATALINA_BASE_PROP, System.getProperty(Globals.CATALINA_HOME_PROP)); Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(System.getProperty("ofbiz.home")); Property defaultHostProp = engineConfig.getProperty("default-host"); if (defaultHostProp == null) { throw new ContainerException("default-host element of server property is required for catalina!"); } tomcat.setHostname(defaultHostProp.value); if (ContainerConfig.getPropertyValue(cc, "use-naming", false)) { tomcat.enableNaming(); } StandardServer server = (StandardServer) tomcat.getServer(); try { server.setGlobalNamingContext(new InitialContext()); } catch (NamingException e) { throw new ContainerException(e); } return tomcat; }
/** * Return a String representation of this component. */ @Override public String toString() { StringBuilder sb = new StringBuilder("StandardServer["); sb.append(getPort()); sb.append("]"); return sb.toString(); }
@Override public void close() { ofNullable(instance).ifPresent(mw -> StandardServer.class.cast(mw.getTomcat().getServer()).stopAwait()); }
private ObjectName getObjectName(Server server) throws MalformedObjectNameException { String domain = (server instanceof StandardServer) ? ((StandardServer) server).getDomain() : ManagementFactory.getPlatformMBeanServer().getDefaultDomain(); return ObjectName.getInstance(domain, "type", "ModClusterListener"); }
/** * Construct a default instance of this class. */ public StandardServer() { super(); ServerFactory.setServer(this); globalNamingResources = new NamingResources(); globalNamingResources.setContainer(this); if (isUseNaming()) { namingContextListener = new NamingContextListener(); namingContextListener.setDebug(getDebug()); addLifecycleListener(namingContextListener); } }
/** * Obtain the MBean domain for this server. The domain is obtained using * the following search order: * <ol> * <li>Name of first {@link org.apache.catalina.Engine}.</li> * <li>Name of first {@link Service}.</li> * </ol> */ @Override protected String getDomainInternal() { String domain = null; Service[] services = findServices(); if (services.length > 0) { Service service = services[0]; if (service != null) { domain = service.getDomain(); } } return domain; }