KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > connector > EditConnectorAction


1 /*
2  * Copyright 2001-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.connector;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33 import org.apache.struts.util.MessageResources;
34
35 import javax.management.MBeanServer JavaDoc;
36 import javax.management.ObjectInstance JavaDoc;
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.JMException JavaDoc;
39
40 import org.apache.webapp.admin.ApplicationServlet;
41 import org.apache.webapp.admin.LabelValueBean;
42 import org.apache.webapp.admin.Lists;
43 import org.apache.webapp.admin.TomcatTreeBuilder;
44
45 /**
46  * The <code>Action</code> that sets up <em>Edit Connector</em> transactions.
47  *
48  * @author Manveen Kaur
49  * @version $Revision: 1.14 $ $Date: 2004/10/18 06:37:53 $
50  */

51
52 public class EditConnectorAction extends Action {
53     
54
55     /**
56      * The MBeanServer we will be interacting with.
57      */

58     private MBeanServer JavaDoc mBServer = null;
59     
60
61     // --------------------------------------------------------- Public Methods
62

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

78     public ActionForward execute(ActionMapping mapping,
79                                  ActionForm form,
80                                  HttpServletRequest JavaDoc request,
81                                  HttpServletResponse JavaDoc response)
82         throws IOException JavaDoc, ServletException JavaDoc {
83         
84         // Acquire the resources that we need
85
HttpSession JavaDoc session = request.getSession();
86         Locale JavaDoc locale = getLocale(request);
87         MessageResources resources = getResources(request);
88         
89         // Acquire a reference to the MBeanServer containing our MBeans
90
try {
91             mBServer = ((ApplicationServlet) getServlet()).getServer();
92         } catch (Throwable JavaDoc t) {
93             throw new ServletException JavaDoc
94             ("Cannot acquire MBeanServer reference", t);
95         }
96         
97         // Set up the object names of the MBeans we are manipulating
98
ObjectName JavaDoc cname = null;
99         StringBuffer JavaDoc sb = null;
100         try {
101             cname = new ObjectName JavaDoc(request.getParameter("select"));
102         } catch (Exception JavaDoc e) {
103             String JavaDoc message =
104                 resources.getMessage(locale, "error.connectorName.bad",
105                                      request.getParameter("select"));
106             getServlet().log(message);
107             response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
108             return (null);
109         }
110
111         // Fill in the form values for display and editing
112
ConnectorForm connectorFm = new ConnectorForm();
113         session.setAttribute("connectorForm", connectorFm);
114         connectorFm.setAdminAction("Edit");
115         connectorFm.setObjectName(cname.toString());
116         sb = new StringBuffer JavaDoc();
117         sb.append(resources.getMessage(locale, "server.service.treeBuilder.connector"));
118         sb.append(" (");
119         sb.append(cname.getKeyProperty("port"));
120         sb.append(")");
121         connectorFm.setNodeLabel(sb.toString());
122         connectorFm.setBooleanVals(Lists.getBooleanValues());
123         connectorFm.setClientAuthVals(Lists.getClientAuthValues());
124         
125         String JavaDoc attribute = null;
126         try {
127
128             // Copy scalar properties
129
// General properties
130
attribute = "scheme";
131             String JavaDoc scheme = (String JavaDoc) mBServer.getAttribute(cname, attribute);
132             connectorFm.setScheme(scheme);
133
134             attribute = "protocolHandlerClassName";
135             String JavaDoc handlerClassName =
136                 (String JavaDoc) mBServer.getAttribute(cname, attribute);
137             int period = handlerClassName.lastIndexOf('.');
138             String JavaDoc connType = handlerClassName.substring(period + 1);
139             String JavaDoc connectorType = "HTTPS";
140             if ("JkCoyoteHandler".equalsIgnoreCase(connType)) {
141                 connectorType = "AJP";
142             } else if ("Http11Protocol".equalsIgnoreCase(connType) &&
143                       ("http".equalsIgnoreCase(scheme))) {
144                 connectorType = "HTTP";
145             }
146             connectorFm.setConnectorType(connectorType);
147             
148             attribute = "acceptCount";
149             connectorFm.setAcceptCountText
150                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
151             attribute = "compression";
152             connectorFm.setCompression
153                 ((String JavaDoc) mBServer.getAttribute(cname, attribute));
154             attribute = "connectionLinger";
155             connectorFm.setConnLingerText
156                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
157             attribute = "connectionTimeout";
158             connectorFm.setConnTimeOutText
159                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
160             attribute = "connectionUploadTimeout";
161             connectorFm.setConnUploadTimeOutText
162                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
163             attribute = "disableUploadTimeout";
164             connectorFm.setDisableUploadTimeout
165                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
166             attribute = "bufferSize";
167             connectorFm.setBufferSizeText
168                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
169             attribute = "enableLookups";
170             connectorFm.setEnableLookups
171                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
172             attribute = "address";
173             connectorFm.setAddress
174                 ((String JavaDoc) mBServer.getAttribute(cname, attribute));
175             attribute = "maxKeepAliveRequests";
176             connectorFm.setMaxKeepAliveText
177                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
178             attribute = "maxSpareThreads";
179             connectorFm.setMaxSpare
180                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
181             attribute = "maxThreads";
182             connectorFm.setMaxThreads
183                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
184             attribute = "minSpareThreads";
185             connectorFm.setMinSpare
186                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
187             attribute = "threadPriority";
188             connectorFm.setThreadPriority
189                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
190             attribute = "secure";
191             connectorFm.setSecure
192                 (((Boolean JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
193             attribute = "tcpNoDelay";
194             connectorFm.setTcpNoDelay
195                 (String.valueOf(mBServer.getAttribute(cname, attribute)));
196             attribute = "xpoweredBy";
197             connectorFm.setXpoweredBy
198                 (((Boolean JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
199             attribute = "URIEncoding";
200             connectorFm.setURIEncodingText
201                 ((String JavaDoc) mBServer.getAttribute(cname, attribute));
202             attribute = "useBodyEncodingForURI";
203             connectorFm.setUseBodyEncodingForURIText
204                 (((Boolean JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
205             attribute = "allowTrace";
206             connectorFm.setAllowTraceText
207                 (((Boolean JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
208           
209             // Ports
210
attribute = "port";
211             connectorFm.setPortText
212                 (((Integer JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
213             attribute = "redirectPort";
214             connectorFm.setRedirectPortText
215                 (((Integer JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
216             
217             // Supported by HTTP and HTTPS only
218
if (!("AJP".equalsIgnoreCase(connectorType))) {
219                 attribute = "proxyName";
220                 connectorFm.setProxyName
221                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
222                 attribute = "proxyPort";
223                 connectorFm.setProxyPortText
224                     (((Integer JavaDoc) mBServer.getAttribute(cname, attribute)).toString());
225             }
226             
227             if ("HTTPS".equalsIgnoreCase(connectorType)) {
228                 // Initialize rest of variables.
229
// These are set only for SSL connectors.
230
attribute = "algorithm";
231                 connectorFm.setAlgorithm
232                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
233                 attribute = "clientAuth";
234                 connectorFm.setClientAuthentication
235                     (((String JavaDoc) mBServer.getAttribute(cname, attribute)));
236                 attribute = "ciphers";
237                 connectorFm.setCiphers
238                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
239                 attribute = "keystoreFile";
240                 connectorFm.setKeyStoreFileName
241                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
242                 attribute = "keystorePass";
243                 connectorFm.setKeyStorePassword
244                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
245                 attribute = "keystoreType";
246                 connectorFm.setKeyStoreType
247                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
248                 attribute = "sslProtocol";
249                 connectorFm.setSslProtocol
250                     ((String JavaDoc) mBServer.getAttribute(cname, attribute));
251             }
252                 
253                         
254         } catch (Throwable JavaDoc t) {
255             getServlet().log
256                 (resources.getMessage(locale, "users.error.attribute.get",
257                                       attribute), t);
258             response.sendError
259                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
260                  resources.getMessage(locale, "users.error.attribute.get",
261                                       attribute));
262             return (null);
263         }
264         
265         // Forward to the connector display page
266
return (mapping.findForward("Connector"));
267         
268     }
269
270
271 }
272
Popular Tags