You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2002/05/08 02:41:18 UTC

cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources SaveDataSourceAction.java

manveen     02/05/07 17:41:18

  Modified:    webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        ApplicationResources_en.properties
                        ApplicationResources_es.properties
                        CommitChangesAction.java
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector
                        SaveConnectorAction.java
  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources
                        SaveDataSourceAction.java
  Log:
  Implemented save jdbc datasource class.
  Added resources "peroperties" to spanish file. Placeholders for localization for now.
  
  Revision  Changes    Path
  1.56      +1 -1      jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties
  
  Index: ApplicationResources_en.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- ApplicationResources_en.properties	7 May 2002 21:19:41 -0000	1.55
  +++ ApplicationResources_en.properties	8 May 2002 00:41:18 -0000	1.56
  @@ -321,7 +321,7 @@
   users.error.rolename.required=Role Name is required
   users.error.select=Error selecting managed objects
   users.error.token=Transaction submitted out of order
  -users.error.username.required=User Name is required
  +users.error.username.required=<li>User Name is required<li>
   users.group.newGroup=Create New Group Properties
   users.group.oldGroup=Edit Existing Group Properties
   users.group.properties=Group Properties
  
  
  
  1.48      +16 -2     jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties
  
  Index: ApplicationResources_es.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- ApplicationResources_es.properties	4 May 2002 19:45:07 -0000	1.47
  +++ ApplicationResources_es.properties	8 May 2002 00:41:18 -0000	1.48
  @@ -2,7 +2,7 @@
   errors.header=<h3><font color="red">Error(es) de Validaci\u00f3n</font></h3>Debe corregir el/los siguiente(s) error(es) antes de continuar:<ul>
   errors.footer=</ul><hr>
   error.login=<li>Nombre de usuario o contrase\u00f1a inv\u00e1lidos</li>
  -prompt.username=Nombre de usuario
  +prompt.username=Nombre de Usuario
   prompt.password=Contrase\u00f1a
   button.login=Autenticar
   button.reset=Reiniciar
  @@ -285,6 +285,19 @@
   resources.error.value.mismatch=<li>El tipo y el valor no se parecen emparejar.</li>
   resources.error.entryType.invalid=<li>El tipo de la entrada no recognized.</li>
   resources.error.entryType.notimpl=<li>Validation for this type not implemented yet.</li>
  +resources.error.url.required=<li>Datasource URL is required.</li>
  +resources.error.driverClass.required=<li>JDBC Driver Class is required.</li>
  +resources.error.active.required=<li>Max Active Connections is required.</li>
  +resources.error.idle.required=<li>Max Idle Connections is required.</li>
  +resources.error.wait.required=<li>Max Wait for a Connection is required.</li>
  +resources.integer.error=<li>Invalid integer error.</li>
  +resources.actions.userdb.create=Create New User Database
  +resources.actions.userdb.edit=Edit User Database
  +resources.actions.userdb.delete=Delete User Databases
  +resources.userdb.location=Location
  +resources.userdb.factory=Factory
  +resources.treeBuilder.userdbs=User Databases
  +resources.error.path.required=<li>Path is required</li>
   
   # ---------- User Database Module ----------
   users.actions.group.create=Cree Al Nuevo Grupo
  @@ -306,8 +319,9 @@
   users.error.password.required=Contrase\u00f1a Requerida
   users.error.quotes=La doble comilla no esta permitida en los campos de valores
   users.error.rolename.required=Se requiere el nombre del role
  +users.error.select=Error selecting managed objects
   users.error.token=Sometido transaccion fuera de servicio
  -users.error.username.required=Se requiere el nombre del utilizador
  +users.error.username.required=<li>Se requiere el nombre del utilizador</li>
   users.group.newGroup=Cree Las Nuevas Properties Del Grupo
   users.group.oldGroup=Corrija Las Properties Existentes Del Grupo
   users.group.properties=Properties del Grupo
  
  
  
  1.2       +7 -15     jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/CommitChangesAction.java
  
  Index: CommitChangesAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/CommitChangesAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CommitChangesAction.java	2 May 2002 23:50:51 -0000	1.1
  +++ CommitChangesAction.java	8 May 2002 00:41:18 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/CommitChangesAction.java,v 1.1 2002/05/02 23:50:51 manveen Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/05/02 23:50:51 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/CommitChangesAction.java,v 1.2 2002/05/08 00:41:18 manveen Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/05/08 00:41:18 $
    *
    * ====================================================================
    *
  @@ -59,7 +59,6 @@
    *
    */
   
  -
   package org.apache.webapp.admin;
   
   
  @@ -89,7 +88,7 @@
    * and writes them out to server.xml
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.1 $ $Date: 2002/05/02 23:50:51 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/08 00:41:18 $
    */
   
   public final class CommitChangesAction extends Action {
  @@ -128,7 +127,6 @@
                                    HttpServletResponse response)
           throws IOException, ServletException {
   
  -        // save to server.xml        
           // Acquire a reference to the MBeanServer containing our MBeans
           try {
               mBServer = ((ApplicationServlet) getServlet()).getServer();
  @@ -144,13 +142,7 @@
               resources = getServlet().getResources();
           }
           
  -
  -        // Invalidate the current session and create a new one
  -        //HttpSession session = request.getSession();
  -        //session.invalidate();
  -        //session = request.getSession(true);
  -
  -        ObjectName sname = null;    
  +       ObjectName sname = null;    
           try {
              sname = new ObjectName(TomcatTreeBuilder.SERVER_TYPE);
           } catch (Exception e) {
  @@ -159,7 +151,7 @@
               response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
               return (null);
           }
  -
  +        
          String operation = "store";
          try {           
               mBServer.invoke(sname, operation, null, null);            
  @@ -175,7 +167,7 @@
           }
    
           //FIX ME-- just a message for debugging
  -        System.out.println("Debugging-- changes written to conf/server.xml.new");
  +        System.out.println("Debugging -- changes saved to conf/server.xml");
           // Forward control back to the banner
           return (mapping.findForward("Banner"));
   
  
  
  
  1.8       +5 -5      jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/SaveConnectorAction.java
  
  Index: SaveConnectorAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/SaveConnectorAction.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SaveConnectorAction.java	30 Apr 2002 21:38:20 -0000	1.7
  +++ SaveConnectorAction.java	8 May 2002 00:41:18 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/SaveConnectorAction.java,v 1.7 2002/04/30 21:38:20 manveen Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/04/30 21:38:20 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/SaveConnectorAction.java,v 1.8 2002/05/08 00:41:18 manveen Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/05/08 00:41:18 $
    *
    * ====================================================================
    *
  @@ -95,7 +95,7 @@
    * <em>Edit Connector</em> transactions.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.7 $ $Date: 2002/04/30 21:38:20 $
  + * @version $Revision: 1.8 $ $Date: 2002/05/08 00:41:18 $
    */
   
   public final class SaveConnectorAction extends Action {
  @@ -203,7 +203,6 @@
                   values[1] = cform.getAddress();
                   values[2] = new Integer(cform.getPortText());
   
  -                // FIX ME -- fix all create operations
                   if ("HTTP".equalsIgnoreCase(connectorType)) {
                           operation = "createHttpConnector"; // HTTP
                   } else if ("HTTPS".equalsIgnoreCase(connectorType)) { 
  @@ -215,6 +214,7 @@
                   cObjectName = (String)
                       mBServer.invoke(fname, operation,
                                       values, createStandardConnectorTypes);
  +                
                   // Add the new Connector to our tree control node
                   TreeControl control = (TreeControl)
                       session.getAttribute("treeControlTest");
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SaveDataSourceAction.java
  
  Index: SaveDataSourceAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SaveDataSourceAction.java,v 1.1 2002/05/08 00:41:18 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/05/08 00:41:18 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.webapp.admin.resources;
  
  import java.io.IOException;
  import java.net.URLDecoder;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.MBeanInfo;
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * <p>Implementation of <strong>Action</strong> that saves a new or
   * updated data source entry.</p>
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/05/08 00:41:18 $
   * @since 4.1
   */
  
  public final class SaveDataSourceAction extends Action {
  
  
      // ----------------------------------------------------- Instance Variables
  
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
  
  
      /**
       * The MBeanServer we will be interacting with.
       */
      private MBeanServer mserver = null;
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
          // Look up the components we will be using as needed
          if (mserver == null) {
              mserver = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
  
          // Has this transaction been cancelled?
          if (isCancelled(request)) {
              return (mapping.findForward("List DataSources Setup"));
          }
  
          // Check the transaction token
          if (!isTokenValid(request)) {
              response.sendError
                  (HttpServletResponse.SC_BAD_REQUEST,
                   resources.getMessage(locale, "users.error.token"));
              return (null);
          }
  
          // Perform any extra validation that is required
          DataSourceForm dataSourceForm = (DataSourceForm) form;
          String objectName = dataSourceForm.getObjectName();
  
          // Perform an "Add DataSource" transaction
          if (objectName == null) {
  
              String signature[] = new String[2];
              signature[0] = "java.lang.String";
              signature[1] = "java.lang.String";
  
              Object params[] = new Object[2];
              params[0] = dataSourceForm.getUrl();
              params[1] = ResourceUtils.DATASOURCE_CLASS;     
             
              ObjectName oname = null;
  
              try {
  
                  // Construct the MBean Name for the naming source
                  oname = new ObjectName(ResourceUtils.NAMINGRESOURCES_TYPE);
  
                  // Create the new object and associated MBean
                  objectName = (String) mserver.invoke(oname, "addResource",
                                                       params, signature);
                                       
              } catch (Exception e) {
  
                  getServlet().log
                      (resources.getMessage(locale, "users.error.invoke",
                                            "addResource"), e);
                  response.sendError
                      (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                       resources.getMessage(locale, "users.error.invoke",
                                            "addResource"));
                  return (null);
              }
  
          }
          
          // Perform an "Update User database" transaction
          String attribute = null;
          try {
              
              ObjectName oname = new ObjectName(objectName);
  
              attribute = "url";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, dataSourceForm.getUrl()));
              attribute = "driverClassName";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, dataSourceForm.getDriverClass()));
              attribute = "username";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, dataSourceForm.getUsername()));
              attribute = "password";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, dataSourceForm.getPassword()));
              attribute = "maxActive";
              int maxActive = 4;
              try {
                  maxActive = Integer.parseInt(dataSourceForm.getActive());
              } catch (Throwable t) {
                  maxActive = 4;
              }
              mserver.setAttribute(oname,
                                    new Attribute(attribute, new Integer(maxActive)));            
              attribute = "maxIdle";
              int maxIdle = 2;
              try {
                  maxIdle = Integer.parseInt(dataSourceForm.getIdle());
              } catch (Throwable t) {
                  maxIdle = 2;
              }
              mserver.setAttribute(oname,
                                    new Attribute(attribute, new Integer(maxIdle)));            
                                    
              attribute = "maxWait";
              int maxWait = 5000;
              try {
                  maxWait = Integer.parseInt(dataSourceForm.getWait());
              } catch (Throwable t) {
                  maxWait = 5000;
              }
              mserver.setAttribute(oname,
                                    new Attribute(attribute, new Integer(maxWait)));            
              
              attribute = "validationQuery";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, dataSourceForm.getQuery()));
  
          } catch (Exception e) {
  
              getServlet().log
                  (resources.getMessage(locale, "users.error.set.attribute",
                                        attribute), e);
              response.sendError
                  (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                   resources.getMessage(locale, "users.error.set.attribute",
                                        attribute));
              return (null);
  
          }
          
          // Proceed to the list entries screen
          return (mapping.findForward("DataSources List Setup"));
  
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>