KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > resources > ListMailSessionsAction


1 /*
2  * Copyright 2002,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.resources;
19
20
21 import java.io.IOException JavaDoc;
22 import java.net.URLDecoder JavaDoc;
23 import java.util.Locale JavaDoc;
24 import javax.management.MBeanServer JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29 import javax.servlet.http.HttpSession JavaDoc;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.util.MessageResources;
35 import org.apache.webapp.admin.ApplicationServlet;
36 import org.apache.webapp.admin.TomcatTreeBuilder;
37
38 /**
39  * <p>Retrieve the set of MBean names for all currently defined mail sessions,
40  * and expose them in a request attribute named "mailSessionsForm". This action
41  * requires the following request parameters to be set:</p>
42  * <ul>
43  * <li><strong>forward</strong> - Global forward to which we should
44  * go after stashing the mailSessions list.</li>
45  * </ul>
46  *
47  * @author Amy Roh
48  * @version $Revision: 1.5 $ $Date: 2004/10/18 06:37:54 $
49  * @since 4.1
50  */

51
52 public class ListMailSessionsAction extends Action {
53
54     // ----------------------------------------------------- Instance Variables
55

56     /**
57      * The MBeanServer we will be interacting with.
58      */

59     private MBeanServer JavaDoc mserver = null;
60
61
62     // --------------------------------------------------------- Public Methods
63

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

80     public ActionForward execute(ActionMapping mapping,
81                                  ActionForm form,
82                                  HttpServletRequest JavaDoc request,
83                                  HttpServletResponse JavaDoc response)
84         throws IOException JavaDoc, ServletException JavaDoc {
85
86
87         // Look up the components we will be using as needed
88
if (mserver == null) {
89             mserver = ((ApplicationServlet) getServlet()).getServer();
90         }
91         MessageResources resources = getResources(request);
92         HttpSession JavaDoc session = request.getSession();
93         Locale JavaDoc locale = getLocale(request);
94         
95         String JavaDoc resourcetype = request.getParameter("resourcetype");
96         String JavaDoc path = request.getParameter("path");
97         String JavaDoc host = request.getParameter("host");
98         String JavaDoc domain = request.getParameter("domain");
99         
100         if (resourcetype != null) {
101             resourcetype = URLDecoder.decode(resourcetype,TomcatTreeBuilder.URL_ENCODING);
102         }
103         if (path != null) {
104             path = URLDecoder.decode(path,TomcatTreeBuilder.URL_ENCODING);
105         }
106         if (host != null) {
107             host = URLDecoder.decode(host,TomcatTreeBuilder.URL_ENCODING);
108         }
109         if (domain != null) {
110             domain = URLDecoder.decode(domain,TomcatTreeBuilder.URL_ENCODING);
111         }
112         
113         // Create a form bean containing the requested MBean Names
114
MailSessionsForm mailSessionsForm = null;
115         try {
116               mailSessionsForm =
117                 ResourceUtils.getMailSessionsForm(mserver, resourcetype,
118                                         path, host, domain);
119         } catch (Exception JavaDoc e) {
120             getServlet().log(resources.getMessage
121                              (locale,
122                               "users.error.attribute.get", "resources"), e);
123             response.sendError
124                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
125                  resources.getMessage
126                  (locale, "users.error.attribute.get", "resources"));
127         }
128
129         // Stash the results in request scope
130
request.setAttribute("mailSessionsForm", mailSessionsForm);
131         saveToken(request);
132         String JavaDoc forward =
133             URLDecoder.decode(request.getParameter("forward"),TomcatTreeBuilder.URL_ENCODING);
134         
135         return (mapping.findForward(forward));
136     }
137
138 }
139
Popular Tags