geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecr...@apache.org
Subject svn commit: r599039 - in /geronimo/sandbox/monitoring/client/client-war/src/main: java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java webapp/WEB-INF/view/monitoringAddServer.jsp webapp/WEB-INF/view/monitoringEditServer.jsp
Date Wed, 28 Nov 2007 15:54:37 GMT
Author: ecraig
Date: Wed Nov 28 07:54:36 2007
New Revision: 599039

URL: http://svn.apache.org/viewvc?rev=599039&view=rev
Log:
Monitoring client needs ability to test connection settings in add/edit server pages

Applied patch from Viet Nguyen in GERONIMO-3642.


Modified:
    geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
    geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringAddServer.jsp
    geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java?rev=599039&r1=599038&r2=599039&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
Wed Nov 28 07:54:36 2007
@@ -212,6 +212,43 @@
             String server_id = actionRequest.getParameter("server_id");
             actionResponse.setRenderParameter("message", alterServerState(
                     server_id, true));
+        } else if(action.equals("testAddServerConnection")) {
+            String name = actionRequest.getParameter("name");
+            String ip = actionRequest.getParameter("ip");
+            String username = actionRequest.getParameter("username");
+            String password = actionRequest.getParameter("password");
+            String password2 = actionRequest.getParameter("password2");
+            String message = testConnection(name, ip, username, password);
+            actionResponse.setRenderParameter("message", message);
+            actionResponse.setRenderParameter("name", name);
+            actionResponse.setRenderParameter("username", username);
+            actionResponse.setRenderParameter("ip", ip);
+            actionResponse.setRenderParameter("password", password);
+            actionResponse.setRenderParameter("password2", password2);
+        } else if(action.equals("testEditServerConnection")) {
+            String name = actionRequest.getParameter("name");
+            String ip = actionRequest.getParameter("ip");
+            String username = actionRequest.getParameter("username");
+            String password = actionRequest.getParameter("password");
+            String password2 = actionRequest.getParameter("password2");
+            String server_id = actionRequest.getParameter("server_id");
+            String message = testConnection(name, ip, username, password);
+            actionResponse.setRenderParameter("message", message);
+            actionResponse.setRenderParameter("name", name);
+            actionResponse.setRenderParameter("username", username);
+            actionResponse.setRenderParameter("ip", ip);
+            actionResponse.setRenderParameter("password", password);
+            actionResponse.setRenderParameter("password2", password2);
+            actionResponse.setRenderParameter("server_id", server_id);
+        }
+    }
+
+    private String testConnection(String name, String ip, String username, String password)
{
+        try {
+            MRCConnector mrc = new MRCConnector(ip, username, password);
+            return "Connection was successfully established.";
+        } catch(Exception e) {
+            return "Failed to create a connection to server.";
         }
     }
 
@@ -642,9 +679,7 @@
                 return;
             }
 
-        }
-        else
-        {
+        } else {
             request.setAttribute("message", request.getParameter("message"));
             normalView.include(request, response);
         }
@@ -758,9 +793,26 @@
             String message = request.getParameter("message");
             request.setAttribute("message", message);
             normalView.include(request, response);
