geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From delaf...@apache.org
Subject svn commit: r159303 [2/2] - in geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop: ./ client/ compiler/ server/
Date Mon, 28 Mar 2005 20:37:44 GMT
Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PutField.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PutField.java?view=auto&rev=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PutField.java (added)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PutField.java Mon Mar 28 12:37:40 2005
@@ -0,0 +1,360 @@
+/**
+ *
+ *  Copyright 2004-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.interop.rmi.iiop;
+
+import java.io.*;
+import java.util.*;
+import java.lang.reflect.*;
+
+/**
+ ** An implementation of java.io.ObjectOutputStream.PutField
+ ** Provide programatic access to the persistent fields to be written
+ ** to ObjectOutput.
+ **/
+
+public class PutField extends java.io.ObjectOutputStream.PutField
+{
+    /** class descriptor describing serializable fields */
+    private final ObjectStreamClass desc;
+    /** primitive field values */
+    private final byte[] primVals;
+    /** object field values */
+    private final Object[] objVals;
+
+    private int primDataSize = 0;
+    private int numObjFields = 0;
+    private ObjectStreamField[] _fields = null;
+
+    private static Method setOffsetMethod;
+
+    static
+    {
+        try
+        {
+            Class osFieldClass = java.io.ObjectStreamField.class;
+            Class[] params = new Class[1];
+            params[0] = int.class;
+            setOffsetMethod = osFieldClass.getDeclaredMethod("setOffset", params);
+            setOffsetMethod.setAccessible(true);
+        }
+        catch (Throwable t)
+        {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * Creates PutField object for writing fields defined in given
+     * class descriptor.
+     */
+    PutField(ObjectStreamClass desc)
+    {
+        this.desc = desc;
+        computeOffsets();
+        primVals = new byte[primDataSize];
+        objVals = new Object[numObjFields];
+    }
+
+    /**
+     * Put the value of the named boolean field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, boolean val)
+    {
+        Bits.putBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named byte field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, byte val)
+    {
+        primVals[getFieldOffset(name, Byte.TYPE)] = val;
+    }
+
+    /**
+     * Put the value of the named char field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, char val)
+    {
+        Bits.putChar(primVals, getFieldOffset(name, Character.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named short field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, short val)
+    {
+        Bits.putShort(primVals, getFieldOffset(name, Short.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named int field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, int val)
+    {
+        Bits.putInt(primVals, getFieldOffset(name, Integer.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named long field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, long val)
+    {
+        Bits.putLong(primVals, getFieldOffset(name, Long.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named float field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, float val)
+    {
+        Bits.putFloat(primVals, getFieldOffset(name, Float.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named double field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, double val)
+    {
+        Bits.putDouble(primVals, getFieldOffset(name, Double.TYPE), val);
+    }
+
+    /**
+     * Put the value of the named Object field into the persistent field.
+     *
+     * @param  name the name of the serializable field
+     * @param  val the value to assign to the field
+     */
+    public void put(String name, Object val)
+    {
+        objVals[getFieldOffset(name, Object.class)] = val;
+    }
+
+    /**
+     * Write the data and fields to the specified ObjectOutput stream.
+     * 
+     * @param  out the stream to write the data and fields to
+     * @throws IOException if I/O errors occur while writing to the
+     *        underlying stream
+     * @deprecated This method does not write the values contained by this
+     *        <code>PutField</code> object in a proper format, and may
+     *        result in corruption of the serialization stream.  The
+     *        correct way to write <code>PutField</code> data is by
+     *        calling the {@link java.io.ObjectOutputStream#writeFields()}
+     *        method.
+     */
+    public void write(ObjectOutput out) throws IOException
+    {
+        /*
+         * Applications should *not* use this method to write PutField
+         * data, as it will lead to stream corruption if the PutField
+         * object writes any primitive data (since block data mode is not
+         * unset/set properly, as is done in OOS.writeFields()).  This
+         * broken implementation is being retained solely for behavioral
+         * compatibility, in order to support applications which use
+         * OOS.PutField.write() for writing only non-primitive data.
+         * 
+         * Serialization of unshared objects is not implemented here since
+         * it is not necessary for backwards compatibility; also, unshared
+         * semantics may not be supported by the given ObjectOutput
+         * instance.  Applications which write unshared objects using the
+         * PutField API must use OOS.writeFields().
+         */
+        throw new IOException("PutField.write(ObjectOutput) - not supported for RMI/IIOP");
+    }
+
+    /**
+     * Writes buffered primitive data and object fields to stream.
+     */
+    void writeFields(ObjectOutputStream o) throws IOException
+    {
+        org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream out = (org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream)o;
+
+        out._cdrOutput.write_align(4, 4); // write any necessary padding
+
+        //Write out the primitive values first
+        for(int i = 0; i < primVals.length; i++)
+        {
+            out.writeByte(primVals[i]);
+        }
+
+        //Write out the object fields
+        java.io.ObjectStreamField[] fields = desc.getFields();
+        int numPrimFields = fields.length - objVals.length;
+        for (int i = 0; i < objVals.length; i++)
+        {
+            out.writeObject(ValueType.getInstance(objVals[i].getClass()), objVals[i]);
+        }
+    }
+
+    /**
+     * Returns offset of field with given name and type.  A specified type
+     * of null matches all types, Object.class matches all non-primitive
+     * types, and any other non-null type matches assignable types only.
+     * Throws IllegalArgumentException if no matching field found.
+     */
+    private int getFieldOffset(String name, Class type)
+    {
+        ObjectStreamField field = getField(name, type);
+        if (field == null)
+        {
+            throw new IllegalArgumentException("no such field");
+        }
+        return field.getOffset();
+    }
+
+    private ObjectStreamField getField(String name, Class type)
+    {
+        if(type == null)
+        {
+            //Return match by name
+            for(int i = 0; i < _fields.length; i++)
+            {
+                if(_fields[i].getName().equals(name))
+                {
+                    return _fields[i];
+                }
+            }
+            return (ObjectStreamField)null;
+        }
+        else if(type == java.lang.Object.class)
+        {
+            //Return match for name, and any non-primitive type
+            for(int i = 0; i < _fields.length; i++)
+            {
+                if(_fields[i].getName().equals(name) && !_fields[i].getType().isPrimitive())
+                {
+                    return _fields[i];
+                }
+            }
+            return (ObjectStreamField)null;
+        }
+        else
+        {
+            for(int i = 0; i < _fields.length; i++)
+            {
+                if(_fields[i].getName().equals(name) && _fields[i].getType().equals(type))
+                {
+                    return _fields[i];
+                }
+            }
+            return (ObjectStreamField)null;
+        }
+    }
+
+    private void computeOffsets()
+    {
+        try
+        {
+            computeFieldOffsets();
+        }
+        catch(Exception e)
+        {
+            throw new RuntimeException(org.apache.geronimo.interop.util.ExceptionUtil.causedBy(e));
+        }
+    }
+
+    private void computeFieldOffsets() throws Exception
+    {
+        primDataSize = 0;
+        numObjFields = 0;
+        int firstObjIndex = -1;
+        java.io.ObjectStreamField[] fields = desc.getFields();
+        _fields = new ObjectStreamField[fields.length];
+        Object[] args = new Object[1];
+
+        for (int i = 0; i < fields.length; i++)
+        {
+            java.io.ObjectStreamField f = fields[i];
+            _fields[i] = new ObjectStreamField(fields[i].getName(), fields[i].getType());
+            ObjectStreamField _f = _fields[i];
+            
+            switch (f.getTypeCode())
+            {
+                case 'Z':
+                case 'B':
+                    args[0] = new Integer(primDataSize++);
+                    setOffsetMethod.invoke(_f, args);
+                    break;
+
+                case 'C':
+                case 'S':
+                    args[0] = new Integer(primDataSize);
+                    setOffsetMethod.invoke(_f, args);
+                    primDataSize += 2;
+                    break;
+
+                case 'I':
+                case 'F':
+                    args[0] = new Integer(primDataSize);
+                    setOffsetMethod.invoke(_f, args);
+                    primDataSize += 4;
+                    break;
+
+                case 'J':
+                case 'D':
+                    args[0] = new Integer(primDataSize);
+                    setOffsetMethod.invoke(_f, args);
+                    primDataSize += 8;
+                    break;
+
+                case '[':
+                case 'L':
+                    args[0] = new Integer(numObjFields++);
+                    setOffsetMethod.invoke(_f, args);
+                    if (firstObjIndex == -1)
+                    {
+                        firstObjIndex = i;
+                    }
+                    break;
+
+                default:
+                    break;
+            }
+        }
+        if (firstObjIndex != -1 && firstObjIndex + numObjFields != fields.length)
+        {   
+            //throw new InvalidClassException(name, "illegal field order");
+        }
+    }
+
+}

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java Mon Mar 28 12:37:40 2005
@@ -19,9 +19,9 @@
 
 import org.apache.geronimo.interop.adapter.Adapter;
 
-public interface RemoteInterface {
+public interface RemoteInterface 
+{
       public ObjectRef getObjectRef();
-//      public RemoteInterface $getSkeleton();
+
       public void invoke(String method, byte[] objectKey, Adapter adapter, ObjectInputStream input, ObjectOutputStream output);
-//    public void $invoke(String method, byte[] objectKey, ObjectInputStream input, ObjectOutputStream output);
 }

Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleIDL.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleIDL.java?view=auto&rev=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleIDL.java (added)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleIDL.java Mon Mar 28 12:37:40 2005
@@ -0,0 +1,23 @@
+/**
+ *
+ *  Copyright 2004-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.interop.rmi.iiop;
+
+public interface SimpleIDL
+{
+    // Intentionally empty.
+}

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java Mon Mar 28 12:37:40 2005
@@ -24,8 +24,6 @@
 
 public class SimpleObjectInputStream extends ObjectInputStream
 {
-    //public static final Component component = new Component(SimpleObjectInputStream.class);
-
     public static ObjectInputStream getInstance()
     {
         ObjectInputStream ois = null;
@@ -34,7 +32,7 @@
         } catch (IOException e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
-        return ois; // getInstance(CdrInputStream.getInstance());
+        return ois;
     }
 
     public static ObjectInputStream getInstance(byte[] bytes)
@@ -44,14 +42,14 @@
 
     public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput)
     {
-        ObjectInputStream input = getInstance(); // (SimpleObjectInputStream)component.getInstance();
+        ObjectInputStream input = getInstance();
         input.init(cdrInput);
         return input;
     }
 
     public static ObjectInputStream getPooledInstance()
     {
-        ObjectInputStream input = null; // (SimpleObjectInputStream)_pool.get();
+        ObjectInputStream input = null;
         if (input == null)
         {
             input = getInstance();
@@ -63,8 +61,6 @@
     // private data
     // -----------------------------------------------------------------------
 
-    //private static ThreadLocalInstancePool _pool = new ThreadLocalInstancePool(SimpleObjectInputStream.class.getName());
-
     // -----------------------------------------------------------------------
     // public methods
     // -----------------------------------------------------------------------
@@ -82,7 +78,6 @@
     public void recycle()
     {
         $reset();
-        //_pool.put(this);
     }
 
     public Exception readException(ValueType type)

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java Mon Mar 28 12:37:40 2005
@@ -24,8 +24,6 @@
 
 public class SimpleObjectOutputStream extends ObjectOutputStream
 {
-    //public static final Component component = new Component(SimpleObjectOutputStream.class);
-
     public static ObjectOutputStream getInstance()
     {
         ObjectOutputStream oos = null;
@@ -34,19 +32,19 @@
         } catch (IOException e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
-        return oos; // getInstance(CdrOutputStream.getInstance());
+        return oos;
     }
 
     public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput)
     {
-        ObjectOutputStream output = getInstance(); // (SimpleObjectOutputStream)component.getInstance();
+        ObjectOutputStream output = getInstance();
         output.init(cdrOutput);
         return output;
     }
 
     public static ObjectOutputStream getPooledInstance()
     {
-        ObjectOutputStream output = null; // (SimpleObjectOutputStream)_pool.get();
+        ObjectOutputStream output = null;
         if (output == null)
         {
             output = getInstance();
@@ -58,8 +56,6 @@
     // private data
     // -----------------------------------------------------------------------
 
-    //private static ThreadLocalInstancePool _pool = new ThreadLocalInstancePool(SimpleObjectOutputStream.class.getName());
-
     // -----------------------------------------------------------------------
     // public methods
     // -----------------------------------------------------------------------
@@ -77,7 +73,6 @@
     public void recycle()
     {
         $reset();
-        //_pool.put(this);
     }
 
     public void writeException(ValueType type, Exception value)

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java Mon Mar 28 12:37:40 2005
@@ -17,14 +17,6 @@
  */
 package org.apache.geronimo.interop.rmi.iiop;
 
-/**
- ** Generated by Sybase EAServer 5.0 - Thu Nov 04 15:51:10 NZDT 2004
- **
- **   from com::sybase::djc::rmi::iiop::StringSeq (file C:/easme/build/idl/com-sybase-djc-rmi-iiop.idl, line 13).
- **
- ** Please do not modify this file.
- **/
-
 public abstract class StringSeqHelper
 {
     public static java.lang.String[] clone
@@ -104,6 +96,6 @@
 
     public static java.lang.String id()
     {
-        return "IDL:com/sybase/djc/rmi/iiop/StringSeq:1.0";
+        return "IDL:org/apache/geronimo/interop/rmi/iiop/StringSeq:1.0";
     }
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java Mon Mar 28 12:37:40 2005
@@ -17,14 +17,6 @@
  */
 package org.apache.geronimo.interop.rmi.iiop;
 
-/**
- ** Generated by Sybase EAServer 5.0 - Thu Nov 04 15:51:10 NZDT 2004
- **
- **   from com::sybase::djc::rmi::iiop::StringSeq (file C:/easme/build/idl/com-sybase-djc-rmi-iiop.idl, line 13).
- **
- ** Please do not modify this file.
- **/
-
 public final class StringSeqHolder implements org.omg.CORBA.portable.Streamable
 {
     public java.lang.String[] value;

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java Mon Mar 28 12:37:40 2005
@@ -281,7 +281,6 @@
         return default_id();
     }
 
-    // Sybase-internal
     /**
      * @param id
      */
@@ -338,7 +337,6 @@
         return _name;
     }
 
-    // Sybase-internal
     /**
      * @param name
      */
@@ -365,7 +363,6 @@
         return _member_name.length;
     }
 
-    // Sybase-internal
     /**
      * @param count
      */
@@ -407,7 +404,6 @@
         return _member_name[index];
     }
 
-    // Sybase-internal
     /**
      * @param index
      * @param name
@@ -441,7 +437,6 @@
         return _member_type[index];
     }
 
-    // Sybase-internal
     /**
      * @param index
      * @param type
@@ -475,7 +470,6 @@
         return _member_label[index];
     }
 
-    // Sybase-internal
     /**
      * @param index
      * @param label
@@ -504,7 +498,6 @@
         return _ref;
     }
 
-    // Sybase-internal
     /**
      * @param disc
      */
@@ -531,7 +524,6 @@
         return _default;
     }
 
