001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ConnectorMBean.java,v 1.4 2002/05/02 02:03:15 amyroh Exp $
003: * $Revision: 1.4 $
004: * $Date: 2002/05/02 02:03:15 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: * [Additional notices, if required by prior licensing conditions]
061: *
062: */
063:
064: package org.apache.catalina.mbeans;
065:
066: import java.lang.reflect.Method;
067: import javax.management.MBeanException;
068: import javax.management.RuntimeOperationsException;
069: import org.apache.catalina.Connector;
070: import org.apache.catalina.Service;
071: import org.apache.commons.modeler.BaseModelMBean;
072:
073: /**
074: * <p>A <strong>ModelMBean</strong> implementation for the
075: * <code>org.apache.coyote.tomcat4.CoyoteConnector</code> component.</p>
076: *
077: * @author Amy Roh
078: * @version $Revision: 1.4 $ $Date: 2002/05/02 02:03:15 $
079: */
080:
081: public class ConnectorMBean extends ClassNameMBean {
082:
083: // ----------------------------------------------------------- Constructors
084:
085: /**
086: * Construct a <code>ModelMBean</code> with default
087: * <code>ModelMBeanInfo</code> information.
088: *
089: * @exception MBeanException if the initializer of an object
090: * throws an exception
091: * @exception RuntimeOperationsException if an IllegalArgumentException
092: * occurs
093: */
094: public ConnectorMBean() throws MBeanException,
095: RuntimeOperationsException {
096:
097: super ();
098:
099: }
100:
101: // ------------------------------------------------------------- Attributes
102:
103: // ------------------------------------------------------------- Operations
104:
105: /**
106: * Return Client authentication info
107: *
108: * @exception Exception if an MBean cannot be created or registered
109: */
110: public boolean getClientAuth() throws Exception {
111:
112: Object clientAuthObj = null;
113: Class coyoteConnectorCls = Class
114: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
115: if (coyoteConnectorCls.isInstance(this .resource)) {
116: // get factory
117: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
118: null);
119: Object factory = meth1.invoke(this .resource, null);
120: Class coyoteServerSocketFactoryCls = Class
121: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
122: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
123: // get clientAuth
124: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
125: "getClientAuth", null);
126: clientAuthObj = meth2.invoke(factory, null);
127: }
128:
129: }
130: if (clientAuthObj instanceof Boolean) {
131: return ((Boolean) clientAuthObj).booleanValue();
132: } else
133: return false;
134:
135: }
136:
137: /**
138: * Set Client authentication info
139: *
140: * @exception Exception if an MBean cannot be created or registered
141: */
142: public void setClientAuth(boolean clientAuth) throws Exception {
143:
144: Class coyoteConnectorCls = Class
145: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
146: if (coyoteConnectorCls.isInstance(this .resource)) {
147: // get factory
148: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
149: null);
150: Object factory = meth1.invoke(this .resource, null);
151: Class coyoteServerSocketFactoryCls = Class
152: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
153: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
154: // set clientAuth
155: Class partypes2[] = new Class[1];
156: partypes2[0] = Boolean.TYPE;
157: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
158: "setClientAuth", partypes2);
159: Object arglist2[] = new Object[1];
160: arglist2[0] = new Boolean(clientAuth);
161: meth2.invoke(factory, arglist2);
162: }
163: }
164:
165: }
166:
167: /**
168: * Return keystoreFile
169: *
170: * @exception Exception if an MBean cannot be created or registered
171: */
172: public String getKeystoreFile() throws Exception {
173:
174: Object keystoreFileObj = null;
175: Class coyoteConnectorCls = Class
176: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
177: if (coyoteConnectorCls.isInstance(this .resource)) {
178: // get keystoreFile
179: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
180: null);
181: Object factory = meth1.invoke(this .resource, null);
182: Class coyoteServerSocketFactoryCls = Class
183: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
184: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
185: // get keystoreFile
186: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
187: "getKeystoreFile", null);
188: keystoreFileObj = meth2.invoke(factory, null);
189: }
190: }
191:
192: if (keystoreFileObj == null) {
193: return null;
194: } else {
195: return keystoreFileObj.toString();
196: }
197:
198: }
199:
200: /**
201: * Set keystoreFile
202: *
203: * @exception Exception if an MBean cannot be created or registered
204: */
205: public void setKeystoreFile(String keystoreFile) throws Exception {
206:
207: if (keystoreFile == null) {
208: keystoreFile = "";
209: }
210: Class coyoteConnectorCls = Class
211: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
212: if (coyoteConnectorCls.isInstance(this .resource)) {
213: // get factory
214: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
215: null);
216: Object factory = meth1.invoke(this .resource, null);
217: Class coyoteServerSocketFactoryCls = Class
218: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
219: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
220: // set keystoreFile
221: Class partypes2[] = new Class[1];
222: String str = new String();
223: partypes2[0] = str.getClass();
224: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
225: "setKeystoreFile", partypes2);
226: Object arglist2[] = new Object[1];
227: arglist2[0] = keystoreFile;
228: meth2.invoke(factory, arglist2);
229: }
230:
231: }
232: }
233:
234: /**
235: * Return keystorePass
236: *
237: * @exception Exception if an MBean cannot be created or registered
238: */
239: public String getKeystorePass() throws Exception {
240:
241: Object keystorePassObj = null;
242: Class coyoteConnectorCls = Class
243: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
244: if (coyoteConnectorCls.isInstance(this .resource)) {
245: // get factory
246: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
247: null);
248: Object factory = meth1.invoke(this .resource, null);
249: Class coyoteServerSocketFactoryCls = Class
250: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
251: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
252: // get keystorePass
253: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
254: "getKeystorePass", null);
255: keystorePassObj = meth2.invoke(factory, null);
256: }
257:
258: }
259:
260: if (keystorePassObj == null) {
261: return null;
262: } else {
263: return keystorePassObj.toString();
264: }
265:
266: }
267:
268: /**
269: * Set keystorePass
270: *
271: * @exception Exception if an MBean cannot be created or registered
272: */
273: public void setKeystorePass(String keystorePass) throws Exception {
274:
275: if (keystorePass == null) {
276: keystorePass = "";
277: }
278: Class coyoteConnectorCls = Class
279: .forName("org.apache.coyote.tomcat4.CoyoteConnector");
280: if (coyoteConnectorCls.isInstance(this .resource)) {
281: // get factory
282: Method meth1 = coyoteConnectorCls.getMethod("getFactory",
283: null);
284: Object factory = meth1.invoke(this .resource, null);
285: Class coyoteServerSocketFactoryCls = Class
286: .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
287: if (coyoteServerSocketFactoryCls.isInstance(factory)) {
288: // set keystorePass
289: Class partypes2[] = new Class[1];
290: String str = new String();
291: partypes2[0] = str.getClass();
292: Method meth2 = coyoteServerSocketFactoryCls.getMethod(
293: "setKeystorePass", partypes2);
294: Object arglist2[] = new Object[1];
295: arglist2[0] = keystorePass;
296: meth2.invoke(factory, arglist2);
297: }
298: }
299: }
300:
301: }
|