KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > ORBManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.util;
24
25 import org.omg.CORBA.ORB JavaDoc;
26
27 import java.util.*;
28 import java.io.*;
29
30 //import javax.rmi.CORBA.Tie;
31
import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import javax.naming.InitialContext JavaDoc;
34 import javax.naming.Context JavaDoc;
35
36 import com.sun.corba.ee.impl.orbutil.ORBConstants;
37 import com.sun.corba.ee.spi.oa.rfm.ReferenceFactoryManager;
38
39 import com.sun.enterprise.log.Log;
40
41 import com.sun.enterprise.server.ApplicationServer;
42 import com.sun.enterprise.server.ServerContext;
43
44 import com.sun.enterprise.config.ConfigContext;
45 import com.sun.enterprise.config.ConfigException;
46 import com.sun.enterprise.config.ConfigBean;
47 import com.sun.enterprise.config.serverbeans.ElementProperty;
48 import com.sun.enterprise.config.serverbeans.Server;
49 import com.sun.enterprise.config.serverbeans.IiopService;
50 import com.sun.enterprise.config.serverbeans.IiopListener;
51 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
52 import com.sun.enterprise.config.serverbeans.Orb;
53 import com.sun.enterprise.admin.monitor.GenericMonitorMBean;
54 import com.sun.enterprise.admin.monitor.MonitoredObjectType;
55 import com.sun.enterprise.admin.monitor.MonitoringHelper;
56 import com.sun.enterprise.iiop.ASORBUtilities;
57 import com.sun.enterprise.iiop.CSIv2SSLTaggedComponentHandlerImpl;
58 import com.sun.enterprise.iiop.FailoverIORInterceptor;
59 import com.sun.enterprise.iiop.IIOPPrimaryToContactInfoImpl;
60 import com.sun.enterprise.iiop.ORBMonitoring;
61 import com.sun.enterprise.iiop.PEORBConfigurator;
62
63 import javax.management.InstanceAlreadyExistsException JavaDoc;
64 import javax.management.MBeanRegistrationException JavaDoc;
65 import com.sun.enterprise.Switch;
66 import com.sun.enterprise.config.serverbeans.Ssl;
67 import com.sun.enterprise.config.serverbeans.SslClientConfig;
68 import java.util.logging.*;
69 import com.sun.logging.*;
70
71 /**
72  * This class initializes the ORB with a list of (standard) properties
73  * and provides a few convenience methods to get the ORB etc.
74  *
75  */

