/** * Create an <code>ObjectName</code> for this <code>ContextResource</code> object. * * @param domain Domain in which this name is to be created * @param resource The ContextResource to be named * @exception MalformedObjectNameException if a name cannot be created */ public static ObjectName createObjectName(String domain, ContextResource resource) throws MalformedObjectNameException { ObjectName name = null; String encodedResourceName = encodeStr(resource.getName()); Object container = resource.getNamingResources().getContainer(); if (container instanceof Server) { name = new ObjectName( domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) path = "/"; Host host = (Host) ((Context) container).getParent(); name = new ObjectName( domain + ":type=Resource" + ",resourcetype=Context,path=" + path + ",host=" + host.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof DefaultContext) { container = ((DefaultContext) container).getParent(); if (container instanceof Host) { Host host = (Host) container; name = new ObjectName( domain + ":type=Resource" + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof Engine) { name = new ObjectName( domain + ":type=Resource" + ",resourcetype=ServiceDefaultContext,class=" + resource.getType() + ",name=" + encodedResourceName); } } return (name); }
/** * Add a new child Host to our associated Engine. * * @param host Child host to add */ private void addHost(Host host) { if (debug >= 3) engine.log("Adding host '" + host.getName() + "'"); host.addContainerListener(this); // Register the host name addAlias(host.getName(), host); // Register all associated aliases String aliases[] = host.findAliases(); for (int i = 0; i < aliases.length; i++) addAlias(aliases[i], host); }
private void initServer() throws Exception { // point catalina at the provided home directory server = new Embedded(); server.setCatalinaHome(catalinaHome.getAbsolutePath()); Engine engine = server.createEngine(); engine.setName("embedded"); server.addEngine(engine); host = server.createHost("localhost", new File(catalinaHome, "webapps").getAbsolutePath()); engine.addChild(host); engine.setDefaultHost(host.getName()); // bind to an available port httpConnector = new EmbeddedConnector(); server.addConnector(httpConnector); // disable session persistence on restart sessions = new MemoryStore(); sessionManager = new PersistentManager(); sessionManager.setDistributable(false); sessionManager.setSaveOnRestart(false); sessionManager.setStore(sessions); Context root = server.createContext("", new File(catalinaHome, "conf").getAbsolutePath()); root.setManager(sessionManager); host.addChild(root); }
/** * Create an <code>ObjectName</code> for this <code>Manager</code> object. * * @param domain Domain in which this name is to be created * @param manager The Manager to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Manager manager) throws MalformedObjectNameException { ObjectName name = null; Container container = manager.getContainer(); if (container instanceof Engine) { name = new ObjectName(domain + ":type=Manager"); } else if (container instanceof Host) { name = new ObjectName(domain + ":type=Manager,host=" + container.getName()); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) { path = "/"; } Host host = (Host) container.getParent(); name = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + host.getName()); } else if (container == null) { DefaultContext defaultContext = manager.getDefaultContext(); if (defaultContext != null) { Container parent = defaultContext.getParent(); if (parent instanceof Engine) { name = new ObjectName(domain + ":type=DefaultManager"); } else if (parent instanceof Host) { name = new ObjectName(domain + ":type=DefaultManager,host=" + parent.getName()); } } } return (name); }
/** * Creates a single webapp configuration to be run in Tomcat. * * @param contextName the context name without leading slash, for example, "openmrs" * @param port the port at which to run tomcat. */ public TomcatManager(String contextName, int port) { // create server container = new Embedded(); container.setCatalinaHome("tomcat"); // create context Context rootContext = container.createContext("/" + contextName, contextName); rootContext.setReloadable(true); // create host Host localHost = container.createHost("localhost", "webapps"); localHost.addChild(rootContext); // create engine Engine engine = container.createEngine(); engine.setName("Catalina"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); container.addEngine(engine); // create http connector Connector httpConnector = container.createConnector((InetAddress) null, port, false); container.addConnector(httpConnector); }
private void silence(Host host, String ctx) { String base = "org.apache.catalina.core.ContainerBase.[default].["; if (host == null) { base += getHost().getName(); } else { base += host.getName(); } base += "].["; base += ctx; base += "]"; LOG.warn(base); }
private void silence(Host host, String ctx) { String base = "org.apache.catalina.core.ContainerBase.[default].["; if (host == null) { base += getHost().getName(); } else { base += host.getName(); } base += "].["; base += ctx; base += "]"; Logger.getLogger(base).setLevel(Level.WARNING); }
/** * Create an <code>ObjectName</code> for this <code>Valve</code> object. * * @param domain Domain in which this name is to be created * @param valve The Valve to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, GlassFishValve valve) throws MalformedObjectNameException { if (valve instanceof ValveBase) { ObjectName name = ((ValveBase) valve).getObjectName(); if (name != null) return name; } ObjectName name = null; Container container = null; String className = valve.getClass().getName(); int period = className.lastIndexOf('.'); if (period >= 0) className = className.substring(period + 1); if (valve instanceof Contained) { container = ((Contained) valve).getContainer(); } if (container == null) { throw new MalformedObjectNameException( "Cannot create mbean for non-contained valve " + valve); } if (container instanceof Engine) { String local = ""; int seq = getSeq(local); String ext = ""; if (seq > 0) { ext = ",seq=" + seq; } name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local); } else if (container instanceof Host) { String local = ",host=" + container.getName(); int seq = getSeq(local); String ext = ""; if (seq > 0) { ext = ",seq=" + seq; } name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) { path = "/"; } Host host = (Host) container.getParent(); String local = ",path=" + path + ",host=" + host.getName(); int seq = getSeq(local); String ext = ""; if (seq > 0) { ext = ",seq=" + seq; } name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local); } return (name); }
/** * Create an <code>ObjectName</code> for this <code>Server</code> object. * * @param domain Domain in which this name is to be created * @param resources The NamingResources to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, NamingResources resources) throws MalformedObjectNameException { ObjectName name = null; Object container = resources.getContainer(); if (container instanceof Server) { name = new ObjectName(domain + ":type=NamingResources" + ",resourcetype=Global"); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) path = "/"; Host host = (Host) ((Context) container).getParent(); name = new ObjectName( domain + ":type=NamingResources" + ",resourcetype=Context,path=" + path + ",host=" + host.getName()); } else if (container instanceof DefaultContext) { container = ((DefaultContext) container).getParent(); if (container instanceof Host) { Host host = (Host) container; name = new ObjectName( domain + ":type=NamingResources" + ",resourcetype=HostDefaultContext,host=" + host.getName()); } else if (container instanceof Engine) { name = new ObjectName( domain + ":type=NamingResources" + ",resourcetype=ServiceDefaultContext"); } } return (name); }
/** Process a "start" event for this Host. */ public void start() { if (log.isDebugEnabled()) log.debug(sm.getString("hostConfig.start")); try { ObjectName hostON = new ObjectName(host.getObjectName()); oname = new ObjectName(hostON.getDomain() + ":type=Deployer,host=" + host.getName()); Registry.getRegistry(null, null).registerComponent(this, oname, this.getClass().getName()); } catch (Exception e) { log.error(sm.getString("hostConfig.jmx.register", oname), e); } if (host.getDeployOnStartup()) deployApps(); }
/** * Create an <code>ObjectName</code> for this <code>DefaultContext</code> object. * * @param domain Domain in which this name is to be created * @param context The DefaultContext to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, DefaultContext context) throws MalformedObjectNameException { ObjectName name = null; Container container = context.getParent(); if (container instanceof Host) { Host host = (Host) container; name = new ObjectName(domain + ":type=DefaultContext,host=" + host.getName()); } else if (container instanceof Engine) { name = new ObjectName(domain + ":type=DefaultContext"); } return (name); }
public void setWrapper(Wrapper wrapper) { if (wrapper != null) { host = (Host) wrapper.getParent().getParent(); try { deployerOName = new ObjectName(host.getParent().getName() + ":type=Deployer,host=" + host.getName()); } catch (MalformedObjectNameException e) { // do nothing here } host.getPipeline().addValve(valve); mBeanServer = Registry.getRegistry(null, null).getMBeanServer(); } else if (host != null) { host.getPipeline().removeValve(valve); } }
public EmbeddedTomcat(String contextPath, int port, String jvmRoute) throws MalformedURLException { this.contextPath = contextPath; this.port = port; // create server container = new Embedded(); container.setCatalinaHome(catalinaHome); // Not really necessasry, but let's still do it... container.setRealm(new MemoryRealm()); // create webapp loader WebappLoader loader = new WebappLoader(this.getClass().getClassLoader()); if (classesDir != null) { loader.addRepository(new File(classesDir).toURI().toURL().toString()); } rootContext = container.createContext("", webappDir); rootContext.setLoader(loader); rootContext.setReloadable(true); // Otherwise we get NPE when instantiating servlets rootContext.setIgnoreAnnotations(true); // create host Host localHost = container.createHost("127.0.0.1", new File("").getAbsolutePath()); localHost.addChild(rootContext); localHost.setDeployOnStartup(true); // create engine engine = container.createEngine(); engine.setName("localEngine"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); engine.setJvmRoute(jvmRoute); engine.setService(new StandardService()); container.addEngine(engine); // create http connector Connector httpConnector = container.createConnector((InetAddress) null, port, false); container.addConnector(httpConnector); container.setAwait(true); // Create the JVMRoute valve for session failover ValveBase valve = new JvmRouteBinderValve(); ((StandardEngine) engine).addValve(valve); }
/** * Create an <code>ObjectName</code> for this <code>Context</code> object. * * @param domain Domain in which this name is to be created * @param context The Context to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Context context) throws MalformedObjectNameException { ObjectName name = null; Host host = (Host) context.getParent(); String path = context.getPath(); if (path.length() < 1) path = "/"; // FIXME name = new ObjectName( domain + ":j2eeType=WebModule,name=//" + host.getName() + path + ",J2EEApplication=none,J2EEServer=none"); return (name); }
/** * Create an <code>ObjectName</code> for this <code>ContextResource</code> object. * * @param resource The resource * @return ObjectName The object name * @exception MalformedObjectNameException if a name cannot be created */ protected ObjectName createObjectName(ContextResource resource) throws MalformedObjectNameException { String domain = null; if (container instanceof StandardServer) { domain = ((StandardServer) container).getDomain(); } else if (container instanceof ContainerBase) { domain = ((ContainerBase) container).getDomain(); } if (domain == null) { domain = "Catalina"; } ObjectName name = null; String quotedResourceName = ObjectName.quote(resource.getName()); if (container instanceof Server) { name = new ObjectName( domain + ":type=DataSource" + ",class=" + resource.getType() + ",name=" + quotedResourceName); } else if (container instanceof Context) { String contextName = ((Context) container).getName(); if (!contextName.startsWith("/")) contextName = "/" + contextName; Host host = (Host) ((Context) container).getParent(); name = new ObjectName( domain + ":type=DataSource" + ",host=" + host.getName() + ",context=" + contextName + ",class=" + resource.getType() + ",name=" + quotedResourceName); } return (name); }
/** * Return a File object representing the "configuration root" directory for our associated Host. */ protected File configBase() { if (configBase != null) { return configBase; } File file = new File(System.getProperty("catalina.base"), "conf"); Container parent = host.getParent(); if ((parent != null) && (parent instanceof Engine)) { file = new File(file, parent.getName()); } file = new File(file, host.getName()); try { configBase = file.getCanonicalFile(); } catch (IOException e) { configBase = file; } return (configBase); }
/** * Remove an existing child Host from our associated Engine. * * @param host Host to be removed */ private void removeHost(Host host) { if (debug >= 3) engine.log("Removing host '" + host.getName() + "'"); host.removeContainerListener(this); // Identify all names mapped to this host ArrayList removes = new ArrayList(); Iterator keys = cache.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (host.equals((Host) cache.get(key))) removes.add(key); } // Remove the associated names keys = removes.iterator(); while (keys.hasNext()) { removeAlias((String) keys.next()); } }
/** * Create an <code>ObjectName</code> for this <code>Realm</code> object. * * @param domain Domain in which this name is to be created * @param realm The Realm to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Realm realm) throws MalformedObjectNameException { ObjectName name = null; Container container = realm.getContainer(); if (container instanceof Engine) { name = new ObjectName(domain + ":type=Realm"); } else if (container instanceof Host) { name = new ObjectName(domain + ":type=Realm,host=" + container.getName()); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) { path = "/"; } Host host = (Host) container.getParent(); name = new ObjectName(domain + ":type=Realm,path=" + path + ",host=" + host.getName()); } return (name); }
public String getHostName() { return host.getName(); }
/** * Add an alias for the specified host. * * @param alias New alias name * @param host Host to resolve to */ private void addAlias(String alias, Host host) { if (debug >= 3) engine.log("Adding alias '" + alias + "' for host '" + host.getName() + "'"); cache.put(alias.toLowerCase(), host); }
/** * Create an <code>ObjectName</code> for this <code>Host</code> object. * * @param domain Domain in which this name is to be created * @param host The Host to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Host host) throws MalformedObjectNameException { ObjectName name = null; name = new ObjectName(domain + ":type=Host,host=" + host.getName()); return (name); }