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()); }
public List<ContextInfo> list() { final List<ContextInfo> list = new ArrayList<ContextInfo>(); final StandardServer server = getServer(); 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) .forEach(context -> { // copy to another object -- not the important part final ContextInfo info = new ContextInfo(context.getPath()); info.setThisPart(context.getThisPart()); info.setNotImportant(context.getNotImportant()); list.add(info); }); return list; }
@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; }
final Service[] services = server.findServices(); if (services == null || services.length != 1 || services[0] != expectedService) { throw new TomcatServiceException(
@Override protected void configure(ServerBuilder sb) throws Exception { sb.http(0); sb.https(0); sb.tlsSelfSigned(); sb.serviceUnder( "/jsp/", TomcatServiceBuilder.forFileSystem(webAppRoot().toPath()) .serviceName(SERVICE_NAME) .configurator(s -> Collections.addAll(tomcatServices, s.findServices())) .build() .decorate(LoggingService.newDecorator())); sb.serviceUnder( "/jar/", TomcatServiceBuilder.forClassPath(Future.class) .serviceName("TomcatServiceTest-JAR") .build() .decorate(LoggingService.newDecorator())); sb.serviceUnder( "/jar_altroot/", TomcatServiceBuilder.forClassPath(Future.class, "/io/netty/util/concurrent") .serviceName("TomcatServiceTest-JAR-AltRoot") .build() .decorate(LoggingService.newDecorator())); } };
/** * 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; }
private String getServiceName() { if (serviceName == null) { final StandardServer server = TomcatHelper.getServer(); serviceName = server == null ? null : server.findServices()[0].getName(); } return serviceName; }
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; }
/** * 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); } }
public void start() { // hook the hosts so we get notified before contexts are started standardServer.addPropertyChangeListener(this); standardServer.addLifecycleListener(this); for (Service service : standardServer.findServices()) { serviceAdded(service); } }
/** * Starts operation. */ public void start() { // hook the hosts so we get notified before contexts are started standardServer.addPropertyChangeListener(this); standardServer.addLifecycleListener(this); for (Service service : standardServer.findServices()) { serviceAdded(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; } } }
public TomcatRsRegistry() { StandardServer standardServer = TomcatHelper.getServer(); for (Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); engine = (Engine) service.getContainer(); break; } } }
public TomcatWsRegistry() { StandardServer standardServer = TomcatHelper.getServer(); for (Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); engine = (Engine) service.getContainer(); break; } } }
public void start() { // hook the hosts so we get notified before contexts are started standardServer.addPropertyChangeListener(this); standardServer.addLifecycleListener(this); for (Service service : standardServer.findServices()) { serviceAdded(service); } }
public TomcatRsRegistry() { for (final Service service : TomcatHelper.getServer().findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); break; } } hosts = SystemInstance.get().getComponent(Hosts.class); }
public TomcatRsRegistry() { for (final Service service : TomcatHelper.getServer().findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); break; } } hosts = SystemInstance.get().getComponent(Hosts.class); }
private void deployWebApp(final Context app) { TomcatHelper.getServer().findServices()[0].getContainer().findChildren()[0].addChild(app); }
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); } } } } }
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); } } } } }