KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > DumpServerAction


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;
19
20
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import javax.management.MBeanServer JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.servlet.ServletException JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
32 import org.apache.struts.action.Action;
33 import org.apache.struts.action.ActionErrors;
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionForward;
36 import org.apache.struts.action.ActionMapping;
37
38
39 /**
40  * Simple debugging action that dumps a list of the MBeans that are
41  * visible in our MBeanServer.
42  *
43  * @author Craig R. McClanahan
44  * @version $Revision: 1.3 $ $Date: 2004/10/18 06:37:53 $
45  */

46
47 public final class DumpServerAction extends Action {
48
49
50     // --------------------------------------------------------- Public Methods
51

52
53     /**
54      * Process the specified HTTP request, and create the corresponding HTTP
55      * response (or forward to another web component that will create it).
56      * Return an <code>ActionForward</code> instance describing where and how
57      * control should be forwarded, or <code>null</code> if the response has
58      * already been completed.
59      *
60      * @param mapping The ActionMapping used to select this instance
61      * @param actionForm The optional ActionForm bean for this request (if any)
62      * @param request The HTTP request we are processing
63      * @param response The HTTP response we are creating
64      *
65      * @exception IOException if an input/output error occurs
66      * @exception ServletException if a servlet exception occurs
67      */

68     public ActionForward execute(ActionMapping mapping,
69                                  ActionForm form,
70                                  HttpServletRequest JavaDoc request,
71                                  HttpServletResponse JavaDoc response)
72         throws IOException JavaDoc, ServletException JavaDoc {
73
74         // Create a request attribute with our collection of MBeans
75
MBeanServer JavaDoc server = ((ApplicationServlet) getServlet()).getServer();
76         Iterator JavaDoc names = server.queryNames(null, null).iterator();
77         ArrayList JavaDoc list = new ArrayList JavaDoc();
78         while (names.hasNext()) {
79             list.add(names.next().toString());
80         }
81         Collections.sort(list);
82         request.setAttribute("names", list);
83
84         // Forward to the corresponding display page
85
return (mapping.findForward("Dump Server Results"));
86
87     }
88
89
90 }
91
Popular Tags