From: markt Date: Sun, 12 Sep 2010 01:25:03 +0000 (+0000) Subject: Further work for https://issues.apache.org/bugzilla/show_bug.cgi?id=49234 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7781a34a0c5b2a96eaf87cc32ce17221e86dd519;p=tomcat7.0 Further work for https://issues.apache.org/bugzilla/show_bug.cgi?id=49234 GSOC 2010. Enable the creation of Services, Engines, Connectors, Hosts and Contexts via JMX from a minimal server.xml that contains only a Server element. Based on a patch by Chamith Buddhika. I added the additional changes to pass the parent class loader down the hierarchy. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@996231 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/Server.java b/java/org/apache/catalina/Server.java index a2a0b7de2..f01ffa1c0 100644 --- a/java/org/apache/catalina/Server.java +++ b/java/org/apache/catalina/Server.java @@ -19,6 +19,7 @@ package org.apache.catalina; import org.apache.catalina.deploy.NamingResources; +import org.apache.catalina.startup.Catalina; /** * A Server element represents the entire Catalina @@ -115,7 +116,23 @@ public interface Server extends Lifecycle { */ public void setShutdown(String shutdown); + + /** + * Return the parent class loader. + */ + public ClassLoader getParentClassLoader(); + + /** + * Return the outer Catalina startup/shutdown component if present. + */ + public Catalina getCatalina(); + + /** + * Set the outer Catalina startup/shutdown component if present. + */ + public void setCatalina(Catalina catalina); + // --------------------------------------------------------- Public Methods diff --git a/java/org/apache/catalina/Service.java b/java/org/apache/catalina/Service.java index 6643e8f46..a31f19e58 100644 --- a/java/org/apache/catalina/Service.java +++ b/java/org/apache/catalina/Service.java @@ -84,6 +84,11 @@ public interface Service extends Lifecycle { */ public void setServer(Server server); + /** + * Return the parent class loader. + */ + public ClassLoader getParentClassLoader(); + // --------------------------------------------------------- Public Methods diff --git a/java/org/apache/catalina/core/StandardEngine.java b/java/org/apache/catalina/core/StandardEngine.java index 0c5386515..16b2020b3 100644 --- a/java/org/apache/catalina/core/StandardEngine.java +++ b/java/org/apache/catalina/core/StandardEngine.java @@ -26,10 +26,12 @@ import org.apache.catalina.Globals; import org.apache.catalina.Host; import org.apache.catalina.LifecycleException; import org.apache.catalina.Realm; +import org.apache.catalina.Server; import org.apache.catalina.Service; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.catalina.realm.JAASRealm; +import org.apache.catalina.startup.Catalina; import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.util.ServerInfo; import org.apache.juli.logging.Log; @@ -333,6 +335,19 @@ public class StandardEngine extends ContainerBase implements Engine { } + /** + * Return the parent class loader for this component. + */ + @Override + public ClassLoader getParentClassLoader() { + if (parentClassLoader != null) + return (parentClassLoader); + if (service != null) { + return (service.getParentClassLoader()); + } + return (ClassLoader.getSystemClassLoader()); + } + // -------------------- JMX registration -------------------- @Override diff --git a/java/org/apache/catalina/core/StandardServer.java b/java/org/apache/catalina/core/StandardServer.java index 8d2d01699..676dc826f 100644 --- a/java/org/apache/catalina/core/StandardServer.java +++ b/java/org/apache/catalina/core/StandardServer.java @@ -40,6 +40,7 @@ import org.apache.catalina.Service; import org.apache.catalina.deploy.NamingResources; import org.apache.catalina.mbeans.MBeanFactory; import org.apache.catalina.mbeans.MBeanUtils; +import org.apache.catalina.startup.Catalina; import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.util.LifecycleMBeanBase; import org.apache.catalina.util.ServerInfo; @@ -156,6 +157,8 @@ public final class StandardServer extends LifecycleMBeanBase protected PropertyChangeSupport support = new PropertyChangeSupport(this); private boolean stopAwait = false; + + private Catalina catalina = null; // ------------------------------------------------------------- Properties @@ -297,6 +300,23 @@ public final class StandardServer extends LifecycleMBeanBase } + /** + * Return the outer Catalina startup/shutdown component if present. + */ + @Override + public Catalina getCatalina() { + return catalina; + } + + + /** + * Set the outer Catalina startup/shutdown component if present. + */ + @Override + public void setCatalina(Catalina catalina) { + this.catalina = catalina; + } + // --------------------------------------------------------- Server Methods @@ -721,6 +741,17 @@ public final class StandardServer extends LifecycleMBeanBase super.destroyInternal(); } + /** + * Return the parent class loader for this component. + */ + @Override + public ClassLoader getParentClassLoader() { + if (catalina != null) { + return (catalina.getParentClassLoader()); + } + return (ClassLoader.getSystemClassLoader()); + } + private ObjectName onameStringCache; private ObjectName onameMBeanFactory; private ObjectName onameNamingResoucres; diff --git a/java/org/apache/catalina/core/StandardService.java b/java/org/apache/catalina/core/StandardService.java index e3774b1c8..e31d83a46 100644 --- a/java/org/apache/catalina/core/StandardService.java +++ b/java/org/apache/catalina/core/StandardService.java @@ -579,6 +579,17 @@ public class StandardService extends LifecycleMBeanBase implements Service { super.destroyInternal(); } + /** + * Return the parent class loader for this component. + */ + @Override + public ClassLoader getParentClassLoader() { + if (server != null) { + return (server.getParentClassLoader()); + } + return (ClassLoader.getSystemClassLoader()); + } + @Override protected String getDomainInternal() { diff --git a/java/org/apache/catalina/core/mbeans-descriptors.xml b/java/org/apache/catalina/core/mbeans-descriptors.xml index 8b9812cf3..7c18bf37f 100644 --- a/java/org/apache/catalina/core/mbeans-descriptors.xml +++ b/java/org/apache/catalina/core/mbeans-descriptors.xml @@ -62,7 +62,8 @@ description="Standard Context Component" domain="Catalina" group="Context" - type="org.apache.catalina.core.StandardContext"> + type="org.apache.catalina.core.StandardContext" + className="org.apache.catalina.mbeans.ContextMBean"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - + description="Java class name of a LifecycleListener class" + type="java.lang.String"/> - + description="Java class name of a ContainerListener class" + type="java.lang.String"/> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group="Engine" + className="org.apache.catalina.mbeans.ContainerMBean"> - + writeable="false"/> + - + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + @@ -583,7 +1110,8 @@ description="Standard Host Component" domain="Catalina" group="Host" - type="org.apache.catalina.core.StandardHost"> + type="org.apache.catalina.core.StandardHost" + className="org.apache.catalina.mbeans.ContainerMBean"> - + type="boolean"/> + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - + + + - + returnType="void"> + + + + + + + + + + @@ -804,30 +1396,27 @@ description="Standard Service Component" domain="Catalina" group="Service" - type="org.apache.catalina.core.StandardService"> + type="org.apache.catalina.core.StandardService" + className="org.apache.catalina.mbeans.ServiceMBean"> - - - - - - + + + + @@ -836,13 +1425,59 @@ description="Add a new connector" impact="ACTION" returnType="void"> - + + + + - - + + + + + + + + + + + + + + + + + + type="org.apache.catalina.core.StandardWrapper" + className="org.apache.catalina.mbeans.ContainerMBean"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + - + - + description="Type(classname) of the lifecycle listeners to be removed" + type="java.lang.String"/> + + + + + + + + + + + + + ModelMBean with default + * ModelMBeanInfo information. + * + * @exception MBeanException if the initializer of an object + * throws an exception + * @exception RuntimeOperationsException if an IllegalArgumentException + * occurs + */ + public ContainerMBean() + throws MBeanException, RuntimeOperationsException { + + super(); + } + + /** + * Add a new child Container to those associated with this Container, + * if supported. Won't start the child yet. Has to be started with a call to + * Start method after necessary configurations are done. + * + * @param type ClassName of the child to be added + * @param name Name of the child to be added + * + * @exception MBeanException if the child cannot be added + */ + public void addChild(String type, String name) throws MBeanException{ + Container contained = null; + try { + contained = (Container)Class.forName(type).newInstance(); + contained.setName(name); + + if(contained instanceof StandardHost){ + HostConfig config = new HostConfig(); + contained.addLifecycleListener(config); + } else if(contained instanceof StandardContext){ + ContextConfig config = new ContextConfig(); + contained.addLifecycleListener(config); + } + + } catch (InstantiationException e) { + throw new MBeanException(e); + } catch (IllegalAccessException e) { + throw new MBeanException(e); + } catch (ClassNotFoundException e) { + throw new MBeanException(e); + } + + boolean oldValue= true; + + ContainerBase container = null; + try { + container = (ContainerBase)getManagedResource(); + oldValue = container.getStartChildren(); + container.setStartChildren(false); + container.addChild(contained); + contained.init(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } catch (LifecycleException e){ + throw new MBeanException(e); + } finally { + if(container != null) { + container.setStartChildren(oldValue); + } + } + } + + /** + * Remove an existing child Container from association with this parent + * Container. + * + * @param name Name of the existing child Container to be removed + */ + public void removeChild(String name) throws MBeanException{ + if(name != null){ + try { + Container container = (Container)getManagedResource(); + Container contained = container.findChild(name); + container.removeChild(contained); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + } + } + + /** + * Adds a valve to this Container instance. + * + * @param valveType ClassName of the valve to be added + * + * @exception MBeanException if a component cannot be removed + */ + public String addValve(String valveType) throws MBeanException{ + Valve valve = null; + try { + valve = (Valve)Class.forName(valveType).newInstance(); + } catch (InstantiationException e) { + throw new MBeanException(e); + } catch (IllegalAccessException e) { + throw new MBeanException(e); + } catch (ClassNotFoundException e) { + throw new MBeanException(e); + } + + if (valve == null) { + return null; + } + + try { + ContainerBase container = (ContainerBase)getManagedResource(); + container.addValve(valve); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + return ((LifecycleMBeanBase)valve).getObjectName().toString(); + } + + /** + * Remove an existing Valve. + * + * @param name MBean Name of the component to remove + * + * @exception MBeanException if a component cannot be removed + */ + public void removeValve(String valveName) throws MBeanException{ + ContainerBase container=null; + try { + container = (ContainerBase)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + ObjectName oname; + try { + oname = new ObjectName(valveName); + } catch (MalformedObjectNameException e) { + throw new MBeanException(e); + } catch (NullPointerException e) { + throw new MBeanException(e); + } + + if(container != null){ + Valve[] valves = container.getPipeline().getValves(); + for (int i = 0; i < valves.length; i++) { + ObjectName voname = ((ValveBase) valves[i]).getObjectName(); + if (voname.equals(oname)) { + container.getPipeline().removeValve(valves[i]); + } + } + } + } + + /** + * Add a LifecycleEvent listener to this component. + * + * @param type ClassName of the listener to add + */ + public void addLifeCycleListener(String type) throws MBeanException{ + LifecycleListener listener = null; + try { + listener = (LifecycleListener)Class.forName(type).newInstance(); + } catch (InstantiationException e) { + throw new MBeanException(e); + } catch (IllegalAccessException e) { + throw new MBeanException(e); + } catch (ClassNotFoundException e) { + throw new MBeanException(e); + } + + if(listener != null){ + try { + ContainerBase container = (ContainerBase)getManagedResource(); + container.addLifecycleListener(listener); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + } + } + + /** + * Remove a LifecycleEvent listeners from this component. + * + * @param listener The ClassName of the listeners to be removed. + * Note that all the listeners having given ClassName will be removed. + */ + public void removeLifeCycleListeners(String type) throws MBeanException{ + ContainerBase container=null; + try { + container = (ContainerBase)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + LifecycleListener[] listeners = container.findLifecycleListeners(); + for(LifecycleListener listener: listeners){ + if(listener.getClass().equals(type)){ + container.removeLifecycleListener(listener); + } + } + } + +} diff --git a/java/org/apache/catalina/mbeans/ContextMBean.java b/java/org/apache/catalina/mbeans/ContextMBean.java new file mode 100644 index 000000000..debaccc78 --- /dev/null +++ b/java/org/apache/catalina/mbeans/ContextMBean.java @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.mbeans; + +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.RuntimeOperationsException; +import javax.management.modelmbean.InvalidTargetObjectTypeException; + +import org.apache.catalina.Context; +import org.apache.catalina.deploy.ApplicationParameter; +import org.apache.catalina.deploy.ErrorPage; +import org.apache.catalina.deploy.FilterDef; +import org.apache.catalina.deploy.FilterMap; +import org.apache.catalina.deploy.SecurityConstraint; + +public class ContextMBean extends ContainerMBean { + + public ContextMBean() throws MBeanException, RuntimeOperationsException { + + super(); + } + + /** + * Return the set of application parameters for this application. + */ + public String[] findApplicationParameters() throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + ApplicationParameter[] params = context.findApplicationParameters(); + String[] stringParams = new String[params.length]; + for(int counter=0; counter < params.length; counter++){ + stringParams[counter]=params[counter].toString(); + } + + return stringParams; + + } + + /** + * Return the security constraints for this web application. + * If there are none, a zero-length array is returned. + */ + public String[] findConstraints() throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + SecurityConstraint[] constraints = context.findConstraints(); + String[] stringConstraints = new String[constraints.length]; + for(int counter=0; counter < constraints.length; counter++){ + stringConstraints[counter]=constraints[counter].toString(); + } + + return stringConstraints; + + } + + /** + * Return the error page entry for the specified HTTP error code, + * if any; otherwise return null. + * + * @param errorCode Error code to look up + */ + public String findErrorPage(int errorCode) throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + return context.findErrorPage(errorCode).toString(); + + } + + /** + * Return the error page entry for the specified Java exception type, + * if any; otherwise return null. + * + * @param exceptionType Exception type to look up + */ + public String findErrorPage(String exceptionType) throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + return context.findErrorPage(exceptionType).toString(); + + } + + /** + * Return the set of defined error pages for all specified error codes + * and exception types. + */ + public String[] findErrorPages() throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + ErrorPage[] pages = context.findErrorPages(); + String[] stringPages = new String[pages.length]; + for(int counter=0; counter < pages.length; counter++){ + stringPages[counter]=pages[counter].toString(); + } + + return stringPages; + + } + + /** + * Return the filter definition for the specified filter name, if any; + * otherwise return null. + * + * @param filterName Filter name to look up + */ + public String findFilterDef(String name) throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + FilterDef filterDef = context.findFilterDef(name); + return filterDef.toString(); + + } + + /** + * Return the set of defined filters for this Context. + */ + public String[] findFilterDefs() throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + ApplicationParameter[] params = context.findApplicationParameters(); + String[] stringParams = new String[params.length]; + for(int counter=0; counter < params.length; counter++){ + stringParams[counter]=params[counter].toString(); + } + + return stringParams; + + } + + /** + * Return the set of filter mappings for this Context. + */ + public String[] findFilterMaps() throws MBeanException { + + Context context; + try { + context = (Context)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + FilterMap[] maps = context.findFilterMaps(); + String[] stringMaps = new String[maps.length]; + for(int counter=0; counter < maps.length; counter++){ + stringMaps[counter]=maps[counter].toString(); + } + + return stringMaps; + + } + +} diff --git a/java/org/apache/catalina/mbeans/ServiceMBean.java b/java/org/apache/catalina/mbeans/ServiceMBean.java new file mode 100644 index 000000000..4f23e1793 --- /dev/null +++ b/java/org/apache/catalina/mbeans/ServiceMBean.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.mbeans; + +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.RuntimeOperationsException; +import javax.management.modelmbean.InvalidTargetObjectTypeException; + +import org.apache.catalina.Executor; +import org.apache.catalina.Service; +import org.apache.catalina.connector.Connector; +import org.apache.tomcat.util.modeler.BaseModelMBean; + +public class ServiceMBean extends BaseModelMBean { + + public ServiceMBean() + throws MBeanException, RuntimeOperationsException { + + super(); + + } + + /** + * Add a new Connector to the set of defined Connectors, and associate it + * with this Service's Container. + * + * @param address The IP address on which to bind + * @param port TCP port number to listen on + * @param isAjp Create a AJP/1.3 Connector + * @param isSSL Create a secure Connector + * + * @throws MBeanException + */ + public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException { + + Service service; + try { + service = (Service)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + Connector connector = new Connector(); + if ((address!=null) && (address.length()>0)) { + connector.setProperty("address", address); + } + + connector.setPort(port); + connector.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1"); + connector.setSecure(isSSL); + connector.setScheme(isSSL ? "https" : "http"); + + service.addConnector(connector); + + } + + /** + * Adds a named executor to the service + * @param type Classname of the Executor to be added + * @throws MBeanException + */ + public void addExecutor(String type) throws MBeanException { + + Service service; + try { + service = (Service)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + Executor executor; + try { + executor = (Executor)Class.forName(type).newInstance(); + } catch (InstantiationException e) { + throw new MBeanException(e); + } catch (IllegalAccessException e) { + throw new MBeanException(e); + } catch (ClassNotFoundException e) { + throw new MBeanException(e); + } + + service.addExecutor(executor); + + } + + /** + * Find and return the set of Connectors associated with this Service. + * @throws MBeanException + */ + public String[] findConnectors() throws MBeanException { + + Service service; + try { + service = (Service)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + Connector[] connectors = service.findConnectors(); + String[] str = new String[connectors.length]; + + for(int i=0; i< connectors.length; i++){ + str[i] = connectors[i].toString(); + } + + return str; + + } + + /** + * Retrieves all executors + * @throws MBeanException + */ + public String[] findExecutors() throws MBeanException { + + Service service; + try { + service = (Service)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + Executor[] executors = service.findExecutors(); + String[] str = new String[executors.length]; + + for(int i=0; i< executors.length; i++){ + str[i] = executors[i].toString(); + } + + return str; + } + + /** + * Retrieves executor by name + * @param name Name of the executor to be retrieved + * @throws MBeanException + */ + public String getExecutor(String name) throws MBeanException{ + + Service service; + try { + service = (Service)getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (RuntimeOperationsException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + Executor executor = service.getExecutor(name); + return executor.toString(); + + } + +} diff --git a/java/org/apache/catalina/startup/Catalina.java b/java/org/apache/catalina/startup/Catalina.java index a47b245c1..50e081eb9 100644 --- a/java/org/apache/catalina/startup/Catalina.java +++ b/java/org/apache/catalina/startup/Catalina.java @@ -174,11 +174,12 @@ public class Catalina { * @param parentClassLoader The shared extensions class loader. */ public void setParentClassLoader(ClassLoader parentClassLoader) { - this.parentClassLoader = parentClassLoader; - } + public ClassLoader getParentClassLoader() { + return parentClassLoader; + } public void setServer(Server server) { this.server = server; @@ -528,6 +529,8 @@ public class Catalina { return; } + getServer().setCatalina(this); + // Stream redirection initStreams(); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index bc98fd45c..34009313d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -135,6 +135,12 @@ Ensure that Context elements defined in server.xml use any configClass setting specified in the parent Host element. (markt) + + GSOC 2010. Enable the creation of Services, Engines, Connectors, Hosts + and Contexts via JMX from a minimal server.xml that contains only a + Server element. Based on a patch by Chamith Buddhika. (markt) + +