public Service getService(String serviceName) { Service service; if (serviceName == null) { Service[] services = server.findServices(); if (services == null || services.length == 0) throw new IllegalStateException("No services in server"); if (services.length > 1) throw new IllegalStateException("More than one service in server. Provide name of desired server" + Arrays.asList(services)); service = services[0]; } else { service = server.findService(serviceName); } return service; }
/** * Remove an existing Service. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeService(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String serviceName = oname.getKeyProperty("serviceName"); Server server = ServerFactory.getServer(); Service service = server.findService(serviceName); // Remove this component from its parent component server.removeService(service); }
public void configure(Map<String, String> params) { String serviceId = params.get("service"); Server server = ServerFactory.getServer(); if (server == null) throw new NullPointerException("Could not get Tomcat server"); Service service = null; if (serviceId != null) service = server.findService(serviceId); else { Service[] services = server.findServices(); if (services != null && services.length > 0) service = services[0]; } if (service == null) throw new NullPointerException("Could not find Tomcat service for: " + (serviceId != null ? serviceId : "(default)")); engine = (Engine)service.getContainer(); if (engine == null) throw new NullPointerException("Could not find Tomcat container for: " + (serviceId != null ? serviceId : "(default)")); }
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0); ObjectName name = new ObjectName("Catalina", "type", "Server"); Server server = (Server) mBeanServer.getAttribute(name, "managedResource"); Service service = server.findService("Catalina"); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(engine.getDefaultHost()); host.getAppBase(); //Got it.
public void configure(Map<String, String> params) { String serviceId = params.get("service"); Server server = ServerFactory.getServer(); if (server == null) throw new NullPointerException("Could not get Tomcat server"); Service service = null; if (serviceId != null) service = server.findService(serviceId); else { Service[] services = server.findServices(); if (services != null && services.length > 0) service = services[0]; } if (service == null) throw new NullPointerException("Could not find Tomcat service for: " + (serviceId != null ? serviceId : "(default)")); engine = (Engine)service.getContainer(); if (engine == null) throw new NullPointerException("Could not find Tomcat container for: " + (serviceId != null ? serviceId : "(default)")); }
public void configure(Map<String, String> params) { String serviceId = params.get("service"); Server server = ServerFactory.getServer(); if (server == null) throw new NullPointerException("Could not get GlassFish V3 server"); Service service = null; if (serviceId != null) service = server.findService(serviceId); else { Service[] services = server.findServices(); if (services != null && services.length > 0) service = services[0]; } if (service == null) throw new NullPointerException("Could not find GlassFish V3 service for: " + (serviceId != null ? serviceId : "(default)")); engine = (Engine)service.getContainer(); if (engine == null) throw new NullPointerException("Could not find GlassFish V3 container for: " + (serviceId != null ? serviceId : "(default)")); }