KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > catalina > ApplyConnectorAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ApplyConnectorAction.java,v 1.15 2005/04/22 14:14:25 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.catalina;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import org.apache.struts.action.ActionMessage;
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39 import org.objectweb.jonas.jmx.JonasManagementRepr;
40 import org.objectweb.jonas.jmx.JonasObjectName;
41 import org.objectweb.jonas.jmx.CatalinaObjectName;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
44
45 /**
46  * @author Michel-Ange ANTON
47  * @author Adriana Danes - update to Tomact 5.0
48  * Replace MBeanFactory usage with JOnAS CatalinaConnectorFactory MBean
49  * in order to avoid class loader problems occuring with JRMP
50  */

51 public class ApplyConnectorAction extends CatalinaBaseAction {
52
53     /**
54      * Signature for the <code>createStandardConnector</code> operation.
55      */

56     private String JavaDoc[] saCreateStandardConnectorTypes = {
57         "java.lang.String", "java.lang.String", "int" // port
58
};
59
60 // --------------------------------------------------------- Public Methods
61

62     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
63         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
64         throws IOException JavaDoc, ServletException JavaDoc {
65         // Next forward
66
String JavaDoc sForward = "Catalina Connector";
67         // Identify the requested action
68
ConnectorForm oForm = (ConnectorForm) p_Form;
69         String JavaDoc sAction = oForm.getAction();
70         String JavaDoc sObjectName = oForm.getObjectName();
71         String JavaDoc sConnectorType = oForm.getConnectorType();
72
73         // Populate
74
try {
75             // Perform a "Create Connector operation"
76
if ("create".equals(sAction)) {
77                 String JavaDoc address = oForm.getAddress(); // IP address
78

79                 // Ensure that the requested connector name is unique
80
ObjectName JavaDoc onConnector = CatalinaObjectName.catalinaConnector(
81                         m_WhereAreYou.getCurrentCatalinaDomainName(),
82                         oForm.getPortText());
83                 if (JonasAdminJmx.hasMBeanName(onConnector) == true) {
84                     m_Errors.add("connector", new ActionMessage("error.catalina.connector.exists"));
85                     saveErrors(p_Request, m_Errors);
86                     return (new ActionForward(p_Mapping.getInput()));
87                 }
88
89                 // Use CatalinaConnectorFactory to create connector
90
ObjectName JavaDoc onConnectorFactory = JonasObjectName.catalinaConnectorFactory(
91                         m_WhereAreYou.getCurrentDomainName());
92                 Object JavaDoc values[] = new Object JavaDoc[3];
93                 values[0] = sConnectorType;
94                 values[1] = address;
95                 values[2] = new Integer JavaDoc(oForm.getPortText());
96                 String JavaDoc operation = "createConnector";
97                 sObjectName = (String JavaDoc) JonasManagementRepr.invoke(onConnectorFactory, operation, values
98                         , saCreateStandardConnectorTypes);
99
100                 /*
101                 // Look up the Catalina MBeanFactory
102                 ObjectName onFactory = CatalinaObjectName.catalinaFactory();
103                 values[0] = CatalinaObjectName.catalinaService(m_WhereAreYou.
104                     getCurrentCatalinaDomainName()
105                     , m_WhereAreYou.getCurrentCatalinaServiceName()).toString();
106                 values[1] = address;
107                 values[2] = new Integer(oForm.getPortText());
108
109                 if ("HTTP".equalsIgnoreCase(sConnectorType)) {
110                     operation = "createHttpConnector"; // HTTP
111                 }
112                 else if ("HTTPS".equalsIgnoreCase(sConnectorType)) {
113                     operation = "createHttpsConnector"; // HTTPS
114                 }
115                 else {
116                     operation = "createAjpConnector"; // AJP(HTTP)
117                 }
118                 sObjectName = (String) JonasManagementRepr.invoke(onFactory, operation, values
119                     , sa_CreateStandardConnectorTypes);
120                 */

121                 if (sObjectName == null) {
122                     saveErrors(p_Request, m_Errors);
123                     return (p_Mapping.findForward("Global Error"));
124                 }
125                 // refresh tree
126
refreshTree(p_Request);
127                 // Force the node selected in tree
128
String JavaDoc nodeName = getTreeBranchName(DEPTH_SERVER)
129                     + WhereAreYou.NODE_SEPARATOR + "protocols"
130                     + WhereAreYou.NODE_SEPARATOR + "connectors"
131                     //+ WhereAreYou.NODE_SEPARATOR + m_WhereAreYou.getCurrentCatalinaServiceName()
132
+ WhereAreYou.NODE_SEPARATOR + oForm.getPortText();
133                 if (address != null) {
134                     nodeName = nodeName
135                     + WhereAreYou.NODE_SEPARATOR + address;
136                 }
137                 m_WhereAreYou.selectNameNode(nodeName, true);
138
139             }
140
141             ObjectName JavaDoc oObjectName = new ObjectName JavaDoc(sObjectName);
142
143             setIntegerAttribute(oObjectName, "debug", oForm.getDebugLvl());
144             setIntegerAttribute(oObjectName, "acceptCount", oForm.getAcceptCountText());
145             setIntegerAttribute(oObjectName, "connectionTimeout", oForm.getConnTimeOutText());
146             setIntegerAttribute(oObjectName, "bufferSize", oForm.getBufferSizeText());
147             setBooleanAttribute(oObjectName, "enableLookups", oForm.isEnableLookups());
148             setIntegerAttribute(oObjectName, "redirectPort", oForm.getRedirectPortText());
149             setIntegerAttribute(oObjectName, "maxProcessors", oForm.getMaxThreadsText());
150             setIntegerAttribute(oObjectName, "minProcessors", oForm.getMinSpareThreadsText());
151             setIntegerAttribute(oObjectName, "maxSpareThreads", oForm.getMaxSpareThreadsText());
152
153             // proxy name and port do not exist for AJP connector
154
if ("AJP".equalsIgnoreCase(sConnectorType) == false) {
155                 setStringAttribute(oObjectName, "proxyName", oForm.getProxyName());
156                 setIntegerAttribute(oObjectName, "proxyPort", oForm.getProxyPortText());
157             }
158
159             // HTTPS specific properties
160
if ("HTTPS".equalsIgnoreCase(sConnectorType) == true) {
161                 setBooleanAttribute(oObjectName, "clientAuth", oForm.isClientAuth());
162                 setStringAttribute(oObjectName, "keystoreFile", oForm.getKeystoreFile());
163                 setStringAttribute(oObjectName, "keystorePass", oForm.getKeystorePass());
164             }
165
166             if ("create".equals(sAction) == true) {
167                 m_Session.removeAttribute(p_Mapping.getAttribute());
168                 sForward = "ActionListCatalinaConnectors";
169             }
170
171             // Save in configuration file
172
if (oForm.isSave() == true) {
173                 oForm.setSave(false);
174                 p_Request.setAttribute("forward", sForward);
175                 sForward = "ActionEditServletServer";
176                 //ObjectName on = CatalinaObjectName.catalinaServer();
177
//JonasManagementRepr.invoke(on, "store", null, null);
178
}
179         } catch (Throwable JavaDoc t) {
180             addGlobalError(t);
181             saveErrors(p_Request, m_Errors);
182             return (p_Mapping.findForward("Global Error"));
183         }
184
185         // Forward to the connector display page or the list if create
186
return p_Mapping.findForward(sForward);
187     }
188 }
189
Popular Tags