tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manv...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service AddServiceForm.java
Date Fri, 08 Feb 2002 01:13:42 GMT
manveen     02/02/07 17:13:42

  Modified:    webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service
                        AddServiceForm.java
  Log:
  backend for creating and adding a new service through the admin tool.
  
  Revision  Changes    Path
  1.2       +63 -42    jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceForm.java
  
  Index: AddServiceForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceForm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AddServiceForm.java	4 Feb 2002 17:59:19 -0000	1.1
  +++ AddServiceForm.java	8 Feb 2002 01:13:42 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceForm.java,v
1.1 2002/02/04 17:59:19 manveen Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/04 17:59:19 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceForm.java,v
1.2 2002/02/08 01:13:42 manveen Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/08 01:13:42 $
    *
    * ====================================================================
    *
  @@ -79,14 +79,27 @@
   import org.apache.webapp.admin.ApplicationServlet;
   import org.apache.webapp.admin.TomcatTreeBuilder;
   
  +import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanOperationInfo;
  +import javax.management.MBeanInfo;
  +
  +import javax.management.modelmbean.ModelMBean;
  +import javax.management.modelmbean.ModelMBeanInfo;
  +
   import org.apache.commons.modeler.ManagedBean;
   import org.apache.commons.modeler.Registry;
   
  +import javax.management.RuntimeOperationsException;
  +import javax.management.MBeanException;
  +import java.lang.RuntimeException;
  +
  +//import org.apache.catalina.mbeans.MBeanUtils;
  +
   /**
    * Form bean for the add service page.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.1 $ $Date: 2002/02/04 17:59:19 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/08 01:13:42 $
    */
   
   public final class AddServiceForm extends ActionForm {
  @@ -220,6 +233,7 @@
           this.defaultHost = defaultHost;
           
       }
  +    
       // --------------------------------------------------------- Public Methods
       
       /**
  @@ -251,6 +265,7 @@
           
           ActionErrors errors = new ActionErrors();
           String submit = request.getParameter("submit");
  +        ObjectInstance mBeanFactory = null;
           
           if (submit != null) {
               
  @@ -259,49 +274,55 @@
                   new ActionError("error.serviceName.required"));
               } else {
                   
  -                // just try to register mBean
  -                // if exception is bean already registered, then add error message.
  +                // try to create a new service.
                   try {
                       
  -                    Registry registry = Registry.getRegistry();
  -                    String[] all = registry.findManagedBeans();
  -                    
  -                    for (int i=0; i<all.length; i++) {
  -                        System.out.println(all[i]);
  -                    }
  -                    
                       ApplicationServlet servlet = (ApplicationServlet)getServlet();
                       mBServer = servlet.getServer();
                       
  -                    System.out.println("Creating MBeans ...");
  -                    
  -                    ManagedBean managed = registry.findManagedBean("StandardService");
  -                      /*
  -                      String domain = mserver.getDefaultDomain();
  -                       
  -                      mbean.setClassName("org.apache.catalina.mbeans.StandardContextMBean");
  -                      mbean.setDomain(mBServer.getDefaultDomain());
  -                       
  -                      ModelMBean mbean = managed.createMBean(userDatabase);
  -                      ObjectName oname = createObjectName(domain, userDatabase);
  -                      */
  -                    ObjectName oName = new ObjectName(
  -                    TomcatTreeBuilder.ENGINE_TYPE + ",service=" + serviceName);
  -                    
  -                    ObjectInstance oInst = mBServer.createMBean(
  -                    "org.apache.catalina.mbeans.StandardContextMBean", oName);
  -                    
  -                    ModelMBean mbean = managed.createMBean();
  -                    
  -                    mBServer.registerMBean(mbean, oName);
  -                    
  -                    // check that this service name does not already exist.
  -                    //} catch(InstanceAlreadyExistsException iaee) {
  -                    // a service with this name does not exist before
  -                    // therefore add it.
  -                    
  -                    //System.out.println("created mBean!");
  -                    
  +                    // Get hold of the parent server.
  +                    Iterator serverItr =
  +                    mBServer.queryMBeans(new ObjectName(TomcatTreeBuilder.SERVER_TYPE +
  +                    TomcatTreeBuilder.WILDCARD), null).iterator();
  +                    
  +                    ObjectInstance objInstance = (ObjectInstance)serverItr.next();
  +                    ObjectName server = (objInstance).getObjectName();
  +                    
  +                    mBeanFactory = TomcatTreeBuilder.getMBeanFactory();
  +                    ObjectName factory = mBeanFactory.getObjectName();
  +                    
  +                    Object[] params = new Object[2];
  +                    // mBean name of the parent server
  +                    params[0] = new String(server.toString());
  +                    // name of the new service to be added
  +                    params[1] = new String(serviceName);
  +                    
  +                    String[] types = new String[2];
  +                    types[0]= "java.lang.String";
  +                    types[1]= "java.lang.String";
  +                    
  +                    // get a unique service name for the new service.
  +                    String newService = (String)
  +                    mBServer.invoke(factory, "createStandardService", params, types);
  +                    
  +                    // add this newly created service to the server mBean.
  +                    Object[] serviceParam = new Object[1];
  +                    serviceParam[0] = new String(newService);
  +                    
  +                    String[] type = new String[1];
  +                    type[0]= "java.lang.String";
  +                    
  +                    // System.out.println("Created Service " + newService);
  +                    mBServer.invoke(server, "addService", serviceParam, type);
  +                    
  +                } catch (RuntimeOperationsException ex) {
  +                    RuntimeException e = ex.getTargetException();
  +                    // print the root exception
  +                    if (e instanceof RuntimeOperationsException){
  +                        ((RuntimeOperationsException)e).getTargetException().printStackTrace();
  +                    } else {
  +                        e.printStackTrace();
  +                    }
                   } catch (Throwable t) {
                       t.printStackTrace();
                   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message