[jboss-remoting-commits] JBoss Remoting SVN: r3607 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Mar 12 23:28:25 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-03-12 23:28:24 -0400 (Wed, 12 Mar 2008)
New Revision: 3607

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
Log:
JBREM-167: Added ability to marshal/unmarshal in both directions.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java	2008-03-13 03:27:14 UTC (rev 3606)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java	2008-03-13 03:28:24 UTC (rev 3607)
@@ -29,12 +29,22 @@
 import org.jboss.remoting.ServerInvoker;
 import org.jboss.remoting.marshal.MarshalFactory;
 import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.MarshallerDecorator;
 import org.jboss.remoting.marshal.UnMarshaller;
 import org.jboss.remoting.marshal.UnMarshallerDecorator;
+import org.jboss.remoting.marshal.VersionedMarshaller;
+import org.jboss.remoting.marshal.VersionedUnMarshaller;
+import org.jboss.remoting.marshal.rmi.RMIMarshaller;
+import org.jboss.remoting.marshal.rmi.RMIUnMarshaller;
 import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.serialization.SerializationManager;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jboss.util.propertyeditor.PropertyEditors;
 import org.jboss.logging.Logger;
 
 import javax.net.SocketFactory;
+
+import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -55,6 +65,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 /**
@@ -66,10 +77,13 @@
  */
 public class RMIServerInvoker extends ServerInvoker implements RMIServerInvokerInf, Cloneable
 {
+   public static String RMI_ONEWAY_MARSHALLING = "rmiOnewayMarshalling";
+   
    private static final Logger log = Logger.getLogger(RMIServerInvoker.class);
 
    protected boolean isPrimaryServer = true;
    protected Set secondaryServers = new HashSet();
+   protected boolean rmiOnewayMarshalling;
    
    private Remote stub;
    
@@ -124,6 +138,14 @@
       }
    }
    
+   protected void setup() throws Exception
+   {
+      Properties props = new Properties();
+      props.putAll(getConfiguration());
+      PropertyEditors.mapJavaBeanProperties(this, props, false);
+      super.setup();
+   }
+   
    protected RMIServerInvoker copy() throws IOException
    {
       Object o = null;
@@ -329,7 +351,7 @@
    {
 
       Object payload = invocation;
-      if(unmarshaller != null)
+      if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller))
       {
          if(unmarshaller instanceof UnMarshallerDecorator)
          {
@@ -337,26 +359,42 @@
          }
          else
          {
-            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-            ObjectOutputStream oos = new ObjectOutputStream(byteOut);
-            oos.writeObject(payload);
-            oos.flush();
+            ByteArrayInputStream is = null;
+            if (rmiOnewayMarshalling)
+            {
+               // Legacy treatment, pre 2.4.0
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
+               ObjectOutputStream oos = manager.createOutput(baos);
+               oos.writeObject(payload);
+               oos.flush();
+               oos.close();
+               is = new ByteArrayInputStream(baos.toByteArray());
+            }
+            else
+            {
+               is = new ByteArrayInputStream((byte[]) payload);
+            }
 
-            ByteArrayInputStream is = new ByteArrayInputStream(byteOut.toByteArray());
-
             try
             {
-               oos.close();
-               payload = unmarshaller.read(is, null);
-               is.close();
+               if (unmarshaller instanceof VersionedUnMarshaller)
+               {
+                  payload = ((VersionedUnMarshaller) unmarshaller).read(is, null, getVersion());
+                  is.close();
+               }
+               else
+               {
+                  payload = unmarshaller.read(is, null);
+                  is.close();
+               }
             }
             catch(ClassNotFoundException e)
             {
-               log.error("Could not unmarshall invocation request" + payload, e);
+               log.debug("Could not unmarshall invocation request" + payload, e);
                throw new IOException(e.getMessage());
             }
          }
-
       }
 
       if (payload instanceof InvocationRequest)
@@ -380,32 +418,34 @@
       }
       Object response = invoke(payload);
 
-      /* Jira Issue: JBREM-167
-      if(marshaller != null)
+      if(marshaller != null && !(marshaller instanceof RMIMarshaller) && !rmiOnewayMarshalling)
       {
-         PipedOutputStream pos = new PipedOutputStream();
-         PipedInputStream pis = new PipedInputStream();
-         pos.connect(pis);
-         ObjectOutputStream oos = new ObjectOutputStream(pos);
-         marshaller.write(response, oos);
-         pos.flush();
-         pos.write(new byte[0]);
-         pos.flush();
-         ObjectInputStream ois = new ObjectInputStream(pis);
-         try
+         if(marshaller instanceof MarshallerDecorator)
          {
-            oos.close();
-            response = ois.readObject();
-            ois.close();
+            response = ((MarshallerDecorator) marshaller).addDecoration(response);
          }
-         catch(ClassNotFoundException e)
+         else
          {
-            log.error("Could not marshall invocation response object " + response, e);
-            throw new IOException(e.getMessage());
+            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+            if (marshaller instanceof VersionedMarshaller)
+               ((VersionedMarshaller) marshaller).write(response, byteOut, getVersion());
+            else
+               marshaller.write(response, byteOut);
+            
+            byteOut.close();
+            response = byteOut.toByteArray();
          }
       }
-      */
-
       return response;
    }
+
+   public boolean isRmiOnewayMarshalling()
+   {
+      return rmiOnewayMarshalling;
+   }
+
+   public void setRmiOnewayMarshalling(boolean rmiOnewayMarshalling)
+   {
+      this.rmiOnewayMarshalling = rmiOnewayMarshalling;
+   }
 }




More information about the jboss-remoting-commits mailing list