Source code: org/apache/webapp/admin/resources/SetUpResourceLinkAction.java
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 package org.apache.webapp.admin.resources;
18
19 import java.io.IOException;
20 import java.net.URLDecoder;
21 import java.util.Iterator;
22 import java.util.Locale;
23 import javax.management.Attribute;
24 import javax.management.MBeanServer;
25 import javax.management.MBeanServerFactory;
26 import javax.management.QueryExp;
27 import javax.management.Query;
28 import javax.management.ObjectInstance;
29 import javax.management.ObjectName;
30 import javax.management.JMException;
31 import javax.management.MBeanAttributeInfo;
32 import javax.management.MBeanOperationInfo;
33 import javax.management.MBeanInfo;
34 import javax.servlet.ServletException;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import javax.servlet.http.HttpSession;
38 import org.apache.struts.action.Action;
39 import org.apache.struts.action.ActionErrors;
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionForward;
42 import org.apache.struts.action.ActionMapping;
43 import org.apache.struts.util.MessageResources;
44 import org.apache.webapp.admin.ApplicationServlet;
45
46
47 /**
48 * <p>Implementation of <strong>Action</strong> that sets up and stashes
49 * a <code>ResourceLinkForm</code> bean in request scope. The form bean will have
50 * a null <code>objectName</code> property if this form represents a ResourceLink
51 * being added, or a non-null value for an existing ResourceLink.</p>
52 *
53 * @author Amy Roh
54 * @version $Revision: 303390 $ $Date: 2004-10-18 02:37:56 -0400 (Mon, 18 Oct 2004) $
55 * @since 4.1
56 */
57
58 public final class SetUpResourceLinkAction extends Action {
59
60 // ----------------------------------------------------- Instance Variables
61
62
63 /**
64 * The MBeanServer we will be interacting with.
65 */
66 private MBeanServer mserver = null;
67
68
69 // --------------------------------------------------------- Public Methods
70
71
72 /**
73 * Process the specified HTTP request, and create the corresponding HTTP
74 * response (or forward to another web component that will create it).
75 * Return an <code>ActionForward</code> instance describing where and how
76 * control should be forwarded, or <code>null</code> if the response has
77 * already been completed.
78 *
79 * @param mapping The ActionMapping used to select this instance
80 * @param actionForm The optional ActionForm bean for this request (if any)
81 * @param request The HTTP request we are processing
82 * @param response The HTTP response we are creating
83 *
84 * @exception IOException if an input/output error occurs
85 * @exception ServletException if a servlet exception occurs
86 */
87 public ActionForward execute(ActionMapping mapping,
88 ActionForm form,
89 HttpServletRequest request,
90 HttpServletResponse response)
91 throws IOException, ServletException {
92
93 // Look up the components we will be using as needed
94 if (mserver == null) {
95 mserver = ((ApplicationServlet) getServlet()).getServer();
96 }
97 MessageResources resources = getResources(request);
98 HttpSession session = request.getSession();
99 Locale locale = getLocale(request);
100
101 // Set up the form bean based on the creating or editing state
102 String objectName = request.getParameter("objectName");
103 String resourcetype = request.getParameter("resourcetype");
104 String path = request.getParameter("path");
105 String host = request.getParameter("host");
106 String domain = request.getParameter("domain");
107
108 ResourceLinkForm resourceLinkForm = new ResourceLinkForm();
109 resourceLinkForm.setResourcetype(resourcetype);
110 resourceLinkForm.setPath(path);
111 resourceLinkForm.setHost(host);
112 resourceLinkForm.setDomain(domain);
113
114 if (objectName == null) {
115 resourceLinkForm.setNodeLabel
116 (resources.getMessage(locale, "resources.actions.resourcelk.create"));
117 resourceLinkForm.setObjectName(null);
118
119 } else {
120 resourceLinkForm.setNodeLabel
121 (resources.getMessage(locale, "resources.actions.resourcelk.edit"));
122 resourceLinkForm.setObjectName(objectName);
123
124 String attribute = null;
125 try {
126 ObjectName oname = new ObjectName(objectName);
127 attribute = "name";
128 resourceLinkForm.setName
129 ((String) mserver.getAttribute(oname, attribute));
130 attribute = "global";
131 resourceLinkForm.setGlobal
132 ((String) mserver.getAttribute(oname, attribute));
133 attribute = "type";
134 resourceLinkForm.setType
135 ((String) mserver.getAttribute(oname, attribute));
136
137 } catch (Exception e) {
138 getServlet().log
139 (resources.getMessage(locale,
140 "users.error.attribute.get", attribute), e);
141 response.sendError
142 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
143 resources.getMessage
144 (locale, "users.error.attribute.get", attribute));
145 return (null);
146 }
147 }
148
149 // Stash the form bean and forward to the display page
150 saveToken(request);
151 request.setAttribute("resourceLinkForm", resourceLinkForm);
152 return (mapping.findForward("ResourceLink"));
153
154 }
155 }