-        }
-        else
+        } else if(action.equals("testAddServerConnection")) {
+            request.setAttribute("name", request.getParameter("name"));
+            request.setAttribute("ip", request.getParameter("ip"));
+            request.setAttribute("username", request.getParameter("username"));
+            request.setAttribute("password", request.getParameter("password"));
+            request.setAttribute("password2", request.getParameter("password2"));
+            request.setAttribute("message", request.getParameter("message"));
+            addServer.include(request, response);
+        }  else if(action.equals("testEditServerConnection")) {
+            request.setAttribute("name", request.getParameter("name"));
+            request.setAttribute("ip", request.getParameter("ip"));
+            request.setAttribute("username", request.getParameter("username"));
+            request.setAttribute("password", request.getParameter("password"));
+            request.setAttribute("password2", request.getParameter("password2"));
+            request.setAttribute("message", request.getParameter("message"));
+            request.setAttribute("server_id", request.getParameter("server_id"));
+            editServer.include(request, response);
+        } else {
             editNormalView.include(request, response);
+        }
     }
 
     private void updateView(ActionRequest actionRequest,

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringAddServer.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringAddServer.jsp?rev=599039&r1=599038&r2=599039&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringAddServer.jsp
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringAddServer.jsp
Wed Nov 28 07:54:36 2007
@@ -37,12 +37,23 @@
 <%
 
 String message = (String) request.getAttribute("message");
-
-
-if (message == null)
-    message = new String("");
-
-
+String name = (String) request.getAttribute("name");
+String ip = (String) request.getAttribute("ip");
+String username = (String) request.getAttribute("username");
+String password = (String) request.getAttribute("password");
+String password2 = (String) request.getAttribute("password2");
+if(message == null)
+    message = "";
+if(name == null)
+    name = "";
+if(ip == null)
+    ip = "";
+if(username == null)
+    username = "";
+if(password == null)
+    password = "";
+if(password2 == null)
+    password2 = "";
 %>
 <!-- <head> -->
 
@@ -53,42 +64,42 @@
         <script type = "text/javascript">
 <!--
 function hide(x) {
-document.getElementById(x).style.display='none';
+    document.getElementById(x).style.display='none';
 }
 function show(x) {
-document.getElementById(x).style.display='';
+    document.getElementById(x).style.display='';
 }
 function validate() {
-   if (! (document.addServer.name.value 
-      && document.addServer.ip.value 
-      && document.addServer.username.value
-      && document.addServer.password.value ))
-   {
-      alert("Name, Address, and Username and password are all required fields");
-      return false;
-   }
-   if (document.addServer.password.value != document.addServer.password2.value)
-   {
-      alert("Passwords do not match");
-      return false;
-   }
-   return;
+	if (! (document.addServer.name.value 
+		&& document.addServer.ip.value 
+		&& document.addServer.username.value
+		&& document.addServer.password.value ))
+	{
+		alert("Name, Address, and Username and password are all required fields");
+		return false;
+	}
+	if (document.addServer.password.value != document.addServer.password2.value)
+	{
+		alert("Passwords do not match");
+		return false;
+	}
+	return true;
 }
-function noAlpha(obj){
+function noAlpha(obj) {
     reg = /[^0-9]/g;
     obj.value =  obj.value.replace(reg,"");
- }
+}
 
 //-->
 </script>
 <!-- </head> -->
-        <a HREF="javascript:history.go(-1)"><< Back</a><br>
+        <a HREF="javascript:history.go(-1)"><< Back</a><br/><br/><b>
             <%
  if (!message.equals(""))
  {
  %>
 <div align="left" style="width: 500px">
-<%=message %><br>
+<%=message %></b><br>
 </div>
 <%} %>
 <table>
@@ -101,47 +112,49 @@
             </font>
             </p>         
             <p>
-  <form onsubmit="return validate();" name="addServer" method="POST" action="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="saveAddServer"/></portlet:actionURL>">
+  <form name="addServer" method="POST" action="<portlet:actionURL/>">
   <table cellpadding="1" cellspacing="1">
     <tr>
       <td>Name:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="name" value=""></td>
+      <td align="right"><input type="text" name="name" value=<%= "\"" + name
+ "\"" %>></td>
       <td></td>
     </tr>
     <tr>
       <td>IP/Hostname:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="ip" value=""/></td>
+      <td align="right"><input type="text" name="ip" value=<%= "\"" + ip + "\""
%>/></td>
       <td></td>
     </tr>
     <tr>
       <td>Username:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="username" value=""/></td>
+      <td align="right"><input type="text" name="username" value=<%= "\"" + username
+ "\"" %>/></td>
       <td></td>
     </tr>
     <tr>
       <td>Password:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="password" name="password" value=""/></td>
+      <td align="right"><input type="password" name="password" value=<%= "\""
+ password + "\"" %>/></td>
       <td></td>
     </tr>
     <tr>
       <td>Password (verify):</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="password" name="password2" value=""/></td>
+      <td align="right"><input type="password" name="password2" value=<%= "\""
+ password2 + "\"" %>/></td>
       <td></td>
     </tr>
     <tr><td colspan="2"><font size="-2">&nbsp;</font></td></tr>
     <tr>
+      <input type="hidden" name="mode" value="" />
+      <input type="hidden" name="action" value="" />
       <td colspan="1" align="left"><button type="button" value="Cancel" onclick="javascript:history.go(-1)">Cancel</button></td>
       <td>&nbsp;</td>
-      <td colspan="1" align="right"><input type="submit" value="Add" /></td>
+      <td colspan="1" align="right"><input type="button" value="Add" onclick="document.addServer.action.value='saveAddServer';
document.addServer.mode.value='edit'; if(validate()) document.addServer.submit();" /></td>
       <td></td>
     </tr>
   </table>
-  </form>
+  
 
             </p>
 
@@ -162,14 +175,15 @@
                     <td bgcolor="#FFFFFF" nowrap>
                         &nbsp;<br />
                         <ul>
-                        <li><a href="#">Test these settings</a></li>
+                        <li><a onclick="document.addServer.action.value='testAddServerConnection';
document.addServer.mode.value='edit'; if(validate()) document.addServer.submit();" href="#">Test
these settings</a></li>
                         </ul>
                         &nbsp;<br />
                     </td>   
                 </tr>
             </table>
             
-        </td>        
+        </td>
+        </form>      
     </tr>
 </table>
 

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp?rev=599039&r1=599038&r2=599039&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp
Wed Nov 28 07:54:36 2007
@@ -36,9 +36,26 @@
 
 <%
 
-String server_id = (String) request.getAttribute("server_id"); 
-String message = (String) request.getAttribute("message");
+String server_id = (String) request.getAttribute("server_id");
 
+String message = (String) request.getAttribute("message");
+String name = (String) request.getAttribute("name");
+String ip = (String) request.getAttribute("ip");
+String username = (String) request.getAttribute("username");
+String password = (String) request.getAttribute("password");
+String password2 = (String) request.getAttribute("password2");
+if(message == null)
+    message = "";
+if(name == null)
+    name = "";
+if(ip == null)
+    ip = "";
+if(username == null)
+    username = "";
+if(password == null)
+    password = "";
+if(password2 == null)
+    password2 = "";
 
 DBManager DBase = new DBManager();
 Connection con = DBase.getConnection();
@@ -48,20 +65,19 @@
 MRCConnector MRCConnection = null;
 boolean isOnline = true;
 
-
-if (message == null)
-    message = new String("");
-
-if (rs.next())
-{    
+if (rs.next()) {
+    // name == "" when user has not submitted anything
+    if(name.equals("")) {
+        // store the information from db into the variables
+        name = rs.getString("name");
+        username = rs.getString("username");
+        ip = rs.getString("ip");
+    }
     try {
-        MRCConnection = new MRCConnector(rs.getString("ip"), rs
-            .getString("username"), rs.getString("password"));
+        MRCConnection = new MRCConnector(rs.getString("ip"), rs.getString("username"), rs.getString("password"));
       //TODO: Fix update here
         //rs2.updateTimestamp("last_seen", new Timestamp(System.currentTimeMillis()));
-    }
-    catch (Exception e)
-    {
+    } catch (Exception e) {
         isOnline = false;
         message = message + "<br><font color='red'><li>Server is offline</li></font>";
     }
@@ -75,18 +91,19 @@
         <script type = "text/javascript">
 <!--
 function hide(x) {
-document.getElementById(x).style.display='none';
+    document.getElementById(x).style.display='none';
 }
 function show(x) {
-document.getElementById(x).style.display='';
+    document.getElementById(x).style.display='';
 }
 function validate() {
    if (! (document.editServer.name.value 
       && document.editServer.ip.value 
       && document.editServer.username.value
-      && document.editServer.snapshot.value ))
+      && document.editServer.snapshot.value
+      && document.editServer.password.value ))
    {
-      alert("Name, Address, Username and Snapshot Duration are all required fields");
+      alert("Name, Address, Username, Snapshot Duration, and Password are all required fields.");
       return false;
    }
    if (document.editServer.password.value != document.editServer.password2.value)
@@ -94,7 +111,7 @@
       alert("Passwords do not match");
       return false;
    }
-   return;
+   return true;
 }
 function noAlpha(obj){
     reg = /[^0-9]/g;
@@ -104,13 +121,13 @@
 //-->
 </script>
 <!-- </head> -->
-        <a HREF="javascript:history.go(-1)"><< Back</a><br>
+        <a HREF="javascript:history.go(-1)"><< Back</a><br/><br/><b>
             <%
  if (!message.equals(""))
  {
  %>
 <div align="left" style="width: 500px">
-<%=message %><br>
+<%=message %></b><br>
 </div>
 <%} %>
 <table>
@@ -123,7 +140,7 @@
             </font>
             </p>         
             <p>
-  <form onsubmit="return validate();" name="editServer" method="POST" action="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="saveEditServer"/><portlet:param
name="server_id" value="<%=server_id%>"/></portlet:actionURL>">
+  <form name="editServer" method="POST" action="<portlet:actionURL/>">
   <table cellpadding="1" cellspacing="1">
     <tr>
       <td>Added:</td>
@@ -146,13 +163,13 @@
     <tr>
       <td>Name:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
+      <td align="right"><input type="text" name="name" value=<%= "\"" + name
+ "\"" %>></td>
       <td></td>
     </tr>
     <tr>
       <td>IP/Hostname:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="ip" value="<%=rs.getString("ip")%>"/></td>
+      <td align="right"><input type="text" name="ip" value=<%= "\"" + ip + "\""
%>/></td>
       <td></td>
     </tr>
     <%
@@ -182,30 +199,32 @@
     <tr>
       <td>Username:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" name="username" value="<%=rs.getString("username")%>"/></td>
+      <td align="right"><input type="text" name="username" value=<%= "\"" + username
+ "\"" %>/></td>
       <td></td>
     </tr>
     <tr>
       <td>Password:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="password" name="password" value=""/></td>
+      <td align="right"><input type="password" name="password" value=<%= "\""
+ password + "\"" %>/></td>
       <td></td>
     </tr>
     <tr>
       <td>Password (verify):</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="password" name="password2" value=""/></td>
+      <td align="right"><input type="password" name="password2" value=<%= "\""
+ password2 + "\"" %>/></td>
       <td></td>
     </tr>
     <tr><td colspan="2"><font size="-2">&nbsp;</font></td></tr>
     <tr>
+      <input type="hidden" name="mode" value="" />
+      <input type="hidden" name="action" value="" />
+      <input type="hidden" name="server_id" value=<%= "\"" + server_id + "\"" %>
/>
       <td colspan="1" align="left"><button type="button" value="Cancel" onclick="javascript:history.go(-1)">Cancel</button></td>
       <td>&nbsp;</td>
-      <td colspan="1" align="right"><input type="submit" value="Save" /></td>
+      <td colspan="1" align="right"><input type="button" value="Save" onclick="document.editServer.action.value='saveEditServer';
document.editServer.mode.value='edit'; if(validate()) document.editServer.submit();" /></td>
       <td></td>
     </tr>
   </table>
-  </form>
 
             </p>
 
@@ -226,7 +245,7 @@
                     <td bgcolor="#FFFFFF" nowrap>
                         &nbsp;<br />
                         <ul>
-                        <li><a href="#">Test these settings</a></li>
+                        <li><a onclick="document.editServer.action.value='testEditServerConnection';
document.editServer.mode.value='edit'; if(validate()) document.editServer.submit();" href="#">Test
these settings</a></li>
                         <li><a href="<portlet:actionURL portletMode="edit"><portlet:param
name="action" value="disableServer" /><portlet:param name="server_id" value="<%=rs.getString("server_id")%>"
/></portlet:actionURL>">Disable this server</a></li>
                         <li><a href="<portlet:actionURL portletMode="edit"><portlet:param
name="action" value="deleteServer" /><portlet:param name="server_id" value="<%=rs.getString("server_id")%>"
/></portlet:actionURL>">Delete this server</a></li>
                         <li><a href="<portlet:actionURL portletMode="edit"><portlet:param
name="action" value="showAddServer" /></portlet:actionURL>">Add a new server</a></li>
@@ -236,7 +255,8 @@
                 </tr>
             </table>
             
-        </td>        
+        </td>
+        </form>   
     </tr>
 </table>
 <%



Mime
View raw message