1 19 20 21 package org.netbeans.modules.j2ee.sun.bridge; 22 23 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration; 24 import com.sun.enterprise.admin.jmx.remote.SunOneHttpJmxConnectorFactory; 25 import com.sun.enterprise.config.serverbeans.Config; 26 import com.sun.enterprise.config.serverbeans.Domain; 27 import com.sun.enterprise.config.serverbeans.HttpListener; 28 import com.sun.enterprise.deployapi.SunDeploymentManager; 29 import com.sun.enterprise.deployapi.SunTargetModuleID; 30 import com.sun.enterprise.deployment.client.ServerConnectionEnvironment; 31 import java.io.BufferedInputStream ; 32 import java.io.File ; 33 import java.io.FileInputStream ; 34 import java.io.FileNotFoundException ; 35 import java.io.IOException ; 36 import java.io.InputStream ; 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 import javax.enterprise.deploy.shared.ModuleType ; 40 import javax.enterprise.deploy.spi.DeploymentManager ; 41 import javax.enterprise.deploy.spi.TargetModuleID ; 42 import javax.management.MBeanServerConnection ; 43 import javax.management.ObjectName ; 44 import javax.management.remote.JMXConnector ; 45 import javax.management.remote.JMXServiceURL ; 46 47 54 55 56 public class AppServerBridge { 57 58 public static java.io.File getDirLocation( TargetModuleID tmid){ 59 java.io.File dirLocation=null; 60 try{ 61 SunTargetModuleID ddd = (SunTargetModuleID)tmid; 62 63 if (ddd.getModuleType().equals(ModuleType.WAR)){ 64 ObjectName aaaa = new ObjectName ("com.sun.appserv:type=web-module,name="+ddd.getModuleID()+",category=config"); 65 dirLocation =new java.io.File (""+ddd.getMBeanServerConnection().getAttribute(aaaa,"location")); 66 } else if (ddd.getModuleType().equals(ModuleType.EJB)){ 68 ObjectName aaaa = new ObjectName ("com.sun.appserv:type=ejb-module,name="+ddd.getModuleID()+",category=config"); 69 dirLocation =new java.io.File (""+ddd.getMBeanServerConnection().getAttribute(aaaa,"location")); 70 } 71 72 else if (ddd.getModuleType().equals(ModuleType.EAR)){ 73 ObjectName aaaa = new ObjectName ("com.sun.appserv:type=application,name="+ddd.getModuleID()+",category=config"); 74 dirLocation =new java.io.File (""+ddd.getMBeanServerConnection().getAttribute(aaaa,"location")); 75 } else{ 76 System.out.println("Still Some Work to do in ModuleRestartActikon is AS 8.1 plugin code"); 77 } 78 79 } catch(Exception e) { 80 e.printStackTrace(); 81 IllegalStateException ise = new IllegalStateException (e.getMessage()); 82 ise.initCause(e); 83 throw ise; 84 } 85 return dirLocation; 86 } 87 88 public static boolean isApp(TargetModuleID tmid) { 89 ModuleType mt = ((SunTargetModuleID)tmid).getModuleType(); 90 return mt.equals(ModuleType.EAR); 91 } 92 93 public static boolean isWar(TargetModuleID tmid) { 94 ModuleType mt = ((SunTargetModuleID)tmid).getModuleType(); 95 return mt.equals(ModuleType.WAR); 96 } 97 98 public static Boolean isCar(TargetModuleID tmid) { 99 ModuleType mt = ((SunTargetModuleID)tmid).getModuleType(); 100 return Boolean.valueOf(mt.equals(ModuleType.CAR)); 101 } 102 103 111 public static String getModuleUrl(TargetModuleID module){ 112 ModuleType mt = ((SunTargetModuleID)module).getModuleType(); 113 String suffix = ".jar"; 114 if (mt.equals(ModuleType.EAR)){ 115 suffix = ".ear"; 116 } 117 if (mt.equals(ModuleType.WAR)){ 118 suffix = ".war"; 119 } 120 if (mt.equals(ModuleType.RAR)){ 121 suffix = ".rar"; 122 } 123 124 String moduleID = module.getModuleID(); 125 int i = moduleID.indexOf('#'); 126 if (i > -1) { 127 moduleID = moduleID.substring(i+1); 128 } 129 if (moduleID.endsWith(suffix) || moduleID.endsWith(suffix.toUpperCase())) { 130 return moduleID; 131 } 132 return moduleID + suffix; 133 } 134 135 136 public static String getHostPort(File domainXml, File platformDir){ 137 String hostPort = null; 138 InputStream inFile = null; 139 try { 140 inFile = new BufferedInputStream (new FileInputStream (domainXml)); 141 Domain domain = Domain.createGraph(inFile); 142 String domainSysID = domain.graphManager().getXmlDocument().getDoctype().getSystemId(); 143 144 146 if (null == domainSysID) { 148 return null; 149 } 150 151 int dtdsDex = domainSysID.indexOf("dtds/"); if (-1 == dtdsDex) { 154 return null; 155 } 156 157 File domainDtd = new File (platformDir, "lib/"+ domainSysID.substring(dtdsDex)); 159 160 if (!domainDtd.exists()) { 162 return null; 163 } 164 165 Config conf = domain.getConfigs().getConfigByName("server-config"); HttpListener list = conf.getHttpService().getHttpListenerById("admin-listener"); hostPort = "localhost:" + list.getPort(); } catch (FileNotFoundException ex) { 169 Logger.getLogger("org.netbeans.modules.j2ee.sun.bridge").log(Level.WARNING,"",ex); } catch (IOException ex) { 171 Logger.getLogger("org.netbeans.modules.j2ee.sun.bridge").log(Level.WARNING,"",ex); } catch (RuntimeException re) { 173 Logger.getLogger("org.netbeans.modules.j2ee.sun.bridge").log(Level.WARNING,"",re); } finally { 175 if (null!=inFile) 176 try { 177 inFile.close(); 178 } catch(IOException ioe) { 179 Logger.getLogger("org.netbeans.modules.j2ee.sun.bridge").log(Level.FINE,"",ioe); } 182 } 183 return hostPort; 184 } 185 186 189 public String getNonAdminPortNumber(File domainXml){ 190 String port = null; 191 try{ 192 InputStream inFile = new FileInputStream (domainXml); 193 Domain domain = Domain.createGraph(inFile); 194 Config conf = domain.getConfigs().getConfigByName("server-config"); HttpListener list = conf.getHttpService().getHttpListenerById("http-listener-1"); port = list.getPort(); inFile.close(); 198 }catch(Exception ex){ 199 return null; 200 } 203 return port; 204 } 205 public static MBeanServerConnection getJMXConnector(String host, int port, String username, String password,boolean secure) throws java.net.MalformedURLException , java.io.IOException { 206 MBeanServerConnection serverConn = null; 207 String mode=null; 208 if (secure) 209 mode="s1ashttps"; 210 else 211 mode = "s1ashttp"; 212 JMXServiceURL serverUrl = new JMXServiceURL (mode, host, port); final JMXConnector connector = SunOneHttpJmxConnectorFactory.connect(serverUrl, username, password); 214 serverConn = connector.getMBeanServerConnection(); 215 216 return serverConn; 217 } 218 225 public static void setServerConnectionEnvironment(DeploymentManager dm) { 226 ServerConnectionEnvironment env = new ServerConnectionEnvironment(); 227 env.put(DefaultConfiguration.TRUST_MANAGER_PROPERTY_NAME, new X509TrustManager()); 228 if (dm instanceof SunDeploymentManager) { 229 ((SunDeploymentManager)dm).setServerConnectionEnvironment(env); 230 } } 236 237 238 } 239 | Popular Tags |