Author: andygumbrecht
Date: Thu Aug  1 09:03:56 2013
New Revision: 1509131

URL: http://svn.apache.org/r1509131
Log:
Really fix backwards compatibility for ejbd. The order of read and write can 
only ever be changed 'after' the version has been written.
NOTE: The best place to append new features is in 
org.apache.openejb.client.EJBRequest.Body

Modified:
    
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
    
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
    
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
    
tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/EJBRequestTest.java
    
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
    
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java

Modified: 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
 Thu Aug  1 09:03:56 2013
@@ -29,8 +29,8 @@ import java.util.Properties;
 
 public class ConnectionManager {
 
-    private static Registry<ConnectionFactory> factories = 
Registry.create(ConnectionFactory.class);
-    private static Registry<ConnectionStrategy> strategies = 
Registry.create(ConnectionStrategy.class);
+    private static final Registry<ConnectionFactory> factories = 
Registry.create(ConnectionFactory.class);
+    private static final Registry<ConnectionStrategy> strategies = 
Registry.create(ConnectionStrategy.class);
 
     static {
         final SocketConnectionFactory ejbdFactory = new 
SocketConnectionFactory();
@@ -59,8 +59,12 @@ public class ConnectionManager {
     }
 
     public static Connection getConnection(final ClusterMetaData cluster, 
final ServerMetaData server, final Request req) throws IOException {
-        if (cluster == null) throw new IllegalArgumentException("cluster 
cannot be null");
-        if (server == null) throw new IllegalArgumentException("server cannot 
be null");
+        if (cluster == null) {
+            throw new IllegalArgumentException("cluster cannot be null");
+        }
+        if (server == null) {
+            throw new IllegalArgumentException("server cannot be null");
+        }
 
         String name = cluster.getConnectionStrategy();
 
@@ -70,7 +74,9 @@ public class ConnectionManager {
             name = p.getProperty("openejb.client.connection.strategy", name);
         }
 
-        if (name == null) name = "default";
+        if (name == null) {
+            name = "default";
+        }
 
         final ConnectionStrategy strategy = strategies.get(name);
         if (strategy == null) {
@@ -91,7 +97,9 @@ public class ConnectionManager {
     }
 
     public static Connection getConnection(final URI uri) throws IOException {
-        if (uri == null) throw new IllegalArgumentException("uri cannot be 
null");
+        if (uri == null) {
+            throw new IllegalArgumentException("uri cannot be null");
+        }
 
         final String scheme = uri.getScheme();
         final ConnectionFactory factory = factories.get(scheme);
@@ -154,6 +162,7 @@ public class ConnectionManager {
 
     @Log(Log.Level.SEVERE)
     public static class UnsupportedConnectionStrategyException extends 
IOException {
+
         public UnsupportedConnectionStrategyException(final String message) {
             super(message);
         }
@@ -161,6 +170,7 @@ public class ConnectionManager {
 
     @Log(Log.Level.SEVERE)
     public static class UnsupportedConnectionFactoryException extends 
IOException {
+
         public UnsupportedConnectionFactoryException(final String message) {
             super(message);
         }

Modified: 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
 Thu Aug  1 09:03:56 2013
@@ -140,7 +140,11 @@ public abstract class EJBObjectHandler e
         super(ejb, server, client, null, auth);
     }
 
-    public EJBObjectHandler(final EJBMetaDataImpl ejb, final ServerMetaData 
server, final ClientMetaData client, final Object primaryKey, final 
JNDIContext.AuthenticationInfo auth) {
+    public EJBObjectHandler(final EJBMetaDataImpl ejb,
+                            final ServerMetaData server,
+                            final ClientMetaData client,
+                            final Object primaryKey,
+                            final JNDIContext.AuthenticationInfo auth) {
         super(ejb, server, client, primaryKey, auth);
     }
 
@@ -148,7 +152,11 @@ public abstract class EJBObjectHandler e
         this.ejbHome = ejbHome;
     }
 
-    public static EJBObjectHandler createEJBObjectHandler(final 
EJBMetaDataImpl ejb, final ServerMetaData server, final ClientMetaData client, 
final Object primaryKey, final JNDIContext.AuthenticationInfo auth) {
+    public static EJBObjectHandler createEJBObjectHandler(final 
EJBMetaDataImpl ejb,
+                                                          final ServerMetaData 
server,
+                                                          final ClientMetaData 
client,
+                                                          final Object 
primaryKey,
+                                                          final 
JNDIContext.AuthenticationInfo auth) {
 
         switch (ejb.type) {
             case EJBMetaDataImpl.BMP_ENTITY:
@@ -332,8 +340,9 @@ public abstract class EJBObjectHandler e
         final EJBRequest req = new 
EJBRequest(RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD, ejb, method, args, 
primaryKey, client.getSerializer());
 
         //Currently, we only set the requestId while the asynchronous 
invocation is called
-        req.getBody().setRequestId(requestId);
-        req.setAuthentication(this.authenticationInfo);
+        final EJBRequest.Body body = req.getBody();
+        body.setRequestId(requestId);
+        body.setAuthentication(this.authenticationInfo);
         final EJBResponse res = request(req);
         return _handleBusinessMethodResponse(res);
     }
@@ -456,7 +465,12 @@ public abstract class EJBObjectHandler e
                     if 
(lastMayInterruptIfRunningValue.getAndSet(mayInterruptIfRunning) == 
mayInterruptIfRunning) {
                         return false;
                     }
-                    final EJBRequest req = new 
EJBRequest(RequestMethodCode.FUTURE_CANCEL, ejb, CANCEL, new 
Object[]{Boolean.valueOf(mayInterruptIfRunning)}, primaryKey, 
client.getSerializer());
+                    final EJBRequest req = new 
EJBRequest(RequestMethodCode.FUTURE_CANCEL,
+                                                          ejb,
+                                                          CANCEL,
+                                                          new 
Object[]{Boolean.valueOf(mayInterruptIfRunning)},
+                                                          primaryKey,
+                                                          
client.getSerializer());
                     req.getBody().setRequestId(requestId);
                     try {
                         final EJBResponse res = request(req);

Modified: 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
 Thu Aug  1 09:03:56 2013
@@ -45,8 +45,6 @@ public class EJBRequest implements Clust
     // Only visible on the client side
     private transient final EJBMetaDataImpl ejbMetaData;
 
-    private transient JNDIContext.AuthenticationInfo authentication;
-
     public static final int SESSION_BEAN_STATELESS = 6;
     public static final int SESSION_BEAN_STATEFUL = 7;
     public static final int ENTITY_BM_PERSISTENCE = 8;
@@ -63,11 +61,12 @@ public class EJBRequest implements Clust
                       final Object[] args,
                       final Object primaryKey,
                       final EJBDSerializer serializer) {
-        body = new Body(ejb);
 
+        this.body = new Body(ejb);
         this.serializer = serializer;
         this.ejbMetaData = ejb;
         this.requestMethod = requestMethod;
+
         setDeploymentCode(ejb.deploymentCode);
         setDeploymentId(ejb.deploymentID);
         setMethodInstance(method);
@@ -165,8 +164,136 @@ public class EJBRequest implements Clust
         this.serializer = serializer;
     }
 
-    public void setAuthentication(final JNDIContext.AuthenticationInfo 
authentication) {
-        this.authentication = authentication;
+    @Override
+    public RequestType getRequestType() {
+        return RequestType.EJB_REQUEST;
+    }
+
+    public RequestMethodCode getRequestMethod() {
+        return requestMethod;
+    }
+
+    public Object getClientIdentity() {
+        return clientIdentity;
+    }
+
+    public String getDeploymentId() {
+        return deploymentId;
+    }
+
+    public int getDeploymentCode() {
+        return deploymentCode;
+    }
+
+    public void setRequestMethod(final RequestMethodCode requestMethod) {
+        this.requestMethod = requestMethod;
+    }
+
+    public void setClientIdentity(final Object clientIdentity) {
+        this.clientIdentity = clientIdentity;
+    }
+
+    public void setDeploymentId(final String deploymentId) {
+        this.deploymentId = deploymentId;
+    }
+
+    public void setDeploymentCode(final int deploymentCode) {
+        this.deploymentCode = deploymentCode;
+    }
+
+    @Override
+    public void setServerHash(final int serverHash) {
+        this.serverHash = serverHash;
+    }
+
+    @Override
+    public int getServerHash() {
+        return serverHash;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("EJBRequest{");
+        sb.append("deploymentId='");
+        sb.append(deploymentId);
+        sb.append("'");
+
+        if (requestMethod != null) {
+            sb.append(", type=").append(requestMethod);
+        }
+        if (body != null) {
+            sb.append(", ").append(body.toString());
+        }
+        sb.append("}");
+        return sb.toString();
+    }
+
+    /*
+    When the Request externalizes itself, it will reset
+    the appropriate values so that this instance can be used
+    again.
+
+    There will be one request instance for each handler
+    */
+
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, 
ClassNotFoundException {
+
+        ClassNotFoundException ex = null;
+
+        deploymentId = null;
+        deploymentCode = -1;
+        clientIdentity = null;
+
+        final int code = in.readByte();
+        try {
+            requestMethod = RequestMethodCode.valueOf(code);
+        } catch (IllegalArgumentException iae) {
+            throw new IOException("Invalid request code " + code);
+        }
+        try {
+            deploymentId = (String) in.readObject();
+        } catch (ClassNotFoundException cnfe) {
+            ex = cnfe;
+        }
+        deploymentCode = in.readShort();
+        try {
+            clientIdentity = in.readObject();
+        } catch (ClassNotFoundException cnfe) {
+            if (ex == null) {
+                ex = cnfe;
+            }
+        }
+        serverHash = in.readInt();
+
+        if (ex != null) {
+            throw ex;
+        }
+    }
+
+    /**
+     * Write to server.
+     * WARNING: To maintain backwards compatibility never change the order or 
insert new writes, always append to
+     * {@link 
org.apache.openejb.client.EJBRequest.Body#writeExternal(java.io.ObjectOutput)}
+     *
+     * @param out ObjectOutput
+     * @throws IOException
+     */
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
+        out.writeByte(requestMethod.getCode());
+
+        if (deploymentCode > 0) {
+            out.writeObject(null);
+        } else {
+            out.writeObject(deploymentId);
+        }
+
+        out.writeShort(deploymentCode);
+        out.writeObject(clientIdentity);
+        out.writeInt(serverHash);
+        body.writeExternal(out);
     }
 
     public static class Body implements java.io.Externalizable {
@@ -184,6 +311,8 @@ public class EJBRequest implements Clust
         private transient String requestId;
         private byte version = EJBResponse.VERSION;
 
+        private transient JNDIContext.AuthenticationInfo authentication;
+
         public Body(final EJBMetaDataImpl ejb) {
             this.ejb = ejb;
         }
@@ -195,6 +324,14 @@ public class EJBRequest implements Clust
             return version;
         }
 
+        public void setAuthentication(final JNDIContext.AuthenticationInfo 
authentication) {
+            this.authentication = authentication;
+        }
+
+        public JNDIContext.AuthenticationInfo getAuthentication() {
+            return authentication;
+        }
+
         public Method getMethodInstance() {
             return methodInstance;
         }
@@ -306,6 +443,11 @@ public class EJBRequest implements Clust
                 }
             }
 
+            //Version 3
+            if (this.version >= 3) {
+                authentication = 
JNDIContext.AuthenticationInfo.class.cast(in.readObject());
+            }
+
             if (result != null) {
                 throw result;
             }
@@ -325,6 +467,9 @@ public class EJBRequest implements Clust
             out.writeUTF(methodName);
 
             writeMethodParameters(out, methodParamTypes, methodParameters);
+
+            //Version 3
+            out.writeObject(authentication);
         }
 
         protected void writeMethodParameters(final ObjectOutput out, final 
Class[] types, final Object[] args) throws IOException {
@@ -407,14 +552,14 @@ public class EJBRequest implements Clust
          * @throws java.io.IOException On error
          */
         protected ORB getORB() throws IOException {
-            // first ORB request?  Check our various sources 
+            // first ORB request?  Check our various sources
             if (orb == null) {
                 try {
                     final Context initialContext = new InitialContext();
                     orb = (ORB) initialContext.lookup("java:comp/ORB");
                 } catch (Throwable e) {
                     try {
-                        // any orb will do if we can't get a context one. 
+                        // any orb will do if we can't get a context one.
                         orb = ORB.init();
                     } catch (Throwable ex) {
                         throw new IOException("Unable to connect 
PortableRemoteObject stub to an ORB, no ORB bound to java:comp/ORB");
@@ -534,142 +679,5 @@ public class EJBRequest implements Clust
             return toString;
         }
     }
-
-    @Override
-    public RequestType getRequestType() {
-        return RequestType.EJB_REQUEST;
-    }
-
-    public RequestMethodCode getRequestMethod() {
-        return requestMethod;
-    }
-
-    public Object getClientIdentity() {
-        return clientIdentity;
-    }
-
-    public String getDeploymentId() {
-        return deploymentId;
-    }
-
-    public int getDeploymentCode() {
-        return deploymentCode;
-    }
-
-    public void setRequestMethod(final RequestMethodCode requestMethod) {
-        this.requestMethod = requestMethod;
-    }
-
-    public void setClientIdentity(final Object clientIdentity) {
-        this.clientIdentity = clientIdentity;
-    }
-
-    public void setDeploymentId(final String deploymentId) {
-        this.deploymentId = deploymentId;
-    }
-
-    public void setDeploymentCode(final int deploymentCode) {
-        this.deploymentCode = deploymentCode;
-    }
-
-    @Override
-    public void setServerHash(final int serverHash) {
-        this.serverHash = serverHash;
-    }
-
-    @Override
-    public int getServerHash() {
-        return serverHash;
-    }
-
-    public JNDIContext.AuthenticationInfo getAuthentication() {
-        return authentication;
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder sb = new StringBuilder();
-        sb.append("EJBRequest{");
-        sb.append("deploymentId='");
-        sb.append(deploymentId);
-        sb.append("'");
-
-        if (requestMethod != null) {
-            sb.append(", type=").append(requestMethod);
-        }
-        if (body != null) {
-            sb.append(", ").append(body.toString());
-        }
-        sb.append("}");
-        return sb.toString();
-    }
-
-    /*
-    When the Request externalizes itself, it will reset
-    the appropriate values so that this instance can be used
-    again.
-
-    There will be one request instance for each handler
-    */
-
-    @Override
-    public void readExternal(final ObjectInput in) throws IOException, 
ClassNotFoundException {
-        ClassNotFoundException result = null;
-
-        deploymentId = null;
-        deploymentCode = -1;
-        clientIdentity = null;
-
-        final int code = in.readByte();
-        try {
-            requestMethod = RequestMethodCode.valueOf(code);
-        } catch (IllegalArgumentException iae) {
-            throw new IOException("Invalid request code " + code);
-        }
-        try {
-            deploymentId = (String) in.readObject();
-        } catch (ClassNotFoundException cnfe) {
-            result = cnfe;
-        }
-        deploymentCode = in.readShort();
-        try {
-            clientIdentity = in.readObject();
-        } catch (ClassNotFoundException cnfe) {
-            if (result == null) {
-                result = cnfe;
-            }
-        }
-        serverHash = in.readInt();
-
-        if (this.getVersion() >= 3) {
-            authentication = 
JNDIContext.AuthenticationInfo.class.cast(in.readObject());
-        }
-
-        if (result != null) {
-            throw result;
-        }
-    }
-
-    @Override
-    public void writeExternal(final ObjectOutput out) throws IOException {
-        out.writeByte(requestMethod.getCode());
-
-        if (deploymentCode > 0) {
-            out.writeObject(null);
-        } else {
-            out.writeObject(deploymentId);
-        }
-
-        out.writeShort(deploymentCode);
-        out.writeObject(clientIdentity);
-        out.writeInt(serverHash);
-
-        if (this.getVersion() >= 3) {
-            out.writeObject(authentication);
-        }
-
-        body.writeExternal(out);
-    }
-
 }
 

Modified: 
tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/EJBRequestTest.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/EJBRequestTest.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/EJBRequestTest.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/EJBRequestTest.java
 Thu Aug  1 09:03:56 2013
@@ -16,144 +16,159 @@
  */
 package org.apache.openejb.client;
 
-import java.io.*;
-import java.lang.reflect.Method;
+import junit.framework.TestCase;
+import org.omg.CORBA.UserException;
+
 import javax.ejb.EJBHome;
 import javax.ejb.EJBObject;
 import javax.ejb.Handle;
-
-import junit.framework.TestCase;
-import org.omg.CORBA.UserException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
 
 public class EJBRequestTest extends TestCase {
+
     private EJBMetaDataImpl ejb;
 
     static interface FooHome extends EJBHome {
+
         FooObject create();
+
         FooObject findByPrimaryKey(Integer key);
     }
-    static interface FooObject extends EJBObject{
+
+    static interface FooObject extends EJBObject {
+
         String businessMethod(String param) throws UserException;
     }
 
-
+    @Override
     protected void setUp() throws Exception {
         ejb = new EJBMetaDataImpl(FooHome.class, FooObject.class, 
Integer.class, "BMP_ENTITY", "FooBeanID", InterfaceType.BUSINESS_REMOTE, null, 
null);
     }
 
     public void testEJBHomeCreate() throws Exception {
-        RequestMethodCode requestMethod = RequestMethodCode.EJB_HOME_CREATE;
-        Method method = FooHome.class.getMethod("create", new Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_CREATE;
+        final Method method = FooHome.class.getMethod("create", new Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testEJBHomeFind() throws Exception {
-        RequestMethodCode requestMethod = RequestMethodCode.EJB_HOME_FIND;
-        Method method = FooHome.class.getMethod("findByPrimaryKey", new 
Class[]{Integer.class});
-        Object[] args = new Object[]{new Integer(4)};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_FIND;
+        final Method method = FooHome.class.getMethod("findByPrimaryKey", new 
Class[]{Integer.class});
+        final Object[] args = new Object[]{4};
 
         invoke(requestMethod, method, args);
     }
 
     public void testEJBHomeRemove1() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_REMOVE_BY_HANDLE;
-        Method method = FooHome.class.getMethod("remove", new 
Class[]{Handle.class});
-        Object[] args = new Object[]{null};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_REMOVE_BY_HANDLE;
+        final Method method = FooHome.class.getMethod("remove", new 
Class[]{Handle.class});
+        final Object[] args = new Object[]{null};
 
         invoke(requestMethod, method, args);
     }
 
     public void testEJBHomeRemove2() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_REMOVE_BY_PKEY;
-        Method method = FooHome.class.getMethod("remove", new 
Class[]{Object.class});
-        Object[] args = new Object[]{new Integer(4)};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_REMOVE_BY_PKEY;
+        final Method method = FooHome.class.getMethod("remove", new 
Class[]{Object.class});
+        final Object[] args = new Object[]{4};
 
         invoke(requestMethod, method, args);
     }
 
     public void testGetMetaData() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_GET_EJB_META_DATA;
-        Method method = FooHome.class.getMethod("getEJBMetaData", new 
Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_GET_EJB_META_DATA;
+        final Method method = FooHome.class.getMethod("getEJBMetaData", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testGetHomeHandle() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_GET_HOME_HANDLE;
-        Method method = FooHome.class.getMethod("getHomeHandle", new 
Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_HOME_GET_HOME_HANDLE;
+        final Method method = FooHome.class.getMethod("getHomeHandle", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testBusinessMethod() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD;
-        Method method = FooObject.class.getMethod("businessMethod", new 
Class[]{String.class});
-        Object[] args = new Object[]{"hola mundo"};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD;
+        final Method method = FooObject.class.getMethod("businessMethod", new 
Class[]{String.class});
+        final Object[] args = new Object[]{"hola mundo"};
 
         invoke(requestMethod, method, args);
     }
 
     public void testGetEJBHome() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_EJB_HOME;
-        Method method = FooObject.class.getMethod("getEJBHome", new Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_EJB_HOME;
+        final Method method = FooObject.class.getMethod("getEJBHome", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testGetHandle() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_HANDLE;
-        Method method = FooObject.class.getMethod("getHandle", new Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_HANDLE;
+        final Method method = FooObject.class.getMethod("getHandle", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testGetPrimaryKey() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_PRIMARY_KEY;
-        Method method = FooObject.class.getMethod("getPrimaryKey", new 
Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_GET_PRIMARY_KEY;
+        final Method method = FooObject.class.getMethod("getPrimaryKey", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
     public void testIsIdentical() throws Exception {
-        RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_IS_IDENTICAL;
-        Method method = FooObject.class.getMethod("isIdentical", new 
Class[]{EJBObject.class});
-        Object[] args = new Object[]{null};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_IS_IDENTICAL;
+        final Method method = FooObject.class.getMethod("isIdentical", new 
Class[]{EJBObject.class});
+        final Object[] args = new Object[]{null};
 
         invoke(requestMethod, method, args);
     }
 
     public void testEJBObjectRemove() throws Exception {
-        RequestMethodCode requestMethod = RequestMethodCode.EJB_OBJECT_REMOVE;
-        Method method = FooObject.class.getMethod("remove", new Class[]{});
-        Object[] args = new Object[]{};
+        final RequestMethodCode requestMethod = 
RequestMethodCode.EJB_OBJECT_REMOVE;
+        final Method method = FooObject.class.getMethod("remove", new 
Class[]{});
+        final Object[] args = new Object[]{};
 
         invoke(requestMethod, method, args);
     }
 
-    private void invoke(RequestMethodCode requestMethod, Method method, 
Object[] args) throws IOException, ClassNotFoundException {
-        EJBRequest expected = new EJBRequest(requestMethod, ejb, method, args, 
null, null);
+    private void invoke(final RequestMethodCode requestMethod, final Method 
method, final Object[] args) throws IOException, ClassNotFoundException {
+
+        final EJBRequest expected = new EJBRequest(requestMethod, ejb, method, 
args, null, null);
+        expected.getBody().setAuthentication(new 
JNDIContext.AuthenticationInfo("realm", "user", new char[]{'p', 'w'}));
 
-        EJBRequest actual = new EJBRequest();
+        final EJBRequest actual = new EJBRequest();
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(baos);
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final ObjectOutputStream out = new ObjectOutputStream(baos);
 
         expected.writeExternal(out);
         out.close();
 
-        ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
-        ObjectInputStream in = new ObjectInputStream(bais);
+        final ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
+        final ObjectInputStream in = new ObjectInputStream(bais);
 
         actual.readExternal(in);
         actual.getBody().readExternal(in);
+        final JNDIContext.AuthenticationInfo authentication = 
actual.getBody().getAuthentication();
 
+        assertNotNull(authentication);
+        assertEquals("AuthenticationInfo.Realm", "realm", 
authentication.getRealm());
+        assertEquals("AuthenticationInfo.User", "user", 
authentication.getUser());
 
         assertEquals("RequestType", expected.getRequestType(), 
actual.getRequestType());
         assertEquals("RequestMethod", expected.getRequestMethod(), 
actual.getRequestMethod());
@@ -169,19 +184,14 @@ public class EJBRequestTest extends Test
 
         assertEquals("MethodInstance", expected.getMethodInstance(), 
actual.getMethodInstance());
 
-        Object[] expectedParams = expected.getMethodParameters();
-        Object[] actualParams = actual.getMethodParameters();
+        final Object[] expectedParams = expected.getMethodParameters();
+        final Object[] actualParams = actual.getMethodParameters();
 
-        assertNotNull("MethodParameters",actualParams);
+        assertNotNull("MethodParameters", actualParams);
         assertEquals("MethodParameters.length", expectedParams.length, 
actualParams.length);
         for (int i = 0; i < expectedParams.length; i++) {
-            assertEquals("MethodParameters."+i, expectedParams[i], 
actualParams[i]);
+            assertEquals("MethodParameters." + i, expectedParams[i], 
actualParams[i]);
         }
     }
 
-
-
-
-
-
 }
\ No newline at end of file

Modified: 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
 Thu Aug  1 09:03:56 2013
@@ -339,7 +339,7 @@ public class EjbDaemon implements org.ap
         }
 
         @Override
-        public Serializable serialize(Object o) {
+        public Serializable serialize(final Object o) {
             return instance().serialize(o);
         }
 

Modified: 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java?rev=1509131&r1=1509130&r2=1509131&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
 Thu Aug  1 09:03:56 2013
@@ -126,6 +126,8 @@ class EjbRequestHandler {
                 res.start(EJBResponse.Time.DESERIALIZATION);
 
                 req.getBody().readExternal(in);
+
+                //Client version retrieved from body
                 version = req.getVersion();
 
                 res.stop(EJBResponse.Time.DESERIALIZATION);
@@ -157,7 +159,7 @@ class EjbRequestHandler {
         Object securityToken = null;
         try {
             if (version >= 3) { // login if needed with request
-                final JNDIContext.AuthenticationInfo authentication = 
req.getAuthentication();
+                final JNDIContext.AuthenticationInfo authentication = 
req.getBody().getAuthentication();
                 if (authentication != null) {
                     try {
                         securityToken = 
securityService.login(authentication.getRealm(), authentication.getUser(), new 
String(authentication.getPassword()));


Reply via email to