1. /*
  2. * @(#)ORB.java 1.264 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.corba;
  16. // Import JDK stuff
  17. import java.net.*;
  18. import java.util.*;
  19. import java.applet.Applet;
  20. import java.lang.reflect.Constructor;
  21. import java.lang.reflect.Field ;
  22. import java.lang.reflect.Modifier ;
  23. import java.lang.ThreadLocal;
  24. import java.io.File ;
  25. import java.io.IOException ;
  26. import java.io.FileInputStream ;
  27. import java.io.FileNotFoundException ;
  28. // Import our stuff
  29. import org.omg.CORBA.COMM_FAILURE;
  30. import org.omg.CORBA.DATA_CONVERSION;
  31. import org.omg.CORBA.INITIALIZE;
  32. import org.omg.CORBA.NO_IMPLEMENT;
  33. import org.omg.CORBA.INTERNAL;
  34. import org.omg.CORBA.Context;
  35. import org.omg.CORBA.ContextList;
  36. import org.omg.CORBA.Environment;
  37. import org.omg.CORBA.ExceptionList;
  38. import org.omg.CORBA.ORBPackage.InvalidName;
  39. import org.omg.CORBA.NVList;
  40. import org.omg.CORBA.TCKind;
  41. import org.omg.CORBA.NamedValue;
  42. import org.omg.CORBA.Object;
  43. import org.omg.CORBA.Request;
  44. import org.omg.CORBA.OBJ_ADAPTER;
  45. import org.omg.CORBA.OBJECT_NOT_EXIST;
  46. import org.omg.CORBA.INV_OBJREF;
  47. import org.omg.CORBA.MARSHAL;
  48. import org.omg.CORBA.SystemException;
  49. import org.omg.CORBA.CompletionStatus;
  50. import org.omg.CORBA.TypeCode;
  51. import org.omg.CORBA.Any;
  52. import org.omg.CORBA.StructMember;
  53. import org.omg.CORBA.UnionMember;
  54. import org.omg.CORBA.ValueMember;
  55. import org.omg.CORBA.BAD_PARAM;
  56. import org.omg.CORBA.BAD_INV_ORDER;
  57. import org.omg.CORBA.portable.*;
  58. import org.omg.CORBA.portable.RemarshalException;
  59. import org.omg.CORBA.portable.ValueFactory;
  60. import org.omg.PortableServer.Servant;
  61. import com.sun.corba.se.connection.ORBSocketFactory;
  62. import com.sun.corba.se.internal.core.CodeSetComponentInfo;
  63. import com.sun.corba.se.internal.core.ClientSubcontract;
  64. import com.sun.corba.se.internal.core.ClientResponse;
  65. import com.sun.corba.se.internal.core.ClientRequest;
  66. import com.sun.corba.se.internal.iiop.Connection;
  67. import com.sun.corba.se.internal.ior.IIOPProfile;
  68. import com.sun.corba.se.internal.core.ServerSubcontract;
  69. import com.sun.corba.se.internal.core.ServiceContexts;
  70. import com.sun.corba.se.internal.core.SubcontractRegistry;
  71. import com.sun.corba.se.internal.core.ClientGIOP;
  72. import com.sun.corba.se.internal.core.ServerGIOP;
  73. import com.sun.corba.se.internal.core.ServerRequest;
  74. import com.sun.corba.se.internal.core.MarshalInputStream;
  75. import com.sun.corba.se.internal.core.MarshalOutputStream;
  76. import com.sun.corba.se.internal.core.InternalRuntimeForwardRequest;
  77. import com.sun.corba.se.internal.core.IOR;
  78. import com.sun.corba.se.internal.core.Future;
  79. import com.sun.corba.se.internal.core.Closure;
  80. import com.sun.corba.se.internal.core.Constant;
  81. import com.sun.corba.se.internal.core.GIOPVersion;
  82. import com.sun.corba.se.internal.core.ORBVersion;
  83. import com.sun.corba.se.internal.core.ORBVersionFactory;
  84. import com.sun.corba.se.internal.core.INSObjectKeyMap;
  85. import com.sun.corba.se.internal.core.INSObjectKeyEntry;
  86. import com.sun.corba.se.internal.core.StandardIIOPProfileTemplate;
  87. import com.sun.corba.se.internal.util.Utility;
  88. import com.sun.corba.se.internal.orbutil.ORBUtility;
  89. import com.sun.corba.se.internal.orbutil.ORBClassLoader;
  90. import com.sun.corba.se.internal.orbutil.ORBConstants;
  91. import com.sun.corba.se.internal.orbutil.ORBUtility;
  92. import com.sun.corba.se.internal.orbutil.MinorCodes;
  93. import com.sun.corba.se.internal.orbutil.SubcontractList;
  94. import com.sun.corba.se.internal.iiop.DefaultSocketFactory;
  95. import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
  96. import com.sun.corba.se.internal.iiop.messages.KeyAddr;
  97. import com.sun.corba.se.internal.iiop.messages.ProfileAddr;
  98. import com.sun.corba.se.internal.iiop.messages.ReferenceAddr;
  99. import com.sun.corba.se.internal.ior.IIOPProfileTemplate;
  100. import com.sun.corba.se.internal.ior.IIOPAddress ;
  101. import com.sun.corba.se.internal.ior.IIOPAddressImpl ;
  102. import com.sun.corba.se.internal.ior.ObjectKey ;
  103. import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
  104. import com.sun.corba.se.internal.ior.ObjectId;
  105. import com.sun.corba.se.internal.DynamicAny.DynAnyFactoryImpl;
  106. import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;
  107. import java.security.AccessController;
  108. import java.security.PrivilegedAction;
  109. import sun.security.action.GetPropertyAction;
  110. import javax.rmi.CORBA.Util;
  111. import javax.rmi.CORBA.ValueHandler;
  112. import com.sun.org.omg.SendingContext.CodeBase;
  113. import com.sun.org.omg.SendingContext.CodeBaseHelper;
  114. /**
  115. * The JavaIDL ORB implementation.
  116. */
  117. public abstract class ORB extends com.sun.corba.se.internal.core.ORB
  118. implements TypeCodeFactory
  119. {
  120. //d11638; pure java orb, caching the servant IOR per ORB
  121. private static IOR ior = null;
  122. protected void dprint( String msg )
  123. {
  124. ORBUtility.dprint( this, msg ) ;
  125. }
  126. // Flag set at compile time to debug flag processing: this can't
  127. // be one of the xxxDebugFlags because it is used to debug the mechanism
  128. // that sets the xxxDebugFlags!
  129. public static boolean ORBInitDebug = false;
  130. // Currently defined debug flags. Any additions must be called xxxDebugFlag.
  131. // All debug flags must be public boolean types.
  132. // These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
  133. // Note that x,y,z must not contain spaces.
  134. public boolean transportDebugFlag = false ;
  135. public boolean subcontractDebugFlag = false ;
  136. public boolean poaDebugFlag = false ;
  137. public boolean orbdDebugFlag = false ;
  138. public boolean namingDebugFlag = false ;
  139. public boolean serviceContextDebugFlag = false ;
  140. public boolean transientObjectManagerDebugFlag = false ;
  141. public boolean giopVersionDebugFlag = false;
  142. // public boolean iiopConnectionDebugFlag = false;
  143. public boolean shutdownDebugFlag = false;
  144. public boolean giopDebugFlag = false;
  145. private static final String[] JavaIDLPropertyNames = {
  146. ORBConstants.INITIAL_HOST_PROPERTY,
  147. ORBConstants.INITIAL_PORT_PROPERTY,
  148. ORBConstants.INITIAL_SERVICES_PROPERTY,
  149. ORBConstants.DEFAULT_INIT_REF_PROPERTY,
  150. ORBConstants.ORB_INIT_REF_PROPERTY,
  151. ORBConstants.SERVER_PORT_PROPERTY,
  152. ORBConstants.SERVER_HOST_PROPERTY,
  153. ORBConstants.ORB_ID_PROPERTY,
  154. ORBConstants.DEBUG_PROPERTY,
  155. ORBConstants.HIGH_WATER_MARK_PROPERTY,
  156. ORBConstants.LOW_WATER_MARK_PROPERTY,
  157. ORBConstants.NUMBER_TO_RECLAIM_PROPERTY,
  158. ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY,
  159. ORBConstants.LISTEN_SOCKET_PROPERTY,
  160. //Temporary way of installing a version of GIOP on an ORB.
  161. //Can be beautified later.
  162. ORBConstants.GIOP_VERSION,
  163. ORBConstants.GIOP_FRAGMENT_SIZE,
  164. ORBConstants.GIOP_BUFFER_SIZE,
  165. ORBConstants.GIOP_11_BUFFMGR,
  166. ORBConstants.GIOP_12_BUFFMGR,
  167. ORBConstants.GIOP_TARGET_ADDRESSING,
  168. ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY,
  169. ORBConstants.USE_BOMS,
  170. ORBConstants.USE_BOMS_IN_ENCAPS,
  171. ORBConstants.CHAR_CODESETS,
  172. ORBConstants.WCHAR_CODESETS,
  173. ORBConstants.ALLOW_LOCAL_OPTIMIZATION
  174. };
  175. private static final String[] JavaIDLPropertyNamePrefixes = {
  176. // Intentionally blank;
  177. };
  178. private static final String[] JavaIDLURLPropertyNames = {
  179. ORBConstants.INITIAL_SERVICES_PROPERTY
  180. };
  181. //
  182. // The following fields form our special little collection of global state.
  183. // We keep it bottled up here in the ORB class and attach a reference to
  184. // ourselves to every object reference that we create and handle.
  185. //
  186. // Vector holding deferred Requests
  187. private Vector _dynamicRequests;
  188. protected SynchVariable _svResponseReceived;
  189. // Applet/command-line parameters
  190. protected String ORBInitialHost = "";
  191. protected int ORBInitialPort;
  192. protected String ORBServerHost = "";
  193. protected int ORBServerPort = 0;
  194. protected String appletHost = "";
  195. protected URL appletCodeBase = null;
  196. protected ORBSocketFactory socketFactory;
  197. protected String orbId = "";
  198. public boolean allowLocalOptimization = false ;
  199. private Collection userSpecifiedListenPorts = new Vector();
  200. //Connection management parameters
  201. protected int highWaterMark = 240;
  202. protected int lowWaterMark = 100;
  203. protected int numberToReclaim = 5;
  204. // GIOP Related Constants
  205. // Default is 1.0. We will change it to 1.2 later.
  206. protected GIOPVersion giopVersion = GIOPVersion.DEFAULT_VERSION;
  207. protected int giopFragmentSize = ORBConstants.GIOP_DEFAULT_FRAGMENT_SIZE;
  208. protected int giopBufferSize = ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
  209. protected int giop11BuffMgr = ORBConstants.DEFAULT_GIOP_11_BUFFMGR;
  210. protected int giop12BuffMgr = ORBConstants.DEFAULT_GIOP_12_BUFFMGR;
  211. protected short giopTargetAddressPreference = ORBConstants.ADDR_DISP_HANDLE_ALL;
  212. protected short giopAddressDisposition = KeyAddr.value;
  213. // Synchronization variable for shutdown
  214. private java.lang.Object runObj = new java.lang.Object();
  215. private java.lang.Object shutdownObj = new java.lang.Object();
  216. private java.lang.Object waitForCompletionObj = new java.lang.Object();
  217. private java.lang.Object invocationObj = new java.lang.Object();
  218. private int numInvocations = 0;
  219. protected static final byte STATUS_OPERATING = 1;
  220. protected static final byte STATUS_SHUTTING_DOWN = 2;
  221. protected static final byte STATUS_SHUTDOWN = 3;
  222. protected static final byte STATUS_DESTROYED = 4;
  223. byte status = STATUS_OPERATING;
  224. // thread local variable to store a boolean to detect deadlock in ORB.shutdown(true).
  225. protected ThreadLocal isProcessingInvocation = new ThreadLocal () {
  226. protected java.lang.Object initialValue() {
  227. return Boolean.FALSE;
  228. }
  229. };
  230. // Code set related
  231. protected boolean useByteOrderMarkers = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS;
  232. protected boolean useByteOrderMarkersInEncaps
  233. = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS_IN_ENCAPS;
  234. // Preferred native and conversion code sets for use with connections. Can
  235. // override or change with appropriate properties.
  236. protected CodeSetComponentInfo codesets
  237. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS;
  238. protected boolean alwaysSendCodeSetCtx
  239. = ORBConstants.DEFAULT_ALWAYS_SEND_CODESET_CTX;
  240. InitialNamingClient initialNamingClient;
  241. DynAnyFactoryImpl dynAnyFactory = null;
  242. // This map is needed for resolving recursive type code placeholders
  243. // based on the unique repository id.
  244. private Map typeCodeMap = null;
  245. // This map is caching TypeCodes created for a certain class (key)
  246. // and is used in Util.writeAny()
  247. private Map typeCodeForClassMap = null;
  248. private String savedId = null;
  249. private TypeCodeImpl savedCode = null;
  250. // Cache to hold ValueFactories (Helper classes) keyed on repository ids
  251. protected Hashtable valueFactoryCache = new Hashtable();
  252. // thread local variable to store the current ORB version
  253. private ThreadLocal orbVersionThreadLocal ;
  254. // Table used for all locally registered services.
  255. // This is used for register/resolve/list initial methods.
  256. // This table maps Strings to Closures. The evaluate method
  257. // of the Closure must return a CORBA.Object.
  258. private HashMap initialReferenceTable ;
  259. /**
  260. * Create a new ORB. Should only be invoked from the
  261. * CORBA ORB superclass. Should be followed by the appropriate
  262. * set_parameters() call.
  263. */
  264. public ORB()
  265. {
  266. _dynamicRequests = new Vector();
  267. _svResponseReceived = new SynchVariable();
  268. initialNamingClient = new InitialNamingClient(this);
  269. initialReferenceTable = new HashMap() ;
  270. // default ORB version is the version of ORB with correct Rep-id
  271. // changes
  272. orbVersionThreadLocal = new ThreadLocal () {
  273. protected java.lang.Object initialValue() {
  274. // set default to version of the ORB with correct Rep-ids
  275. return ORBVersionFactory.getORBVersion() ;
  276. }
  277. };
  278. // Register the Dynamic Any factory
  279. Closure closure = new Closure() {
  280. public java.lang.Object evaluate() {
  281. return new DynAnyFactoryImpl( ORB.this ) ;
  282. }
  283. } ;
  284. Future future = new Future( closure ) ;
  285. registerInitialReference( ORBConstants.DYN_ANY_FACTORY_NAME, future ) ;
  286. }
  287. public InitialNamingClient getInitialNamingClient( ) {
  288. return initialNamingClient;
  289. }
  290. public ORBVersion getORBVersion()
  291. {
  292. // return the thread local data
  293. return (ORBVersion)(orbVersionThreadLocal.get()) ;
  294. }
  295. public void setORBVersion(ORBVersion verObj)
  296. {
  297. // set the thread local data
  298. orbVersionThreadLocal.set(verObj);
  299. }
  300. /**
  301. * Should the client send the code set service context on every
  302. * request?
  303. */
  304. public boolean alwaysSendCodeSetServiceContext() {
  305. return alwaysSendCodeSetCtx;
  306. }
  307. /**
  308. * Use byte order markers when applicable during character conversion?
  309. */
  310. public boolean useByteOrderMarkers() {
  311. return useByteOrderMarkers;
  312. }
  313. /**
  314. * Use byte order markers even in encapsulations?
  315. */
  316. public boolean useByteOrderMarkersInEncapsulations() {
  317. return useByteOrderMarkersInEncaps;
  318. }
  319. /**
  320. * Get the prefered code sets for connections.
  321. */
  322. public CodeSetComponentInfo getCodeSetComponentInfo() {
  323. return codesets;
  324. }
  325. /****************************************************************************
  326. * The following methods deal with parsing parameters and doing appropriate
  327. * initialization.
  328. ****************************************************************************/
  329. /**
  330. * Initialize any necessary ORB state; get attributes if possible.
  331. * Called from org.omg.CORBA.ORB.init().
  332. * @param app the applet
  333. * @param props the applet properties
  334. */
  335. protected void set_parameters(Applet app, Properties props)
  336. {
  337. // Note: In some applet-development frameworks
  338. // the applet object may not be directly available and so it's
  339. // possible for the Applet instance to be null.
  340. // Get the full list of property names that we are interested in
  341. String[] propertyNames = getPropertyNames();
  342. String[] propertyNamePrefixes = getPropertyNamePrefixes();
  343. if (app != null) {
  344. appletCodeBase = app.getCodeBase();
  345. if (appletCodeBase != null)
  346. appletHost = appletCodeBase.getHost( );
  347. }
  348. // Build up the full list of configuration properties
  349. // from the applet-params and props-argument.
  350. // Make Properties Vector to handle multiple -ORBInitDef s
  351. Properties propList = new Properties();
  352. // Until we decide it's ok for getSystemProperty() to
  353. // use AccessController.beginPrivileged(), I've commented
  354. // out the use of System properties for applets since
  355. // this will result in confusing SecurityExceptions in
  356. // most situations.
  357. //
  358. /*
  359. findORBPropertiesFromSystem(propList,
  360. propertyNames, propertyNamePrefixes);
  361. */
  362. findPropertiesFromProperties(propList, props,
  363. propertyNames, propertyNamePrefixes);
  364. findPropertiesFromApplet(propList, app,
  365. propertyNames, propertyNamePrefixes);
  366. checkAppletPropertyDefaults(propList);
  367. // Use the full props list to set ORB state.
  368. parseProperties(propList);
  369. }
  370. /**
  371. * Initialize any necessary ORB state; get attributes if possible.
  372. * Called from org.omg.CORBA.ORB.init().
  373. * @param params An array of parameters in the form of alternating <br>
  374. * "-param-name" and "param-value" strings.
  375. * @param props the application properties
  376. */
  377. protected void set_parameters (String[] params, Properties props)
  378. {
  379. // Get the full list of property names that we are interested in
  380. String[] propertyNames = getPropertyNames();
  381. String[] propertyNamePrefixes = getPropertyNamePrefixes();
  382. // Build up the full list of configuration properties
  383. // from the command-line-params, props-argument, System properties.
  384. Properties propList = new Properties();
  385. Vector orbInitRefList = new Vector();
  386. findORBPropertiesFromSystem(propList,
  387. propertyNames, propertyNamePrefixes);
  388. findPropertiesFromProperties(propList, props,
  389. propertyNames, propertyNamePrefixes);
  390. findPropertiesFromFile(propList, propertyNames, propertyNamePrefixes);
  391. findPropertiesFromArgs(propList, orbInitRefList,
  392. params, propertyNames, propertyNamePrefixes);
  393. checkApplicationPropertyDefaults(propList);
  394. // Use the full props list to set ORB state.
  395. parseProperties(propList);
  396. boolean result = initialNamingClient.setORBInitRefList(
  397. orbInitRefList );
  398. // If we are unsuccessful in setting the ORBInitDef list then it means
  399. // there are some malformed URLs presesnt
  400. if( result == false )
  401. {
  402. // Make sure to add the right minor codes here, for now it is
  403. // reusing one of the old Minorcode.
  404. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR,
  405. CompletionStatus.COMPLETED_NO);
  406. }
  407. }
  408. /** Return a list of property names that this ORB is interested in.
  409. * This may be overridden by subclasses, but subclasses must call
  410. * super.getPropertyNames() to get all names.
  411. */
  412. protected String[] getPropertyNames()
  413. {
  414. String[] names = new String[JavaIDLPropertyNames.length];
  415. for ( int i=0; i<JavaIDLPropertyNames.length; i++ )
  416. names[i] = JavaIDLPropertyNames[i];
  417. if (ORBInitDebug)
  418. dprint( "getPropertyNames returns " +
  419. ORBUtility.objectToString( names ) ) ;
  420. return names;
  421. }
  422. /** Return a list of property name prefixes that this ORB is interested in.
  423. * This may be overridden by subclasses, but subclasses must call
  424. * super.getPropertyNames() to get all names.
  425. */
  426. protected String[] getPropertyNamePrefixes()
  427. {
  428. String[] names = new String[JavaIDLPropertyNamePrefixes.length];
  429. for ( int i=0; i<JavaIDLPropertyNamePrefixes.length; i++ ) {
  430. names[i] = JavaIDLPropertyNamePrefixes[i];
  431. }
  432. if (ORBInitDebug) {
  433. dprint( "getPropertyNamePrefixes returns " + ORBUtility.objectToString( names ) ) ;
  434. }
  435. return names;
  436. }
  437. /*
  438. * A callback is used since sometimes we cannot actually get our
  439. * hands on the properties object (e.g., System.properties).
  440. */
  441. private void findPropertiesWithPrefix(String[] propertyNamePrefixes,
  442. Enumeration namesToSearch,
  443. GetPropertyCallback getProperty,
  444. String source,
  445. Properties resultProperties)
  446. {
  447. while (namesToSearch.hasMoreElements()) {
  448. String pn = (String) namesToSearch.nextElement();
  449. for (int j = 0; j < propertyNamePrefixes.length; j++) {
  450. if (pn.startsWith(propertyNamePrefixes[j])) {
  451. String value = getProperty.get(pn);
  452. // Note: do a put even if value is null since just
  453. // the presence of the property may be significant.
  454. resultProperties.put(pn, value);
  455. if (ORBInitDebug) {
  456. dprint( "Found prefixed property " + pn + "=" +
  457. value + " in " + source);
  458. }
  459. }
  460. }
  461. }
  462. }
  463. protected boolean singleParam(String param)
  464. {
  465. // Return true if this param does not have a data field after it
  466. // (e.g. for on/off flags).
  467. return false;
  468. }
  469. protected String findMatchingPropertyName( String[] propertyNames,
  470. String suffix )
  471. {
  472. for (int ctr=0; ctr<propertyNames.length; ctr++) {
  473. if (propertyNames[ctr].endsWith( suffix )) {
  474. return propertyNames[ctr] ;
  475. }
  476. }
  477. return null ;
  478. }
  479. //
  480. // Map command-line arguments to ORB properties.
  481. //
  482. protected void findPropertiesFromArgs(Properties props,
  483. Vector orbInitRefList,
  484. String[] params,
  485. String[] propertyNames,
  486. String[] propertyNamePrefixes)
  487. {
  488. // REVISIT: Parameter propertyNamePrefixes is ignored at this time.
  489. // No OMG specs have -ORB<prefix> at this time.
  490. if (ORBInitDebug)
  491. dprint( "findPropertiesFromArgs called with params=" +
  492. ORBUtility.objectToString( params ) + " propertyNames = " +
  493. ORBUtility.objectToString( propertyNames ) ) ;
  494. if (params == null)
  495. return;
  496. // All command-line args are of the form "-ORBkey value".
  497. // The key is mapped to org.omg.CORBA.key.
  498. String name ;
  499. String value ;
  500. for ( int i=0; i<params.length; i++ ) {
  501. value = null ;
  502. name = null ;
  503. if ( params[i] != null && params[i].startsWith("-ORB") ) {
  504. String argName = params[i].substring( 1 ) ;
  505. name = findMatchingPropertyName( propertyNames, argName ) ;
  506. if (name != null)
  507. if (singleParam(params[i])) {
  508. value = params[i] ;
  509. } else if ( i+1 < params.length && params[i+1] != null ) {
  510. value = params[++i];
  511. }
  512. }
  513. if (value != null) {
  514. if (ORBInitDebug)
  515. dprint( "Found property " + name + "=" + value +
  516. " in args" ) ;
  517. if( name.equals( "org.omg.CORBA.ORBInitRef" ) )
  518. {
  519. orbInitRefList.add( value );
  520. }
  521. else
  522. {
  523. props.put( name, value ) ;
  524. }
  525. }
  526. }
  527. }
  528. //
  529. // Map applet parameters to ORB properties.
  530. //
  531. protected void findPropertiesFromApplet(Properties props,
  532. Applet app,
  533. String[] propertyNames,
  534. String[] propertyNamePrefixes)
  535. {
  536. // REVISIT: propertyNamePrefixes is ignored at this time.
  537. // There is no Java API to get a applet parameter
  538. // by specifying its prefix.
  539. if (app == null)
  540. return;
  541. for (int i=0; i < propertyNames.length; i++) {
  542. String value = app.getParameter(propertyNames[i]);
  543. if (value == null)
  544. continue;
  545. props.put(propertyNames[i], value);
  546. }
  547. //
  548. // Special Case:
  549. //
  550. // Convert any applet parameter relative URLs to an
  551. // absolute URL based on the Document Root. This is so HTML URLs can be
  552. // kept relative which is sometimes useful for managing the
  553. // Document Root layout.
  554. //
  555. for (int i=0; i < JavaIDLURLPropertyNames.length; i++) {
  556. String value;
  557. value = props.getProperty(JavaIDLURLPropertyNames[i]);
  558. if (value == null)
  559. continue;
  560. try {
  561. URL url;
  562. url = new URL(app.getDocumentBase(), value);
  563. props.put(JavaIDLURLPropertyNames[i], url.toExternalForm());
  564. } catch (java.net.MalformedURLException ex) {
  565. //
  566. // This will be caught again later if this property is used.
  567. // Don't worry about reporting exceptions now.
  568. //
  569. }
  570. }
  571. }
  572. private static Class thisClass = ORB.class;
  573. private static String getSystemProperty(final String name)
  574. {
  575. return (String)AccessController.doPrivileged(new GetPropertyAction(name));
  576. }
  577. private static Enumeration getSystemPropertyNames()
  578. {
  579. // This will not throw a SecurityException because this
  580. // class was loaded from rt.jar using the bootstrap classloader.
  581. return (Enumeration)
  582. AccessController.doPrivileged(
  583. new PrivilegedAction() {
  584. public java.lang.Object run() {
  585. return System.getProperties().propertyNames();
  586. }
  587. }
  588. );
  589. }
  590. private void getPropertiesFromFile( Properties props, String fileName )
  591. {
  592. try {
  593. File file = new File( fileName ) ;
  594. if (!file.exists())
  595. return ;
  596. FileInputStream in = new FileInputStream( file ) ;
  597. try {
  598. props.load( in ) ;
  599. } finally {
  600. in.close() ;
  601. }
  602. } catch (Exception exc) {
  603. if (ORBInitDebug)
  604. dprint( "ORB properties file " + fileName + " not found: " +
  605. exc) ;
  606. }
  607. }
  608. Properties getFileProperties()
  609. {
  610. Properties defaults = new Properties() ;
  611. String javaHome = getSystemProperty( "java.home" ) ;
  612. String fileName = javaHome + File.separator + "lib" + File.separator +
  613. "orb.properties" ;
  614. getPropertiesFromFile( defaults, fileName ) ;
  615. Properties results = new Properties( defaults ) ;
  616. String userHome = getSystemProperty( "user.home" ) ;
  617. fileName = userHome + File.separator + "orb.properties" ;
  618. getPropertiesFromFile( results, fileName ) ;
  619. return results ;
  620. }
  621. protected void findPropertiesFromFile(Properties props,
  622. String[] propertyNames,
  623. String[] propertyNamePrefixes)
  624. {
  625. final Properties fileProps = getFileProperties() ;
  626. if (fileProps==null)
  627. return ;
  628. for (int i=0; i < propertyNames.length; i++) {
  629. String value;
  630. value = (String)fileProps.getProperty(propertyNames[i]);
  631. if (value == null)
  632. continue;
  633. props.put(propertyNames[i], value);
  634. if (ORBInitDebug)
  635. dprint( "Found property " + propertyNames[i] + "=" +
  636. value + " in file properties" ) ;
  637. }
  638. findPropertiesWithPrefix(
  639. propertyNamePrefixes, fileProps.propertyNames(),
  640. new GetPropertyCallback() {
  641. public String get(String name) {
  642. return fileProps.getProperty(name);
  643. }
  644. },
  645. "file properties", props
  646. );
  647. }
  648. //
  649. // Map System properties to ORB properties.
  650. // Security bug fix 4278205:
  651. // Allow only reading of system properties with ORB prefixes.
  652. // Previously a malicious subclass was able to read ANY system property.
  653. //
  654. private void findORBPropertiesFromSystem(Properties props,
  655. String[] propertyNames,
  656. String[] propertyNamePrefixes)
  657. {
  658. for (int i=0; i < propertyNames.length; i++) {
  659. if (propertyNames[i].startsWith( ORBConstants.OMG_PREFIX ) ||
  660. propertyNames[i].startsWith( ORBConstants.SUN_PREFIX ) ||
  661. propertyNames[i].startsWith( ORBConstants.SUN_LC_PREFIX ) ||
  662. propertyNames[i].startsWith( ORBConstants.SUN_LC_VERSION_PREFIX ))
  663. {
  664. String value = getSystemProperty(propertyNames[i]);
  665. if (value != null) {
  666. props.put(propertyNames[i], value);
  667. if (ORBInitDebug)
  668. dprint( "Found property " + propertyNames[i] + "=" +
  669. value + " in system properties" ) ;
  670. }
  671. }
  672. }
  673. // Any bad apples spoil the whole bunch.
  674. for (int i = 0; i < propertyNamePrefixes.length; i++) {
  675. if (! propertyNamePrefixes[i].startsWith(
  676. ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX ) )
  677. {
  678. throw
  679. new INTERNAL("findORBPropertiesFromSystem: illegal prefix: "
  680. + propertyNamePrefixes[i]);
  681. }
  682. }
  683. Enumeration systemPropertyNames = getSystemPropertyNames();
  684. findPropertiesWithPrefix(
  685. propertyNamePrefixes,
  686. systemPropertyNames,
  687. new GetPropertyCallback() {
  688. public String get(String name) {
  689. return getSystemProperty(name);
  690. }
  691. },
  692. "system properties",
  693. props);
  694. }
  695. //
  696. // Map/copy the properties argument from set_properties() into our
  697. // ORB properties object.
  698. //
  699. protected void findPropertiesFromProperties(Properties props,
  700. Properties arg,
  701. String[] propertyNames,
  702. String[] propertyNamePrefixes)
  703. {
  704. if (ORBInitDebug)
  705. dprint( "FindPropertiesFromProperties called with args = " +
  706. ORBUtility.objectToString( arg ) + "propertytNames = " +
  707. ORBUtility.objectToString( propertyNames ) ) ;
  708. if (arg == null)
  709. return;
  710. for (int i=0; i < propertyNames.length; i++) {
  711. String value;
  712. value = arg.getProperty(propertyNames[i]);
  713. if (value == null)
  714. continue;
  715. props.put(propertyNames[i], value);
  716. if (ORBInitDebug)
  717. dprint( "Found property " + propertyNames[i] + "=" +
  718. value + " in properties argument" ) ;
  719. }
  720. final Properties finalArg = arg;
  721. findPropertiesWithPrefix(
  722. propertyNamePrefixes,
  723. arg.propertyNames(),
  724. new GetPropertyCallback() {
  725. public String get(String name) {
  726. return finalArg.getProperty(name);
  727. }
  728. },
  729. "properties argument",
  730. props);
  731. }
  732. // Set appropriate defaults for an applet ORB.
  733. private void checkAppletPropertyDefaults(Properties props)
  734. {
  735. String host =
  736. props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  737. if ((host == null) || (host.equals(""))) {
  738. props.put( ORBConstants.INITIAL_HOST_PROPERTY, appletHost);
  739. }
  740. String serverHost =
  741. props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  742. if ((serverHost == null) || (serverHost.equals(""))) {
  743. props.put( ORBConstants.SERVER_HOST_PROPERTY,
  744. getLocalHostName());
  745. }
  746. }
  747. // Set appropriate defaults for an application ORB.
  748. private void checkApplicationPropertyDefaults(Properties props)
  749. {
  750. String host = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  751. if ((host == null) || (host.equals(""))) {
  752. props.put( ORBConstants.INITIAL_HOST_PROPERTY,
  753. getLocalHostName());
  754. }
  755. String serverHost =
  756. props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  757. if ((serverHost == null) || (serverHost.equals(""))) {
  758. props.put( ORBConstants.SERVER_HOST_PROPERTY,
  759. getLocalHostName());
  760. }
  761. }
  762. /* keeping a copy of the getLocalHostName so that it can only be called
  763. * internally and the unauthorized clients cannot have access to the
  764. * localHost information, originally, the above code was calling getLocalHostName
  765. * from Connection.java. If the hostname is cached in Connection.java, then
  766. * it is a security hole, since any unauthorized client has access to
  767. * the host information. With this change it is used internally so the
  768. * security problem is resolved. Also in Connection.java, the getLocalHost()
  769. * implementation has changed to always call the
  770. * InetAddress.getLocalHost().getHostAddress()
  771. */
  772. /*
  773. * getLocalHostName is private in this class.
  774. * Eventually, it should be protected, similar methods
  775. * in the subclasses removed and security check made here.
  776. *
  777. */
  778. private static String localHostString = null;
  779. private String getLocalHostName() {
  780. if (localHostString != null) {
  781. return localHostString;
  782. } else {
  783. try {
  784. synchronized (com.sun.corba.se.internal.corba.ORB.class){
  785. if ( localHostString == null )
  786. localHostString = InetAddress.getLocalHost().getHostAddress();
  787. return localHostString;
  788. }
  789. } catch (Exception ex) {
  790. throw new INTERNAL( MinorCodes.GET_LOCAL_HOST_FAILED,
  791. CompletionStatus.COMPLETED_NO );
  792. }
  793. }
  794. }
  795. protected void setDebugFlags( String args )
  796. {
  797. StringTokenizer st = new StringTokenizer( args, "," ) ;
  798. while (st.hasMoreTokens()) {
  799. String token = st.nextToken() ;
  800. // If there is a public boolean data member in this class
  801. // named token + "DebugFlag", set it to true.
  802. try {
  803. Field fld = this.getClass().getField( token + "DebugFlag" ) ;
  804. int mod = fld.getModifiers() ;
  805. if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
  806. if (fld.getType() == boolean.class)
  807. fld.setBoolean( this, true ) ;
  808. } catch (Exception exc) {
  809. // ignore it
  810. }
  811. }
  812. }
  813. /** Use the properties object to configure ORB state.
  814. * This may be overridden by subclasses, but they must call
  815. * super.parseProperties() to allow this class to set its state.
  816. */
  817. protected void parseProperties(Properties props)
  818. {
  819. // get server debug flags
  820. String debugFlags = props.getProperty( ORBConstants.DEBUG_PROPERTY ) ;
  821. if (debugFlags != null) {
  822. if (ORBInitDebug)
  823. dprint( "Setting debug flags to " + debugFlags ) ;
  824. setDebugFlags(debugFlags) ;
  825. }
  826. String param = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  827. if (param != null) {
  828. if (ORBInitDebug)
  829. dprint( "setting initial host to " + param ) ;
  830. ORBInitialHost = param;
  831. }
  832. param = props.getProperty( ORBConstants.INITIAL_PORT_PROPERTY ) ;
  833. if (param != null) {
  834. try {
  835. ORBInitialPort = Integer.parseInt(param);
  836. if (ORBInitDebug)
  837. dprint( "setting initial services port to " + ORBInitialPort ) ;
  838. initialNamingClient.setInitialServicesPort(ORBInitialPort);
  839. } catch (java.lang.NumberFormatException e) {}
  840. }
  841. param = props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  842. if (param != null) {
  843. if (ORBInitDebug)
  844. dprint( "setting ORB server host to " + param ) ;
  845. ORBServerHost = param;
  846. }
  847. param = props.getProperty( ORBConstants.SERVER_PORT_PROPERTY ) ;
  848. if (param != null) {
  849. try {
  850. ORBServerPort = Integer.parseInt(param);
  851. if (ORBInitDebug)
  852. dprint( "setting ORB server port to " + ORBServerPort ) ;
  853. } catch (java.lang.NumberFormatException e) { }
  854. }
  855. param = props.getProperty( ORBConstants.ORB_ID_PROPERTY ) ;
  856. if (param != null) {
  857. if (ORBInitDebug)
  858. dprint( "setting ORB Id to " + param ) ;
  859. orbId = param;
  860. }
  861. param = props.getProperty( ORBConstants.INITIAL_SERVICES_PROPERTY ) ;
  862. if (param != null) {
  863. try {
  864. if (ORBInitDebug)
  865. dprint( "setting initial services URL to " + param ) ;
  866. initialNamingClient.setServicesURL(new URL(param));
  867. } catch (java.io.IOException ex) {
  868. // Fallthrough
  869. }
  870. }
  871. param = props.getProperty( ORBConstants.ORB_INIT_REF_PROPERTY );
  872. if (param != null) {
  873. try {
  874. if (ORBInitDebug)
  875. dprint( "setting ORBInitRef to " + param ) ;
  876. initialNamingClient.addORBInitRef(param);
  877. } catch (Exception ex) {
  878. // Fallthrough
  879. }
  880. }
  881. param = props.getProperty( ORBConstants.DEFAULT_INIT_REF_PROPERTY ) ;
  882. if (param != null) {
  883. try {
  884. if (ORBInitDebug)
  885. dprint( "setting ORBDefaultInitRef to " + param ) ;
  886. initialNamingClient.setORBDefaultInitRef(param);
  887. } catch (Exception ex) {
  888. // Fallthrough
  889. }
  890. }
  891. //...//The following 3 parameters are there for connection management.
  892. param = props.getProperty( ORBConstants.HIGH_WATER_MARK_PROPERTY ) ;
  893. if (param != null) {
  894. try {
  895. highWaterMark = Integer.parseInt(param);
  896. if (ORBInitDebug)
  897. dprint( "setting high water mark for connections " + highWaterMark ) ;
  898. } catch (java.lang.NumberFormatException e) {}
  899. }
  900. param = props.getProperty( ORBConstants.LOW_WATER_MARK_PROPERTY ) ;
  901. if (param != null) {
  902. try {
  903. lowWaterMark = Integer.parseInt(param);
  904. if (ORBInitDebug)
  905. dprint( "setting low water mark for connections " + lowWaterMark ) ;
  906. } catch (java.lang.NumberFormatException e) {}
  907. }
  908. param = props.getProperty( ORBConstants.NUMBER_TO_RECLAIM_PROPERTY ) ;
  909. if (param != null) {
  910. try {
  911. numberToReclaim = Integer.parseInt(param);
  912. if (ORBInitDebug)
  913. dprint( "setting number of connections to reclaim during cleanup " +
  914. numberToReclaim ) ;
  915. } catch (java.lang.NumberFormatException e) {}
  916. }
  917. //GIOP Related Constants.
  918. param = props.getProperty( ORBConstants.GIOP_VERSION ) ;
  919. if (param != null) {
  920. try {
  921. giopVersion = GIOPVersion.parseVersion(param);
  922. if (ORBInitDebug)
  923. dprint( "setting default GIOP version to " + giopVersion);
  924. } catch (java.lang.NumberFormatException e) {
  925. if (ORBInitDebug)
  926. dprint( "Error: " + e);
  927. }
  928. }
  929. param = props.getProperty( ORBConstants.GIOP_FRAGMENT_SIZE ) ;
  930. if (param != null) {
  931. try {
  932. giopFragmentSize = Integer.parseInt(param);
  933. if(giopFragmentSize < ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE){
  934. throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
  935. + " Illegal value: " + giopFragmentSize
  936. + " (must be at least "
  937. + ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE
  938. + ")");
  939. }
  940. if (giopFragmentSize % ORBConstants.GIOP_FRAGMENT_DIVISOR != 0)
  941. throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
  942. + " Illegal value: " + giopFragmentSize
  943. + " (not divisible by "
  944. + ORBConstants.GIOP_FRAGMENT_DIVISOR
  945. + ")");
  946. if (ORBInitDebug)
  947. dprint( "setting GIOP fragment size to " + giopFragmentSize ) ;
  948. } catch (java.lang.NumberFormatException e) {}
  949. }
  950. param = props.getProperty( ORBConstants.GIOP_BUFFER_SIZE ) ;
  951. if (param != null) {
  952. try {
  953. giopBufferSize = Integer.parseInt(param);
  954. if (ORBInitDebug)
  955. dprint( "setting GIOP buffer size to " + giopFragmentSize ) ;
  956. } catch (java.lang.NumberFormatException e) {}
  957. }
  958. param = props.getProperty( ORBConstants.GIOP_11_BUFFMGR ) ;
  959. if (param != null) {
  960. try {
  961. giop11BuffMgr = Integer.parseInt(param);
  962. if (ORBInitDebug)
  963. dprint( "setting default GIOP11 BuffMgr to " + giop11BuffMgr);
  964. } catch (java.lang.NumberFormatException e) {
  965. if (ORBInitDebug)
  966. dprint( "Error: " + e);
  967. }
  968. }
  969. param = props.getProperty( ORBConstants.GIOP_12_BUFFMGR ) ;
  970. if (param != null) {
  971. try {
  972. giop12BuffMgr = Integer.parseInt(param);
  973. if (ORBInitDebug)
  974. dprint( "setting default GIOP12 BuffMgr to " + giop12BuffMgr);
  975. } catch (java.lang.NumberFormatException e) {
  976. if (ORBInitDebug)
  977. dprint( "Error: " + e);
  978. }
  979. }
  980. param = props.getProperty(ORBConstants.GIOP_TARGET_ADDRESSING);
  981. if (param != null) {
  982. try {
  983. short targetAddressing = Short.parseShort(param);
  984. switch (targetAddressing) {
  985. case ORBConstants.ADDR_DISP_OBJKEY :
  986. giopAddressDisposition = KeyAddr.value;
  987. giopTargetAddressPreference = targetAddressing;
  988. break;
  989. case ORBConstants.ADDR_DISP_PROFILE :
  990. giopAddressDisposition = ProfileAddr.value;
  991. giopTargetAddressPreference = targetAddressing;
  992. break;
  993. case ORBConstants.ADDR_DISP_IOR :
  994. giopAddressDisposition = ReferenceAddr.value;
  995. giopTargetAddressPreference = targetAddressing;
  996. break;
  997. case ORBConstants.ADDR_DISP_HANDLE_ALL :
  998. giopAddressDisposition = KeyAddr.value;
  999. giopTargetAddressPreference = targetAddressing;
  1000. break;
  1001. default:
  1002. throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
  1003. " Illegal value : " + param);
  1004. }
  1005. if (ORBInitDebug) {
  1006. dprint("setting GIOP TargetAddressing to " +
  1007. giopTargetAddressPreference);
  1008. }
  1009. } catch (java.lang.NumberFormatException e) {
  1010. if (ORBInitDebug)
  1011. dprint( "Error: " + e);
  1012. throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
  1013. " Illegal value : " + param);
  1014. }
  1015. }
  1016. // Code set related
  1017. param = props.getProperty(ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY);
  1018. if (param != null) {
  1019. alwaysSendCodeSetCtx = Boolean.valueOf(param).booleanValue();
  1020. if (ORBInitDebug)
  1021. dprint("Setting alwaysSendCodeSetCtx to " + alwaysSendCodeSetCtx);
  1022. }
  1023. param = props.getProperty(ORBConstants.USE_BOMS);
  1024. if (param != null) {
  1025. useByteOrderMarkers = Boolean.valueOf(param).booleanValue();
  1026. if (ORBInitDebug)
  1027. dprint("Setting useByteOrderMarkers to " + useByteOrderMarkers);
  1028. }
  1029. param = props.getProperty(ORBConstants.USE_BOMS_IN_ENCAPS);
  1030. if (param != null) {
  1031. useByteOrderMarkersInEncaps = Boolean.valueOf(param).booleanValue();
  1032. if (ORBInitDebug)
  1033. dprint("Setting useByteOrderMarkersInEncaps to " + useByteOrderMarkersInEncaps);
  1034. }
  1035. CodeSetComponentInfo.CodeSetComponent charData
  1036. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getCharComponent();
  1037. param = props.getProperty(ORBConstants.CHAR_CODESETS);
  1038. if (param != null) {
  1039. charData = CodeSetComponentInfo.createFromString(param);
  1040. if (ORBInitDebug)
  1041. dprint("charData: " + charData);
  1042. }
  1043. CodeSetComponentInfo.CodeSetComponent wcharData
  1044. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getWCharComponent();
  1045. param = props.getProperty(ORBConstants.WCHAR_CODESETS);
  1046. if (param != null) {
  1047. wcharData = CodeSetComponentInfo.createFromString(param);
  1048. if (ORBInitDebug)
  1049. dprint("wcharData: " + wcharData);
  1050. }
  1051. codesets = new CodeSetComponentInfo(charData, wcharData);
  1052. param = props.getProperty( ORBConstants.ALLOW_LOCAL_OPTIMIZATION ) ;
  1053. if (param != null) {
  1054. allowLocalOptimization = true ;
  1055. }
  1056. //...//
  1057. param = props.getProperty( ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY ) ;
  1058. if (param != null) {
  1059. try {
  1060. Class socketFactoryClass = ORBClassLoader.loadClass(param);
  1061. // For security reasons avoid creating an instance if
  1062. // this socket factory class is not one that would fail
  1063. // the class cast anyway.
  1064. if (ORBSocketFactory.class.isAssignableFrom(socketFactoryClass)) {
  1065. socketFactory = (ORBSocketFactory)socketFactoryClass.newInstance();
  1066. if (ORBInitDebug) {
  1067. dprint("setting socketFactory to: " + socketFactory);
  1068. }
  1069. } else {
  1070. // throw some exception just to get into the outer catch clause
  1071. throw new ClassCastException();
  1072. }
  1073. } catch (Exception ex) {
  1074. // ClassNotFoundException, IllegalAccessException,