1 23 package com.sun.enterprise.server; 24 25 import java.io.*; 26 import java.util.Properties ; 27 import java.util.Vector ; 28 import java.net.*; 29 import javax.rmi.CORBA.Tie ; 30 import javax.rmi.PortableRemoteObject ; 31 import org.omg.CORBA.ORB ; 32 import java.security.SecureRandom ; 33 import com.sun.corba.ee.impl.orbutil.ORBConstants; 34 35 import com.sun.enterprise.*; 36 import com.sun.enterprise.util.*; 37 import com.sun.enterprise.log.*; 38 import com.sun.enterprise.repository.*; 39 import com.sun.enterprise.naming.*; 40 import com.sun.enterprise.distributedtx.*; 41 import com.sun.enterprise.appverification.factory.AppVerification; 42 import com.sun.enterprise.resource.ResourceInstaller; 43 import com.sun.enterprise.iiop.POAProtocolMgr; 44 import com.sun.enterprise.iiop.PEORBConfigurator; 45 import com.sun.enterprise.iiop.ORBMonitoring; 46 import com.sun.ejb.ContainerFactory; 47 import com.sun.ejb.containers.ContainerFactoryImpl; 48 import java.util.logging.*; 49 import com.sun.logging.*; 50 51 import com.sun.appserv.server.ServerLifecycleException; 52 53 import com.sun.enterprise.server.ServerContext; 54 import com.sun.enterprise.server.ServerContextImpl; 55 import com.sun.enterprise.config.ConfigContext; 56 import com.sun.enterprise.config.ConfigBean; 57 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 58 import com.sun.enterprise.config.ConfigException; 59 import com.sun.enterprise.server.ApplicationServer; 60 import com.sun.enterprise.config.serverbeans.IiopService; 61 import com.sun.enterprise.config.serverbeans.IiopListener; 62 import com.sun.enterprise.config.serverbeans.TransactionService; 63 import com.sun.enterprise.config.serverbeans.Server; 64 import com.sun.enterprise.config.serverbeans.Domain; 65 import com.sun.enterprise.transaction.monitor.JTSMonitorMBean; 66 import com.sun.enterprise.config.serverbeans.JmsService; 67 import com.sun.enterprise.util.diagnostics.Reporter; 68 import com.sun.enterprise.util.ORBManager; 69 import com.sun.enterprise.config.serverbeans.ElementProperty; 70 71 72 import javax.resource.spi.ManagedConnectionFactory ; 73 74 import com.sun.enterprise.deployment.ConnectorDescriptor; 75 import com.sun.enterprise.deployment.Descriptor; 76 import com.sun.enterprise.deployment.io.ConnectorDeploymentDescriptorFile; 77 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr; 78 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 79 import com.sun.enterprise.connectors.ConnectorRuntime; 80 import com.sun.enterprise.connectors.util.JmsRaUtil; 81 82 import com.sun.enterprise.deployment.backend.OptionalPkgDependency; 83 84 91 92 public final class J2EEServer 93 { 94 private static final Logger _logger = 98 LogDomains.getLogger(LogDomains.CORE_LOGGER); 99 public static final SecureRandom secureRandom = new SecureRandom (); 100 static { 101 secureRandom.setSeed(System.currentTimeMillis()); 102 } 103 public static final String J2EE_HOME="com.sun.enterprise.home"; 104 105 public static final String J2EE_APPNAME = 106 "com.sun.enterprise.appname"; 107 public static final String JTS_SERVER_ID = 108 "com.sun.jts.persistentServerId"; 109 public static final String J2EE_SERVER_ID_PROP = 110 "com.sun.enterprise.J2EEServerId"; 111 112 private static final boolean debug = 114 com.sun.enterprise.util.logging.Debug.enabled; 115 116 private static LocalStringManagerImpl localStrings = 117 new LocalStringManagerImpl(J2EEServer.class); 118 119 private static java.io.PrintStream ostream = System.out; 120 private static java.io.PrintStream estream = System.err; 121 122 private static final int MAX_INITIAL_CONTEXT_RETRIES = 15; 123 124 125 private static final String DefaultDbDir= "orb.db"; 126 private static final String LISTEN_PROP = 127 "com.sun.CORBA.connection.ORBListenSocket"; 128 129 private static final String OUTPUT_LOG= "system.out"; 130 private static final String ERROR_LOG= "system.err"; 131 132 133 private File repositoryDir; 136 137 private int orbInitialPort; 139 private Configuration conf = null; 140 private ORB orb; 141 private ProtocolManager protocolMgr; 142 143 private ServerContext serverContext; 144 145 148 public J2EEServer() 149 { 150 } 151 152 private void run(String [] args, boolean verbose, boolean startJMS) 153 { 154 ConnectorRuntime.getRuntime().initialize(ConnectorRuntime.SERVER); 155 try { 156 if ( (serverContext != null) && 157 (serverContext instanceof ServerContextImpl) ) { 158 159 ServerContextImpl ctxImp = (ServerContextImpl)serverContext; 160 String seedFile = ctxImp.getServerConfigPath() + 161 File.separator + "secure.seed"; 162 File secureSeedFile = new File(seedFile); 163 164 long seed = readSecureSeed(secureSeedFile); 166 secureRandom.setSeed(seed); 167 seed = secureRandom.nextLong(); 169 writeSecureSeed(secureSeedFile, seed); 170 secureSeedFile = null; 171 172 } else { 173 _logger.log(Level.FINE,"Unable to initialize secure seed."); 174 } 175 176 Properties props = System.getProperties(); 178 179 props.setProperty(J2EE_APPNAME, "j2ee"); 182 183 184 Switch theSwitch = Switch.getSwitch(); 186 theSwitch.setContainerType(Switch.EJBWEB_CONTAINER); 187 188 189 Switch.getSwitch().setProviderManager(ProviderManager.getProviderManager()); 190 191 192 InvocationManager invMgr = new InvocationManagerImpl(); 194 theSwitch.setInvocationManager(invMgr); 195 196 NamingManager nm = new NamingManagerImpl(); 198 theSwitch.setNamingManager(nm); 199 200 InjectionManager injectionMgr = new InjectionManagerImpl(); 202 theSwitch.setInjectionManager(injectionMgr); 203 204 J2EETransactionManager tm = 205 J2EETransactionManagerImpl.createTransactionManager(); 206 theSwitch.setTransactionManager(tm); 207 208 209 ResourceInstaller installer = theSwitch.getResourceInstaller(); 211 212 ConnectorRuntime connRuntime = ConnectorRuntime.getRuntime(); 214 215 JmsRaUtil raUtil = new JmsRaUtil(); 217 raUtil.upgradeIfNecessary(); 218 219 initRoleMapperFactory(); 221 222 233 ManagementObjectManager mgmtObjectMgr = 235 theSwitch.getManagementObjectManager(); 236 237 244 ResourcesUtil resourcesUtil = 246 ResourcesUtil.getInstance(serverContext); 247 248 installer.installPersistenceManagerResources(); 249 installer.installCustomResources(); 250 installer.installExternalJndiResources(); 251 installer.installMailResources(); 252 253 256 ContainerFactory cf = new ContainerFactoryImpl(); 258 theSwitch.setContainerFactory(cf); 259 260 try { 262 _logger.fine("satisfy.optionalpkg.dependency"); 263 OptionalPkgDependency.satisfyOptionalPackageDependencies(); 264 } catch (Exception e) { 265 _logger.log(Level.WARNING, 266 "optionalpkg.error", e); 267 } 268 269 270 com.sun.enterprise.admin.monitor.MonitoringHelper.registerTxnMonitoringMBean(new JTSMonitorMBean()); 272 273 nm.publishObject("UserTransaction", new UserTransactionImpl(),true); 275 276 ConnectorRuntime.getRuntime().initializeConnectorMonitoring(); 278 279 String startupComplete = 280 localStrings.getLocalString("j2ee.started", 281 "J2EE server startup complete."); 282 _logger.log(Level.FINE,startupComplete); 283 } 284 catch (Exception ex) { 285 if(_logger.isLoggable(Level.SEVERE)) 286 _logger.log(Level.SEVERE,"enterprise.j2eeservice_running_exception",ex.toString()); 287 if ( debug ) 288 _logger.log(Level.FINEST,"Exception running j2ee services",ex); 289 Log.err.flush(); 290 throw new RuntimeException (ex.getMessage(), ex); 291 } 292 } 293 294 296 private void initRoleMapperFactory() throws Exception 297 { 298 Object o = null; 299 Class c=null; 300 try { 302 c = Class.forName("com.sun.enterprise.security.acl.RoleMapperFactory"); 303 if (c!=null) { 304 o = c.newInstance(); 305 if (o!=null && o instanceof SecurityRoleMapperFactory) { 306 SecurityRoleMapperFactoryMgr.registerFactory((SecurityRoleMapperFactory) o); 307 } 308 } 309 if (o==null) { 310 _logger.log(Level.SEVERE,localStrings.getLocalString("j2ee.norolemapper", 311 "Cannot instantiate the SecurityRoleMapperFactory")); 312 } 313 } catch(Exception cnfe) { 314 _logger.log(Level.SEVERE, 315 localStrings.getLocalString("j2ee.norolemapper", "Cannot instantiate the SecurityRoleMapperFactory"), 316 cnfe); 317 throw cnfe; 318 } 319 } 320 321 326 private long readSecureSeed(File fname){ 327 byte[] seed; 328 try { 329 BufferedReader fis = new BufferedReader(new FileReader(fname)); 330 try{ 331 String line = fis.readLine(); 332 fis.close(); 333 Long lseed = new Long (line); 335 return lseed.longValue(); 336 } catch (IOException e){ 337 if (fis != null) 338 fis.close(); 339 } 340 } catch (Throwable e){ } 342 347 secureRandom.setSeed(System.currentTimeMillis()); 348 long newSeed = secureRandom.nextLong(); 349 return newSeed; 350 } 351 352 357 private void writeSecureSeed(File fname, long seed){ 358 try{ 359 FileOutputStream fos = new FileOutputStream(fname); 360 String sseed = Long.toString(seed); 361 fos.write(sseed.getBytes()); 362 fos.close(); 363 }catch(IOException e){ 364 String errmsg = 365 localStrings.getLocalString("j2ee.startupslow", 366 "Cannot write the seed file for fast startup. The next startup will be slow."); 367 368 _logger.log(Level.WARNING,"enterprise.j2ee_startupslow"); 369 } 370 371 } 372 373 376 public static void main(ServerContext serverContext) throws ServerLifecycleException 377 { 378 String [] args = serverContext.getCmdLineArgs(); 379 if (args == null) args = new String [0]; 380 381 382 Utility.checkJVMVersion(); 383 384 boolean verbose = false; 386 boolean startJMS = true; 387 388 if (System.getProperty("j2ee.appverification.home") != null) { 389 AppVerification.setInstrument(true); 390 } 391 _logger.log(Level.FINE, "S1AS AVK Instrumentation " 392 + (AppVerification.doInstrument() ? "enabled" : "disabled")); 393 394 try { 395 396 ORBManager.setORBSystemProperties(); 399 400 J2EEServer j2ee = new J2EEServer(); 402 j2ee.setServerContext(serverContext); 403 j2ee.run(args, verbose, startJMS); 404 } catch(Exception e) { 405 _logger.log(Level.SEVERE,"enterprise.run_exception",e); 406 if(e.getMessage() != null) { 407 if(_logger.isLoggable(Level.SEVERE)) 408 _logger.log(Level.SEVERE,"enterprise.j2ee_server_error",e.getMessage()); 409 } 410 _logger.log(Level.SEVERE,"enterprise.j2ee_server_error1"); 411 System.err.flush(); 412 throw new ServerLifecycleException(e.getMessage(), e); 413 } 414 } 415 416 private void setServerContext(ServerContext serverContext) { 417 this.serverContext = serverContext; 418 } 419 420 421 424 public static void shutdown() { 425 PEMain.shutdownStarted = true; 426 try { 427 if(_logger.isLoggable(Level.FINE)) 428 _logger.log(Level.FINE,localStrings.getLocalString("j2ee.shutdown","Shutting down the J2EE server...")); 429 430 if (AppVerification.doInstrument()) { 431 AppVerification.getInstrumentLogger().writeResults(); 432 } 433 434 Log.flushAll(); 435 } catch(Throwable t) { 436 if(_logger.isLoggable(Level.SEVERE)) 437 _logger.log(Level.SEVERE,"enterprise.shutdown_exception",t.toString()); 438 if(_logger.isLoggable(Level.FINE)) 439 _logger.log(Level.FINE,localStrings.getLocalString("j2ee.cannot.shutdown","Unable to shutdown the J2EE server...")); 440 } 441 if (PEMain.shutdownThreadInvoked == false) 442 System.exit(0); 443 444 } 445 } 446 447 449 450 451 452 | Popular Tags |