Java Code Examples for org.apache.catalina.Service#getContainer()
The following examples show how to use
org.apache.catalina.Service#getContainer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanUtils.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Determine the name of the domain to register MBeans for from a given * Service. * * @param service * * @deprecated To be removed since to creates a circular dependency. Will * be replaced in Tomcat 8 by a new method on {@link * Service}. */ @Deprecated public static String getDomain(Service service) { // Null service -> return null if (service == null) { return null; } String domain = null; Container engine = service.getContainer(); // Use the engine name first if (engine != null) { domain = engine.getName(); } // No engine or no engine name, use the service name if (domain == null) { domain = service.getName(); } // No service name, use null return domain; }
Example 2
Source File: ThreadLocalLeakPreventionListener.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private void registerListenersForServer(Server server) { for (Service service : server.findServices()) { Engine engine = (Engine) service.getContainer(); engine.addContainerListener(this); registerListenersForEngine(engine); } }
Example 3
Source File: GlobalListenerSupport.java From tomee with Apache License 2.0 | 5 votes |
/** * Service is added. * * @param service tomcat service */ private void serviceAdded(final Service service) { final Container container = service.getContainer(); if (container instanceof StandardEngine) { final StandardEngine engine = (StandardEngine) container; engineAdded(engine); } }
Example 4
Source File: TomcatSecurityService.java From tomee with Apache License 2.0 | 5 votes |
public TomcatSecurityService() { final Server server = TomcatHelper.getServer(); for (final Service service : server.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = (Engine) service.getContainer(); if (engine.getRealm() != null) { defaultRealm = engine.getRealm(); break; } } } }
Example 5
Source File: TomcatWsRegistry.java From tomee with Apache License 2.0 | 5 votes |
public TomcatWsRegistry() { final StandardServer standardServer = TomcatHelper.getServer(); for (final Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { connectors = Arrays.asList(service.findConnectors()); engine = (Engine) service.getContainer(); break; } } }
Example 6
Source File: ThreadLocalLeakPreventionListener.java From tomcatsrc with Apache License 2.0 | 5 votes |
private void registerListenersForServer(Server server) { for (Service service : server.findServices()) { Engine engine = (Engine) service.getContainer(); engine.addContainerListener(this); registerListenersForEngine(engine); } }
Example 7
Source File: MBeanFactory.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
Example 8
Source File: MBeanFactory.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Create a new StandardHost. * * @param parent MBean Name of the associated parent component * @param name Unique name of this Host * @param appBase Application base directory name * @param autoDeploy Should we auto deploy? * @param deployOnStartup Deploy on server startup? * @param deployXML Should we deploy Context XML config files property? * @param unpackWARs Should we unpack WARs when auto deploying? * * @exception Exception if an MBean cannot be created or registered */ public String createStandardHost(String parent, String name, String appBase, boolean autoDeploy, boolean deployOnStartup, boolean deployXML, boolean unpackWARs) throws Exception { // Create a new StandardHost instance StandardHost host = new StandardHost(); host.setName(name); host.setAppBase(appBase); host.setAutoDeploy(autoDeploy); host.setDeployOnStartup(deployOnStartup); host.setDeployXML(deployXML); host.setUnpackWARs(unpackWARs); // add HostConfig for active reloading HostConfig hostConfig = new HostConfig(); host.addLifecycleListener(hostConfig); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Service service = getService(pname); Engine engine = (Engine) service.getContainer(); engine.addChild(host); // Return the corresponding MBean name return (host.getObjectName().toString()); }
Example 9
Source File: OpenEJBListener.java From tomee with Apache License 2.0 | 5 votes |
private static File tryToFindAndExtractWar(final StandardServer source) { if (System.getProperties().containsKey("openejb.war")) { return new File(System.getProperty("openejb.war")); } for (final Service service : source.findServices()) { final Container container = service.getContainer(); if (container instanceof StandardEngine) { final StandardEngine engine = (StandardEngine) container; for (final Container child : engine.findChildren()) { if (child instanceof StandardHost) { final StandardHost host = (StandardHost) child; final File base = hostDir(System.getProperty("catalina.base"), host.getAppBase()); final File[] files = base.listFiles(); if (files != null) { for (final File file : files) { if (isTomEEWar(file)) { return file; } } } } } } } return null; }
Example 10
Source File: TomcatRsRegistry.java From tomee with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: OpenEJBListener.java From tomee with Apache License 2.0 | 5 votes |
private static File findOpenEjbWar() { // in Tomcat 5.5 the OpenEjb war is in the server/webapps director final String catalinaBase = System.getProperty("catalina.base"); final File serverWebapps = new File(catalinaBase, "server/webapps"); File openEjbWar = findOpenEjbWar(serverWebapps); if (openEjbWar != null) { return openEjbWar; } try { // in Tomcat 6 the OpenEjb war is normally in webapps, but we just // scan all hosts directories for (final Service service : TomcatHelper.getServer().findServices()) { final Container container = service.getContainer(); if (container instanceof StandardEngine) { final StandardEngine engine = (StandardEngine) container; for (final Container child : engine.findChildren()) { if (child instanceof StandardHost) { final StandardHost host = (StandardHost) child; final File hostDir = hostDir(catalinaBase, host.getAppBase()); openEjbWar = findOpenEjbWar(hostDir); if (openEjbWar != null) { return openEjbWar; } else { return findOpenEjbWar(host); } } } } } } catch (final Exception e) { LOGGER.log(Level.WARNING, "OpenEJBListener.findOpenEjbWar: {0}", e.getMessage()); } return null; }
Example 12
Source File: MBeanFactory.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Create a new StandardHost. * * @param parent MBean Name of the associated parent component * @param name Unique name of this Host * @param appBase Application base directory name * @param autoDeploy Should we auto deploy? * @param deployOnStartup Deploy on server startup? * @param deployXML Should we deploy Context XML config files property? * @param unpackWARs Should we unpack WARs when auto deploying? * * @exception Exception if an MBean cannot be created or registered */ public String createStandardHost(String parent, String name, String appBase, boolean autoDeploy, boolean deployOnStartup, boolean deployXML, boolean unpackWARs) throws Exception { // Create a new StandardHost instance StandardHost host = new StandardHost(); host.setName(name); host.setAppBase(appBase); host.setAutoDeploy(autoDeploy); host.setDeployOnStartup(deployOnStartup); host.setDeployXML(deployXML); host.setUnpackWARs(unpackWARs); // add HostConfig for active reloading HostConfig hostConfig = new HostConfig(); host.addLifecycleListener(hostConfig); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Service service = getService(pname); Engine engine = (Engine) service.getContainer(); engine.addChild(host); // Return the corresponding MBean name return (host.getObjectName().toString()); }
Example 13
Source File: GlobalListenerSupport.java From tomee with Apache License 2.0 | 5 votes |
/** * Service removed. * * @param service tomcat service */ private void serviceRemoved(final Service service) { final Container container = service.getContainer(); if (container instanceof StandardEngine) { final StandardEngine engine = (StandardEngine) container; engineRemoved(engine); } }
Example 14
Source File: ThreadLocalLeakPreventionListener.java From Tomcat8-Source-Read with MIT License | 5 votes |
private void registerListenersForServer(Server server) { for (Service service : server.findServices()) { Engine engine = service.getContainer(); if (engine != null) { engine.addContainerListener(this); registerListenersForEngine(engine); } } }
Example 15
Source File: MBeanFactory.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
Example 16
Source File: WebappDeployer.java From tomee with Apache License 2.0 | 5 votes |
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); } } } } }
Example 17
Source File: MBeanFactory.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Create a new StandardContext. * * @param parent MBean Name of the associated parent component * @param path The context path for this Context * @param docBase Document base directory (or WAR) for this Context * * @exception Exception if an MBean cannot be created or registered */ public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware, boolean tldValidation, boolean tldNamespaceAware) throws Exception { // Create a new StandardContext instance StandardContext context = new StandardContext(); path = getPathStr(path); context.setPath(path); context.setDocBase(docBase); context.setXmlValidation(xmlValidation); context.setXmlNamespaceAware(xmlNamespaceAware); context.setTldValidation(tldValidation); context.setTldNamespaceAware(tldNamespaceAware); ContextConfig contextConfig = new ContextConfig(); context.addLifecycleListener(contextConfig); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ObjectName deployer = new ObjectName(pname.getDomain()+ ":type=Deployer,host="+ pname.getKeyProperty("host")); if(mserver.isRegistered(deployer)) { String contextName = context.getName(); mserver.invoke(deployer, "addServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); String configPath = (String)mserver.getAttribute(deployer, "configBaseName"); String baseName = context.getBaseName(); File configFile = new File(new File(configPath), baseName+".xml"); if (configFile.isFile()) { context.setConfigFile(configFile.toURI().toURL()); } mserver.invoke(deployer, "manageApp", new Object[] {context}, new String[] {"org.apache.catalina.Context"}); mserver.invoke(deployer, "removeServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); } else { log.warn("Deployer not found for "+pname.getKeyProperty("host")); Service service = getService(pname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(pname.getKeyProperty("host")); host.addChild(context); } // Return the corresponding MBean name return context.getObjectName().toString(); }
Example 18
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 4 votes |
/** * Creates a new web application builder * instance. */ public TomcatWebAppBuilder() { SystemInstance.get().setComponent(WebAppBuilder.class, this); SystemInstance.get().setComponent(TomcatWebAppBuilder.class, this); initJEEInfo = "true".equalsIgnoreCase(SystemInstance.get().getProperty(TomEESystemConfig.TOMEE_INIT_J2EE_INFO, "true")); // TODO: re-write this bit, so this becomes part of the listener, and we register this with the mbean server. final StandardServer standardServer = TomcatHelper.getServer(); globalListenerSupport = new GlobalListenerSupport(standardServer, this); //Getting host config listeners hosts = new Hosts(); SystemInstance.get().setComponent(Hosts.class, hosts); final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); for (final Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = service.getContainer(); // add the global router if relevant final URL globalRouterConf = RouterValve.serverRouterConfigurationURL(); if (globalRouterConf != null) { final RouterValve routerValve = new RouterValve(); routerValve.setConfigurationPath(globalRouterConf); engine.getPipeline().addValve(routerValve); } parentClassLoader = engine.getParentClassLoader(); if (parentClassLoader == ClassLoader.getSystemClassLoader() && parentClassLoader != tccl) { parentClassLoader = tccl; engine.setParentClassLoader(tccl); } // else assume tomcat was setup to force a classloader and then respect it manageCluster(engine.getCluster()); hosts.setDefault(engine.getDefaultHost()); addTomEERealm(engine); for (final Container engineChild : engine.findChildren()) { if (engineChild instanceof StandardHost) { final StandardHost host = (StandardHost) engineChild; manageCluster(host.getCluster()); addTomEERealm(host); host.getPipeline().addValve(new OpenEJBSecurityListener.RequestCapturer()); hosts.add(host); for (final LifecycleListener listener : host.findLifecycleListeners()) { if (listener instanceof HostConfig) { final HostConfig hostConfig = (HostConfig) listener; deployers.put(host.getName(), hostConfig); } } } } } } SystemInstance.get().addObserver(new ClusterObserver(clusters)); final OpenEjbConfigurationFactory component = SystemInstance.get().getComponent(OpenEjbConfigurationFactory.class); ConfigurationFactory configurationFactory = ConfigurationFactory.class.isInstance(component) ? ConfigurationFactory.class.cast(component) : SystemInstance.get().getComponent(ConfigurationFactory.class); if (configurationFactory == null) { configurationFactory = new ConfigurationFactory(); } this.configurationFactory = configurationFactory; deploymentLoader = new DeploymentLoader(); servletContextHandler = new ServletContextHandler(); setComponentsUsedByCDI(); try { // before tomcat was using ServiceLoader or manually instantiation, now it uses SL for itself so we can be in conflict WebSockets.setConfigurator(); } catch (final Throwable th) { // no-op: can be another API impl, normally we are ok, this is really just a safe belt } noHostCheck = !Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.host.check", "true")); }
Example 19
Source File: MBeanFactory.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Create a new StandardContext. * * @param parent MBean Name of the associated parent component * @param path The context path for this Context * @param docBase Document base directory (or WAR) for this Context * * @exception Exception if an MBean cannot be created or registered */ public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware, boolean tldValidation, boolean tldNamespaceAware) throws Exception { // Create a new StandardContext instance StandardContext context = new StandardContext(); path = getPathStr(path); context.setPath(path); context.setDocBase(docBase); context.setXmlValidation(xmlValidation); context.setXmlNamespaceAware(xmlNamespaceAware); context.setTldValidation(tldValidation); context.setTldNamespaceAware(tldNamespaceAware); ContextConfig contextConfig = new ContextConfig(); context.addLifecycleListener(contextConfig); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ObjectName deployer = new ObjectName(pname.getDomain()+ ":type=Deployer,host="+ pname.getKeyProperty("host")); if(mserver.isRegistered(deployer)) { String contextName = context.getName(); mserver.invoke(deployer, "addServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); String configPath = (String)mserver.getAttribute(deployer, "configBaseName"); String baseName = context.getBaseName(); File configFile = new File(new File(configPath), baseName+".xml"); if (configFile.isFile()) { context.setConfigFile(configFile.toURI().toURL()); } mserver.invoke(deployer, "manageApp", new Object[] {context}, new String[] {"org.apache.catalina.Context"}); mserver.invoke(deployer, "removeServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); } else { log.warn("Deployer not found for "+pname.getKeyProperty("host")); Service service = getService(pname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(pname.getKeyProperty("host")); host.addChild(context); } // Return the corresponding MBean name return context.getObjectName().toString(); }
Example 20
Source File: MBeanFactory.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Create a new StandardContext. * * @param parent MBean Name of the associated parent component * @param path The context path for this Context * @param docBase Document base directory (or WAR) for this Context * @param xmlValidation if XML descriptors should be validated * @param xmlNamespaceAware if the XML processor should namespace aware * @return the object name of the created context * * @exception Exception if an MBean cannot be created or registered */ public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware) throws Exception { // Create a new StandardContext instance StandardContext context = new StandardContext(); path = getPathStr(path); context.setPath(path); context.setDocBase(docBase); context.setXmlValidation(xmlValidation); context.setXmlNamespaceAware(xmlNamespaceAware); ContextConfig contextConfig = new ContextConfig(); context.addLifecycleListener(contextConfig); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ObjectName deployer = new ObjectName(pname.getDomain()+ ":type=Deployer,host="+ pname.getKeyProperty("host")); if(mserver.isRegistered(deployer)) { String contextName = context.getName(); mserver.invoke(deployer, "addServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); String configPath = (String)mserver.getAttribute(deployer, "configBaseName"); String baseName = context.getBaseName(); File configFile = new File(new File(configPath), baseName+".xml"); if (configFile.isFile()) { context.setConfigFile(configFile.toURI().toURL()); } mserver.invoke(deployer, "manageApp", new Object[] {context}, new String[] {"org.apache.catalina.Context"}); mserver.invoke(deployer, "removeServiced", new Object [] {contextName}, new String [] {"java.lang.String"}); } else { log.warn("Deployer not found for "+pname.getKeyProperty("host")); Service service = getService(pname); Engine engine = service.getContainer(); Host host = (Host) engine.findChild(pname.getKeyProperty("host")); host.addChild(context); } // Return the corresponding MBean name return context.getObjectName().toString(); }