001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplyConnectorAction.java 10100 2007-03-27 13:55:44Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.catalina;
025:
026: import java.io.IOException;
027: import java.net.InetAddress;
028:
029: import javax.management.ObjectName;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.apache.struts.action.ActionMessage;
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.jmx.CatalinaObjectName;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
042: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
043:
044: /**
045: * @author Michel-Ange ANTON
046: * @author Adriana Danes - update to Tomact 5.0
047: * Replace MBeanFactory usage with JOnAS CatalinaConnectorFactory MBean
048: * in order to avoid class loader problems occuring with JRMP
049: */
050: public class ApplyConnectorAction extends CatalinaBaseAction {
051:
052: /**
053: * Signature for the <code>createStandardConnector</code> operation.
054: */
055: private String[] saCreateStandardConnectorTypes = {
056: "java.lang.String", "java.lang.String", "int" // port
057: };
058:
059: // --------------------------------------------------------- Public Methods
060:
061: public ActionForward executeAction(ActionMapping p_Mapping,
062: ActionForm p_Form, HttpServletRequest p_Request,
063: HttpServletResponse p_Response) throws IOException,
064: ServletException {
065: // Current JOnAS server name
066: String serverName = m_WhereAreYou.getCurrentJonasServerName();
067: // Next forward
068: String sForward = "Catalina Connector";
069: // Identify the requested action
070: ConnectorForm oForm = (ConnectorForm) p_Form;
071: String sAction = oForm.getAction();
072: String sObjectName = oForm.getObjectName();
073: String sConnectorType = oForm.getConnectorType();
074:
075: // Populate
076: try {
077: // Perform a "Create Connector operation"
078: if ("create".equals(sAction)) {
079: String address = oForm.getAddress(); // IP address
080:
081: // Ensure that the requested connector name is unique
082: ObjectName onConnector = CatalinaObjectName
083: .catalinaConnector(m_WhereAreYou
084: .getCurrentCatalinaDomainName(), oForm
085: .getPortText());
086: if (JonasAdminJmx.hasMBeanName(onConnector, serverName)) {
087: m_Errors.add("connector", new ActionMessage(
088: "error.catalina.connector.exists"));
089: saveErrors(p_Request, m_Errors);
090: return (new ActionForward(p_Mapping.getInput()));
091: }
092:
093: // Use CatalinaConnectorFactory to create connector
094: ObjectName onConnectorFactory = JonasObjectName
095: .catalinaConnectorFactory(m_WhereAreYou
096: .getCurrentDomainName());
097: Object values[] = new Object[3];
098: values[0] = sConnectorType;
099: values[1] = address;
100: values[2] = new Integer(oForm.getPortText());
101: String operation = "createConnector";
102: sObjectName = (String) JonasManagementRepr.invoke(
103: onConnectorFactory, operation, values,
104: saCreateStandardConnectorTypes, serverName);
105:
106: /*
107: // Look up the Catalina MBeanFactory
108: ObjectName onFactory = CatalinaObjectName.catalinaFactory();
109: values[0] = CatalinaObjectName.catalinaService(m_WhereAreYou.
110: getCurrentCatalinaDomainName()
111: , m_WhereAreYou.getCurrentCatalinaServiceName()).toString();
112: values[1] = address;
113: values[2] = new Integer(oForm.getPortText());
114:
115: if ("HTTP".equalsIgnoreCase(sConnectorType)) {
116: operation = "createHttpConnector"; // HTTP
117: }
118: else if ("HTTPS".equalsIgnoreCase(sConnectorType)) {
119: operation = "createHttpsConnector"; // HTTPS
120: }
121: else {
122: operation = "createAjpConnector"; // AJP(HTTP)
123: }
124: sObjectName = (String) JonasManagementRepr.invoke(onFactory, operation, values
125: , sa_CreateStandardConnectorTypes);
126: */
127: if (sObjectName == null) {
128: saveErrors(p_Request, m_Errors);
129: return (p_Mapping.findForward("Global Error"));
130: }
131: // refresh tree
132: refreshTree(p_Request);
133: // Force the node selected in tree
134: String nodeName = getTreeBranchName(DEPTH_SERVER)
135: + WhereAreYou.NODE_SEPARATOR + "protocols"
136: + WhereAreYou.NODE_SEPARATOR + "connectors";
137: //+ WhereAreYou.NODE_SEPARATOR + m_WhereAreYou.getCurrentCatalinaServiceName()
138: //+ WhereAreYou.NODE_SEPARATOR + oForm.getPortText();
139: if (address != null) {
140: nodeName = nodeName + WhereAreYou.NODE_SEPARATOR
141: + address;
142: }
143: m_WhereAreYou.selectNameNode(nodeName, true);
144:
145: }
146:
147: ObjectName oObjectName = new ObjectName(sObjectName);
148:
149: setIntegerAttribute(oObjectName, "acceptCount", oForm
150: .getAcceptCountText());
151: String addressValue = oForm.getAddress();
152: InetAddress inetAddress = InetAddress
153: .getByName(addressValue);
154: JonasManagementRepr.setAttribute(oObjectName, "address",
155: inetAddress, serverName);
156: setBooleanAttribute(oObjectName, "allowTrace", oForm
157: .isAllowTrace());
158: setIntegerAttribute(oObjectName, "connectionTimeout", oForm
159: .getConnTimeOutText());
160: setIntegerAttribute(oObjectName, "bufferSize", oForm
161: .getBufferSizeText());
162: setIntegerAttribute(oObjectName, "maxPostSize", oForm
163: .getMaxPostSizeText());
164: setBooleanAttribute(oObjectName, "enableLookups", oForm
165: .isEnableLookups());
166: setBooleanAttribute(oObjectName, "emptySessionPath", oForm
167: .isEmptySessionPath());
168: setBooleanAttribute(oObjectName, "xpoweredBy", oForm
169: .isXpoweredBy());
170: setBooleanAttribute(oObjectName, "tcpNoDelay", oForm
171: .isTcpNoDelay());
172: setBooleanAttribute(oObjectName, "useBodyEncodingForURI",
173: oForm.isUseBodyEncodingForURI());
174: setIntegerAttribute(oObjectName, "redirectPort", oForm
175: .getRedirectPortText());
176: setIntegerAttribute(oObjectName, "maxThreads", oForm
177: .getMaxThreadsText());
178: setIntegerAttribute(oObjectName, "minSpareThreads", oForm
179: .getMinSpareThreadsText());
180: setIntegerAttribute(oObjectName, "maxSpareThreads", oForm
181: .getMaxSpareThreadsText());
182:
183: // proxy name and port do not exist for AJP connector
184: if ("AJP".equalsIgnoreCase(sConnectorType) == false) {
185: setStringAttribute(oObjectName, "proxyName", oForm
186: .getProxyName());
187: setIntegerAttribute(oObjectName, "proxyPort", oForm
188: .getProxyPortText());
189: }
190:
191: // HTTPS specific properties
192: if ("HTTPS".equalsIgnoreCase(sConnectorType) == true) {
193: setBooleanAttribute(oObjectName, "clientAuth", oForm
194: .isClientAuth());
195: setStringAttribute(oObjectName, "keystoreFile", oForm
196: .getKeystoreFile());
197: setStringAttribute(oObjectName, "keystorePass", oForm
198: .getKeystorePass());
199: }
200:
201: if ("create".equals(sAction) == true) {
202: m_Session.removeAttribute(p_Mapping.getAttribute());
203: sForward = "ActionListCatalinaConnectors";
204: }
205:
206: // Save in configuration file
207: if (oForm.isSave() == true) {
208: oForm.setSave(false);
209: p_Request.setAttribute("forward", sForward);
210: sForward = "ActionEditServletServer";
211: //ObjectName on = CatalinaObjectName.catalinaServer();
212: //JonasManagementRepr.invoke(on, "store", null, null);
213: }
214: } catch (Throwable t) {
215: addGlobalError(t);
216: saveErrors(p_Request, m_Errors);
217: return (p_Mapping.findForward("Global Error"));
218: }
219:
220: // Forward to the connector display page or the list if create
221: return p_Mapping.findForward(sForward);
222: }
223: }
|