76
77 public final class ORBManager {
78     static Logger logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER);
79     private static final boolean debug = com.sun.enterprise.util.logging.Debug.enabled;
80
81     // Various pluggable classes defined in the app server that are used
82
// by the ORB.
83
private static final String JavaDoc ORB_CLASS =
84     "com.sun.corba.ee.impl.orb.ORBImpl";
85     private static final String JavaDoc ORB_SINGLETON_CLASS =
86     "com.sun.corba.ee.impl.orb.ORBSingleton";
87
88     private static final String JavaDoc ORB_SE_CLASS =
89     "com.sun.corba.se.impl.orb.ORBImpl";
90     private static final String JavaDoc ORB_SE_SINGLETON_CLASS =
91     "com.sun.corba.se.impl.orb.ORBSingleton";
92
93     private static final String JavaDoc PEORB_CONFIG_CLASS =
94     "com.sun.enterprise.iiop.PEORBConfigurator";
95     private static final String JavaDoc IIOP_SSL_SOCKET_FACTORY_CLASS =
96     "com.sun.enterprise.iiop.IIOPSSLSocketFactory";
97     private static final String JavaDoc RMI_UTIL_CLASS =
98     "com.sun.corba.ee.impl.javax.rmi.CORBA.Util";
99     private static final String JavaDoc RMI_STUB_CLASS =
100     "com.sun.corba.ee.impl.javax.rmi.CORBA.StubDelegateImpl";
101     private static final String JavaDoc RMI_PRO_CLASS =
102     "com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject";
103
104     // JNDI constants
105
public static final String JavaDoc JNDI_PROVIDER_URL_PROPERTY =
106     "java.naming.provider.url";
107     public static final String JavaDoc JNDI_CORBA_ORB_PROPERTY =
108     "java.naming.corba.orb";
109
110     // RMI-IIOP delegate constants
111
public static final String JavaDoc ORB_UTIL_CLASS_PROPERTY =
112     "javax.rmi.CORBA.UtilClass";
113     public static final String JavaDoc RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY =
114     "javax.rmi.CORBA.StubClass";
115     public static final String JavaDoc RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY =
116     "javax.rmi.CORBA.PortableRemoteObjectClass";
117     
118     // ORB constants: OMG standard
119
public static final String JavaDoc OMG_ORB_CLASS_PROPERTY =
120     "org.omg.CORBA.ORBClass";
121     public static final String JavaDoc OMG_ORB_SINGLETON_CLASS_PROPERTY =
122     "org.omg.CORBA.ORBSingletonClass";
123     public static final String JavaDoc OMG_ORB_INIT_HOST_PROPERTY =
124     ORBConstants.INITIAL_HOST_PROPERTY ;
125     public static final String JavaDoc OMG_ORB_INIT_PORT_PROPERTY =
126     ORBConstants.INITIAL_PORT_PROPERTY ;
127     private static final String JavaDoc PI_ORB_INITIALIZER_CLASS_PREFIX =
128     ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX ;
129
130     // ORB constants: Sun specific
131
public static final String JavaDoc SUN_USER_CONFIGURATOR_PREFIX =
132     ORBConstants.USER_CONFIGURATOR_PREFIX ;
133     public static final String JavaDoc SUN_ORB_ID_PROPERTY =
134     ORBConstants.ORB_ID_PROPERTY ;
135     public static final String JavaDoc SUN_ORB_SERVER_HOST_PROPERTY =
136     ORBConstants.SERVER_HOST_PROPERTY ;
137     public static final String JavaDoc SUN_ORB_SERVER_PORT_PROPERTY =
138     ORBConstants.SERVER_PORT_PROPERTY ;
139     public static final String JavaDoc SUN_ORB_SOCKET_FACTORY_CLASS_PROPERTY =
140     ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY ;
141     public static final String JavaDoc SUN_ORB_IOR_TO_SOCKETINFO_CLASS_PROPERTY =
142     ORBConstants.IOR_TO_SOCKET_INFO_CLASS_PROPERTY ;
143     public static final String JavaDoc SUN_MAX_CONNECTIONS_PROPERTY =
144     ORBConstants.HIGH_WATER_MARK_PROPERTY;
145     public static final String JavaDoc ORB_LISTEN_SOCKET_PROPERTY =
146     ORBConstants.LISTEN_SOCKET_PROPERTY ;
147     //
148
// XXX The following constants do not appear to be used in the ORB
149
public static final String JavaDoc ORB_DISABLED_PORTS_PROPERTY =
150     "com.sun.CORBA.connection.ORBDisabledListenPorts";
151     private static final String JavaDoc SUN_LISTEN_ADDR_ANY_ADDRESS =
152     "com.sun.CORBA.orb.AddrAnyAddress";
153     private static final String JavaDoc ORB_IOR_ADDR_ANY_INITIALIZER =
154     "com.sun.enterprise.iiop.IORAddrAnyInitializer";
155
156     // ORB configuration constants
157
private static final String JavaDoc DEFAULT_SERVER_ID = "100" ;
158     private static final String JavaDoc DEFAULT_MAX_CONNECTIONS = "1024";
159     private static final String JavaDoc J2EE_INITIALIZER =
160     "com.sun.enterprise.iiop.J2EEInitializer";
161     private static final String JavaDoc SUN_GIOP_DEFAULT_FRAGMENT_SIZE = "1024";
162     private static final String JavaDoc SUN_GIOP_DEFAULT_BUFFER_SIZE = "1024";
163
164     private static final String JavaDoc IIOP_CLEAR_TEXT_CONNECTION =
165             "IIOP_CLEAR_TEXT";
166     private static final String JavaDoc DEFAULT_ORB_INIT_HOST = "localhost";
167
168     // This will only apply for stand-alone java clients, since
169
// in the server the orb port comes from domain.xml, and in an appclient
170
// the port is set from the sun-acc.xml. It's set to the same
171
// value as the default orb port in domain.xml as a convenience.
172
// That way the code only needs to do a "new InitialContext()"
173
// without setting any jvm properties and the naming service will be
174
// found. Of course, if the port was changed in domain.xml for some
175
// reason the code will still have to set org.omg.CORBA.ORBInitialPort.
176
private static final String JavaDoc DEFAULT_ORB_INIT_PORT = "3700";
177
178     // CSIv2 config
179
private static final String JavaDoc SSL = "SSL";
180     private static final String JavaDoc SSL_MUTUALAUTH = "SSL_MUTUALAUTH";
181     private static final String JavaDoc ORB_SSL_CERTDB_PATH =
182             "com.sun.CSIV2.ssl.CertDB";
183     private static final String JavaDoc ORB_SSL_CERTDB_PASSWORD =
184             "com.sun.CSIV2.ssl.CertDBPassword";
185     public static final String JavaDoc SUN_GIOP_FRAGMENT_SIZE_PROPERTY =
186             "com.sun.CORBA.giop.ORBFragmentSize";
187     public static final String JavaDoc SUN_GIOP_BUFFER_SIZE_PROPERTY =
188             "com.sun.CORBA.giop.ORBBufferSize";
189     
190     // This property is true (in appclient Main)
191
// if SSL is required to be used by clients.
192
public static final String JavaDoc ORB_SSL_CLIENT_REQUIRED =
193     "com.sun.CSIV2.ssl.client.required";
194     //
195
// This property is true if SSL is required to be used by
196
// non-EJB CORBA objects in the server.
197
public static final String JavaDoc ORB_SSL_SERVER_REQUIRED =
198     "com.sun.CSIV2.ssl.server.required";
199     //
200
// This property is true if client authentication is required by
201
// non-EJB CORBA objects in the server.
202
public static final String JavaDoc ORB_CLIENT_AUTH_REQUIRED =
203     "com.sun.CSIV2.client.auth.required";
204     
205     // We need this to get the ORB monitoring set up correctly
206
public static final String JavaDoc S1AS_ORB_ID = "S1AS-ORB";
207
208     private static boolean propertiesInitialized = false;
209     
210     // the ORB instance shared throughout the app server
211
private static org.omg.CORBA.ORB JavaDoc orb = null;
212
213     // The ReferenceFactoryManager from the orb.
214
private static ReferenceFactoryManager rfm = null;
215
216     private static int orbInitialPort = -1;
217
218     private static IiopListener[] iiopListenerBeans = null;
219     private static Orb orbBean = null;
220     private static IiopService iiopServiceBean = null;
221
222     private static Properties csiv2Props = new Properties();
223
224     private static final Properties EMPTY_PROPERTIES = new Properties() ;
225
226    /**
227     * don't want any subclassing of this class
228     */

