KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > server > EditServerAction


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.webapp.admin.server;
19
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import javax.servlet.http.HttpSession JavaDoc;
29 import org.apache.struts.action.Action;
30 import org.apache.struts.action.ActionErrors;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import javax.management.MBeanServer JavaDoc;
35 import javax.management.MBeanServerFactory JavaDoc;
36 import javax.management.QueryExp JavaDoc;
37 import javax.management.Query JavaDoc;
38 import javax.management.ObjectInstance JavaDoc;
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.JMException JavaDoc;
41
42 import javax.management.modelmbean.ModelMBean JavaDoc;
43 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
44
45 import org.apache.struts.util.MessageResources;
46 import org.apache.webapp.admin.LabelValueBean;
47 import org.apache.webapp.admin.Lists;
48 import org.apache.webapp.admin.TomcatTreeBuilder;
49 import org.apache.webapp.admin.ApplicationServlet;
50
51 /**
52  * Test <code>Action</code> that handles events from the tree control test
53  * page.
54  *
55  * @author Jazmin Jonson
56  * @author Manveen Kaur
57  * @version $Revision: 1.7 $ $Date: 2004/10/18 06:37:54 $
58  */

59
60 public class EditServerAction extends Action {
61     
62
63     /**
64      * The MBeanServer we will be interacting with.
65      */

66     private MBeanServer JavaDoc mBServer = null;
67     
68     // --------------------------------------------------------- Public Methods
69

70     /**
71      * Process the specified HTTP request, and create the corresponding HTTP
72      * response (or forward to another web component that will create it).
73      * Return an <code>ActionForward</code> instance describing where and how
74      * control should be forwarded, or <code>null</code> if the response has
75      * already been completed.
76      *
77      * @param mapping The ActionMapping used to select this instance
78      * @param actionForm The optional ActionForm bean for this request (if any)
79      * @param request The HTTP request we are processing
80      * @param response The HTTP response we are creating
81      *
82      * @exception IOException if an input/output error occurs
83      * @exception ServletException if a servlet exception occurs
84      */

85     public ActionForward execute(ActionMapping mapping,
86     ActionForm form,
87     HttpServletRequest JavaDoc request,
88     HttpServletResponse JavaDoc response)
89     throws IOException JavaDoc, ServletException JavaDoc {
90         
91          // Acquire the resources that we need
92
HttpSession JavaDoc session = request.getSession();
93         Locale JavaDoc locale = getLocale(request);
94         MessageResources resources = getResources(request);
95         // Acquire a reference to the MBeanServer containing our MBeans
96
try {
97             mBServer = ((ApplicationServlet) getServlet()).getServer();
98         } catch (Throwable JavaDoc t) {
99             throw new ServletException JavaDoc
100             ("Cannot acquire MBeanServer reference", t);
101         }
102
103         // label of the node that was clicked on.
104
String JavaDoc nodeLabel = request.getParameter("nodeLabel");
105         String JavaDoc select = request.getParameter("select");
106         
107         ServerForm serverFm = new ServerForm();
108         session.setAttribute("serverForm", serverFm);
109         serverFm.setNodeLabel(nodeLabel);
110         serverFm.setObjectName(select);
111         
112         ObjectName JavaDoc sname = null;
113         try {
114             sname = new ObjectName JavaDoc(select);
115         } catch (Exception JavaDoc e) {
116             String JavaDoc message =
117                 resources.getMessage(locale, "error.serviceName.bad",
118                                      request.getParameter("select"));
119             getServlet().log(message);
120             response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
121             return (null);
122         }
123       
124         String JavaDoc attribute = null;
125         try {
126             // Copy scalar properties
127
attribute = "port";
128             serverFm.setPortNumberText
129                 (((Integer JavaDoc) mBServer.getAttribute(sname, attribute)).toString());
130             attribute = "shutdown";
131             serverFm.setShutdownText
132                 ((String JavaDoc) mBServer.getAttribute(sname, attribute));
133
134             } catch (Throwable JavaDoc t) {
135             getServlet().log
136                 (resources.getMessage(locale, "users.error.attribute.get",
137                                       attribute), t);
138             response.sendError
139                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
140                  resources.getMessage(locale, "users.error.attribute.get",
141                                       attribute));
142             return (null);
143         }
144
145         //forward to the server jsp.
146
return (mapping.findForward("Server"));
147     }
148         
149 }
150
Popular Tags