-    // Sybase-internal
     /**
      * @param index
      */
@@ -567,7 +559,6 @@
         return _length;
     }
 
-    // Sybase-internal
     /**
      * @param length
      */
@@ -601,7 +592,6 @@
         return _ref;
     }
 
-    // Sybase-internal
     /**
      * @param type
      */
@@ -629,7 +619,6 @@
         return _digits;
     }
 
-    // Sybase-internal
     /**
      * @param digits
      */
@@ -657,7 +646,6 @@
         return _scale;
     }
 
-    // Sybase-internal
     /**
      * @param scale
      */
@@ -691,7 +679,6 @@
         return _member_visibility[index];
     }
 
-    // Sybase-internal
     /**
      * @param index
      * @param visibility
@@ -720,7 +707,6 @@
         return _type_modifier;
     }
 
-    // Sybase-internal
     /**
      * @param modifier
      */
@@ -748,7 +734,6 @@
         return _ref;
     }
 
-    // Sybase-internal
     /**
      * @param base
      */
@@ -757,7 +742,6 @@
         _ref = base;
     }
 
-    // Sybase-internal
     /**
      * @param ref
      */
@@ -767,7 +751,6 @@
         _indirection = true;
     }
 
-    // Sybase-internal
     /**
      * @param id
      */
