- /*
- * @(#)ORB.java 1.264 03/01/23
- *
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
- /*
- * Licensed Materials - Property of IBM
- * RMI-IIOP v1.0
- * Copyright IBM Corp. 1998 1999 All Rights Reserved
- *
- * US Government Users Restricted Rights - Use, duplication or
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- package com.sun.corba.se.internal.corba;
- // Import JDK stuff
- import java.net.*;
- import java.util.*;
- import java.applet.Applet;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Field ;
- import java.lang.reflect.Modifier ;
- import java.lang.ThreadLocal;
- import java.io.File ;
- import java.io.IOException ;
- import java.io.FileInputStream ;
- import java.io.FileNotFoundException ;
- // Import our stuff
- import org.omg.CORBA.COMM_FAILURE;
- import org.omg.CORBA.DATA_CONVERSION;
- import org.omg.CORBA.INITIALIZE;
- import org.omg.CORBA.NO_IMPLEMENT;
- import org.omg.CORBA.INTERNAL;
- import org.omg.CORBA.Context;
- import org.omg.CORBA.ContextList;
- import org.omg.CORBA.Environment;
- import org.omg.CORBA.ExceptionList;
- import org.omg.CORBA.ORBPackage.InvalidName;
- import org.omg.CORBA.NVList;
- import org.omg.CORBA.TCKind;
- import org.omg.CORBA.NamedValue;
- import org.omg.CORBA.Object;
- import org.omg.CORBA.Request;
- import org.omg.CORBA.OBJ_ADAPTER;
- import org.omg.CORBA.OBJECT_NOT_EXIST;
- import org.omg.CORBA.INV_OBJREF;
- import org.omg.CORBA.MARSHAL;
- import org.omg.CORBA.SystemException;
- import org.omg.CORBA.CompletionStatus;
- import org.omg.CORBA.TypeCode;
- import org.omg.CORBA.Any;
- import org.omg.CORBA.StructMember;
- import org.omg.CORBA.UnionMember;
- import org.omg.CORBA.ValueMember;
- import org.omg.CORBA.BAD_PARAM;
- import org.omg.CORBA.BAD_INV_ORDER;
- import org.omg.CORBA.portable.*;
- import org.omg.CORBA.portable.RemarshalException;
- import org.omg.CORBA.portable.ValueFactory;
- import org.omg.PortableServer.Servant;
- import com.sun.corba.se.connection.ORBSocketFactory;
- import com.sun.corba.se.internal.core.CodeSetComponentInfo;
- import com.sun.corba.se.internal.core.ClientSubcontract;
- import com.sun.corba.se.internal.core.ClientResponse;
- import com.sun.corba.se.internal.core.ClientRequest;
- import com.sun.corba.se.internal.iiop.Connection;
- import com.sun.corba.se.internal.ior.IIOPProfile;
- import com.sun.corba.se.internal.core.ServerSubcontract;
- import com.sun.corba.se.internal.core.ServiceContexts;
- import com.sun.corba.se.internal.core.SubcontractRegistry;
- import com.sun.corba.se.internal.core.ClientGIOP;
- import com.sun.corba.se.internal.core.ServerGIOP;
- import com.sun.corba.se.internal.core.ServerRequest;
- import com.sun.corba.se.internal.core.MarshalInputStream;
- import com.sun.corba.se.internal.core.MarshalOutputStream;
- import com.sun.corba.se.internal.core.InternalRuntimeForwardRequest;
- import com.sun.corba.se.internal.core.IOR;
- import com.sun.corba.se.internal.core.Future;
- import com.sun.corba.se.internal.core.Closure;
- import com.sun.corba.se.internal.core.Constant;
- import com.sun.corba.se.internal.core.GIOPVersion;
- import com.sun.corba.se.internal.core.ORBVersion;
- import com.sun.corba.se.internal.core.ORBVersionFactory;
- import com.sun.corba.se.internal.core.INSObjectKeyMap;
- import com.sun.corba.se.internal.core.INSObjectKeyEntry;
- import com.sun.corba.se.internal.core.StandardIIOPProfileTemplate;
- import com.sun.corba.se.internal.util.Utility;
- import com.sun.corba.se.internal.orbutil.ORBUtility;
- import com.sun.corba.se.internal.orbutil.ORBClassLoader;
- import com.sun.corba.se.internal.orbutil.ORBConstants;
- import com.sun.corba.se.internal.orbutil.ORBUtility;
- import com.sun.corba.se.internal.orbutil.MinorCodes;
- import com.sun.corba.se.internal.orbutil.SubcontractList;
- import com.sun.corba.se.internal.iiop.DefaultSocketFactory;
- import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
- import com.sun.corba.se.internal.iiop.messages.KeyAddr;
- import com.sun.corba.se.internal.iiop.messages.ProfileAddr;
- import com.sun.corba.se.internal.iiop.messages.ReferenceAddr;
- import com.sun.corba.se.internal.ior.IIOPProfileTemplate;
- import com.sun.corba.se.internal.ior.IIOPAddress ;
- import com.sun.corba.se.internal.ior.IIOPAddressImpl ;
- import com.sun.corba.se.internal.ior.ObjectKey ;
- import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
- import com.sun.corba.se.internal.ior.ObjectId;
- import com.sun.corba.se.internal.DynamicAny.DynAnyFactoryImpl;
- import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;
- import java.security.AccessController;
- import java.security.PrivilegedAction;
- import sun.security.action.GetPropertyAction;
- import javax.rmi.CORBA.Util;
- import javax.rmi.CORBA.ValueHandler;
- import com.sun.org.omg.SendingContext.CodeBase;
- import com.sun.org.omg.SendingContext.CodeBaseHelper;
- /**
- * The JavaIDL ORB implementation.
- */
- public abstract class ORB extends com.sun.corba.se.internal.core.ORB
- implements TypeCodeFactory
- {
- //d11638; pure java orb, caching the servant IOR per ORB
- private static IOR ior = null;
- protected void dprint( String msg )
- {
- ORBUtility.dprint( this, msg ) ;
- }
- // Flag set at compile time to debug flag processing: this can't
- // be one of the xxxDebugFlags because it is used to debug the mechanism
- // that sets the xxxDebugFlags!
- public static boolean ORBInitDebug = false;
- // Currently defined debug flags. Any additions must be called xxxDebugFlag.
- // All debug flags must be public boolean types.
- // These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
- // Note that x,y,z must not contain spaces.
- public boolean transportDebugFlag = false ;
- public boolean subcontractDebugFlag = false ;
- public boolean poaDebugFlag = false ;
- public boolean orbdDebugFlag = false ;
- public boolean namingDebugFlag = false ;
- public boolean serviceContextDebugFlag = false ;
- public boolean transientObjectManagerDebugFlag = false ;
- public boolean giopVersionDebugFlag = false;
- // public boolean iiopConnectionDebugFlag = false;
- public boolean shutdownDebugFlag = false;
- public boolean giopDebugFlag = false;
- private static final String[] JavaIDLPropertyNames = {
- ORBConstants.INITIAL_HOST_PROPERTY,
- ORBConstants.INITIAL_PORT_PROPERTY,
- ORBConstants.INITIAL_SERVICES_PROPERTY,
- ORBConstants.DEFAULT_INIT_REF_PROPERTY,
- ORBConstants.ORB_INIT_REF_PROPERTY,
- ORBConstants.SERVER_PORT_PROPERTY,
- ORBConstants.SERVER_HOST_PROPERTY,
- ORBConstants.ORB_ID_PROPERTY,
- ORBConstants.DEBUG_PROPERTY,
- ORBConstants.HIGH_WATER_MARK_PROPERTY,
- ORBConstants.LOW_WATER_MARK_PROPERTY,
- ORBConstants.NUMBER_TO_RECLAIM_PROPERTY,
- ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY,
- ORBConstants.LISTEN_SOCKET_PROPERTY,
- //Temporary way of installing a version of GIOP on an ORB.
- //Can be beautified later.
- ORBConstants.GIOP_VERSION,
- ORBConstants.GIOP_FRAGMENT_SIZE,
- ORBConstants.GIOP_BUFFER_SIZE,
- ORBConstants.GIOP_11_BUFFMGR,
- ORBConstants.GIOP_12_BUFFMGR,
- ORBConstants.GIOP_TARGET_ADDRESSING,
- ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY,
- ORBConstants.USE_BOMS,
- ORBConstants.USE_BOMS_IN_ENCAPS,
- ORBConstants.CHAR_CODESETS,
- ORBConstants.WCHAR_CODESETS,
- ORBConstants.ALLOW_LOCAL_OPTIMIZATION
- };
- private static final String[] JavaIDLPropertyNamePrefixes = {
- // Intentionally blank;
- };
- private static final String[] JavaIDLURLPropertyNames = {
- ORBConstants.INITIAL_SERVICES_PROPERTY
- };
- //
- // The following fields form our special little collection of global state.
- // We keep it bottled up here in the ORB class and attach a reference to
- // ourselves to every object reference that we create and handle.
- //
- // Vector holding deferred Requests
- private Vector _dynamicRequests;
- protected SynchVariable _svResponseReceived;
- // Applet/command-line parameters
- protected String ORBInitialHost = "";
- protected int ORBInitialPort;
- protected String ORBServerHost = "";
- protected int ORBServerPort = 0;
- protected String appletHost = "";
- protected URL appletCodeBase = null;
- protected ORBSocketFactory socketFactory;
- protected String orbId = "";
- public boolean allowLocalOptimization = false ;
- private Collection userSpecifiedListenPorts = new Vector();
- //Connection management parameters
- protected int highWaterMark = 240;
- protected int lowWaterMark = 100;
- protected int numberToReclaim = 5;
- // GIOP Related Constants
- // Default is 1.0. We will change it to 1.2 later.
- protected GIOPVersion giopVersion = GIOPVersion.DEFAULT_VERSION;
- protected int giopFragmentSize = ORBConstants.GIOP_DEFAULT_FRAGMENT_SIZE;
- protected int giopBufferSize = ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
- protected int giop11BuffMgr = ORBConstants.DEFAULT_GIOP_11_BUFFMGR;
- protected int giop12BuffMgr = ORBConstants.DEFAULT_GIOP_12_BUFFMGR;
- protected short giopTargetAddressPreference = ORBConstants.ADDR_DISP_HANDLE_ALL;
- protected short giopAddressDisposition = KeyAddr.value;
- // Synchronization variable for shutdown
- private java.lang.Object runObj = new java.lang.Object();
- private java.lang.Object shutdownObj = new java.lang.Object();
- private java.lang.Object waitForCompletionObj = new java.lang.Object();
- private java.lang.Object invocationObj = new java.lang.Object();
- private int numInvocations = 0;
- protected static final byte STATUS_OPERATING = 1;
- protected static final byte STATUS_SHUTTING_DOWN = 2;
- protected static final byte STATUS_SHUTDOWN = 3;
- protected static final byte STATUS_DESTROYED = 4;
- byte status = STATUS_OPERATING;
- // thread local variable to store a boolean to detect deadlock in ORB.shutdown(true).
- protected ThreadLocal isProcessingInvocation = new ThreadLocal () {
- protected java.lang.Object initialValue() {
- return Boolean.FALSE;
- }
- };
- // Code set related
- protected boolean useByteOrderMarkers = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS;
- protected boolean useByteOrderMarkersInEncaps
- = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS_IN_ENCAPS;
- // Preferred native and conversion code sets for use with connections. Can
- // override or change with appropriate properties.
- protected CodeSetComponentInfo codesets
- = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS;
- protected boolean alwaysSendCodeSetCtx
- = ORBConstants.DEFAULT_ALWAYS_SEND_CODESET_CTX;
- InitialNamingClient initialNamingClient;
- DynAnyFactoryImpl dynAnyFactory = null;
- // This map is needed for resolving recursive type code placeholders
- // based on the unique repository id.
- private Map typeCodeMap = null;
- // This map is caching TypeCodes created for a certain class (key)
- // and is used in Util.writeAny()
- private Map typeCodeForClassMap = null;
- private String savedId = null;
- private TypeCodeImpl savedCode = null;
- // Cache to hold ValueFactories (Helper classes) keyed on repository ids
- protected Hashtable valueFactoryCache = new Hashtable();
- // thread local variable to store the current ORB version
- private ThreadLocal orbVersionThreadLocal ;
- // Table used for all locally registered services.
- // This is used for register/resolve/list initial methods.
- // This table maps Strings to Closures. The evaluate method
- // of the Closure must return a CORBA.Object.
- private HashMap initialReferenceTable ;
- /**
- * Create a new ORB. Should only be invoked from the
- * CORBA ORB superclass. Should be followed by the appropriate
- * set_parameters() call.
- */
- public ORB()
- {
- _dynamicRequests = new Vector();
- _svResponseReceived = new SynchVariable();
- initialNamingClient = new InitialNamingClient(this);
- initialReferenceTable = new HashMap() ;
- // default ORB version is the version of ORB with correct Rep-id
- // changes
- orbVersionThreadLocal = new ThreadLocal () {
- protected java.lang.Object initialValue() {
- // set default to version of the ORB with correct Rep-ids
- return ORBVersionFactory.getORBVersion() ;
- }
- };
- // Register the Dynamic Any factory
- Closure closure = new Closure() {
- public java.lang.Object evaluate() {
- return new DynAnyFactoryImpl( ORB.this ) ;
- }
- } ;
- Future future = new Future( closure ) ;
- registerInitialReference( ORBConstants.DYN_ANY_FACTORY_NAME, future ) ;
- }
- public InitialNamingClient getInitialNamingClient( ) {
- return initialNamingClient;
- }
- public ORBVersion getORBVersion()
- {
- // return the thread local data
- return (ORBVersion)(orbVersionThreadLocal.get()) ;
- }
- public void setORBVersion(ORBVersion verObj)
- {
- // set the thread local data
- orbVersionThreadLocal.set(verObj);
- }
- /**
- * Should the client send the code set service context on every
- * request?
- */
- public boolean alwaysSendCodeSetServiceContext() {
- return alwaysSendCodeSetCtx;
- }
- /**
- * Use byte order markers when applicable during character conversion?
- */
- public boolean useByteOrderMarkers() {
- return useByteOrderMarkers;
- }
- /**
- * Use byte order markers even in encapsulations?
- */
- public boolean useByteOrderMarkersInEncapsulations() {
- return useByteOrderMarkersInEncaps;
- }
- /**
- * Get the prefered code sets for connections.
- */
- public CodeSetComponentInfo getCodeSetComponentInfo() {
- return codesets;
- }
- /****************************************************************************
- * The following methods deal with parsing parameters and doing appropriate
- * initialization.
- ****************************************************************************/
- /**
- * Initialize any necessary ORB state; get attributes if possible.
- * Called from org.omg.CORBA.ORB.init().
- * @param app the applet
- * @param props the applet properties
- */
- protected void set_parameters(Applet app, Properties props)
- {
- // Note: In some applet-development frameworks
- // the applet object may not be directly available and so it's
- // possible for the Applet instance to be null.
- // Get the full list of property names that we are interested in
- String[] propertyNames = getPropertyNames();
- String[] propertyNamePrefixes = getPropertyNamePrefixes();
- if (app != null) {
- appletCodeBase = app.getCodeBase();
- if (appletCodeBase != null)
- appletHost = appletCodeBase.getHost( );
- }
- // Build up the full list of configuration properties
- // from the applet-params and props-argument.
- // Make Properties Vector to handle multiple -ORBInitDef s
- Properties propList = new Properties();
- // Until we decide it's ok for getSystemProperty() to
- // use AccessController.beginPrivileged(), I've commented
- // out the use of System properties for applets since
- // this will result in confusing SecurityExceptions in
- // most situations.
- //
- /*
- findORBPropertiesFromSystem(propList,
- propertyNames, propertyNamePrefixes);
- */
- findPropertiesFromProperties(propList, props,
- propertyNames, propertyNamePrefixes);
- findPropertiesFromApplet(propList, app,
- propertyNames, propertyNamePrefixes);
- checkAppletPropertyDefaults(propList);
- // Use the full props list to set ORB state.
- parseProperties(propList);
- }
- /**
- * Initialize any necessary ORB state; get attributes if possible.
- * Called from org.omg.CORBA.ORB.init().
- * @param params An array of parameters in the form of alternating <br>
- * "-param-name" and "param-value" strings.
- * @param props the application properties
- */
- protected void set_parameters (String[] params, Properties props)
- {
- // Get the full list of property names that we are interested in
- String[] propertyNames = getPropertyNames();
- String[] propertyNamePrefixes = getPropertyNamePrefixes();
- // Build up the full list of configuration properties
- // from the command-line-params, props-argument, System properties.
- Properties propList = new Properties();
- Vector orbInitRefList = new Vector();
- findORBPropertiesFromSystem(propList,
- propertyNames, propertyNamePrefixes);
- findPropertiesFromProperties(propList, props,
- propertyNames, propertyNamePrefixes);
- findPropertiesFromFile(propList, propertyNames, propertyNamePrefixes);
- findPropertiesFromArgs(propList, orbInitRefList,
- params, propertyNames, propertyNamePrefixes);
- checkApplicationPropertyDefaults(propList);
- // Use the full props list to set ORB state.
- parseProperties(propList);
- boolean result = initialNamingClient.setORBInitRefList(
- orbInitRefList );
- // If we are unsuccessful in setting the ORBInitDef list then it means
- // there are some malformed URLs presesnt
- if( result == false )
- {
- // Make sure to add the right minor codes here, for now it is
- // reusing one of the old Minorcode.
- throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR,
- CompletionStatus.COMPLETED_NO);
- }
- }
- /** Return a list of property names that this ORB is interested in.
- * This may be overridden by subclasses, but subclasses must call
- * super.getPropertyNames() to get all names.
- */
- protected String[] getPropertyNames()
- {
- String[] names = new String[JavaIDLPropertyNames.length];
- for ( int i=0; i<JavaIDLPropertyNames.length; i++ )
- names[i] = JavaIDLPropertyNames[i];
- if (ORBInitDebug)
- dprint( "getPropertyNames returns " +
- ORBUtility.objectToString( names ) ) ;
- return names;
- }
- /** Return a list of property name prefixes that this ORB is interested in.
- * This may be overridden by subclasses, but subclasses must call
- * super.getPropertyNames() to get all names.
- */
- protected String[] getPropertyNamePrefixes()
- {
- String[] names = new String[JavaIDLPropertyNamePrefixes.length];
- for ( int i=0; i<JavaIDLPropertyNamePrefixes.length; i++ ) {
- names[i] = JavaIDLPropertyNamePrefixes[i];
- }
- if (ORBInitDebug) {
- dprint( "getPropertyNamePrefixes returns " + ORBUtility.objectToString( names ) ) ;
- }
- return names;
- }
- /*
- * A callback is used since sometimes we cannot actually get our
- * hands on the properties object (e.g., System.properties).
- */
- private void findPropertiesWithPrefix(String[] propertyNamePrefixes,
- Enumeration namesToSearch,
- GetPropertyCallback getProperty,
- String source,
- Properties resultProperties)
- {
- while (namesToSearch.hasMoreElements()) {
- String pn = (String) namesToSearch.nextElement();
- for (int j = 0; j < propertyNamePrefixes.length; j++) {
- if (pn.startsWith(propertyNamePrefixes[j])) {
- String value = getProperty.get(pn);
- // Note: do a put even if value is null since just
- // the presence of the property may be significant.
- resultProperties.put(pn, value);
- if (ORBInitDebug) {
- dprint( "Found prefixed property " + pn + "=" +
- value + " in " + source);
- }
- }
- }
- }
- }
- protected boolean singleParam(String param)
- {
- // Return true if this param does not have a data field after it
- // (e.g. for on/off flags).
- return false;
- }
- protected String findMatchingPropertyName( String[] propertyNames,
- String suffix )
- {
- for (int ctr=0; ctr<propertyNames.length; ctr++) {
- if (propertyNames[ctr].endsWith( suffix )) {
- return propertyNames[ctr] ;
- }
- }
- return null ;
- }
- //
- // Map command-line arguments to ORB properties.
- //
- protected void findPropertiesFromArgs(Properties props,
- Vector orbInitRefList,
- String[] params,
- String[] propertyNames,
- String[] propertyNamePrefixes)
- {
- // REVISIT: Parameter propertyNamePrefixes is ignored at this time.
- // No OMG specs have -ORB<prefix> at this time.
- if (ORBInitDebug)
- dprint( "findPropertiesFromArgs called with params=" +
- ORBUtility.objectToString( params ) + " propertyNames = " +
- ORBUtility.objectToString( propertyNames ) ) ;
- if (params == null)
- return;
- // All command-line args are of the form "-ORBkey value".
- // The key is mapped to org.omg.CORBA.key.
- String name ;
- String value ;
- for ( int i=0; i<params.length; i++ ) {
- value = null ;
- name = null ;
- if ( params[i] != null && params[i].startsWith("-ORB") ) {
- String argName = params[i].substring( 1 ) ;
- name = findMatchingPropertyName( propertyNames, argName ) ;
- if (name != null)
- if (singleParam(params[i])) {
- value = params[i] ;
- } else if ( i+1 < params.length && params[i+1] != null ) {
- value = params[++i];
- }
- }
- if (value != null) {
- if (ORBInitDebug)
- dprint( "Found property " + name + "=" + value +
- " in args" ) ;
- if( name.equals( "org.omg.CORBA.ORBInitRef" ) )
- {
- orbInitRefList.add( value );
- }
- else
- {
- props.put( name, value ) ;
- }
- }
- }
- }
- //
- // Map applet parameters to ORB properties.
- //
- protected void findPropertiesFromApplet(Properties props,
- Applet app,
- String[] propertyNames,
- String[] propertyNamePrefixes)
- {
- // REVISIT: propertyNamePrefixes is ignored at this time.
- // There is no Java API to get a applet parameter
- // by specifying its prefix.
- if (app == null)
- return;
- for (int i=0; i < propertyNames.length; i++) {
- String value = app.getParameter(propertyNames[i]);
- if (value == null)
- continue;
- props.put(propertyNames[i], value);
- }
- //
- // Special Case:
- //
- // Convert any applet parameter relative URLs to an
- // absolute URL based on the Document Root. This is so HTML URLs can be
- // kept relative which is sometimes useful for managing the
- // Document Root layout.
- //
- for (int i=0; i < JavaIDLURLPropertyNames.length; i++) {
- String value;
- value = props.getProperty(JavaIDLURLPropertyNames[i]);
- if (value == null)
- continue;
- try {
- URL url;
- url = new URL(app.getDocumentBase(), value);
- props.put(JavaIDLURLPropertyNames[i], url.toExternalForm());
- } catch (java.net.MalformedURLException ex) {
- //
- // This will be caught again later if this property is used.
- // Don't worry about reporting exceptions now.
- //
- }
- }
- }
- private static Class thisClass = ORB.class;
- private static String getSystemProperty(final String name)
- {
- return (String)AccessController.doPrivileged(new GetPropertyAction(name));
- }
- private static Enumeration getSystemPropertyNames()
- {
- // This will not throw a SecurityException because this
- // class was loaded from rt.jar using the bootstrap classloader.
- return (Enumeration)
- AccessController.doPrivileged(
- new PrivilegedAction() {
- public java.lang.Object run() {
- return System.getProperties().propertyNames();
- }
- }
- );
- }
- private void getPropertiesFromFile( Properties props, String fileName )
- {
- try {
- File file = new File( fileName ) ;
- if (!file.exists())
- return ;
- FileInputStream in = new FileInputStream( file ) ;
- try {
- props.load( in ) ;
- } finally {
- in.close() ;
- }
- } catch (Exception exc) {
- if (ORBInitDebug)
- dprint( "ORB properties file " + fileName + " not found: " +
- exc) ;
- }
- }
- Properties getFileProperties()
- {
- Properties defaults = new Properties() ;
- String javaHome = getSystemProperty( "java.home" ) ;
- String fileName = javaHome + File.separator + "lib" + File.separator +
- "orb.properties" ;
- getPropertiesFromFile( defaults, fileName ) ;
- Properties results = new Properties( defaults ) ;
- String userHome = getSystemProperty( "user.home" ) ;
- fileName = userHome + File.separator + "orb.properties" ;
- getPropertiesFromFile( results, fileName ) ;
- return results ;
- }
- protected void findPropertiesFromFile(Properties props,
- String[] propertyNames,
- String[] propertyNamePrefixes)
- {
- final Properties fileProps = getFileProperties() ;
- if (fileProps==null)
- return ;
- for (int i=0; i < propertyNames.length; i++) {
- String value;
- value = (String)fileProps.getProperty(propertyNames[i]);
- if (value == null)
- continue;
- props.put(propertyNames[i], value);
- if (ORBInitDebug)
- dprint( "Found property " + propertyNames[i] + "=" +
- value + " in file properties" ) ;
- }
- findPropertiesWithPrefix(
- propertyNamePrefixes, fileProps.propertyNames(),
- new GetPropertyCallback() {
- public String get(String name) {
- return fileProps.getProperty(name);
- }
- },
- "file properties", props
- );
- }
- //
- // Map System properties to ORB properties.
- // Security bug fix 4278205:
- // Allow only reading of system properties with ORB prefixes.
- // Previously a malicious subclass was able to read ANY system property.
- //
- private void findORBPropertiesFromSystem(Properties props,
- String[] propertyNames,
- String[] propertyNamePrefixes)
- {
- for (int i=0; i < propertyNames.length; i++) {
- if (propertyNames[i].startsWith( ORBConstants.OMG_PREFIX ) ||
- propertyNames[i].startsWith( ORBConstants.SUN_PREFIX ) ||
- propertyNames[i].startsWith( ORBConstants.SUN_LC_PREFIX ) ||
- propertyNames[i].startsWith( ORBConstants.SUN_LC_VERSION_PREFIX ))
- {
- String value = getSystemProperty(propertyNames[i]);
- if (value != null) {
- props.put(propertyNames[i], value);
- if (ORBInitDebug)
- dprint( "Found property " + propertyNames[i] + "=" +
- value + " in system properties" ) ;
- }
- }
- }
- // Any bad apples spoil the whole bunch.
- for (int i = 0; i < propertyNamePrefixes.length; i++) {
- if (! propertyNamePrefixes[i].startsWith(
- ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX ) )
- {
- throw
- new INTERNAL("findORBPropertiesFromSystem: illegal prefix: "
- + propertyNamePrefixes[i]);
- }
- }
- Enumeration systemPropertyNames = getSystemPropertyNames();
- findPropertiesWithPrefix(
- propertyNamePrefixes,
- systemPropertyNames,
- new GetPropertyCallback() {
- public String get(String name) {
- return getSystemProperty(name);
- }
- },
- "system properties",
- props);
- }
- //
- // Map/copy the properties argument from set_properties() into our
- // ORB properties object.
- //
- protected void findPropertiesFromProperties(Properties props,
- Properties arg,
- String[] propertyNames,
- String[] propertyNamePrefixes)
- {
- if (ORBInitDebug)
- dprint( "FindPropertiesFromProperties called with args = " +
- ORBUtility.objectToString( arg ) + "propertytNames = " +
- ORBUtility.objectToString( propertyNames ) ) ;
- if (arg == null)
- return;
- for (int i=0; i < propertyNames.length; i++) {
- String value;
- value = arg.getProperty(propertyNames[i]);
- if (value == null)
- continue;
- props.put(propertyNames[i], value);
- if (ORBInitDebug)
- dprint( "Found property " + propertyNames[i] + "=" +
- value + " in properties argument" ) ;
- }
- final Properties finalArg = arg;
- findPropertiesWithPrefix(
- propertyNamePrefixes,
- arg.propertyNames(),
- new GetPropertyCallback() {
- public String get(String name) {
- return finalArg.getProperty(name);
- }
- },
- "properties argument",
- props);
- }
- // Set appropriate defaults for an applet ORB.
- private void checkAppletPropertyDefaults(Properties props)
- {
- String host =
- props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
- if ((host == null) || (host.equals(""))) {
- props.put( ORBConstants.INITIAL_HOST_PROPERTY, appletHost);
- }
- String serverHost =
- props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
- if ((serverHost == null) || (serverHost.equals(""))) {
- props.put( ORBConstants.SERVER_HOST_PROPERTY,
- getLocalHostName());
- }
- }
- // Set appropriate defaults for an application ORB.
- private void checkApplicationPropertyDefaults(Properties props)
- {
- String host = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
- if ((host == null) || (host.equals(""))) {
- props.put( ORBConstants.INITIAL_HOST_PROPERTY,
- getLocalHostName());
- }
- String serverHost =
- props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
- if ((serverHost == null) || (serverHost.equals(""))) {
- props.put( ORBConstants.SERVER_HOST_PROPERTY,
- getLocalHostName());
- }
- }
- /* keeping a copy of the getLocalHostName so that it can only be called
- * internally and the unauthorized clients cannot have access to the
- * localHost information, originally, the above code was calling getLocalHostName
- * from Connection.java. If the hostname is cached in Connection.java, then
- * it is a security hole, since any unauthorized client has access to
- * the host information. With this change it is used internally so the
- * security problem is resolved. Also in Connection.java, the getLocalHost()
- * implementation has changed to always call the
- * InetAddress.getLocalHost().getHostAddress()
- */
- /*
- * getLocalHostName is private in this class.
- * Eventually, it should be protected, similar methods
- * in the subclasses removed and security check made here.
- *
- */
- private static String localHostString = null;
- private String getLocalHostName() {
- if (localHostString != null) {
- return localHostString;
- } else {
- try {
- synchronized (com.sun.corba.se.internal.corba.ORB.class){
- if ( localHostString == null )
- localHostString = InetAddress.getLocalHost().getHostAddress();
- return localHostString;
- }
- } catch (Exception ex) {
- throw new INTERNAL( MinorCodes.GET_LOCAL_HOST_FAILED,
- CompletionStatus.COMPLETED_NO );
- }
- }
- }
- protected void setDebugFlags( String args )
- {
- StringTokenizer st = new StringTokenizer( args, "," ) ;
- while (st.hasMoreTokens()) {
- String token = st.nextToken() ;
- // If there is a public boolean data member in this class
- // named token + "DebugFlag", set it to true.
- try {
- Field fld = this.getClass().getField( token + "DebugFlag" ) ;
- int mod = fld.getModifiers() ;
- if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
- if (fld.getType() == boolean.class)
- fld.setBoolean( this, true ) ;
- } catch (Exception exc) {
- // ignore it
- }
- }
- }
- /** Use the properties object to configure ORB state.
- * This may be overridden by subclasses, but they must call
- * super.parseProperties() to allow this class to set its state.
- */
- protected void parseProperties(Properties props)
- {
- // get server debug flags
- String debugFlags = props.getProperty( ORBConstants.DEBUG_PROPERTY ) ;
- if (debugFlags != null) {
- if (ORBInitDebug)
- dprint( "Setting debug flags to " + debugFlags ) ;
- setDebugFlags(debugFlags) ;
- }
- String param = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
- if (param != null) {
- if (ORBInitDebug)
- dprint( "setting initial host to " + param ) ;
- ORBInitialHost = param;
- }
- param = props.getProperty( ORBConstants.INITIAL_PORT_PROPERTY ) ;
- if (param != null) {
- try {
- ORBInitialPort = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting initial services port to " + ORBInitialPort ) ;
- initialNamingClient.setInitialServicesPort(ORBInitialPort);
- } catch (java.lang.NumberFormatException e) {}
- }
- param = props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
- if (param != null) {
- if (ORBInitDebug)
- dprint( "setting ORB server host to " + param ) ;
- ORBServerHost = param;
- }
- param = props.getProperty( ORBConstants.SERVER_PORT_PROPERTY ) ;
- if (param != null) {
- try {
- ORBServerPort = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting ORB server port to " + ORBServerPort ) ;
- } catch (java.lang.NumberFormatException e) { }
- }
- param = props.getProperty( ORBConstants.ORB_ID_PROPERTY ) ;
- if (param != null) {
- if (ORBInitDebug)
- dprint( "setting ORB Id to " + param ) ;
- orbId = param;
- }
- param = props.getProperty( ORBConstants.INITIAL_SERVICES_PROPERTY ) ;
- if (param != null) {
- try {
- if (ORBInitDebug)
- dprint( "setting initial services URL to " + param ) ;
- initialNamingClient.setServicesURL(new URL(param));
- } catch (java.io.IOException ex) {
- // Fallthrough
- }
- }
- param = props.getProperty( ORBConstants.ORB_INIT_REF_PROPERTY );
- if (param != null) {
- try {
- if (ORBInitDebug)
- dprint( "setting ORBInitRef to " + param ) ;
- initialNamingClient.addORBInitRef(param);
- } catch (Exception ex) {
- // Fallthrough
- }
- }
- param = props.getProperty( ORBConstants.DEFAULT_INIT_REF_PROPERTY ) ;
- if (param != null) {
- try {
- if (ORBInitDebug)
- dprint( "setting ORBDefaultInitRef to " + param ) ;
- initialNamingClient.setORBDefaultInitRef(param);
- } catch (Exception ex) {
- // Fallthrough
- }
- }
- //...//The following 3 parameters are there for connection management.
- param = props.getProperty( ORBConstants.HIGH_WATER_MARK_PROPERTY ) ;
- if (param != null) {
- try {
- highWaterMark = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting high water mark for connections " + highWaterMark ) ;
- } catch (java.lang.NumberFormatException e) {}
- }
- param = props.getProperty( ORBConstants.LOW_WATER_MARK_PROPERTY ) ;
- if (param != null) {
- try {
- lowWaterMark = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting low water mark for connections " + lowWaterMark ) ;
- } catch (java.lang.NumberFormatException e) {}
- }
- param = props.getProperty( ORBConstants.NUMBER_TO_RECLAIM_PROPERTY ) ;
- if (param != null) {
- try {
- numberToReclaim = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting number of connections to reclaim during cleanup " +
- numberToReclaim ) ;
- } catch (java.lang.NumberFormatException e) {}
- }
- //GIOP Related Constants.
- param = props.getProperty( ORBConstants.GIOP_VERSION ) ;
- if (param != null) {
- try {
- giopVersion = GIOPVersion.parseVersion(param);
- if (ORBInitDebug)
- dprint( "setting default GIOP version to " + giopVersion);
- } catch (java.lang.NumberFormatException e) {
- if (ORBInitDebug)
- dprint( "Error: " + e);
- }
- }
- param = props.getProperty( ORBConstants.GIOP_FRAGMENT_SIZE ) ;
- if (param != null) {
- try {
- giopFragmentSize = Integer.parseInt(param);
- if(giopFragmentSize < ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE){
- throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
- + " Illegal value: " + giopFragmentSize
- + " (must be at least "
- + ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE
- + ")");
- }
- if (giopFragmentSize % ORBConstants.GIOP_FRAGMENT_DIVISOR != 0)
- throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
- + " Illegal value: " + giopFragmentSize
- + " (not divisible by "
- + ORBConstants.GIOP_FRAGMENT_DIVISOR
- + ")");
- if (ORBInitDebug)
- dprint( "setting GIOP fragment size to " + giopFragmentSize ) ;
- } catch (java.lang.NumberFormatException e) {}
- }
- param = props.getProperty( ORBConstants.GIOP_BUFFER_SIZE ) ;
- if (param != null) {
- try {
- giopBufferSize = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting GIOP buffer size to " + giopFragmentSize ) ;
- } catch (java.lang.NumberFormatException e) {}
- }
- param = props.getProperty( ORBConstants.GIOP_11_BUFFMGR ) ;
- if (param != null) {
- try {
- giop11BuffMgr = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting default GIOP11 BuffMgr to " + giop11BuffMgr);
- } catch (java.lang.NumberFormatException e) {
- if (ORBInitDebug)
- dprint( "Error: " + e);
- }
- }
- param = props.getProperty( ORBConstants.GIOP_12_BUFFMGR ) ;
- if (param != null) {
- try {
- giop12BuffMgr = Integer.parseInt(param);
- if (ORBInitDebug)
- dprint( "setting default GIOP12 BuffMgr to " + giop12BuffMgr);
- } catch (java.lang.NumberFormatException e) {
- if (ORBInitDebug)
- dprint( "Error: " + e);
- }
- }
- param = props.getProperty(ORBConstants.GIOP_TARGET_ADDRESSING);
- if (param != null) {
- try {
- short targetAddressing = Short.parseShort(param);
- switch (targetAddressing) {
- case ORBConstants.ADDR_DISP_OBJKEY :
- giopAddressDisposition = KeyAddr.value;
- giopTargetAddressPreference = targetAddressing;
- break;
- case ORBConstants.ADDR_DISP_PROFILE :
- giopAddressDisposition = ProfileAddr.value;
- giopTargetAddressPreference = targetAddressing;
- break;
- case ORBConstants.ADDR_DISP_IOR :
- giopAddressDisposition = ReferenceAddr.value;
- giopTargetAddressPreference = targetAddressing;
- break;
- case ORBConstants.ADDR_DISP_HANDLE_ALL :
- giopAddressDisposition = KeyAddr.value;
- giopTargetAddressPreference = targetAddressing;
- break;
- default:
- throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
- " Illegal value : " + param);
- }
- if (ORBInitDebug) {
- dprint("setting GIOP TargetAddressing to " +
- giopTargetAddressPreference);
- }
- } catch (java.lang.NumberFormatException e) {
- if (ORBInitDebug)
- dprint( "Error: " + e);
- throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
- " Illegal value : " + param);
- }
- }
- // Code set related
- param = props.getProperty(ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY);
- if (param != null) {
- alwaysSendCodeSetCtx = Boolean.valueOf(param).booleanValue();
- if (ORBInitDebug)
- dprint("Setting alwaysSendCodeSetCtx to " + alwaysSendCodeSetCtx);
- }
- param = props.getProperty(ORBConstants.USE_BOMS);
- if (param != null) {
- useByteOrderMarkers = Boolean.valueOf(param).booleanValue();
- if (ORBInitDebug)
- dprint("Setting useByteOrderMarkers to " + useByteOrderMarkers);
- }
- param = props.getProperty(ORBConstants.USE_BOMS_IN_ENCAPS);
- if (param != null) {
- useByteOrderMarkersInEncaps = Boolean.valueOf(param).booleanValue();
- if (ORBInitDebug)
- dprint("Setting useByteOrderMarkersInEncaps to " + useByteOrderMarkersInEncaps);
- }
- CodeSetComponentInfo.CodeSetComponent charData
- = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getCharComponent();
- param = props.getProperty(ORBConstants.CHAR_CODESETS);
- if (param != null) {
- charData = CodeSetComponentInfo.createFromString(param);
- if (ORBInitDebug)
- dprint("charData: " + charData);
- }
- CodeSetComponentInfo.CodeSetComponent wcharData
- = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getWCharComponent();
- param = props.getProperty(ORBConstants.WCHAR_CODESETS);
- if (param != null) {
- wcharData = CodeSetComponentInfo.createFromString(param);
- if (ORBInitDebug)
- dprint("wcharData: " + wcharData);
- }
- codesets = new CodeSetComponentInfo(charData, wcharData);
- param = props.getProperty( ORBConstants.ALLOW_LOCAL_OPTIMIZATION ) ;
- if (param != null) {
- allowLocalOptimization = true ;
- }
- //...//
- param = props.getProperty( ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY ) ;
- if (param != null) {
- try {
- Class socketFactoryClass = ORBClassLoader.loadClass(param);
- // For security reasons avoid creating an instance if
- // this socket factory class is not one that would fail
- // the class cast anyway.
- if (ORBSocketFactory.class.isAssignableFrom(socketFactoryClass)) {
- socketFactory = (ORBSocketFactory)socketFactoryClass.newInstance();
- if (ORBInitDebug) {
- dprint("setting socketFactory to: " + socketFactory);
- }
- } else {
- // throw some exception just to get into the outer catch clause
- throw new ClassCastException();
- }
- } catch (Exception ex) {
- // ClassNotFoundException, IllegalAccessException,