📄 mbeanfactory.java
字号:
* @param address The IP address on which to bind
* @param port TCP port number to listen on
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createAjpConnector(String parent, String address, int port)
throws Exception {
Object retobj = null;
try {
// Create a new CoyoteConnector instance for AJP
// use reflection to avoid j-t-c compile-time circular dependencies
Class cls = Class.forName("org.apache.coyote.tomcat5.CoyoteConnector");
Constructor ct = cls.getConstructor(null);
retobj = ct.newInstance(null);
Class partypes1 [] = new Class[1];
// Set address
String str = new String();
if ((address!=null) && (address.length()>0)) {
partypes1[0] = str.getClass();
Method meth1 = cls.getMethod("setAddress", partypes1);
Object arglist1[] = new Object[1];
arglist1[0] = address;
meth1.invoke(retobj, arglist1);
}
// Set port number
Class partypes2 [] = new Class[1];
partypes2[0] = Integer.TYPE;
Method meth2 = cls.getMethod("setPort", partypes2);
Object arglist2[] = new Object[1];
arglist2[0] = new Integer(port);
meth2.invoke(retobj, arglist2);
// set protocolHandlerClassName for AJP
Class partypes3 [] = new Class[1];
partypes3[0] = str.getClass();
Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
Object arglist3[] = new Object[1];
arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
meth3.invoke(retobj, arglist3);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
service.addConnector((Connector)retobj);
Method getObjectName = cls.getMethod("getObjectName", null);
// Return the corresponding MBean name
//ObjectName coname = (ObjectName)getObjectName.invoke(retobj, null);
ObjectName coname =
MBeanUtils.createObjectName(pname.getDomain(), (Connector)retobj);
return (coname.toString());
} catch (Exception e) {
throw new MBeanException(e);
}
}
/**
* Create a new DefaultContext.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createDefaultContext(String parent)
throws Exception {
// XXX FIXME
// Create a new StandardDefaultContext instance
StandardDefaultContext context = new StandardDefaultContext();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
Engine engine = (Engine) service.getContainer();
String hostName = pname.getKeyProperty("host");
if (hostName == null) { //if DefaultContext is nested in Engine
context.setParent(engine);
engine.addDefaultContext(context);
} else { // if DefaultContext is nested in Host
Host host = (Host) engine.findChild(hostName);
context.setParent(host);
host.addDefaultContext(context);
}
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("DefaultContext");
ObjectName oname =
MBeanUtils.createObjectName(managed.getDomain(), context);
return (oname.toString());
}
/**
* Create a new FileLogger.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createFileLogger(String parent)
throws Exception {
// Create a new FileLogger instance
FileLogger fileLogger = new FileLogger();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
// Add the new instance to its parent component
containerBase.setLogger(fileLogger);
// Return the corresponding MBean name
ObjectName oname = fileLogger.getObjectName();
return (oname.toString());
}
/**
* Create a new HttpConnector
*
* @param parent MBean Name of the associated parent component
* @param address The IP address on which to bind
* @param port TCP port number to listen on
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createHttpConnector(String parent, String address, int port)
throws Exception {
Object retobj = null;
try {
// Create a new CoyoteConnector instance
// use reflection to avoid j-t-c compile-time circular dependencies
Class cls = Class.forName("org.apache.coyote.tomcat5.CoyoteConnector");
Constructor ct = cls.getConstructor(null);
retobj = ct.newInstance(null);
Class partypes1 [] = new Class[1];
// Set address
String str = new String();
if ((address!=null) && (address.length()>0)) {
partypes1[0] = str.getClass();
Method meth1 = cls.getMethod("setAddress", partypes1);
Object arglist1[] = new Object[1];
arglist1[0] = address;
meth1.invoke(retobj, arglist1);
}
// Set port number
Class partypes2 [] = new Class[1];
partypes2[0] = Integer.TYPE;
Method meth2 = cls.getMethod("setPort", partypes2);
Object arglist2[] = new Object[1];
arglist2[0] = new Integer(port);
meth2.invoke(retobj, arglist2);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
service.addConnector((Connector)retobj);
Method getObjectName = cls.getMethod("getObjectName", null);
// Return the corresponding MBean name
ObjectName coname = (ObjectName)getObjectName.invoke(retobj, null);
//ObjectName coname =
// MBeanUtils.createObjectName(pname.getDomain(), (Connector)retobj);
return (coname.toString());
} catch (Exception e) {
throw new MBeanException(e);
}
}
/**
* Create a new HttpsConnector
*
* @param parent MBean Name of the associated parent component
* @param address The IP address on which to bind
* @param port TCP port number to listen on
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createHttpsConnector(String parent, String address, int port)
throws Exception {
Object retobj = null;
// Create a new CoyoteConnector instance
// use reflection to avoid j-t-c compile-time circular dependencies
Class cls = Class.forName("org.apache.coyote.tomcat5.CoyoteConnector");
try {
Constructor ct = cls.getConstructor(null);
retobj = ct.newInstance(null);
Class partypes1 [] = new Class[1];
// Set address
String str = new String();
if ((address!=null) && (address.length()>0)) {
partypes1[0] = str.getClass();
Method meth1 = cls.getMethod("setAddress", partypes1);
Object arglist1[] = new Object[1];
arglist1[0] = address;
meth1.invoke(retobj, arglist1);
}
// Set port number
Class partypes2 [] = new Class[1];
partypes2[0] = Integer.TYPE;
Method meth2 = cls.getMethod("setPort", partypes2);
Object arglist2[] = new Object[1];
arglist2[0] = new Integer(port);
meth2.invoke(retobj, arglist2);
// Set scheme
Class partypes3 [] = new Class[1];
partypes3[0] = str.getClass();
Method meth3 = cls.getMethod("setScheme", partypes3);
Object arglist3[] = new Object[1];
arglist3[0] = new String("https");
meth3.invoke(retobj, arglist3);
// Set secure
Class partypes4 [] = new Class[1];
partypes4[0] = Boolean.TYPE;
Method meth4 = cls.getMethod("setSecure", partypes4);
Object arglist4[] = new Object[1];
arglist4[0] = new Boolean(true);
meth4.invoke(retobj, arglist4);
// Set factory
Class serverSocketFactoryCls =
Class.forName("org.apache.catalina.net.ServerSocketFactory");
Class coyoteServerSocketFactoryCls =
Class.forName("org.apache.coyote.tomcat5.CoyoteServerSocketFactory");
Constructor factoryConst =
coyoteServerSocketFactoryCls.getConstructor(null);
Object factoryObj = factoryConst.newInstance(null);
Class partypes5 [] = new Class[1];
partypes5[0] = serverSocketFactoryCls;
Method meth5 = cls.getMethod("setFactory", partypes5);
Object arglist5[] = new Object[1];
arglist5[0] = factoryObj;
meth5.invoke(retobj, arglist5);
} catch (Exception e) {
throw new MBeanException(e);
}
try {
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
service.addConnector((Connector)retobj);
Method getObjectName = cls.getMethod("getObjectName", null);
// Return the corresponding MBean name
//ObjectName coname = (ObjectName)getObjectName.invoke(retobj, null);
ObjectName coname =
MBeanUtils.createObjectName(pname.getDomain(), (Connector)retobj);
return (coname.toString());
} catch (Exception e) {
// FIXME
// disply error message
// the user needs to use keytool to configure SSL first
// addConnector will fail otherwise
return null;
}
}
/**
* Create a new JDBC Realm.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createJDBCRealm(String parent, String driverName,
String connectionName, String connectionPassword, String connectionURL)
throws Exception {
// Create a new JDBCRealm instance
JDBCRealm realm = new JDBCRealm();
realm.setDriverName(driverName);
realm.setConnectionName(connectionName);
realm.setConnectionPassword(connectionPassword);
realm.setConnectionURL(connectionURL);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
// Add the new instance to its parent component
containerBase.setRealm(realm);
// Return the corresponding MBean name
ObjectName oname = realm.getObjectName();
// FIXME getObjectName() returns null
//ObjectName oname =
// MBeanUtils.createObjectName(pname.getDomain(), realm);
if (oname != null) {
return (oname.toString());
} else {
return null;
}
}
/**
* Create a new JNDI Realm.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createJNDIRealm(String parent)
throws Exception {
// Create a new JNDIRealm instance
JNDIRealm realm = new JNDIRealm();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
// Add the new instance to its parent component
containerBase.setRealm(realm);
// Return the corresponding MBean name
ObjectName oname = realm.getObjectName();
// FIXME getObjectName() returns null
//ObjectName oname =
// MBeanUtils.createObjectName(pname.getDomain(), realm);
if (oname != null) {
return (oname.toString());
} else {
return null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -