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/connector ConnectorAction.java
Date Wed, 13 Feb 2002 22:07:53 GMT
manveen     02/02/13 14:07:53

  Modified:    webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        ServerAction.java SetUpServerAction.java
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector
                        ConnectorAction.java
  Log:
  Throw appropriate exception and error messages when there is a problem getting/setting properties
on server mBean or acquiring the mBean itself.
  
  Revision  Changes    Path
  1.4       +55 -39    jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java
  
  Index: ServerAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServerAction.java	14 Dec 2001 23:22:33 -0000	1.3
  +++ ServerAction.java	13 Feb 2002 22:07:53 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v
1.3 2001/12/14 23:22:33 patrickl Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/12/14 23:22:33 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v
1.4 2002/02/13 22:07:53 manveen Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/13 22:07:53 $
    *
    * ====================================================================
    *
  @@ -63,6 +63,7 @@
   package org.apache.webapp.admin;
   
   import java.util.Iterator;
  +import java.util.Locale;
   import java.io.IOException;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
  @@ -79,23 +80,20 @@
   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;
   
   /**
  - * Implementation of <strong>Action</strong> that validates a user logon.
  + * Implementation of <strong>Action</strong> that saves server properties.
    *
    * @author Jazmin Jonson
    * @author Manveen Kaur
  - * @version $Revision: 1.3 $ $Date: 2001/12/14 23:22:33 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/13 22:07:53 $
    */
   
   public final class ServerAction extends Action {
       
       private static MBeanServer mBServer = null;
  +    private MessageResources resources = null;
       
       // --------------------------------------------------------- Public Methods
       
  @@ -121,33 +119,45 @@
       HttpServletResponse response)
       throws IOException, ServletException {
           
  -        try{
  -            
  -            // front end validation and checking.
  -            // ===================================================
  -            MessageResources messages = getResources();
  -            
  -            // Validate the request parameters specified by the user
  -            ActionErrors errors = new ActionErrors();
  -            
  -            // Report any errors we have discovered back to the original form
  -            if (!errors.empty()) {
  -                saveErrors(request, errors);
  -                return (new ActionForward(mapping.getInput()));
  -            }
  -            
  -            if(mBServer == null) {
  -                ApplicationServlet servlet = (ApplicationServlet)getServlet();
  -                mBServer = servlet.getServer();
  -            }
  +        if (resources == null) {
  +            resources = getServlet().getResources();
  +        }
  +        Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY);
  +        
  +        ActionErrors errors = new ActionErrors();
  +        
  +        // Report any errors we have discovered back to the original form
  +        if (!errors.empty()) {
  +            saveErrors(request, errors);
  +            return (new ActionForward(mapping.getInput()));
  +        }
  +        
  +        // Acquire a reference to the MBeanServer containing our MBeans
  +        try {
  +            mBServer = ((ApplicationServlet) getServlet()).getServer();
  +        } catch (Throwable t) {
  +            throw new ServletException
  +            ("Cannot acquire MBeanServer reference", t);
  +        }
  +        
  +        // Acquire a reference to the Server MBean
  +        ObjectName serverObjName = null;
  +        try {
               Iterator serverItr =
               mBServer.queryMBeans(new ObjectName(TomcatTreeBuilder.SERVER_TYPE +
  -            TomcatTreeBuilder. WILDCARD),
  +            TomcatTreeBuilder.WILDCARD),
               null).iterator();
               
  -            ObjectName serverObjName =
  +            serverObjName =
               ((ObjectInstance)serverItr.next()).getObjectName();
  -            
  +        } catch (Throwable t) {
  +            throw new ServletException
  +            ("Cannot acquire Server MBean reference ", t);
  +        }
  +        
  +        String attribute = null;
  +        // read properties from the mBean
  +        try{
               String shutdownText = request.getParameter("shutdownText");
               String portNumberText = request.getParameter("portNumberText");
               String debugLvlText = request.getParameter("debugLvl");
  @@ -155,7 +165,7 @@
               if(shutdownText != null) {
                   
                   mBServer.setAttribute(serverObjName,
  -                new Attribute(SetUpServerAction.SHUTDOWN_PROP_NAME,
  +                new Attribute(attribute=SetUpServerAction.SHUTDOWN_PROP_NAME,
                   shutdownText));
               }
               
  @@ -163,24 +173,30 @@
                   
                   Integer port = new Integer(portNumberText);
                   mBServer.setAttribute(serverObjName,
  -                new Attribute(SetUpServerAction.PORT_PROP_NAME,
  +                new Attribute(attribute=SetUpServerAction.PORT_PROP_NAME,
                   port));
               }
               
               if(debugLvlText != null) {
                   Integer debugLvl = new Integer(debugLvlText);
                   mBServer.setAttribute(serverObjName,
  -                new Attribute(SetUpServerAction.DEBUG_PROP_NAME,
  +                new Attribute(attribute=SetUpServerAction.DEBUG_PROP_NAME,
                   debugLvl));
               }
  -            
  -        }catch(Throwable t){
  -            t.printStackTrace(System.out);
  -            //forward to error page
  +        } catch(Exception e){
  +            getServlet().log
  +            (resources.getMessage(locale, "users.error.attribute.set",
  +            attribute), e);
  +            response.sendError
  +            (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  +            resources.getMessage(locale, "users.error.attribute.set",
  +            attribute));
  +            return (null);
           }
  +        
           if (servlet.getDebug() >= 1)
               servlet.log(" Forwarding to success page");
  -        // Forward back to the test page
  +        // Forward back to the success page
           return (mapping.findForward("Save Successful"));
           
       }
  
  
  
  1.8       +46 -43    jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java
  
  Index: SetUpServerAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SetUpServerAction.java	10 Jan 2002 03:41:13 -0000	1.7
  +++ SetUpServerAction.java	13 Feb 2002 22:07:53 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v
1.7 2002/01/10 03:41:13 patrickl Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/01/10 03:41:13 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v
1.8 2002/02/13 22:07:53 manveen Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/02/13 22:07:53 $
    *
    * ====================================================================
    *
  @@ -98,13 +98,14 @@
    *
    * @author Jazmin Jonson
    * @author Manveen Kaur
  - * @version $Revision: 1.7 $ $Date: 2002/01/10 03:41:13 $
  + * @version $Revision: 1.8 $ $Date: 2002/02/13 22:07:53 $
    */
   
   public class SetUpServerAction extends Action {
       
       private static MBeanServer mBServer = null;
  -    
  +    private MessageResources resources = null;
  +
       public final static String PORT_PROP_NAME = "port";
       public final static String SHUTDOWN_PROP_NAME = "shutdown";
       public final static String DEBUG_PROP_NAME = "debug";
  @@ -135,8 +136,11 @@
       throws IOException, ServletException {
           
           HttpSession session = request.getSession();
  +        Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
           
  -        // Do I have to do this part ??
  +        if (resources == null) {
  +            resources = getServlet().getResources();
  +        }        
           if (form == null) {
               getServlet().log(" Creating new ServerForm bean under key "
               + mapping.getAttribute());
  @@ -152,8 +156,6 @@
           // label of the node that was clicked on.
           String nodeLabel = request.getParameter("nodeLabel");
           
  -        // Do transaction stuff before this
  -        
           ServerForm serverFm = (ServerForm) form;
           
           if(debugLvlList == null) {
  @@ -174,59 +176,60 @@
           Integer portNumb = null;
           Integer debug = null;
           String shutdown = null;
  +        
  +        // Acquire a reference to the MBeanServer containing our MBeans
  +        try {
  +            mBServer = ((ApplicationServlet) getServlet()).getServer();
  +        } catch (Throwable t) {
  +            throw new ServletException
  +            ("Cannot acquire MBeanServer reference", t);
  +        }
  +        
  +        ObjectName serverObjName = null;
           try{
  -            
  -            if(mBServer == null) {
  -                ApplicationServlet servlet = (ApplicationServlet)getServlet();
  -                mBServer = servlet.getServer();
  -            }
  -            
               Iterator serverItr =
               mBServer.queryMBeans(new ObjectName(TomcatTreeBuilder.SERVER_TYPE +
  -            TomcatTreeBuilder. WILDCARD),
  +            TomcatTreeBuilder.WILDCARD),
               null).iterator();
               
  -            ObjectName serverObjName =
  -            ((ObjectInstance)serverItr.next()).getObjectName();
  -            
  -            /*
  -            ModelMBeanInfo info = (ModelMBeanInfo) mBServer.getMBeanInfo(serverObjName);
  -            MBeanAttributeInfo attrs[] = info.getAttributes();
  -            for (int i = 0; i < attrs.length; i++)
  -                System.out.println("  AttributeInfo=" + attrs[i]);
  -             
  -            MBeanOperationInfo opers[] = info.getOperations();
  -            for (int i = 0; i < opers.length; i++)
  -                System.out.println("  Operation=" + opers[i]);
  -             */
  -            
  +            serverObjName =
  +            ((ObjectInstance)serverItr.next()).getObjectName();            
  +        } catch (Throwable t) {
  +            throw new ServletException
  +            ("Cannot acquire Server MBean reference ", t);
  +        }
  +        
  +        String attribute = null;
  +        try {
               portNumb = (Integer)mBServer.getAttribute(serverObjName,
  -            PORT_PROP_NAME);
  +            attribute=PORT_PROP_NAME);
               
               debug = (Integer)mBServer.getAttribute(serverObjName,
  -            DEBUG_PROP_NAME);
  +            attribute=DEBUG_PROP_NAME);
               
               shutdown = (String)mBServer.getAttribute(serverObjName,
  -            SHUTDOWN_PROP_NAME);
  -            
  -            request.setAttribute("debugLvlVals", debugLvlList);
  +            attribute=SHUTDOWN_PROP_NAME);
               
  -        }catch(Throwable t){
  -            t.printStackTrace(System.out);
  -            //forward to error page
  +        } catch(Exception e){
  +            getServlet().log
  +            (resources.getMessage(locale, "users.error.attribute.get",
  +            attribute), e);
  +            response.sendError
  +            (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  +            resources.getMessage(locale, "users.error.attribute.get",
  +            attribute));
  +            return (null);
           }
           
  +        //setting values obtained from the mBean to be displayed in the form.
           serverFm.setNodeLabel(nodeLabel);        
           serverFm.setPortNumberText(portNumb.toString());
  -        // Hardcode debuglvl for now
           serverFm.setDebugLvl(debug.toString());
           serverFm.setShutdownText(shutdown);
           serverFm.setDebugLvlVals(debugLvlList);
           
  -        // Forward back to the test page
  -        return (mapping.findForward("Server"));
  -        
  +        //forward to the server jsp.
  +        return (mapping.findForward("Server"));        
       }
  -    
  -    
  +        
   }
  
  
  
  1.2       +4 -5      jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/ConnectorAction.java
  
  Index: ConnectorAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/ConnectorAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectorAction.java	13 Feb 2002 00:13:11 -0000	1.1
  +++ ConnectorAction.java	13 Feb 2002 22:07:53 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/ConnectorAction.java,v
1.1 2002/02/13 00:13:11 manveen Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/13 00:13:11 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/connector/ConnectorAction.java,v
1.2 2002/02/13 22:07:53 manveen Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/13 22:07:53 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
    * actions on a Connector.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.1 $ $Date: 2002/02/13 00:13:11 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/13 22:07:53 $
    */
   
   public final class ConnectorAction extends Action {
  @@ -125,8 +125,7 @@
       HttpServletRequest request,
       HttpServletResponse response)
       throws IOException, ServletException {
  -        
  -        
  +                
           if (resources == null) {
               resources = getServlet().getResources();
           }
  
  
  

--
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