1 25 26 package org.objectweb.jonas.web.catalina55; 27 28 import javax.management.InstanceNotFoundException ; 29 import javax.management.MBeanException ; 30 import javax.management.MBeanServer ; 31 import javax.management.ObjectName ; 32 import javax.management.ReflectionException ; 33 34 import org.objectweb.jonas.server.LoaderManager; 35 import org.objectweb.jonas.jmx.CatalinaObjectName; 36 37 42 public class CatalinaConnectorFactory implements CatalinaConnectorFactoryMBean { 43 47 private MBeanServer myServer = null; 48 49 52 private static final int CONNECTOR_NB_VALUES = 3; 53 54 55 62 public String createConnector(String type, String address, int port) { 63 String sObjectName = null; 64 try { 65 ObjectName onFactory = CatalinaObjectName.catalinaFactory(); 67 ObjectName onServer = CatalinaObjectName.catalinaServer(); 69 ObjectName [] aonServices = (ObjectName []) myServer.getAttribute(onServer, "serviceNames"); 71 String currentCatalinaServiceName = aonServices[0].getKeyProperty("serviceName"); 73 String currentCatalinaDomainName = aonServices[0].getDomain(); 75 ObjectName onService = CatalinaObjectName.catalinaService(currentCatalinaDomainName, currentCatalinaServiceName); 77 Object [] values = new Object [CONNECTOR_NB_VALUES]; 79 values[0] = onService.toString(); 80 values[1] = address; 81 values[2] = new Integer (port); 82 String operation = null; 83 if ("HTTP".equalsIgnoreCase(type)) { 84 operation = "createHttpConnector"; } else if ("HTTPS".equalsIgnoreCase(type)) { 86 operation = "createHttpsConnector"; } else if ("AJP".equalsIgnoreCase(type)) { 88 operation = "createAjpConnector"; } else { 90 throw new IllegalArgumentException ("Unknown type : '" + type + "'."); 91 } 92 ClassLoader old = Thread.currentThread().getContextClassLoader(); 94 Thread.currentThread().setContextClassLoader(LoaderManager.getInstance().getCatalinaLoader()); 95 sObjectName = (String ) myServer.invoke(onFactory, operation, values 97 , saCreateStandardConnectorTypes); 98 Thread.currentThread().setContextClassLoader(old); 100 } catch (InstanceNotFoundException e) { 101 e.printStackTrace(); 103 } catch (MBeanException e) { 104 e.printStackTrace(); 106 } catch (ReflectionException e) { 107 e.printStackTrace(); 109 } catch (Exception e) { 110 e.printStackTrace(); 112 } 113 return sObjectName; 114 } 115 116 119 private String [] saCreateStandardConnectorTypes = { 120 "java.lang.String", "java.lang.String", "int" }; 122 125 public MBeanServer getMyServer() { 126 return myServer; 127 } 128 131 public void setMyServer(MBeanServer myServer) { 132 this.myServer = myServer; 133 } 134 } 135 | Popular Tags |