1 22 package org.jboss.iiop; 23 24 import java.io.InputStream ; 25 import java.util.Hashtable ; 26 import java.util.Iterator ; 27 import java.util.Properties ; 28 29 import javax.ejb.spi.HandleDelegate ; 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 import javax.naming.Name ; 33 import javax.naming.Reference ; 34 import javax.naming.spi.ObjectFactory ; 35 36 import org.jboss.iiop.naming.ORBInitialContextFactory; 37 import org.jboss.metadata.MetaData; 38 import org.jboss.proxy.ejb.handle.HandleDelegateImpl; 39 import org.jboss.security.SecurityDomain; 40 import org.jboss.system.Registry; 41 import org.jboss.system.ServiceMBeanSupport; 42 import org.jboss.system.server.ServerConfigUtil; 43 import org.omg.CORBA.ORB ; 44 import org.omg.CORBA.Policy ; 45 import org.omg.PortableServer.IdAssignmentPolicy ; 46 import org.omg.PortableServer.IdAssignmentPolicyValue ; 47 import org.omg.PortableServer.IdUniquenessPolicyValue ; 48 import org.omg.PortableServer.LifespanPolicy ; 49 import org.omg.PortableServer.LifespanPolicyValue ; 50 import org.omg.PortableServer.POA ; 51 import org.omg.PortableServer.POAHelper ; 52 import org.omg.PortableServer.RequestProcessingPolicyValue ; 53 import org.omg.PortableServer.ServantRetentionPolicyValue ; 54 import org.w3c.dom.Element ; 55 56 64 public class CorbaORBService 65 extends ServiceMBeanSupport 66 implements CorbaORBServiceMBean, ObjectFactory 67 { 68 70 public static String ORB_NAME = "JBossCorbaORB"; 71 public static String POA_NAME = "JBossCorbaPOA"; 72 public static String IR_POA_NAME = "JBossCorbaInterfaceRepositoryPOA"; 73 public static String SSL_DOMAIN = "JBossCorbaSSLDomain"; 74 75 77 private String orbClass = null; 78 private String orbSingletonClass = null; 79 private String orbSingletonDelegate = null; 80 private String orbPropertiesFileName = "orb-properties-file-not-defined"; 81 private Element portableInterceptorInitializers = null; 82 private int port = 0; 83 private int sslPort = 0; 84 private String sslDomain = null; 85 private boolean sunJDK14IsLocalBugFix = true; 86 87 89 private static ORB orb; 90 private static POA poa; 91 private static POA otsPoa; 92 private static POA otsResourcePoa; 93 private static POA irPoa; 94 private static HandleDelegate hd; 95 private static int oaSslPort; 96 97 102 private static boolean sslComponentsEnabledFlag = false; 103 104 113 private static boolean sendSasAcceptWithExceptionEnabledFlag = true; 114 115 118 private static boolean otsContextPropagationEnabledFlag = false; 119 120 124 public static int getTheActualSSLPort() 125 { 126 return oaSslPort; 127 } 128 129 133 public static boolean getSSLComponentsEnabledFlag() 134 { 135 return sslComponentsEnabledFlag; 136 } 137 138 143 public static boolean getSendSASAcceptWithExceptionEnabledFlag() 144 { 145 return sendSasAcceptWithExceptionEnabledFlag; 146 } 147 148 153 public static boolean getOTSContextPropagationEnabledFlag() 154 { 155 return otsContextPropagationEnabledFlag; 156 } 157 158 162 public static POA getOtsPoa() 163 { 164 return otsPoa; 165 } 166 167 174 public static POA getOtsResourcePoa() 175 { 176 return otsResourcePoa; 177 } 178 179 181 protected void startService() 182 throws Exception 183 { 184 185 Properties props = new Properties (); 186 187 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 189 InputStream is = cl.getResourceAsStream(orbPropertiesFileName); 190 props.load(is); 191 String oaiAddr = props.getProperty("OAIAddr"); 192 if (oaiAddr == null) 193 oaiAddr = ServerConfigUtil.getSpecificBindAddress(); 194 if (oaiAddr != null) 195 props.setProperty("OAIAddr", oaiAddr); 196 log.debug("Using OAIAddr=" + oaiAddr); 197 198 Properties systemProps = System.getProperties(); 200 if (orbClass != null) { 201 props.put("org.omg.CORBA.ORBClass", orbClass); 202 systemProps.put("org.omg.CORBA.ORBClass", orbClass); 203 } 204 if (orbSingletonClass != null) { 205 props.put("org.omg.CORBA.ORBSingletonClass", orbSingletonClass); 206 systemProps.put("org.omg.CORBA.ORBSingletonClass", orbSingletonClass); 207 } 208 if (orbSingletonDelegate != null) 209 systemProps.put(org.jboss.system.ORBSingleton.DELEGATE_CLASS_KEY, 210 orbSingletonDelegate); 211 212 String str = props.getProperty("jacorb.config.log.verbosity"); 219 if (str != null) 220 systemProps.put("jacorb.config.log.verbosity", str); 221 222 if (sunJDK14IsLocalBugFix) 224 { 225 229 try 230 { 231 Class SunJDK14IsLocalBugFix = cl.loadClass("org.jboss.iiop.SunJDK14IsLocalBugFix"); 232 log.debug("Was able to load SunJDK14IsLocalBugFix, class="+SunJDK14IsLocalBugFix); 233 systemProps.put("javax.rmi.CORBA.UtilClass", "org.jboss.iiop.SunJDK14IsLocalBugFix"); 235 } 236 catch(Throwable t) 237 { 238 log.debug("Ignoring sunJDK14IsLocalBugFix=true due to inability to load org.jboss.iiop.SunJDK14IsLocalBugFix", t); 239 } 240 } 241 242 System.setProperties(systemProps); 243 244 Iterator initializerElements = 246 MetaData.getChildrenByTagName(portableInterceptorInitializers, 247 "initializer"); 248 if (initializerElements != null) 249 { 250 while (initializerElements.hasNext()) 251 { 252 Element initializerElement = (Element ) initializerElements.next(); 253 String portableInterceptorInitializerClassName = 254 MetaData.getElementContent(initializerElement); 255 log.debug("Adding portable interceptor initializer: " + 256 portableInterceptorInitializerClassName); 257 if (portableInterceptorInitializerClassName != null 258 && !portableInterceptorInitializerClassName.equals("")) 259 props.put("org.omg.PortableInterceptor.ORBInitializerClass." 260 + portableInterceptorInitializerClassName, ""); 261 } 262 } 263 264 if (port != 0) 267 props.put("OAPort", Integer.toString(this.port)); 268 if (sslPort != 0) 269 props.put("OASSLPort", Integer.toString(this.sslPort)); 270 271 String oaSslPortString = props.getProperty("OASSLPort"); 274 if (oaSslPortString != null) 275 oaSslPort = Integer.parseInt(oaSslPortString); 276 277 if (sslDomain != null) 279 { 280 InitialContext ctx = new InitialContext (); 281 log.debug("sslDomain: " + sslDomain); 282 try 283 { 284 SecurityDomain domain = (SecurityDomain) ctx.lookup(sslDomain); 285 286 Registry.bind(SSL_DOMAIN, domain); 288 } 289 catch (Exception e) 290 { 291 log.warn("Security domain " + sslDomain + " not found"); 292 log.debug("Exception looking up " + sslDomain + ": ", e); 293 } 294 } 295 296 orb = ORB.init(new String [0], props); 298 bind(ORB_NAME, "org.omg.CORBA.ORB"); 299 CorbaORB.setInstance(orb); 300 ORBInitialContextFactory.setORB(orb); 301 302 poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 304 bind(POA_NAME, "org.omg.PortableServer.POA"); 305 306 324 Policy [] policies = { poa.create_lifespan_policy( 326 LifespanPolicyValue.PERSISTENT), 327 poa.create_id_assignment_policy( 328 IdAssignmentPolicyValue.USER_ID), 329 poa.create_servant_retention_policy( 330 ServantRetentionPolicyValue.NON_RETAIN), 331 poa.create_request_processing_policy( 332 RequestProcessingPolicyValue.USE_DEFAULT_SERVANT), 333 poa.create_id_uniqueness_policy( 334 IdUniquenessPolicyValue.MULTIPLE_ID), 335 }; 336 337 otsPoa = poa.create_POA("OTS", null, policies); 339 340 otsResourcePoa = 345 poa.create_POA("OTSResources", otsPoa.the_POAManager(), policies); 346 347 poa.the_POAManager().activate(); 349 350 new Thread ( 352 new Runnable () { 353 public void run() { 354 orb.run(); 355 } 356 }, "ORB thread" 357 ).start(); 358 359 try { 361 LifespanPolicy lifespanPolicy = 362 poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 363 IdAssignmentPolicy idAssignmentPolicy = 364 poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); 365 366 irPoa = poa.create_POA("IR", null, 367 new Policy []{lifespanPolicy, 368 idAssignmentPolicy}); 369 bind(IR_POA_NAME, "org.omg.PortableServer.POA"); 370 371 irPoa.the_POAManager().activate(); 373 374 } catch (Exception ex) { 375 getLog().error("Error in IR POA initialization", ex); 376 } 377 378 hd = new HandleDelegateImpl(); 380 } 381 382 protected void stopService() throws Exception 383 { 384 394 try { 395 unbind(ORB_NAME); 397 unbind(POA_NAME); 398 unbind(IR_POA_NAME); 399 400 orb.shutdown(false); 402 403 Registry.unbind(SSL_DOMAIN); 405 } catch (Exception e) { 406 log.error("Exception while stopping ORB service", e); 407 } 408 } 409 410 412 public ORB getORB() 413 { 414 return orb; 415 } 416 417 public HandleDelegate getHandleDelegate() 418 { 419 return hd; 420 } 421 422 public String getORBClass() 423 { 424 return orbClass; 425 } 426 427 public void setORBClass(String orbClass) 428 { 429 this.orbClass = orbClass; 430 } 431 432 public String getORBSingletonClass() 433 { 434 return orbSingletonClass; 435 } 436 437 public void setORBSingletonClass(String orbSingletonClass) 438 { 439 this.orbSingletonClass = orbSingletonClass; 440 } 441 442 public String getORBSingletonDelegate() 443 { 444 return orbSingletonDelegate; 445 } 446 447 public void setORBSingletonDelegate(String orbSingletonDelegate) 448 { 449 this.orbSingletonDelegate = orbSingletonDelegate; 450 } 451 452 public void setORBPropertiesFileName(String orbPropertiesFileName) 453 { 454 this.orbPropertiesFileName = orbPropertiesFileName; 455 } 456 457 public String getORBPropertiesFileName() 458 { 459 return orbPropertiesFileName; 460 } 461 462 public Element getPortableInterceptorInitializers() 463 { 464 return portableInterceptorInitializers; 465 } 466 467 public void setPortableInterceptorInitializers( 468 Element portableInterceptorInitializers) 469 { 470 this.portableInterceptorInitializers = portableInterceptorInitializers; 471 } 472 473 public void setPort(int port) 474 { 475 this.port = port; 476 } 477 478 public int getPort() 479 { 480 return this.port; 481 } 482 483 public void setSSLPort(int sslPort) 484 { 485 this.sslPort = sslPort; 486 } 487 488 public int getSSLPort() 489 { 490 return this.sslPort; 491 } 492 493 public void setSecurityDomain(String sslDomain) 494 { 495 this.sslDomain = sslDomain; 496 } 497 498 public String getSecurityDomain() 499 { 500 return this.sslDomain; 501 } 502 503 public boolean getSSLComponentsEnabled() 504 { 505 return CorbaORBService.sslComponentsEnabledFlag; 506 } 507 508 public void setSSLComponentsEnabled(boolean sslComponentsEnabled) 509 { 510 CorbaORBService.sslComponentsEnabledFlag = sslComponentsEnabled; 511 } 512 513 public boolean getSendSASAcceptWithExceptionEnabled() 514 { 515 return CorbaORBService.sendSasAcceptWithExceptionEnabledFlag; 516 } 517 518 public void setSendSASAcceptWithExceptionEnabled(boolean value) 519 { 520 CorbaORBService.sendSasAcceptWithExceptionEnabledFlag = value; 521 } 522 523 public boolean getOTSContextPropagationEnabled() 524 { 525 return CorbaORBService.otsContextPropagationEnabledFlag; 526 } 527 528 public void setOTSContextPropagationEnabled(boolean value) 529 { 530 CorbaORBService.otsContextPropagationEnabledFlag = value; 531 } 532 533 public boolean getSunJDK14IsLocalBugFix() 534 { 535 return sunJDK14IsLocalBugFix; 536 } 537 538 public void setSunJDK14IsLocalBugFix(boolean sunJDK14IsLocalBugFix) 539 { 540 this.sunJDK14IsLocalBugFix = sunJDK14IsLocalBugFix; 541 } 542 543 545 public Object getObjectInstance(Object obj, Name name, 546 Context nameCtx, Hashtable environment) 547 throws Exception 548 { 549 String s = name.toString(); 550 if (getLog().isTraceEnabled()) 551 getLog().trace("getObjectInstance: obj.getClass().getName=\"" + 552 obj.getClass().getName() + 553 "\n name=" + s); 554 if (ORB_NAME.equals(s)) 555 return orb; 556 if (POA_NAME.equals(s)) 557 return poa; 558 if (IR_POA_NAME.equals(s)) 559 return irPoa; 560 return null; 561 } 562 563 564 566 private void bind(String name, String className) 567 throws Exception 568 { 569 Reference ref = new Reference (className, getClass().getName(), null); 570 new InitialContext ().bind("java:/"+name, ref); 571 } 572 573 private void unbind(String name) 574 throws Exception 575 { 576 new InitialContext ().unbind("java:/"+name); 577 } 578 579 } 580 581 | Popular Tags |