229     private ORBManager () {}
230
231     /** Returns whether an adapterName (from ServerRequestInfo.adapter_name)
232      * represents an EJB or not.
233      */

234     public static boolean isEjbAdapterName( String JavaDoc[] adapterName ) {
235     // If the rfm does not exist, the ORB has not been created yet,
236
// and so there are no EJBs with remote interfaces defined.
237
boolean result = false ;
238     if (rfm != null)
239         result = rfm.find( adapterName ) != null ;
240
241     return result ;
242     }
243
244     /** Returns whether the operationName corresponds to an "is_a" call
245      * or not (used to implement PortableRemoteObject.narrow.
246      */

247     public static boolean isIsACall( String JavaDoc operationName ) {
248     return operationName.equals( "_is_a" ) ;
249     }
250
251     /** Return the shared ORB instance for the app server.
252      * If the ORB is not already initialized, it is created
253      * with the standard server properties, which can be
254      * overridden by Properties passed in the props argument.
255      */

256     public static synchronized org.omg.CORBA.ORB JavaDoc getORB( Properties props ) {
257     try {
258         if(logger.isLoggable(Level.FINEST)) {
259         logger.log(Level.FINEST, "ORBManager.getORB->: " + orb);
260         }
261
262         initProperties() ;
263         if (orb == null)
264             initORB( props ) ;
265
266         return orb;
267     } finally {
268         if(logger.isLoggable(Level.FINEST)) {
269         logger.log(Level.FINEST, "ORBManager.getORB<-: " + orb);
270         }
271     }
272     }
273
274     public static org.omg.CORBA.ORB JavaDoc getORB() {
275     return getORB( EMPTY_PROPERTIES ) ;
276     }
277
278     public static synchronized Properties getCSIv2Props() {
279     initProperties() ;
280
281     return csiv2Props;
282     }
283
284     public static synchronized int getORBInitialPort() {
285     initProperties() ;
286
287     return orbInitialPort;
288     }
289
290     private static void initProperties() {
291     try {
292         if (logger.isLoggable(Level.FINE)) {
293         logger.log(Level.FINE, "ORBManager.initProperties->: " + orb);
294         }
295
296         if (propertiesInitialized)
297         return ;
298
299         try {
300         ServerContext serverContext = ApplicationServer.getServerContext();
301         if (serverContext == null) {
302             // serverContext is null inside the ACC.
303
String JavaDoc initialPort = checkORBInitialPort( EMPTY_PROPERTIES ) ;
304
305             return ;
306         } else {
307             ConfigContext configContext = serverContext.getConfigContext();
308             assert(configContext != null);
309
310             Server serverBean = ServerBeansFactory.getServerBean(configContext);
311             assert(serverBean != null);
312
313             iiopServiceBean = ServerBeansFactory.getIiopServiceBean(configContext);
314
315             assert(iiopServiceBean != null);
316
317             iiopListenerBeans = iiopServiceBean.getIiopListener();
318             assert (iiopListenerBeans != null && iiopListenerBeans.length > 0);
319
320             // checkORBInitialPort looks at iiopListenerBeans, if present
321
String JavaDoc initialPort = checkORBInitialPort( EMPTY_PROPERTIES ) ;
322
323             orbBean = iiopServiceBean.getOrb();
324             assert (orbBean != null);
325
326             // Initialize IOR security config for non-EJB CORBA objects
327
//iiopServiceBean.isClientAuthenticationRequired()));
328
csiv2Props.put(ORB_CLIENT_AUTH_REQUIRED, String.valueOf(
329             iiopServiceBean.isClientAuthenticationRequired()));
330             boolean corbaSSLRequired = true;
331             // If there is at least one non-SSL listener, then it means
332
// SSL is not required for CORBA objects.
333
for ( int i=0; i<iiopListenerBeans.length; i++ ) {
334             if ( iiopListenerBeans[i].getSsl() == null ) {
335                 corbaSSLRequired = false;
336                 break;
337             }
338             }
339
340             csiv2Props.put(ORB_SSL_SERVER_REQUIRED, String.valueOf(
341             corbaSSLRequired));
342         }
343         } catch (ConfigException cfe) {
344         logger.log(Level.SEVERE,"enterprise_util.orbmgr_config_excep", cfe);
345         } catch (NullPointerException JavaDoc npe) {
346         // REVISIT: Ignoring the NPE because the appclient container shares this code
347
logger.log(Level.FINE,"Server Context is NULL. Ignoring and proceeding.");
348         }
349     } finally {
350         // Whether this succeeds or not, only do initProperties once.
351
propertiesInitialized = true ;
352         if(logger.isLoggable(Level.FINE)) {
353         logger.log(Level.FINE, "ORBManager.initProperties<-: " + orb);
354         }
355     }
356     }
357
358     /** Set ORB-related system properties that are required in case
359      * user code in the app server or app client container creates a
360      * new ORB instance. The default result of calling
361      * ORB.init( String[], Properties ) must be a fully usuable, consistent
362      * ORB. This avoids difficulties with having the ORB class set
363      * to a different ORB than the RMI-IIOP delegates.
364      */

