1 14 package org.compiere.install; 15 16 import java.io.*; 17 import java.net.*; 18 import java.util.*; 19 20 import javax.naming.*; 21 23 import javax.rmi.PortableRemoteObject ; 24 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 25 26 import org.apache.log4j.*; 27 28 import org.compiere.interfaces.*; 29 30 36 public class ConnectTest 37 { 38 42 public ConnectTest (String serverName) 43 { 44 System.out.println("ConnectTest: " + serverName); 45 System.out.println(); 46 Logger.getRootLogger().setLevel(Level.ALL); 47 Hashtable env = new Hashtable(); 49 env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 50 env.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 51 env.put(InitialContext.PROVIDER_URL, serverName); 52 57 System.out.println ("Creating context ..."); 59 System.out.println (" " + env); 60 InitialContext context = null; 61 try 62 { 63 context = new InitialContext(env); 64 } 65 catch (Exception e) 66 { 67 System.err.println("ERROR: Could not create context: " + e); 68 return; 69 } 70 71 testJNP (serverName, context); 72 testEJB (serverName, context); 73 74 } 76 81 private void testJNP (String serverName, InitialContext context) 82 { 83 System.out.println(); 85 System.out.println ("Connecting to MBean ..."); 86 try 87 { 88 String connectorName = "jmx:" + serverName + ":rmi"; 89 RMIAdaptor server = (RMIAdaptor) context.lookup (connectorName); 90 System.out.println("- have Server"); 91 System.out.println("- Default Domain=" + server.getDefaultDomain()); 92 System.out.println("- MBeanCount = " + server.getMBeanCount()); 93 94 97 100 Object [] params = {}; 101 String [] signature = {}; 102 } 103 catch (Exception e) 104 { 105 System.err.println("ERROR: Could not contact MBean: " + e); 106 return; 107 } 108 109 System.out.println(); 111 System.out.println(" Examining context ...."); 112 try 113 { 114 System.out.println(" Namespace=" + context.getNameInNamespace()); 115 System.out.println(" Environment=" + context.getEnvironment()); 116 System.out.println(" Context '/':"); 117 NamingEnumeration ne = context.list("/"); 118 while (ne.hasMore()) 119 System.out.println(" - " + ne.nextElement()); 120 System.out.println(" Context 'ejb':"); 122 ne = context.list("ejb"); 123 while (ne.hasMore()) 124 System.out.println(" - " + ne.nextElement()); 125 System.out.println(" Context 'ejb/compiere':"); 127 ne = context.list("ejb/compiere"); 128 while (ne.hasMore()) 129 System.out.println(" - " + ne.nextElement()); 130 } 131 catch (Exception e) 132 { 133 System.err.println("ERROR: Could not examine context: " + e); 134 return; 135 } 136 } 138 143 private void testEJB (String serverName, InitialContext context) 144 { 145 System.out.println(); 146 System.out.println ("Connecting to EJB server ..."); 147 try 148 { 149 System.out.println(" Name=" + StatusHome.JNDI_NAME); 150 StatusHome staHome = (StatusHome)context.lookup (StatusHome.JNDI_NAME); 151 System.out.println(" .. home created"); 152 Status sta = staHome.create(); 153 System.out.println(" .. bean created"); 154 System.out.println(" ServerVersion=" + sta.getMainVersion() + " " + sta.getDateVersion()); 155 sta.remove(); 156 System.out.println(" .. bean removed"); 157 } 158 catch (Exception e) 159 { 160 System.err.println("ERROR: Could not connect: " + e); 161 return; 162 } 163 164 System.out.println(); 165 System.out.println("SUCCESS !!"); 166 } 168 169 170 171 175 public static void main(String [] args) 176 { 177 String serverName = null; 178 if (args.length > 0) 179 serverName = args[0]; 180 if (serverName == null || serverName.length() == 0) 181 { 182 try 183 { 184 serverName = InetAddress.getLocalHost().getHostName(); 185 } 186 catch (UnknownHostException ex) 187 { 188 ex.printStackTrace(); 189 } 190 } 191 192 LogManager.resetConfiguration(); 194 Logger root = Logger.getRootLogger(); 195 root.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n"))); 196 197 ConnectTest ct = new ConnectTest (serverName); 199 } 201 } | Popular Tags |