@@ -778,7 +761,6 @@
         _indirection = true;
     }
 
-    // Sybase-internal
     /**
      *
      */

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java Mon Mar 28 12:37:40 2005
@@ -26,10 +26,13 @@
 import java.util.*;
 import org.omg.CORBA.TCKind;
 
+/**
+ ** A wrapper over java.lang.Class to help improve performance of using
+ ** the Java reflection API for valuetype marshalling. We keep as much
+ ** derived information as possible for optimal performance.
+ **/
 public class ValueType
 {
-    //public static final Component component = new Component(ValueType.class);
-
     public static ValueType getInstance(Class forClass)
     {
         ValueType vt = (ValueType)_valueTypeMap.get(forClass);
@@ -40,7 +43,6 @@
                 vt = (ValueType)_valueTypeMap.get(forClass);
                 if (vt == null)
                 {
-                    //vt = (ValueType)component.getInstance();
                     vt = new ValueType();
                     _valueTypeMap.put(forClass, vt);
                     vt.init(forClass);
@@ -524,14 +526,14 @@
     {
         final String sixteenZeros = "0000000000000000";
         final int requiredLength = 16;
-        if (isAny)
+       /* if (isAny)
         {
             id = "#ANY-TODO#";
             return;
-        }
+        }*/
         if (isArray && primitiveArray != 0)
         {
-            id = "#ARRAY-TODO#";
+            id = "RMI:" + _class.getName() + ":" + sixteenZeros;
             return;
         }
         if (_class == String.class)
@@ -551,8 +553,7 @@
         }
         if (_class == java.math.BigInteger.class)
         {
-            id = "RMI:java.math.BigInteger:8CAD1A3C6C0A9DF0:8CFC9F1FA93BFB1D";
-            skipCustomFlags = true; // TODO: move this and check usage
+            id = "RMI:java.math.BigInteger:E2F79B6E7A470003:8CFC9F1FA93BFB1D";
             return;
         }
         if (_objectStreamClass == null)
@@ -759,6 +760,11 @@
         {
             throw new org.omg.CORBA.INV_IDENT(id);
         }
+    }
+
+    public Class getTheClass()
+    {
+        return _class;
     }
 
     static Class loadClass(String className)

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java Mon Mar 28 12:37:40 2005
@@ -17,9 +17,7 @@
  */
 package org.apache.geronimo.interop.rmi.iiop.client;
 
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Random;
+import java.util.*;
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NameNotFoundException;
@@ -36,14 +34,19 @@
 import org.apache.geronimo.interop.rmi.iiop.compiler.StubFactory;
 import org.apache.geronimo.interop.util.ExceptionUtil;
 
-public class ClientNamingContext implements Context, java.io.Serializable {
+public class ClientNamingContext implements Context, java.io.Serializable 
+{
 
-    public static ClientNamingContext getInstance(Hashtable env) {
+    public static ClientNamingContext getInstance(Hashtable env)
+    {
         ClientNamingContext nc = (ClientNamingContext) contextMap.get(env);
-        if (nc == null) {
-            synchronized (contextMap) {
+        if (nc == null)
+        {
+            synchronized (contextMap)
+            {
                 nc = (ClientNamingContext) contextMap.get(env);
-                if (nc == null) {
+                if (nc == null) 
+                {
                     nc = new ClientNamingContext();
                     nc.init(env);
                     contextMap.put(env, nc);
@@ -53,54 +56,72 @@
         return nc;
     }
 
-    public static final StringProperty usernameProperty =
-            new StringProperty(SystemProperties.class, "java.naming.security.principal");
-
-    public static final StringProperty passwordProperty =
-            new StringProperty(SystemProperties.class, "java.naming.security.credentials");
 
     public static final IntProperty idleConnectionTimeoutProperty =
-            new IntProperty(SystemProperties.class, "org.apache.geronimo.interop.rmi.idleConnectionTimeout")
-            .defaultValue(60); // seconds
+        new IntProperty(SystemProperties.class, "idleConnectionTimeout")
+        .defaultValue(60); // 60 seconds
+
+    public static final IntProperty lookupCacheTimeoutProperty =
+        new IntProperty(SystemProperties.class, "lookupCacheTimeout")
+        .defaultValue(600); // 10 minutes
+
+    public static final StringProperty usernameSystemProperty =
+        new StringProperty(SystemProperties.class, "java.naming.security.principal");
 
-    private static int idleConnectionTimeout =
-            idleConnectionTimeoutProperty.getInt();
+    public static final StringProperty passwordSystemProperty =
+        new StringProperty(SystemProperties.class, "java.naming.security.credentials");
 
-    private static int namingContextCacheTimeout =
-            SystemProperties.rmiNamingContextCacheTimeoutProperty.getInt();
+    private static long     idleConnectionTimeout;
+
+    private static long     lookupCacheTimeout;
+
+    private static int      socketTimeout;
 
     private static HashMap  contextMap = new HashMap();
+
     private static HashMap  hostListCache = new HashMap();
-    private static HashMap  multiHostMap = new HashMap();
-    private static Random   random = new Random();
+
+//    private ArrayList       requestKeys;
+
     private HashMap         cache = new HashMap();
+
     private Hashtable       env;
+
     private ConnectionPool  connectionPool;
+
     private PropertyMap     connectionProperties;
+
     static private HashMap  nameMap = new HashMap();
-    private String          prefix;
+
     private String          username;
+
     private String          password;
 
+    private String          namePrefix;
+
     private org.apache.geronimo.interop.CosNaming.NamingContext serverNamingContext;
 
     public ConnectionPool getConnectionPool() {
         return connectionPool;
     }
 
-    public PropertyMap getConnectionProperties() {
+    public PropertyMap getConnectionProperties()
+    {
         return connectionProperties;
     }
 
-    public int getIdleConnectionTimeout() {
+    public long getIdleConnectionTimeout()
+    {
         return idleConnectionTimeout;
     }
 
-    public String getUsername() {
+    public String getUsername()
+    {
         return username;
     }
 
-    public String getPassword() {
+    public String getPassword()
+    {
         return password;
     }
 
@@ -268,11 +289,11 @@
         throw new OperationNotSupportedException();
     }
 
-    protected void init(Hashtable env) {
-        env = env;
+    protected void init(Hashtable env) 
+    {
+        this.env = env;
         Object urlObject = env.get(Context.PROVIDER_URL);
         if (urlObject == null) {
-            System.out.println("ClientNamingContext.init(): TODO: urlObject was null, create one based on the current hostname.");
             urlObject = SystemProperties.getInstance().getProperty("java.naming.provider.url",
                                                                    "iiop://" + "delafran-t30" + ":2000");
         }
@@ -280,59 +301,88 @@
         UrlInfo urlInfo = UrlInfo.getInstance(url);
         serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext)
                 StubFactory.getInstance().getStub(org.apache.geronimo.interop.CosNaming.NamingContext.class);
+
+        namePrefix = urlInfo.getNamePrefix();
+
         ObjectRef ncRef = (ObjectRef) serverNamingContext;
         ncRef.$setNamingContext(this);
         ncRef.$setProtocol(urlInfo.getProtocol());
         ncRef.$setHost("ns~" + urlInfo.getHost());
         ncRef.$setPort(urlInfo.getPort());
         ncRef.$setObjectKey(urlInfo.getObjectKey());
-        connectionProperties = urlInfo.getProperties();
         connectionPool = ConnectionPool.getInstance(this);
         Object u = env.get(Context.SECURITY_PRINCIPAL);
         Object p = env.get(Context.SECURITY_CREDENTIALS);
-        if (u == null) {
-            u = usernameProperty.getString();
+        if (u == null)
+        {
+            u = usernameSystemProperty.getString();
         }
-        if (p == null) {
-            p = passwordProperty.getString();
+        if (p == null)
+        {
+            p = passwordSystemProperty.getString();
         }
         username = u != null ? u.toString() : null;
         password = p != null ? p.toString() : null;
 
-        /*
-        if (_serverNamingContext._is_a("IDL:org.apache.geronimo.interop/rmi/iiop/NameService:1.0"))
+        PropertyMap props = urlInfo.getProperties();
+        props.putAll(env);
+        PropertyMap copyProps = new PropertyMap();
+        copyProps.putAll(props);
+        for (Iterator i = copyProps.entrySet().iterator(); i.hasNext();)
         {
-            _serverNamingContext = (org.apache.geronimo.interop.rmi.iiop.NameService)
-                StubFactory.getInstance().getStub(org.apache.geronimo.interop.rmi.iiop.NameService.class);
-            ncRef = (ObjectRef)_serverNamingContext;
-            ncRef.$setNamingContext(this);
-            ncRef.$setProtocol(urlInfo.getProtocol());
-            ncRef.$setHost("ns~" + urlInfo.getHost());
-            ncRef.$setPort(urlInfo.getPort());
-            ncRef.$setObjectKey(urlInfo.getObjectKey());
+            Map.Entry entry = (Map.Entry)i.next();
+            String property = (String)entry.getKey();
+            Object value = entry.getValue();
+
+            String startsWith = "org.apache.geronimo.interop.rmi.";
+            if (property.startsWith(startsWith))
+            {
+                int replace = startsWith.length();
+                props.remove(property);
+                props.put(property.substring(replace), value);
+            }
         }
-        */
+        for (Iterator i = SystemProperties.getInstance().entrySet().iterator(); i.hasNext();)
+        {
+            Map.Entry entry = (Map.Entry)i.next();
+            String property = (String)entry.getKey();
+            Object value = entry.getValue();
+            if (property.startsWith("djc."))
+            {
+                props.put(property.substring(4), value);
+            }
+        }
+        connectionProperties = props;
+        idleConnectionTimeout = 1000 * idleConnectionTimeoutProperty.getInt(url, props);
+        lookupCacheTimeout = 1000 * lookupCacheTimeoutProperty.getInt(url, props);
     }
 
-    protected NameBinding resolve(String name) throws NamingException {
+    protected NameBinding resolve(String name) throws NamingException
+    {
         Object value = org.apache.geronimo.interop.naming.NameService.getInitialContext().lookupReturnNullIfNotFound(name);
-        if (value != null) {
+        if (value != null)
+        {
             NameBinding nb = new NameBinding();
             nb.object = value;
-            nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout;
+            nb.cacheTimeout = System.currentTimeMillis() + lookupCacheTimeout;
             return nb;
         }
-        try {
+        try
+        {
             org.apache.geronimo.interop.CosNaming.NameComponent[] resolveName =
-                    {new org.apache.geronimo.interop.CosNaming.NameComponent(name, "")};
+                { new org.apache.geronimo.interop.CosNaming.NameComponent(namePrefix + name, "") };
             org.omg.CORBA.Object object = serverNamingContext.resolve(resolveName);
             NameBinding nb = new NameBinding();
             nb.object = object;
-            nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout;
+            nb.cacheTimeout = System.currentTimeMillis() + lookupCacheTimeout;
             return nb;
-        } catch (org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound notFound) {
+        }
+        catch (org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound notFound)
+        {
             throw new NameNotFoundException(name);
-        } catch (Exception ex) {
+        }
+        catch (Exception ex)
+        {
             throw new javax.naming.NamingException(ExceptionUtil.getStackTrace(ex));
         }
     }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java Mon Mar 28 12:37:40 2005
@@ -18,6 +18,8 @@
 package org.apache.geronimo.interop.rmi.iiop.client;
 
 import java.net.Socket;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
 
 import org.apache.geronimo.interop.GIOP.*;
 import org.apache.geronimo.interop.IOP.*;
@@ -26,25 +28,31 @@
 import org.apache.geronimo.interop.properties.IntProperty;
 import org.apache.geronimo.interop.properties.PropertyMap;
 import org.apache.geronimo.interop.properties.SystemProperties;
-import org.apache.geronimo.interop.rmi.iiop.BadMagicException;
-import org.apache.geronimo.interop.rmi.iiop.CdrInputStream;
-import org.apache.geronimo.interop.rmi.iiop.CdrOutputStream;
-import org.apache.geronimo.interop.rmi.iiop.GiopMessage;
-import org.apache.geronimo.interop.rmi.iiop.ObjectRef;
-import org.apache.geronimo.interop.rmi.iiop.SecurityInfo;
-import org.apache.geronimo.interop.rmi.iiop.UnsupportedProtocolVersionException;
+import org.apache.geronimo.interop.rmi.iiop.*;
 import org.apache.geronimo.interop.util.ExceptionUtil;
 import org.apache.geronimo.interop.util.InstancePool;
 import org.apache.geronimo.interop.util.StringUtil;
 import org.apache.geronimo.interop.util.ThreadContext;
 import org.apache.geronimo.interop.util.UTF8;
 
-public class Connection {
+public class Connection 
+{
 
-    public Connection() {
+    private static final byte reservedBA[] = new byte[] { 0, 0, 0};
+    private int requestid_ = 0;
+    
+    // http tunnelling related
+    private boolean httpTunnelled;
+    private String  httpHeaders;
+    private String  webProxyHost;
+    private int     webProxyPort;
+
+    public Connection()
+    {
     }
 
-    public static Connection getInstance(String endpoint, ObjectRef objectRef, PropertyMap connProps) {
+    public static Connection getInstance(String endpoint, ObjectRef objectRef, PropertyMap connProps) 
+    {
         Connection conn = new Connection();
         conn.init(endpoint, objectRef, connProps);
         return conn;
@@ -55,40 +63,69 @@
 
     public static final IntProperty socketTimeoutProperty =
             new IntProperty(Connection.class, "socketTimeout")
-            .defaultValue(SystemProperties.rmiSocketTimeoutProperty.getInt());
+            .defaultValue(600); // 10 minutes
+
+    private static final boolean SIMPLE_IDL = simpleIDLProperty.getBoolean();
+
+    private static final ServiceContext[] EMPTY_SERVICE_CONTEXT = {};
+
+    private static final byte[] CODE_SET_ENCAPSULATION =
+    {
+        (byte)0, // big endian
+        (byte)0, (byte)0, (byte)0, // padding
+        (byte)0x05, (byte)0x01, (byte)0x00, (byte)0x01, // 0x05010001 = CodeSet ID for UTF-8
+        (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x09, // 0x00010109 = CodeSet ID for UTF-16
+    };
+
+    private static final ServiceContext CODE_SET_SERVICE_CONTEXT = new ServiceContext(1, CODE_SET_ENCAPSULATION);
 
-    private static final boolean SIMPLE_IDL = false; // simpleIDLProperty.getBoolean();
-    private ServiceContext[]    EMPTY_SERVICE_CONTEXT = {};
     private String              url;
+
     private boolean             ok;
+
     private InstancePool        pool;
-    private String              serverHost;
+
     private Socket              socket;
+
+    protected org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input;
+
+    protected org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output;
+
     private CdrOutputStream     parameters;
+
     private CdrOutputStream     requestOut;
+
     private CdrInputStream      results;
+
     private String              exceptionType;
+
     private Exception           exception;
+
     private RequestHeader_1_2   requestHeader;
+
     private int                 callForget;
 
-    private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream  input;
-    private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output;
 
     protected java.io.InputStream   socketIn;
+
     protected java.io.OutputStream  socketOut;
 
-    public String getInstanceName() {
+    public String getInstanceName() 
+    {
         return url;
     }
 
-    public void close() {
+    public void close() 
+    {
         parameters = null;
         input = null;
         output = null;
-        if (ok) {
+        if (ok) 
+        {
             pool.put(this);
-        } else {
+        }
+        else
+        {
             shutdown();
         }
     }
@@ -101,62 +138,85 @@
     public void forget(Object requestKey) {
     }
 
-    public void invoke(ObjectRef object, String method, Object requestKey, int retryCount) {
-        RequestHeader_1_2 request = requestHeader;
+    public void invoke(ObjectRef object, String method, Object requestKey, int retryCount)
+    {
+        if(object.$getForwardingAddress() != null)
+        {
+            object = object.$getForwardingAddress();
+        }
 
-        System.out.println( "object = " + object );
-        System.out.println( "method = " + method );
-        System.out.println( "requestKey = " + requestKey );
+        RequestHeader_1_2 request = requestHeader;
 
-        request.request_id = 0;
+        request.request_id = requestid_++;
         request.response_flags = 3;
         request.target = new TargetAddress();
         request.target.object_key(object.$getObjectKey());
         request.operation = method;
         request.service_context = getServiceContext(object, requestKey, retryCount);
+        request.reserved = reservedBA;  // Sun's generated org.omg.GIOP.RequestHeader_1_2Helper wants this....
 
-        request.reserved = new byte[3];  // Sun's generated org.omg.GIOP.RequestHeader_1_2Helper wants this....
-
-        if (requestOut == null) {
-            System.out.println( "requestOut == null" );
+        if (requestOut == null)
+        {
             requestOut = CdrOutputStream.getInstance();
         }
-        System.out.println( "write_request" );
         requestOut.write_request(request, parameters);
 
-        try {
-            requestOut.send_message(socketOut, url);//_serverHost);
+
+        try 
+        {
+            if(httpTunnelled)
+            {
+                requestOut.send_http_request(socketOut, url, httpHeaders);
+            }
+            else
+            {
+                requestOut.send_message(socketOut, url);
+            }
         } catch (RuntimeException ex) {
-            //if (object.$getAutomaticFailover())
-            //{
-            //    throw new RetryInvokeException(ex);
-            //}
             throw ex;
         }
 
         requestOut.reset();
 
-        if (results == null) {
+        if (results == null)
+        {
             results = CdrInputStream.getInstance();
-        } else {
+        }
+        else
+        {
             results.reset();
         }
 
         results.setNamingContext(object.$getNamingContext());
         GiopMessage message;
-        try {
-            message = results.receive_message(socketIn, url);//_serverHost);
-        } catch (BadMagicException ex) {
+        try
+        {
+            if(httpTunnelled)
+            {
+                message = results.receive_http_response(socketIn, url);
+            }
+            else
+            {
+                message = results.receive_message(socketIn, url);//_serverHost);
+            }
+        }
+        catch (BadMagicException ex)
+        {
             throw new SystemException(ex);
-        } catch (UnsupportedProtocolVersionException ex) {
+        }
+        catch (UnsupportedProtocolVersionException ex)
+        {
             throw new SystemException(ex);
-        } catch (RuntimeException ex) {
+        }
+        catch (RuntimeException ex)
+        {
             throw new RetryInvokeException(ex);
         }
 
-        switch (message.type) {
-            case MsgType_1_1._Reply:
-                processReply(message.reply);
+        switch (message.type)
+        {
+          case MsgType_1_1._Reply:
+                processReply(message.reply, object);
                 break;
 
             default:
@@ -224,23 +284,75 @@
         }
     }
 
+    public void clearException()
+    {
+        exceptionType = null;
+        exception = null;
+    }
+
     // TODO: check why we have 'objectRef' parameter???
-    protected void init(String endpoint, ObjectRef objectRef, PropertyMap connProps) {
+    protected void init(String endpoint, ObjectRef objectRef, PropertyMap connProps)
+    {
+        setHttpTunnelledPropsIfTrue(connProps);
+
+        if(httpTunnelled)
+        {
+            httpInit(endpoint, connProps);
+            return;
+        }
+
         url = "iiop://" + endpoint;
         UrlInfo urlInfo = UrlInfo.getInstance(url);
         String host = urlInfo.getHost();
         int port = urlInfo.getPort();
         int socketTimeout = socketTimeoutProperty.getInt(endpoint, connProps);
-        try {
+        try
+        {
+            socket = new Socket(host, port);
+            socketIn = socket.getInputStream();
+            socketOut = socket.getOutputStream();
+            socket.setSoTimeout(1000 * socketTimeout);
+        }
+        catch (Exception ex) 
+        {
+            throw new SystemException(ex);
+        }
+        requestHeader = new RequestHeader_1_2();
+        requestHeader.reserved = reservedBA;
+    }
+
+    private void httpInit(String endpoint, PropertyMap connProps)
+    {
+        String host = null;
+        int port;
+        url = "iiop://" + endpoint;
+        int socketTimeout = socketTimeoutProperty.getInt(endpoint, connProps);
+
+        if(webProxyHost != null)
+        {
+            host = webProxyHost;
+            port = webProxyPort;
+        }
+        else
+        {
+            UrlInfo urlInfo = UrlInfo.getInstance(url);
+            host = urlInfo.getHost();
+            port = urlInfo.getPort();
+        }
+
+        try
+        {
             socket = new Socket(host, port);
             socketIn = socket.getInputStream();
             socketOut = socket.getOutputStream();
             socket.setSoTimeout(1000 * socketTimeout);
-            serverHost = host;
-        } catch (Exception ex) {
-            throw new SystemException(errorConnectFailed(host, port, ex));
+        }
+        catch (IOException ex)
+        {
+            throw new SystemException(ex);
         }
         requestHeader = new RequestHeader_1_2();
+        requestHeader.reserved = reservedBA;
     }
 
     public ServiceContext[] getServiceContext(ObjectRef object, Object requestKey, int retryCount) {
@@ -276,53 +388,53 @@
         if (requestKey != null) {
             count++;
         }
-        if (count == 0) {
-            return EMPTY_SERVICE_CONTEXT; // avoid allocating empty array.
-        }
         ServiceContext[] context = new ServiceContext[count];
         int index = 0;
+        context[index++] = CODE_SET_SERVICE_CONTEXT;
         if (username != null) {
             context[index++] = new ServiceContext(SecurityInfo.TAG_USERNAME, SecurityInfo.encode(username));
         }
         if (password != null) {
             context[index++] = new ServiceContext(SecurityInfo.TAG_PASSWORD, SecurityInfo.encode(password));
         }
-        if (requestKey != null) {
-            if (retryCount == 0) {
-                // 'BF' indicates Before Failure
-                context[index++] = new ServiceContext(0xBFBFBFBF, UTF8.fromString((String) requestKey));
-            } else {
-                // 'AF' indicates After Failure
-                context[index++] = new ServiceContext(0xAFAFAFAF, UTF8.fromString((String) requestKey));
-            }
-        }
         return context;
     }
 
-    protected void processReply(ReplyHeader_1_2 reply) {
+    protected void processReply(ReplyHeader_1_2 reply, ObjectRef object)
+    {
         processReplyServiceContext(reply);
         int status = reply.reply_status.value();
-        switch (status) {
-            case ReplyStatusType_1_2._NO_EXCEPTION:
-                processNormalReply(reply);
-                break;
-            case ReplyStatusType_1_2._USER_EXCEPTION:
-                processUserException(reply);
-                break;
-            case ReplyStatusType_1_2._SYSTEM_EXCEPTION:
-                processSystemException(reply);
-                break;
-            case ReplyStatusType_1_2._LOCATION_FORWARD:
-                throw new SystemException("TODO");
-            case ReplyStatusType_1_2._LOCATION_FORWARD_PERM:
-                throw new SystemException("TODO");
-            case ReplyStatusType_1_2._NEEDS_ADDRESSING_MODE:
-                throw new SystemException("TODO");
-            default:
-                throw new SystemException("reply status = " + status);
+        switch (status)
+        {
+          case ReplyStatusType_1_2._NO_EXCEPTION:
+            processNormalReply(reply);
+            break;
+          case ReplyStatusType_1_2._USER_EXCEPTION:
+            processUserException(reply);
+            break;
+          case ReplyStatusType_1_2._SYSTEM_EXCEPTION:
+            processSystemException(reply);
+            break;
+          case ReplyStatusType_1_2._LOCATION_FORWARD:
+            processLocationForward(reply, object);
+            break;
+          case ReplyStatusType_1_2._LOCATION_FORWARD_PERM:
+            processLocationForward(reply, object);
+            break;
+          case ReplyStatusType_1_2._NEEDS_ADDRESSING_MODE:
+            throw new SystemException("TODO");
+          default:
+            throw new SystemException("reply status = " + status);
         }
     }
 
+    protected void processLocationForward(ReplyHeader_1_2 reply, ObjectRef object)
+    {
+        ObjectRef ref = (ObjectRef)results.read_Object();
+        object.$setForwardingAddress(ref);
+        throw new RetryInvokeException(new RuntimeException("LOCATION_FORWARD"));
+    }
+
     protected void processReplyServiceContext(ReplyHeader_1_2 reply) {
         ServiceContext[] list = reply.service_context;
         int n = list.length;
@@ -341,35 +453,126 @@
         // Intentionally empty.
     }
 
-    protected void processUserException(ReplyHeader_1_2 reply) {
+    protected void processUserException(ReplyHeader_1_2 reply)
+    {
         exception = null;
-        exceptionType = results.read_string();
+        String type = results.read_string();
+        type = StringUtil.removePrefix(type, "IDL:");
+        type = StringUtil.removeSuffix(type, ":1.0");
+        if (! (input instanceof SimpleObjectInputStream))
+        {
+            if (type.endsWith("Ex"))
+            {
+                type = StringUtil.removeSuffix(type, "Ex") + "Exception";
+            }
+        }
+        type = type.replace('/', '.');
+        exceptionType = type;
         ok = true;
     }
 
-    protected void processSystemException(ReplyHeader_1_2 reply) {
+    protected void processSystemException(ReplyHeader_1_2 reply)
+    {
         exceptionType = "???";
         SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(results);
         String id = replyBody.exception_id;
+        id = StringUtil.removePrefix(id, "IDL:CORBA/"); // ancient servers might send this!
         id = StringUtil.removePrefix(id, "IDL:omg.org/CORBA/");
         id = StringUtil.removeSuffix(id, ":1.0");
-        String stackTrace = null;
-        if (results.hasMoreData()) {
-            stackTrace = results.read_string() + ExceptionUtil.getDivider();
+        String causedBy = null;
+        if (results.hasMoreData())
+        {
+            // This is non-standard for IIOP, but if the data isn't present,
+            // we wont try to read it!
+            causedBy = ExceptionUtil.causedBy(results.read_string());
         }
         ok = true;
         String exceptionClassName = "org.omg.CORBA." + id;
-        try {
+        try
+        {
             Class exceptionClass = ThreadContext.loadClass(exceptionClassName);
-            org.omg.CORBA.SystemException corbaException = (org.omg.CORBA.SystemException) exceptionClass.newInstance();
+            Constructor constructor = exceptionClass.getConstructor
+            (
+                new Class[] { String.class }
+            );
+            org.omg.CORBA.SystemException corbaException;
+            corbaException = (org.omg.CORBA.SystemException)constructor.newInstance
+            (
+                new Object[] { causedBy == null ? "" : causedBy }
+            );
             corbaException.minor = replyBody.minor_code_value;
             corbaException.completed = org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status);
-            exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException);
-        } catch (Exception ex) {
-            exception = new org.apache.geronimo.interop.SystemException(stackTrace,
-                                                                         new org.omg.CORBA.UNKNOWN(replyBody.exception_id,
-                                                                                                   replyBody.minor_code_value,
-                                                                                                   org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status)));
+            exception = corbaException;
+        }
+        catch (Exception ex)
+        {
+            // Shouldn't happen, but just in case
+            ex.printStackTrace();
+            if (causedBy == null)
+            {
+                causedBy = replyBody.exception_id;
+            }
+            else
+            {
+                causedBy = replyBody.exception_id + "\nCaused by: " + causedBy;
+            }
+            exception = new org.omg.CORBA.UNKNOWN(causedBy,
+                replyBody.minor_code_value,
+                org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status));
+        }
+    }
+
+    private void setHttpTunnelledPropsIfTrue(PropertyMap connprops)
+    {
+        if(connprops.get("http") != null)
+        {
+            httpTunnelled = true;
+        }
+        else
+        {
+            httpTunnelled = false;
+        }
+
+        if(httpTunnelled)
+        {
+            // get http extra headers if present
+            httpHeaders = connprops.getProperty("HttpExtraHeader");
+            
+            if(httpHeaders != null && httpHeaders.toLowerCase().indexOf("user-agent") == -1)
+            {
+                httpHeaders += "User-Agent: Geronimo/1.0\r\n";
+            }
+
+            if(httpHeaders == null)
+            {
+                httpHeaders = "User-Agent: Geronimo/1.0\r\n";
+            }
+
+            //get webproxy host/port if present:
+            webProxyHost = connprops.getProperty("WebProxyHost");
+            String port = connprops.getProperty("WebProxyPort");
+            
+            if(port != null)
+            {
+                try
+                {
+                    webProxyPort = java.lang.Integer.parseInt(port);
+                }
+                catch(java.lang.NumberFormatException e)
+                {
+                    throw new SystemException(org.apache.geronimo.interop.util.ExceptionUtil.causedBy(e));
+                }
+            }
+
+            if(port == null && webProxyHost != null)
+            {
+                webProxyPort = 80;  //default
+            }
+        }
+        else
+        {
+            webProxyHost = null;
+            httpHeaders = null;
         }
     }
 
@@ -395,11 +598,5 @@
             }
             socket = null;
         }
-    }
-
-    protected String errorConnectFailed(String host, int port, Exception ex) {
-        String msg;
-        msg = "Error: errorConnectFailed: host=" + host + ", port=" + port + ", ex = " + ex;
-        return msg;
     }
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java Mon Mar 28 12:37:40 2005
@@ -30,6 +30,14 @@
 import org.apache.geronimo.interop.util.StringUtil;
 
 public class UrlInfo {
+
+    private String namePrefix = "";
+    private int    ver;
+    
+    final static int IIOP_1_0 = 0;
+    final static int IIOP_1_1 = 1;
+    final static int IIOP_1_2 = 2;
+
     public static UrlInfo getInstance(String url) {
         UrlInfo object = new UrlInfo();
         object.init(url);
@@ -46,12 +54,41 @@
     }
 
     private int         protocol;
+
     private String      host;
+
     private int         port;
+
     private String      objectKey;
+
     private PropertyMap properties;
 
-    protected void init(String urlString) {
+    private boolean handleUrl(String url)
+    {
+        if(!UrlScheme.canProcess(url))
+            return false;
+
+        UrlScheme us = new UrlScheme(url);
+        us.process();
+        
+        host = us.getHost(0);
+        port = us.getPort(0);
+        ver = us.getVersion(0);
+        objectKey = us.getObjectKey();
+        namePrefix = us.getNamePrefix();
+        properties = new PropertyMap();
+        protocol = Protocol.IIOP;
+        
+        return true;
+    }
+
+    protected void init(String urlString)
+    {
+        if(handleUrl(urlString))
+        {
+            return;
+        }
+
         int cssPos = urlString.indexOf("://");
         if (cssPos == -1) {
             throw new IllegalArgumentException(urlString);
@@ -120,6 +157,16 @@
 
     public PropertyMap getProperties() {
         return properties;
+    }
+
+    public String getNamePrefix()
+    {
+        return namePrefix;
+    }
+
+    public int getVersion()
+    {
+        return ver;
     }
 
     public String toString() {

Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlScheme.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlScheme.java?view=auto&rev=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlScheme.java (added)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlScheme.java Mon Mar 28 12:37:40 2005
@@ -0,0 +1,280 @@
+/**
+ *
+ *  Copyright 2004-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.interop.rmi.iiop.client;
+
+/**
+ * corbaname and corbaloc urls
+ */
+
+public class UrlScheme
+{
+    class Addr
+    {
+        Addr(String h, int port, int ver)
+        {
+            _host = h;
+            _port = port;
+            _version = ver;
+        }
+
+        String _host;
+        int    _port;
+        int    _version;
+    }
+
+    static final int IIOP_1_0 = 0;
+    static final int IIOP_1_1 = 1;
+    static final int IIOP_1_2 = 2;
+
+    private boolean _corbaloc, _corbaname;
+    private java.util.ArrayList _addrList;
+    private String _url;
+    private String _namePrefix;
+    private String _objKey;
+
+    public UrlScheme(String url)
+    {
+        _url = url;
+        _addrList = new java.util.ArrayList();
+    }
+
+    public String getHost(int i)
+    {
+        Addr addr = getEntry(i);
+        return addr._host;
+    }
+
+    public int getPort(int i)
+    {
+        Addr addr = getEntry(i);
+        return addr._port;
+    }
+
+    public int getVersion(int i)
+    {
+        Addr addr = getEntry(i);
+        return addr._version;
+    }
+
+    public String getObjectKey()
+    {
+        return _objKey;
+    }
+
+    public String getNamePrefix()
+    {
+        return _namePrefix;
+    }
+
+    public int getAddressCount()
+    {
+        return _addrList.size();
+    }
+
+    private Addr getEntry(int i)
+    {
+        try
+        {
+            return (Addr)_addrList.get(i);
+        }
+        catch(IndexOutOfBoundsException e)
+        {
+            throw new IllegalArgumentException(_url);
+        }
+    }
+
+    public static boolean canProcess(String url)
+    {
+        return url.startsWith("corbaloc:") || url.startsWith("corbaname:");
+    }
+
+    public boolean process()
+    {
+        boolean handled = false;
+
+        String cloc = "corbaloc:";
+        String cname = "corbaname:";
+        
+        _corbaloc = _url.startsWith(cloc);
+        _corbaname =_url.startsWith(cname);
+
+        if(_corbaloc || _corbaname)
+        {
+            try
+            {
+                int keySep = _url.indexOf("/");
+                int nameSep = _url.indexOf("#");
+
+                if(keySep > nameSep) //we may have "/" in a name
+                {
+                    keySep = -1;
+                }
+        
+                int addrStart = _corbaloc ? "corbaloc:".length() : "corbaname:".length();
+                String addrlist;
+                
+                if(keySep != -1)
+                {
+                    addrlist = _url.substring(addrStart, keySep);
+                }
+                else if(nameSep != -1)
+                {
+                    addrlist = _url.substring(addrStart, nameSep);
+                }
+                else
+                {
+                    addrlist = _url.substring(addrStart);
+                }
+
+                readAddrList(addrlist);
+                readKeyAndName(keySep, nameSep);
+            }
+            catch(Exception e)
+            {
+                throw new IllegalArgumentException(_url);
+            }
+        }
+
+        return handled;
+    }
+
+    //addr,addr...
+    private void readAddrList(String addrlist)
+    {
+        java.util.StringTokenizer tk = new java.util.StringTokenizer(addrlist, ",");
+        if(tk.countTokens() < 1)
+        {
+            throw new IllegalArgumentException(_url);
+        }
+        
+        while(tk.hasMoreElements())
+        {
+            String addr = tk.nextToken();
+            readAddr(addr);
+        }
+    }
+
+    //supported protocol: iiop
+    //addr       <-   <":" | "iiop:">[<version><host> [":" <port>]]
+    //version    <-   <major>.<minor>"@" | empty_string
+
+    private void readAddr(String addr)
+    {
+        String host;
+        int port, ver = IIOP_1_2;
+
+        int addrlen = addr.length();
+
+        if(!addr.startsWith("iiop:") && !addr.startsWith(":"))
+        {
+            throw new IllegalArgumentException(_url);
+        }
+
+        int curindex = addr.indexOf(":") + 1;
+
+        //VERSION
+        if( (curindex + 3) < addrlen && addr.charAt(curindex + 3) == '@' )
+        {
+            if(addr.startsWith("1.0@", curindex))
+            {
+                ver = IIOP_1_0;
+            }
+            else if(addr.startsWith("1.1@", curindex))
+            {
+                ver = IIOP_1_1;
+            }
+            else if(addr.startsWith("1.2@", curindex))
+            {
+                ver = IIOP_1_2;
+            }
+            else
+            {
+                throw new IllegalArgumentException(_url);
+            }
+            curindex += 4;
+        }
+
+        //defaults
+        host = "localhost";
+        port = 2089; 
+
+        //HOST
+        if(curindex < addrlen)
+        {
+            //is it ipv6 address? (Enclosed between '[' and ']')
+            if(addr.charAt(curindex) == '[')
+            {
+                int lastindex = addr.indexOf(']', curindex);
+                if(-1 == lastindex)
+                {
+                    throw new IllegalArgumentException(_url);
+                }
+                host = addr.substring(curindex, lastindex + 1);
+                curindex = lastindex + 1;
+            }
+            else if(addr.charAt(curindex) != ':')
+            {
+                int i = addr.indexOf(":", curindex);
+                if(-1 == i)
+                {
+                    i = addrlen;
+                }
+                host = addr.substring(curindex, i);
+                curindex = i + 1;
+            }
+        }
+
+        //PORT
+        if(curindex < addrlen)
+        {
+            try
+            {
+                String sport = addr.substring(curindex);
+                port = new Integer(sport).intValue();
+            }
+            catch(NumberFormatException e)
+            {
+                throw new IllegalArgumentException(_url);
+            }
+        }
+
+        _addrList.add(new Addr(host, port, ver));
+    }
+
+    //TODO: key may be escaped
+    private void readKeyAndName(int keySep, int nameSep)
+    {
+        _objKey = "NameService";
+        _namePrefix = "";
+
+        if(keySep != -1)
+        {
+            int i = nameSep;
+            if(-1 == i)
+            {
+                i = _url.length();
+            }
+            _objKey = _url.substring(keySep + 1, i);
+        }
+
+        if(nameSep != -1)
+        {
+            _namePrefix = _url.substring(nameSep + 1);
+        }
+    }
+}

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java Mon Mar 28 12:37:40 2005
@@ -236,12 +236,12 @@
         //            catch (java.lang.Exception $ex_1)
         //            {
         //                Listed here are the individual catches that the method can throw
-        //                if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.NotFound)
+        //                if ($ex_1 instanceof org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound)
         //                {
         //                    $output.writeException(type$4, $ex_1);
         //                    return;
         //                }
-        //                if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.CannotProceed)
+        //                if ($ex_1 instanceof org.apache.geronimo.interop.CosNaming.NamingContextPackage.CannotProceed)
         //                {
         //                    $output.writeException(type$5, $ex_1);
         //                    return;

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/MessageHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/MessageHandler.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/MessageHandler.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/MessageHandler.java Mon Mar 28 12:37:40 2005
@@ -26,13 +26,13 @@
 import org.apache.geronimo.interop.GIOP.*;
 import org.apache.geronimo.interop.IOP.*;
 import org.apache.geronimo.interop.SystemException;
-import org.apache.geronimo.interop.adapter.HomeAdapter;
+//import org.apache.geronimo.interop.adapter.HomeAdapter;
 import org.apache.geronimo.interop.adapter.AdapterManager;
 import org.apache.geronimo.interop.adapter.Adapter;
 import org.apache.geronimo.interop.naming.NameService;
 import org.apache.geronimo.interop.rmi.iiop.*;
 import org.apache.geronimo.interop.util.UTF8;
-import org.openejb.server.ServiceException;
+//import org.openejb.server.ServiceException;
 
 public class MessageHandler {
 
@@ -49,7 +49,7 @@
         this.writeSystemExceptionStackTrace = writeSystemExceptionStackTrace;
     }
 
-    public void service(Socket socket) throws ServiceException, IOException {
+    public void service(Socket socket) throws Exception {
 
         InputStream in;
         OutputStream out;
@@ -124,7 +124,14 @@
 
             if (sendResponse) {
                 try {
-                    output.send_message( out, clientInfo );
+                    if(inputMessage.httpTunneling)
+                    {
+                        output.send_http_response( out, clientInfo );
+                    }
+                    else
+                    {
+                        output.send_message( out, clientInfo );
+                    }
                 } catch (Exception ex) {
                     warnSendFailed(clientInfo, ex);
                     closeStreams( in, out );

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/RmiIiopServerGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/RmiIiopServerGBean.java?view=diff&r1=159302&r2=159303
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/RmiIiopServerGBean.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/RmiIiopServerGBean.java Mon Mar 28 12:37:40 2005
@@ -22,15 +22,16 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.openejb.server.SocketService;
-import org.openejb.server.ServerService;
-import org.openejb.server.ServiceException;
+//import org.openejb.server.SocketService;
+//import org.openejb.server.ServerService;
+//import org.openejb.server.ServiceException;
 
 import java.util.*;
 import java.net.Socket;
 import java.io.IOException;
 
-public class RmiIiopServerGBean implements ServerService {
+//public class RmiIiopServerGBean implements ServerService {
+public class RmiIiopServerGBean {
 
     private final Log log = LogFactory.getLog(RmiIiopServerGBean.class);
 
@@ -62,7 +63,7 @@
         this.msgHandler = null;
     }
 
-    public void service(Socket socket) throws ServiceException, IOException {
+    public void service(Socket socket) throws Exception {
         log.debug( "RmiIiopServerGBean.service(): socket = " + socket );
         msgHandler.service(socket);
     }
@@ -72,11 +73,11 @@
         //To change body of implemented methods use File | Settings | File Templates.
     }
 
-    public void start() throws ServiceException {
+    public void start() throws Exception {
         log.debug( "RmiIiopServerGBean.start(): " );
     }
 
-    public void stop() throws ServiceException {
+    public void stop() throws Exception {
         log.debug( "RmiIiopServerGBean.stop(): " );
     }
 
@@ -137,7 +138,7 @@
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(RmiIiopServerGBean.class);
 
-        infoFactory.addInterface(SocketService.class);
+        //infoFactory.addInterface(SocketService.class);
 
         infoFactory.addAttribute("args", ArrayList.class, true);
         infoFactory.addAttribute("props", Properties.class, true);



Mime
View raw message