365     public static void setORBSystemProperties() {
366
367     java.security.AccessController.doPrivileged(
368         new java.security.PrivilegedAction JavaDoc() {
369         public java.lang.Object JavaDoc run() {
370             if (System.getProperty(OMG_ORB_CLASS_PROPERTY) == null) {
371             System.setProperty( OMG_ORB_CLASS_PROPERTY, ORB_SE_CLASS ) ;
372             }
373
374             if (System.getProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY) == null) {
375             System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY,
376                 ORB_SE_SINGLETON_CLASS);
377             }
378
379             System.setProperty(ORB_UTIL_CLASS_PROPERTY,
380                        RMI_UTIL_CLASS ) ;
381             
382             System.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY,
383                        RMI_STUB_CLASS ) ;
384             
385             System.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY,
386                        RMI_PRO_CLASS ) ;
387
388             return null;
389         }
390         }
391     );
392     }
393
394     /** Set the ORB properties for IIOP failover and load balancing.
395      */

396     private static void setFOLBProperties( Properties orbInitProperties ) {
397
398     orbInitProperties.put(ORBConstants.RFM_PROPERTY,"dummy");
399     orbInitProperties.put(SUN_ORB_SOCKET_FACTORY_CLASS_PROPERTY,
400         IIOP_SSL_SOCKET_FACTORY_CLASS ) ;
401
402     // ClientGroupManager.
403
// Registers itself as
404
// ORBInitializer (that registers ClientRequestInterceptor)
405
// IIOPPrimaryToContactInfo
406
// IORToSocketInfo
407
orbInitProperties.setProperty(
408         ORBConstants.USER_CONFIGURATOR_PREFIX
409         + com.sun.corba.ee.impl.folb.ClientGroupManager.class.getName(),
410         "dummy");
411     
412     // This configurator registers the CSIv2SSLTaggedComponentHandler
413
orbInitProperties.setProperty(
414         ORBConstants.USER_CONFIGURATOR_PREFIX
415         + CSIv2SSLTaggedComponentHandlerImpl.class.getName(),
416         "dummy");
417
418     if (ASORBUtilities.isGMSAvailableAndClusterHeartbeatEnabled()) {
419         if(logger.isLoggable(Level.FINE)) {
420         logger.log(Level.FINE, "GMS available and enabled - doing EE initialization");
421         }
422         
423         // Register ServerGroupManager.
424
// Causes it to register itself as an ORBInitializer
425
// that then registers it as
426
// IOR and ServerRequest Interceptors.
427
orbInitProperties.setProperty(
428         ORBConstants.USER_CONFIGURATOR_PREFIX
429         + com.sun.corba.ee.impl.folb.ServerGroupManager.class.getName(),
430         "dummy");
431
432         if(logger.isLoggable(Level.FINE)) {
433         logger.log(Level.FINE, "Did EE property initialization");
434         }
435     } else {
436         if(logger.isLoggable(Level.FINE)) {
437         logger.log(Level.FINE, "Doing PE initialization");
438         }
439
440         orbInitProperties.put(ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX
441         + FailoverIORInterceptor.class.getName(), "dummy");
442
443         if(logger.isLoggable(Level.FINE)) {
444         logger.log(Level.FINE, "Did PE property initialization");
445         }
446     }
447     }
448     
449     private static void initORB(Properties props) {
450     try {
451         if(logger.isLoggable(Level.FINE)) {
452         logger.log(Level.FINE, ".initORB->: " );
453         }
454
455         //setORBSystemProperties() ;
456

457         Properties orbInitProperties = new Properties();
458         orbInitProperties.putAll(props);
459
460         // The main configurator.
461
orbInitProperties.put(SUN_USER_CONFIGURATOR_PREFIX
462         + PEORB_CONFIG_CLASS, "dummy" );
463
464         setFOLBProperties( orbInitProperties ) ;
465
466         // Standard OMG Properties.
467
orbInitProperties.put(ORBConstants.ORB_SERVER_ID_PROPERTY,
468         DEFAULT_SERVER_ID ) ;
469         orbInitProperties.put( OMG_ORB_CLASS_PROPERTY, ORB_CLASS);
470         orbInitProperties.put(
471         PI_ORB_INITIALIZER_CLASS_PREFIX + J2EE_INITIALIZER, "");
472
473         orbInitProperties.put(ORBConstants.ALLOW_LOCAL_OPTIMIZATION,
474         "true" ) ;
475
476         orbInitProperties.put(SUN_ORB_ID_PROPERTY, S1AS_ORB_ID);
477             orbInitProperties.put(ORBConstants.SHOW_INFO_MESSAGES, "true");
478
479         // Do this even if propertiesInitialized, since props may override
480
// ORBInitialHost and port.
481
String JavaDoc initialPort = checkORBInitialPort(orbInitProperties);
482
483         String JavaDoc orbInitialHost = checkORBInitialHost(orbInitProperties);
484         
485         // Add -ORBInitRef for INS to work
486
String JavaDoc[] args = getORBInitRef(orbInitialHost, initialPort);
487
488             checkAdditionalORBListeners(orbInitProperties);
489             checkConnectionSettings(orbInitProperties);
490             checkMessageFragmentSize(orbInitProperties);
491         checkServerSSLOutboundSettings(orbInitProperties);
492         checkForOrbPropertyValues(orbInitProperties);
493         
494         // The following is done only on the Server Side to set the
495
// ThreadPoolManager in the ORB. ThreadPoolManager on the server
496
// is initialized based on configuration parameters found in
497
// domain.xml. On the client side this is not done
498
if (Switch.getSwitch().getContainerType() == Switch.EJBWEB_CONTAINER) {
499         PEORBConfigurator.setThreadPoolManager();
500         }
501
502         // orb MUST be set before calling getFVDCodeBaseIOR, or we can
503
// recurse back into initORB due to interceptors that run
504
// when the TOA supporting the FVD is created!
505
// DO NOT MODIFY initORB to return ORB!!!
506
orb = ORB.init(args, orbInitProperties);
507
508         rfm = (ReferenceFactoryManager)orb.resolve_initial_references(
509         ORBConstants.REFERENCE_FACTORY_MANAGER ) ;
510
511         ASORBUtilities.initGIS(orb);
512
513         // SeeBeyond fix for 6325988: needs testing.
514
// Still do not know why this might make any difference.
515
// Invoke this for its side-effects: ignore returned IOR.
516
((com.sun.corba.ee.spi.orb.ORB)orb).getFVDCodeBaseIOR() ;
517        
518     } catch ( Exception JavaDoc ex ) {
519             logger.log(Level.SEVERE,"enterprise_util.excep_in_createorb",ex);
520         throw new RuntimeException JavaDoc( ex ) ;
521     } finally {
522         if(logger.isLoggable(Level.FINE)) {
523         logger.log(Level.FINE, ".initORB<-: " );
524         }
525     }
526     }
527     
528     private static String JavaDoc checkForAddrAny(Properties props, String JavaDoc orbInitialHost) {
529         if ((orbInitialHost.equals("0.0.0.0")) || (orbInitialHost.equals("::"))
530             || (orbInitialHost.equals("::ffff:0.0.0.0"))) {
531         /* FIXME -DHIRU
532             props.setProperty(SUN_LISTEN_ADDR_ANY_ADDRESS, orbInitialHost);
533             props.put(PI_ORB_INITIALIZER_CLASS_PREFIX + ORB_IOR_ADDR_ANY_INITIALIZER, "");
534         */

535             try {
536                 String JavaDoc localAddress = java.net.InetAddress.getLocalHost().getHostAddress();
537                 return localAddress;
538             } catch (java.net.UnknownHostException JavaDoc uhe) {
539                 logger.log(Level.WARNING,"Unknown host exception - Setting host to localhost");
540                 return DEFAULT_ORB_INIT_HOST;
541             }
542         } else {
543         // Set com.sun.CORBA.ORBServerHost only if it's not one of "0.0.0.0",
544
// "::" or "::ffff:0.0.0.0"
545
props.setProperty(SUN_ORB_SERVER_HOST_PROPERTY, orbInitialHost);
546             return orbInitialHost;
547         }
548     }
549
550     private static String JavaDoc checkORBInitialHost(Properties props) {
551     // Host setting in system properties always takes precedence.
552
String JavaDoc orbInitialHost = System.getProperty(OMG_ORB_INIT_HOST_PROPERTY);
553     if ( orbInitialHost == null )
554         orbInitialHost = props.getProperty(OMG_ORB_INIT_HOST_PROPERTY);
555     if ( orbInitialHost == null ) {
556             try {
557                 orbInitialHost = iiopListenerBeans[0].getAddress();
558                 orbInitialHost = checkForAddrAny(props, orbInitialHost);
559             } catch (NullPointerException JavaDoc npe) {
560                 // REVISIT: Ignoring the NPE because the appclient container shares this code
561
logger.log(Level.FINE,"IIOP listener element is null. Ignoring and proceeding.");
562             }
563     }
564     if( orbInitialHost == null )
565         orbInitialHost = DEFAULT_ORB_INIT_HOST;
566
567     props.setProperty(OMG_ORB_INIT_HOST_PROPERTY, orbInitialHost);
568
569     if ( debug ) {
570             if (logger.isLoggable(Level.FINE))
571                 logger.log(Level.FINE,"Setting orb initial host to " + orbInitialHost);
572         }
573         return orbInitialHost;
574     }
575
576     private static String JavaDoc checkORBInitialPort(Properties props) {
577     // Port setting in system properties always takes precedence.
578
String JavaDoc initialPort = System.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
579     if ( initialPort == null )
580         initialPort = props.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
581
582     if ( initialPort == null ) {
583             try {
584                 initialPort = iiopListenerBeans[0].getPort();
585                 if (!iiopListenerBeans[0].isEnabled()) {
586                     props.setProperty(ORB_DISABLED_PORTS_PROPERTY, initialPort);
587                 }
588                 // Set the default server port to equal the initial port.
589
// This will be the port that is used both for object refs and
590
// for the name service
591
// REVISIT: For now setting this value only if we have a valid
592
// server configuration. This is meant to circumvent a client-side
593
// problem. The ACC uses the same ORBManager and hence ends up
594
// creating a listener (yuk!) during root POA initialization (yuk!).
595
// It is best to let this listener not come up on any fixed port.
596
// Once this problem is fixed we can move this property setting
597
// outside.
598
if (!iiopListenerBeans[0].isEnabled()) {
599             // If the plain iiop listener is disabled do not create
600
// a listener on this port - bug 4927187
601
props.setProperty(SUN_ORB_SERVER_PORT_PROPERTY, "-1");
602         } else {
603             props.setProperty(SUN_ORB_SERVER_PORT_PROPERTY, initialPort);
604         }
605             } catch (NullPointerException JavaDoc npe) {
606                 logger.log(Level.FINE,"IIOP listener element is null. Ignoring and proceeding.");
607             }
608     }
609
610     if( initialPort == null )
611         initialPort = DEFAULT_ORB_INIT_PORT;
612
613     // Make sure we set initial port in System properties so that
614
// any instantiations of com.sun.jndi.cosnaming.CNCtxFactory
615
// use same port.
616
props.setProperty(OMG_ORB_INIT_PORT_PROPERTY, initialPort);
617
618     // Done to initialize the Persistent Server Port, before any
619
// POAs are created. This was earlier done in POAEJBORB
620
// Do it only in the appserver, not on appclient
621
if (Switch.getSwitch().getContainerType() == Switch.EJBWEB_CONTAINER) {
622             props.setProperty(ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
623                 initialPort);
624         }
625
626     if ( debug ) {
627             if (logger.isLoggable(Level.FINE))
628                 logger.log(Level.FINE,"Setting orb initial port to " + initialPort);
629         }
630
631     orbInitialPort = new Integer JavaDoc(initialPort).intValue();
632
633     return initialPort;
634     }
635
636     private static void checkAdditionalORBListeners(Properties props) {
637         // REVISIT: Having to do the null check because this code is shared by the ACC
638
if (iiopListenerBeans != null) {
639             // This should be the only place we set additional ORB listeners.
640
// So there is no need to check if the property is already set.
641
StringBuffer JavaDoc listenSockets = new StringBuffer JavaDoc("");
642             for (int i=0; i<iiopListenerBeans.length; i++) {
643         if ( i==0 && iiopListenerBeans[0].getSsl() == null ) {
644             // Ignore first listener if its non-SSL, because it
645
// gets created by default using ORBInitialHost/Port.
646
continue;
647         }
648         
649                 if (iiopListenerBeans[i].isEnabled()) {
650                     if (!iiopListenerBeans[i].isSecurityEnabled() ||
651             iiopListenerBeans[i].getSsl() == null) {
652
653                         checkForAddrAny(props, iiopListenerBeans[i].getAddress());
654                         listenSockets.append((listenSockets.length()>0 ? "," : "")
655                                 + IIOP_CLEAR_TEXT_CONNECTION
656                                 + ":" + iiopListenerBeans[i].getPort());
657                     } else {
658                         Ssl sslBean = null;
659                         sslBean = iiopListenerBeans[i].getSsl();
660                         assert sslBean != null;
661
662                         // parse clientAuth
663
String JavaDoc type;
664                         boolean clientAuth = sslBean.isClientAuthEnabled();
665                         if (clientAuth)
666                             type = SSL_MUTUALAUTH;
667                         else
668                             type = SSL;
669             
670                         // Ignoring cert alias etc.
671
listenSockets.append((listenSockets.length()>0 ? ",":"")
672                             + type+":"+iiopListenerBeans[i].getPort());
673                     }
674                 }
675             }
676         
677             // Set the value both in the props object and in the system properties.
678
props.setProperty(ORB_LISTEN_SOCKET_PROPERTY, listenSockets.toString());
679         }
680
681         return;
682     }
683
684     private static void checkConnectionSettings(Properties props) {
685         if (orbBean != null) {
686             String JavaDoc maxConnections;
687             
688             try {
689                 maxConnections = orbBean.getMaxConnections();
690         
691                 // Validate number formats
692
Integer.parseInt(maxConnections);
693             } catch (NumberFormatException JavaDoc nfe) {
694                 if(logger.isLoggable(Level.WARNING)) {
695                    logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt", nfe);
696                 }
697
698                 maxConnections = DEFAULT_MAX_CONNECTIONS;
699             }
700
701             props.setProperty(SUN_MAX_CONNECTIONS_PROPERTY, maxConnections);
702         }
703         return;
704     }
705
706     private static void checkMessageFragmentSize(Properties props) {
707         if (orbBean != null) {
708             String JavaDoc fragmentSize, bufferSize;
709             try {
710                 int fsize = ((Integer.parseInt(orbBean.getMessageFragmentSize().trim()))/8) * 8;
711                 if (fsize < 32) {
712                     fragmentSize = "32";
713                     logger.log(Level.INFO,"Setting ORB Message Fragment size to " + fragmentSize);
714                 }
715                 else {
716                     fragmentSize = String.valueOf(fsize);
717                 }
718                 bufferSize = fragmentSize;
719             } catch (NumberFormatException JavaDoc nfe) {
720                 // Print stack trace and use default values
721
logger.log(Level.WARNING,"enterprise_util.excep_in_reading_fragment_size", nfe);
722                 logger.log(Level.INFO,"Setting ORB Message Fragment size to Default " +
723             SUN_GIOP_DEFAULT_FRAGMENT_SIZE);
724                 fragmentSize = SUN_GIOP_DEFAULT_FRAGMENT_SIZE;
725                 bufferSize = SUN_GIOP_DEFAULT_BUFFER_SIZE;
726             }
727             props.setProperty(SUN_GIOP_FRAGMENT_SIZE_PROPERTY, fragmentSize);
728             props.setProperty(SUN_GIOP_BUFFER_SIZE_PROPERTY, bufferSize);
729         }
730     }
731
732     private static void checkServerSSLOutboundSettings(Properties props) {
733         if (iiopServiceBean != null) {
734             SslClientConfig sslClientConfigBean = iiopServiceBean.getSslClientConfig();
735             if (sslClientConfigBean != null) {
736                 Ssl ssl = sslClientConfigBean.getSsl();
737                 assert(ssl != null);
738             }
739         }
740     }
741
742     private static void checkForOrbPropertyValues(Properties props) {
743         if (orbBean != null) {
744             ElementProperty[] ep = orbBean.getElementProperty() ;
745             if (ep != null) {
746                 for (int i = 0; i < ep.length; i++) {
747                     props.setProperty(ep[i].getName(), ep[i].getValue());
748                 }
749             }
750         }
751     }
752
753     private static String JavaDoc[] getORBInitRef(String JavaDoc orbInitialHost,
754                String JavaDoc initialPort)
755     {
756     // Add -ORBInitRef NameService=....
757
// This ensures that INS will be used to talk with the NameService.
758
String JavaDoc[] newArgs = new String JavaDoc[]{
759         "-ORBInitRef",
760         "NameService=corbaloc:iiop:1.2@"
761         + orbInitialHost + ":"
762         + initialPort + "/NameService"
763     } ;
764
765     return newArgs;
766     }
767 }
768
Popular Tags