tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject svn commit: r1511348 [2/3] - in /tomee/tomee/trunk/server: openejb-client/src/main/java/org/apache/openejb/client/ openejb-client/src/test/java/org/apache/openejb/client/ openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ openejb-ejbd/src/test/...
Date Wed, 07 Aug 2013 15:06:22 GMT
Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIRequest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIRequest.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIRequest.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIRequest.java Wed Aug  7 15:06:21 2013
@@ -26,15 +26,21 @@ public class JNDIRequest implements Clus
     private transient String requestString;
     private transient String moduleId;
     private transient int serverHash;
+    private transient ProtocolMetaData metaData;
 
     public JNDIRequest() {
     }
 
-    public JNDIRequest(RequestMethodCode requestMethod, String requestString) {
+    public JNDIRequest(final RequestMethodCode requestMethod, final String requestString) {
         this.requestMethod = requestMethod;
         this.requestString = requestString;
     }
 
+    public void setMetaData(final ProtocolMetaData metaData) {
+        this.metaData = metaData;
+    }
+
+    @Override
     public RequestType getRequestType() {
         return RequestType.JNDI_REQUEST;
     }
@@ -51,30 +57,33 @@ public class JNDIRequest implements Clus
         return moduleId;
     }
 
-    public void setModuleId(String moduleId) {
+    public void setModuleId(final String moduleId) {
         this.moduleId = moduleId;
     }
 
-    public void setRequestMethod(RequestMethodCode requestMethod) {
+    public void setRequestMethod(final RequestMethodCode requestMethod) {
         this.requestMethod = requestMethod;
     }
 
-    public void setRequestString(String requestString) {
+    public void setRequestString(final String requestString) {
         this.requestString = requestString;
     }
 
-    public void setServerHash(int serverHash) {
+    @Override
+    public void setServerHash(final int serverHash) {
         this.serverHash = serverHash;
     }
 
+    @Override
     public int getServerHash() {
         return serverHash;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        byte version = in.readByte(); // future use
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final byte version = in.readByte(); // future use
 
-        int code = in.readByte();
+        final int code = in.readByte();
         try {
             requestMethod = RequestMethodCode.valueOf(code);
         } catch (IllegalArgumentException iae) {
@@ -85,7 +94,8 @@ public class JNDIRequest implements Clus
         serverHash = in.readInt();
     }
 
-    public void writeExternal(ObjectOutput out) throws IOException {
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
         // write out the version of the serialized data for future use
         out.writeByte(1);
 
@@ -96,7 +106,7 @@ public class JNDIRequest implements Clus
     }
 
     public String toString() {
-        StringBuilder sb = new StringBuilder(100);
+        final StringBuilder sb = new StringBuilder(100);
 
         sb.append(requestMethod);
         sb.append(this.moduleId != null ? moduleId : "").append(":");

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java Wed Aug  7 15:06:21 2013
@@ -26,15 +26,30 @@ public class JNDIResponse implements Clu
     private transient int responseCode = -1;
     private transient Object result;
     private transient ServerMetaData server;
+    private transient JNDIRequest request;
+    private transient ProtocolMetaData metaData;
 
     public JNDIResponse() {
     }
 
-    public JNDIResponse(int code, Object obj) {
+    public JNDIResponse(final int code, final Object obj) {
         responseCode = code;
         result = obj;
     }
 
+    @Override
+    public void setMetaData(final ProtocolMetaData metaData) {
+        this.metaData = metaData;
+    }
+
+    public JNDIRequest getRequest() {
+        return request;
+    }
+
+    public void setRequest(final JNDIRequest request) {
+        this.request = request;
+    }
+
     public int getResponseCode() {
         return responseCode;
     }
@@ -43,33 +58,36 @@ public class JNDIResponse implements Clu
         return result;
     }
 
-    public void setResponseCode(int responseCode) {
+    public void setResponseCode(final int responseCode) {
         this.responseCode = responseCode;
     }
 
-    public void setResult(Object result) {
+    public void setResult(final Object result) {
         this.result = result;
     }
 
-    public void setServer(ServerMetaData server) {
+    @Override
+    public void setServer(final ServerMetaData server) {
         this.server = server;
     }
 
     public ServerMetaData getServer() {
         return server;
     }
-    
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        byte version = in.readByte(); // future use
 
-        boolean readServer = in.readBoolean();
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final byte version = in.readByte(); // future use
+
+        final boolean readServer = in.readBoolean();
         if (readServer) {
             server = new ServerMetaData();
+            server.setMetaData(metaData);
             server.readExternal(in);
         }
-        
+
         responseCode = in.readByte();
-        
+
         switch (responseCode) {
             case ResponseCodes.JNDI_BUSINESS_OBJECT:
             case ResponseCodes.JNDI_OK:
@@ -83,46 +101,51 @@ public class JNDIResponse implements Clu
             case ResponseCodes.JNDI_NOT_FOUND:
                 break;
             case ResponseCodes.JNDI_EJBHOME:
-                EJBMetaDataImpl m = new EJBMetaDataImpl();
+                final EJBMetaDataImpl m = new EJBMetaDataImpl();
+                m.setMetaData(metaData);
                 m.readExternal(in);
                 result = m;
                 break;
             case ResponseCodes.JNDI_DATA_SOURCE:
-                DataSourceMetaData ds = new DataSourceMetaData();
+                final DataSourceMetaData ds = new DataSourceMetaData();
+                ds.setMetaData(metaData);
                 ds.readExternal(in);
                 result = ds;
                 break;
             case ResponseCodes.JNDI_INJECTIONS:
-                InjectionMetaData imd = new InjectionMetaData();
+                final InjectionMetaData imd = new InjectionMetaData();
+                imd.setMetaData(metaData);
                 imd.readExternal(in);
                 result = imd;
                 break;
             case ResponseCodes.JNDI_WEBSERVICE:
-                WsMetaData ws = (WsMetaData) in.readObject();
-                result = ws;
+                result = in.readObject();
                 break;
             case ResponseCodes.JNDI_ENUMERATION:
-                NameClassPairEnumeration ncpe = new NameClassPairEnumeration();
+                final NameClassPairEnumeration ncpe = new NameClassPairEnumeration();
+                ncpe.setMetaData(metaData);
                 ncpe.readExternal(in);
                 result = ncpe;
                 break;
             case ResponseCodes.JNDI_REFERENCE:
-                result = (Reference)in.readObject();
+                result = in.readObject();
                 break;
         }
     }
 
-    public void writeExternal(ObjectOutput out) throws IOException {
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
         // write out the version of the serialized data for future use
         out.writeByte(1);
 
         if (null != server) {
             out.writeBoolean(true);
+            server.setMetaData(metaData);
             server.writeExternal(out);
         } else {
             out.writeBoolean(false);
         }
-        
+
         out.writeByte((byte) responseCode);
 
         switch (responseCode) {
@@ -138,47 +161,73 @@ public class JNDIResponse implements Clu
             case ResponseCodes.JNDI_NOT_FOUND:
                 break;
             case ResponseCodes.JNDI_EJBHOME:
-                EJBMetaDataImpl m = (EJBMetaDataImpl) result;
+                final EJBMetaDataImpl m = (EJBMetaDataImpl) result;
+                m.setMetaData(metaData);
                 m.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_DATA_SOURCE:
-                DataSourceMetaData ds = (DataSourceMetaData) result;
+                final DataSourceMetaData ds = (DataSourceMetaData) result;
+                ds.setMetaData(metaData);
                 ds.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_INJECTIONS:
-                InjectionMetaData imd = (InjectionMetaData) result;
+                final InjectionMetaData imd = (InjectionMetaData) result;
+                imd.setMetaData(metaData);
                 imd.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_WEBSERVICE:
-                WsMetaData ws = (WsMetaData) result;
+                final WsMetaData ws = (WsMetaData) result;
                 out.writeObject(ws);
                 break;
             case ResponseCodes.JNDI_ENUMERATION:
-                NameClassPairEnumeration ncpe = (NameClassPairEnumeration) result;
+                final NameClassPairEnumeration ncpe = (NameClassPairEnumeration) result;
+                ncpe.setMetaData(metaData);
                 ncpe.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_REFERENCE:
-                Reference ref = (Reference) result;
+                final Reference ref = (Reference) result;
                 out.writeObject(ref);
                 break;
         }
     }
 
     public String toString() {
-        StringBuilder sb = new StringBuilder(100);
+        final StringBuilder sb = new StringBuilder(100);
 
         switch (responseCode) {
-            case ResponseCodes.JNDI_BUSINESS_OBJECT: sb.append("JNDI_BUSINESS_OBJECT:"); break;
-            case ResponseCodes.JNDI_OK: sb.append("JNDI_OK:"); break;
-            case ResponseCodes.JNDI_NAMING_EXCEPTION: sb.append("JNDI_NAMING_EXCEPTION:"); break;
-            case ResponseCodes.JNDI_RUNTIME_EXCEPTION: sb.append("JNDI_RUNTIME_EXCEPTION:"); break;
-            case ResponseCodes.JNDI_ERROR: sb.append("JNDI_ERROR:"); break;
-            case ResponseCodes.JNDI_RESOURCE: sb.append("JNDI_RESOURCE:"); break;
-            case ResponseCodes.JNDI_CONTEXT: sb.append("JNDI_CONTEXT:"); break;
-            case ResponseCodes.JNDI_NOT_FOUND: sb.append("JNDI_NOT_FOUND:"); break;
-            case ResponseCodes.JNDI_EJBHOME: sb.append("JNDI_EJBHOME:"); break;
-            case ResponseCodes.JNDI_DATA_SOURCE: sb.append("JNDI_DATA_SOURCE:"); break;
-            case ResponseCodes.JNDI_INJECTIONS: sb.append("JNDI_INJECTIONS:"); break;
+            case ResponseCodes.JNDI_BUSINESS_OBJECT:
+                sb.append("JNDI_BUSINESS_OBJECT:");
+                break;
+            case ResponseCodes.JNDI_OK:
+                sb.append("JNDI_OK:");
+                break;
+            case ResponseCodes.JNDI_NAMING_EXCEPTION:
+                sb.append("JNDI_NAMING_EXCEPTION:");
+                break;
+            case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
+                sb.append("JNDI_RUNTIME_EXCEPTION:");
+                break;
+            case ResponseCodes.JNDI_ERROR:
+                sb.append("JNDI_ERROR:");
+                break;
+            case ResponseCodes.JNDI_RESOURCE:
+                sb.append("JNDI_RESOURCE:");
+                break;
+            case ResponseCodes.JNDI_CONTEXT:
+                sb.append("JNDI_CONTEXT:");
+                break;
+            case ResponseCodes.JNDI_NOT_FOUND:
+                sb.append("JNDI_NOT_FOUND:");
+                break;
+            case ResponseCodes.JNDI_EJBHOME:
+                sb.append("JNDI_EJBHOME:");
+                break;
+            case ResponseCodes.JNDI_DATA_SOURCE:
+                sb.append("JNDI_DATA_SOURCE:");
+                break;
+            case ResponseCodes.JNDI_INJECTIONS:
+                sb.append("JNDI_INJECTIONS:");
+                break;
         }
         sb.append(this.getResult());
         return sb.toString();

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/NameClassPairEnumeration.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/NameClassPairEnumeration.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/NameClassPairEnumeration.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/NameClassPairEnumeration.java Wed Aug  7 15:06:21 2013
@@ -18,75 +18,88 @@ package org.apache.openejb.client;
 
 import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
 import java.io.Externalizable;
-import java.io.ObjectOutput;
 import java.io.IOException;
 import java.io.ObjectInput;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Collections;
+import java.io.ObjectOutput;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * The product of a javax.naming.Context.list() method
  */
 public class NameClassPairEnumeration<T extends NameClassPair> implements NamingEnumeration<T>, Externalizable {
 
-    private List<NameClassPair> list;
-    private Iterator<NameClassPair> iterator;
+    private transient List<NameClassPair> list;
+    private transient Iterator<NameClassPair> iterator;
+    private transient ProtocolMetaData metaData;
 
-    public NameClassPairEnumeration(List<NameClassPair> list){
+    public NameClassPairEnumeration(final List<NameClassPair> list) {
         this.list = list;
         this.iterator = list.iterator();
     }
 
+    @SuppressWarnings("unchecked")
     public NameClassPairEnumeration() {
         list = Collections.EMPTY_LIST;
         iterator = list.iterator();
     }
 
+    public void setMetaData(final ProtocolMetaData metaData) {
+        this.metaData = metaData;
+    }
+
+    @Override
     public void close() {
         iterator = null;
     }
 
+    @Override
     public boolean hasMore() {
         return iterator.hasNext();
     }
 
+    @Override
     public boolean hasMoreElements() {
         return hasMore();
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
     public T next() {
         return (T) iterator.next();
     }
 
+    @Override
     public T nextElement() {
         return next();
     }
 
-    public void writeExternal(ObjectOutput out) throws IOException {
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
         // write out the version of the serialized data for future use
         out.writeByte(1);
 
         out.writeInt(list.size());
-        for (NameClassPair pair : list) {
+        for (final NameClassPair pair : list) {
             out.writeObject(pair.getName());
             out.writeObject(pair.getClassName());
         }
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        byte version = in.readByte(); // future use
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final byte version = in.readByte(); // future use
 
         int size = in.readInt();
 
         list = new ArrayList<NameClassPair>(size);
 
         for (; size > 0; size--) {
-            String name = (String) in.readObject();
-            String className = (String) in.readObject();
+            final String name = (String) in.readObject();
+            final String className = (String) in.readObject();
 
             list.add(new NameClassPair(name, className));
         }

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ProtocolMetaData.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ProtocolMetaData.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ProtocolMetaData.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ProtocolMetaData.java Wed Aug  7 15:06:21 2013
@@ -21,6 +21,7 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Serializable;
 
 /**
  * OpenEJB Enterprise Javabean Protocol (OEJP)
@@ -34,7 +35,9 @@ import java.io.OutputStream;
  * @version $Revision$ $Date$
  */
 @SuppressWarnings("UnusedDeclaration")
-public class ProtocolMetaData {
+public class ProtocolMetaData implements Serializable {
+
+    public static final String VERSION = "4.6";
 
     private static final String OEJB = "OEJP";
     private String id;
@@ -42,10 +45,7 @@ public class ProtocolMetaData {
     private int minor;
 
     public ProtocolMetaData() {
-    }
-
-    public ProtocolMetaData(final String version) {
-        init(OEJB + "/" + version);
+        init(OEJB + "/" + VERSION);
     }
 
     private void init(final String spec) {
@@ -62,8 +62,8 @@ public class ProtocolMetaData {
         this.minor = Integer.parseInt(new String(chars, 7, 1));
     }
 
-    public boolean isAtLeast(final int major, int minor) {
-        return this.major >= major || (this.major == major && this.minor >= minor);
+    public boolean isAtLeast(final int major, final int minor) {
+        return this.major >= major && (this.major != major || this.minor >= minor);
     }
 
     public String getId() {

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java Wed Aug  7 15:06:21 2013
@@ -23,6 +23,12 @@ import java.io.ObjectOutput;
 
 public interface Response extends Externalizable {
 
+    /**
+     * Set the protocol metadata that can be used for version checking
+     * @param metaData
+     */
+    public void setMetaData(final ProtocolMetaData metaData);
+
     @Override
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
 

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java Wed Aug  7 15:06:21 2013
@@ -25,18 +25,23 @@ import java.util.Arrays;
 
 public class ServerMetaData implements Externalizable {
 
-    private URI[] locations;
-    private URI location;
+    private transient URI[] locations;
+    private transient URI location;
+    private transient ProtocolMetaData metaData;
 
     public ServerMetaData() {
     }
 
-    public ServerMetaData(URI ... locations)  {
+    public ServerMetaData(final URI... locations) {
         this.locations = locations;
         location = locations[0];
     }
 
-    public void merge(ServerMetaData toMerge) {
+    public void setMetaData(final ProtocolMetaData metaData) {
+        this.metaData = metaData;
+    }
+
+    public void merge(final ServerMetaData toMerge) {
         locations = toMerge.locations;
     }
 
@@ -50,20 +55,22 @@ public class ServerMetaData implements E
 
     public int buildHash() {
         int locationsHash = 0;
-        for (URI location : this.locations) {
+        for (final URI location : this.locations) {
             locationsHash += location.hashCode();
         }
         return locationsHash;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        byte version = in.readByte();
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final byte version = in.readByte();
 
         locations = (URI[]) in.readObject();
         location = locations[0];
     }
 
-    public void writeExternal(ObjectOutput out) throws IOException {
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
         // write out the version of the serialized data for future use
         out.writeByte(1);
 
@@ -74,15 +81,18 @@ public class ServerMetaData implements E
         return Arrays.toString(locations);
     }
 
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
+    public boolean equals(final Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
 
         final ServerMetaData that = (ServerMetaData) o;
 
-        if (location != null ? !location.equals(that.location) : that.location != null) return false;
+        return !(location != null ? !location.equals(that.location) : that.location != null);
 
-        return true;
     }
 
     public int hashCode() {

Modified: tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ThrowableArtifact.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ThrowableArtifact.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ThrowableArtifact.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/main/java/org/apache/openejb/client/ThrowableArtifact.java Wed Aug  7 15:06:21 2013
@@ -18,27 +18,34 @@
 package org.apache.openejb.client;
 
 import java.io.Externalizable;
-import java.io.ObjectOutput;
 import java.io.IOException;
 import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.Stack;
 
 /**
  * @version $Revision$ $Date$
  */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 public class ThrowableArtifact implements Externalizable {
 
-    private Throwable throwable;
+    private transient Throwable throwable;
+    private transient ProtocolMetaData metaData;
 
-    public ThrowableArtifact(Throwable throwable) {
+    public ThrowableArtifact(final Throwable throwable) {
         this.throwable = throwable;
     }
 
     public ThrowableArtifact() {
     }
 
-    public void writeExternal(ObjectOutput out) throws IOException {
-        Stack<MockThrowable> stack = new Stack<MockThrowable>();
+    public void setMetaData(final ProtocolMetaData metaData) {
+        this.metaData = metaData;
+    }
+
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
+        final Stack<MockThrowable> stack = new Stack<MockThrowable>();
 
         for (Throwable cause = throwable; cause != null; cause = cause.getCause()) {
             stack.add(new MockThrowable(cause));
@@ -47,12 +54,15 @@ public class ThrowableArtifact implement
         out.writeObject(stack);
         try {
             out.writeObject(throwable);
-        } catch (IOException dontCare) {
+        } catch (IOException e) {
+            //Ignore
         }
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        Stack<MockThrowable> stack = (Stack<MockThrowable>) in.readObject();
+    @SuppressWarnings("unchecked")
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final Stack<MockThrowable> stack = (Stack<MockThrowable>) in.readObject();
         try {
             throwable = (Throwable) in.readObject();
         } catch (Exception e) {
@@ -60,14 +70,14 @@ public class ThrowableArtifact implement
         }
     }
 
-    private Throwable createMockThrowable(Stack<MockThrowable> stack) {
+    private Throwable createMockThrowable(final Stack<MockThrowable> stack) {
         Throwable throwable = stack.pop();
 
-        while (!stack.isEmpty()){
+        while (!stack.isEmpty()) {
             throwable = stack.pop().initCause(throwable);
         }
 
-        return new ClientRuntimeException("The exception sent could not be serialized or deserialized.  This is a mock recreation:\n"+throwable, throwable);
+        return new ClientRuntimeException("The exception sent could not be serialized or deserialized.  This is a mock recreation:\n" + throwable, throwable);
     }
 
     public Throwable getThrowable() {
@@ -79,21 +89,22 @@ public class ThrowableArtifact implement
     }
 
     private static class MockThrowable extends Throwable {
+
         private final String classType;
 
-        public MockThrowable(Throwable t){
-            this(t.getMessage(),t.getClass().getName(), t.getStackTrace());
+        public MockThrowable(final Throwable t) {
+            this(t.getMessage(), t.getClass().getName(), t.getStackTrace());
         }
 
-        public MockThrowable(String message, String classType, StackTraceElement[] stackTrace) {
+        public MockThrowable(final String message, final String classType, final StackTraceElement[] stackTrace) {
             super(message);
             this.classType = classType;
             this.setStackTrace(stackTrace);
         }
 
         public String toString() {
-            String s = classType;
-            String message = getLocalizedMessage();
+            final String s = classType;
+            final String message = getLocalizedMessage();
             return (message != null) ? (s + ": " + message) : s;
         }
     }

Modified: tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/JndiRequestTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/JndiRequestTest.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/JndiRequestTest.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/JndiRequestTest.java Wed Aug  7 15:06:21 2013
@@ -31,8 +31,8 @@ import java.io.ObjectOutputStream;
 public class JndiRequestTest extends TestCase {
 
     public void testExternalize() throws Exception {
-        JNDIRequest expected = new JNDIRequest(RequestMethodCode.JNDI_LOOKUP, "this/is/a/jndi/name");
-        JNDIRequest actual = new JNDIRequest();
+        final JNDIRequest expected = new JNDIRequest(RequestMethodCode.JNDI_LOOKUP, "this/is/a/jndi/name");
+        final JNDIRequest actual = new JNDIRequest();
 
         externalize(expected, actual);
 
@@ -43,9 +43,9 @@ public class JndiRequestTest extends Tes
 
 
     public void testExternalize2() throws Exception {
-        JNDIRequest expected = new JNDIRequest(RequestMethodCode.JNDI_LOOKUP, "this/is/a/jndi/name");
+        final JNDIRequest expected = new JNDIRequest(RequestMethodCode.JNDI_LOOKUP, "this/is/a/jndi/name");
         expected.setModuleId("foobar");
-        JNDIRequest actual = new JNDIRequest();
+        final JNDIRequest actual = new JNDIRequest();
 
         externalize(expected, actual);
 
@@ -55,15 +55,15 @@ public class JndiRequestTest extends Tes
     }
 
 
-    private void externalize(Externalizable original, Externalizable copy) throws IOException, ClassNotFoundException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(baos);
+    private void externalize(final Externalizable original, final Externalizable copy) throws IOException, ClassNotFoundException {
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final ObjectOutputStream out = new ObjectOutputStream(baos);
 
         original.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);
 
         copy.readExternal(in);
     }

Modified: tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/OverlyStickyConnectionTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/OverlyStickyConnectionTest.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/OverlyStickyConnectionTest.java (original)
+++ tomee/tomee/trunk/server/openejb-client/src/test/java/org/apache/openejb/client/OverlyStickyConnectionTest.java Wed Aug  7 15:06:21 2013
@@ -50,28 +50,28 @@ public class OverlyStickyConnectionTest 
         assertEquals(new URI("mock://red:4201"), connection.get().getURI());
     }
 
-    private InitialContext getContext(String uri) throws NamingException {
-        Properties p = new Properties();
+    private InitialContext getContext(final String uri) throws NamingException {
+        final Properties p = new Properties();
         p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
         p.put("java.naming.provider.url", uri);
 
         return new InitialContext(p);
     }
 
-    private final ThreadLocal<Connection> connection = new ThreadLocal<Connection>();
+    private static final ThreadLocal<Connection> connection = new ThreadLocal<Connection>();
 
     public class MockConnectionFactory implements ConnectionFactory {
 
         @Override
         public Connection getConnection(final URI uri) throws IOException {
             return new Connection() {
-                private ByteArrayInputStream in;
-                private ByteArrayOutputStream out = new ByteArrayOutputStream();
+                private final ByteArrayInputStream in;
+                private final ByteArrayOutputStream out = new ByteArrayOutputStream();
 
                 {
                     connection.set(this);
-                    new ProtocolMetaData("3.1").writeExternal(out);
-                    ObjectOutputStream oos = new ObjectOutputStream(out);
+                    new ProtocolMetaData().writeExternal(out);
+                    final ObjectOutputStream oos = new ObjectOutputStream(out);
                     new ClusterResponse(ClusterResponse.Code.CURRENT).writeExternal(oos);
                     new JNDIResponse(ResponseCodes.JNDI_CONTEXT, null).writeExternal(oos);
                     oos.close();

Modified: tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java (original)
+++ tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java Wed Aug  7 15:06:21 2013
@@ -19,6 +19,8 @@ package org.apache.openejb.server.ejbd;
 import org.apache.openejb.client.AuthenticationRequest;
 import org.apache.openejb.client.AuthenticationResponse;
 import org.apache.openejb.client.ClientMetaData;
+import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
 import org.apache.openejb.client.ResponseCodes;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.SecurityService;
@@ -29,17 +31,34 @@ import org.apache.openejb.util.Messages;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
-class AuthRequestHandler {
+class AuthRequestHandler extends RequestHandler {
 
     Messages _messages = new Messages("org.apache.openejb.server.util.resources");
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("auth"), "org.apache.openejb.server.util.resources");
+    private static final boolean debug = logger.isDebugEnabled();
 
-    AuthRequestHandler(final EjbDaemon daemon) {
+    protected AuthRequestHandler(final EjbDaemon daemon) {
+        super(daemon);
     }
 
-    public void processRequest(final ObjectInputStream in, final ObjectOutputStream out) {
+    @Override
+    public String getName() {
+        return "Authentication";
+    }
+
+    @Override
+    public Logger getLogger() {
+        return logger;
+    }
+
+    @Override
+    public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+
         final AuthenticationRequest req = new AuthenticationRequest();
+        req.setMetaData(metaData);
+
         final AuthenticationResponse res = new AuthenticationResponse();
+        res.setMetaData(metaData);
 
         try {
             req.readExternal(in);
@@ -52,6 +71,7 @@ class AuthRequestHandler {
             final Object token = securityService.login(securityRealm, username, password);
 
             final ClientMetaData client = new ClientMetaData();
+            client.setMetaData(metaData);
             client.setClientIdentity(token);
 
             res.setIdentity(client);
@@ -60,19 +80,33 @@ class AuthRequestHandler {
             res.setResponseCode(ResponseCodes.AUTH_DENIED);
             res.setDeniedCause(t);
         } finally {
-            if (logger.isDebugEnabled()) {
+            if (debug) {
                 try {
                     logger.debug("AUTH REQUEST: " + req + " -- RESPONSE: " + res);
-                } catch (Exception justInCase) {
+                } catch (Exception e) {
+                    //Ignore
                 }
             }
+        }
+
+        return res;
+    }
+
+    @Override
+    public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+
+        if (AuthenticationResponse.class.isInstance(response)) {
+
+            final AuthenticationResponse res = AuthenticationResponse.class.cast(response);
+            res.setMetaData(metaData);
 
             try {
                 res.writeExternal(out);
-            } catch (java.io.IOException ie) {
-                logger.fatal("Couldn't write AuthenticationResponse to output stream", ie);
+            } catch (Exception e) {
+                logger.fatal("Could not write AuthenticationResponse to output stream", e);
             }
+        } else {
+            logger.error("AuthRequestHandler cannot process an instance of: " + response.getClass().getName());
         }
     }
-
 }
\ No newline at end of file

Modified: tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java (original)
+++ tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java Wed Aug  7 15:06:21 2013
@@ -37,10 +37,10 @@ class ClientObjectFactory implements org
 
     protected ServerMetaData defaultServerMetaData;
 
-    public ClientObjectFactory(EjbDaemon daemon, Properties props) {
+    public ClientObjectFactory(final EjbDaemon daemon, final Properties props) {
 
         try {
-            String uriString = props.getProperty("openejb.ejbd.uri", "foo://127.0.0.1:4201");
+            final String uriString = props.getProperty("openejb.ejbd.uri", "foo://127.0.0.1:4201");
             this.defaultServerMetaData = new ServerMetaData(new URI(uriString));
         } catch (Exception e) {
             e.printStackTrace();
@@ -48,22 +48,21 @@ class ClientObjectFactory implements org
     }
 
     @Override
-    public javax.ejb.EJBMetaData getEJBMetaData(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
+    public javax.ejb.EJBMetaData getEJBMetaData(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
 
-        BeanContext beanContext = info.getBeanContext();
-        int idCode = -1;
+        final BeanContext beanContext = info.getBeanContext();
+        final int idCode = -1;
 
-        EJBMetaDataImpl metaData = buildEjbMetaData(info, beanContext, idCode);
-        return metaData;
+        return buildEjbMetaData(info, beanContext, idCode);
     }
 
     @Override
-    public javax.ejb.Handle getHandle(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
-        BeanContext beanContext = info.getBeanContext();
+    public javax.ejb.Handle getHandle(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
+        final BeanContext beanContext = info.getBeanContext();
 
-        int idCode = -1;
+        final int idCode = -1;
 
         Object securityIdentity = null;
         try {
@@ -71,11 +70,11 @@ class ClientObjectFactory implements org
         } catch (Exception e) {
 
         }
-        ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
-        EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
-        Object primKey = info.getPrimaryKey();
+        final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
+        final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
+        final Object primKey = info.getPrimaryKey();
 
-        EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
+        final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
 
         return new EJBObjectHandle(handler.createEJBObjectProxy());
     }
@@ -89,11 +88,11 @@ class ClientObjectFactory implements org
     }
 
     @Override
-    public javax.ejb.HomeHandle getHomeHandle(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
-        BeanContext beanContext = info.getBeanContext();
+    public javax.ejb.HomeHandle getHomeHandle(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
+        final BeanContext beanContext = info.getBeanContext();
 
-        int idCode = -1;
+        final int idCode = -1;
 
         Object securityIdentity = null;
         try {
@@ -101,20 +100,20 @@ class ClientObjectFactory implements org
         } catch (Exception e) {
             e.printStackTrace();
         }
-        ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
-        EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
+        final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
+        final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
 
-        EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData, getServerMetaData(), cMetaData, call.get(JNDIContext.AuthenticationInfo.class));
+        final EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData, getServerMetaData(), cMetaData, call.get(JNDIContext.AuthenticationInfo.class));
 
         return new EJBHomeHandle(hanlder.createEJBHomeProxy());
     }
 
     @Override
-    public javax.ejb.EJBObject getEJBObject(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
-        BeanContext beanContext = info.getBeanContext();
+    public javax.ejb.EJBObject getEJBObject(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
+        final BeanContext beanContext = info.getBeanContext();
 
-        int idCode = -1;
+        final int idCode = -1;
 
         Object securityIdentity = null;
         try {
@@ -122,21 +121,21 @@ class ClientObjectFactory implements org
         } catch (Exception e) {
             e.printStackTrace();
         }
-        ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
-        EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
-        Object primKey = info.getPrimaryKey();
+        final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
+        final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
+        final Object primKey = info.getPrimaryKey();
 
-        EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
+        final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
 
         return (javax.ejb.EJBObject) hanlder.createEJBObjectProxy();
     }
 
     @Override
-    public Object getBusinessObject(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
-        BeanContext beanContext = info.getBeanContext();
+    public Object getBusinessObject(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
+        final BeanContext beanContext = info.getBeanContext();
 
-        int idCode = -1;
+        final int idCode = -1;
 
         Object securityIdentity = null;
         try {
@@ -144,8 +143,8 @@ class ClientObjectFactory implements org
         } catch (Exception e) {
             e.printStackTrace();
         }
-        ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
-        EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(null, null,
+        final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
+        final EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(null, null,
                 beanContext.getPrimaryKeyClass(),
                 beanContext.getComponentType().toString(),
                 beanContext.getDeploymentID().toString(),
@@ -155,14 +154,14 @@ class ClientObjectFactory implements org
                 beanContext.getAsynchronousMethodSignatures());
         eMetaData.loadProperties(beanContext.getProperties());
         
-        Object primKey = info.getPrimaryKey();
+        final Object primKey = info.getPrimaryKey();
 
-        EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
+        final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData, getServerMetaData(), cMetaData, primKey, null);
 
         return hanlder.createEJBObjectProxy();
     }
 
-    public static InterfaceType convert(org.apache.openejb.InterfaceType type) {
+    public static InterfaceType convert(final org.apache.openejb.InterfaceType type) {
         switch (type) {
             case EJB_HOME: return InterfaceType.EJB_HOME;
             case EJB_OBJECT: return InterfaceType.EJB_OBJECT;
@@ -177,11 +176,11 @@ class ClientObjectFactory implements org
     }
 
     @Override
-    public javax.ejb.EJBHome getEJBHome(ProxyInfo info) {
-        CallContext call = CallContext.getCallContext();
-        BeanContext beanContext = info.getBeanContext();
+    public javax.ejb.EJBHome getEJBHome(final ProxyInfo info) {
+        final CallContext call = CallContext.getCallContext();
+        final BeanContext beanContext = info.getBeanContext();
 
-        int idCode = -1;
+        final int idCode = -1;
 
         Object securityIdentity = null;
         try {
@@ -189,16 +188,16 @@ class ClientObjectFactory implements org
         } catch (Exception e) {
             e.printStackTrace();
         }
-        ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
-        EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
+        final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
+        final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
 
-        EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData, getServerMetaData(), cMetaData, null);
+        final EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData, getServerMetaData(), cMetaData, null);
 
         return hanlder.createEJBHomeProxy();
     }
 
-    private EJBMetaDataImpl buildEjbMetaData(ProxyInfo info, BeanContext beanContext, int idCode) {
-        EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(beanContext.getHomeInterface(),
+    private EJBMetaDataImpl buildEjbMetaData(final ProxyInfo info, final BeanContext beanContext, final int idCode) {
+        final EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(beanContext.getHomeInterface(),
                 beanContext.getRemoteInterface(),
                 beanContext.getPrimaryKeyClass(),
                 beanContext.getComponentType().toString(),

Modified: tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClusterRequestHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClusterRequestHandler.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClusterRequestHandler.java (original)
+++ tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClusterRequestHandler.java Wed Aug  7 15:06:21 2013
@@ -16,22 +16,24 @@
  */
 package org.apache.openejb.server.ejbd;
 
+import org.apache.openejb.client.ClusterMetaData;
 import org.apache.openejb.client.ClusterRequest;
 import org.apache.openejb.client.ClusterResponse;
-import org.apache.openejb.client.ClusterMetaData;
+import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
 import org.apache.openejb.server.DiscoveryListener;
+import org.apache.openejb.util.Join;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
-import org.apache.openejb.util.Exceptions;
-import org.apache.openejb.util.Join;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.net.URISyntaxException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.LinkedHashSet;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -39,37 +41,45 @@ import java.util.concurrent.locks.Reentr
 /**
  * @version $Rev$ $Date$
  */
-public class ClusterRequestHandler implements DiscoveryListener {
+public class ClusterRequestHandler extends RequestHandler implements DiscoveryListener {
 
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("cluster"), ClusterRequestHandler.class);
 
     private final Data data = new Data();
 
-    public ClusterRequestHandler(EjbDaemon daemon) {
+    public ClusterRequestHandler(final EjbDaemon daemon) {
+        super(daemon);
+    }
+
+    @Override
+    public Logger getLogger() {
+        return logger;
     }
 
+    @Override
+    public ClusterResponse processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
 
-    public void processRequest(ObjectInputStream in, ObjectOutputStream out) throws IOException {
-        ClusterRequest req = new ClusterRequest();
-        ClusterResponse res = new ClusterResponse();
+        final ClusterRequest req = new ClusterRequest();
+        req.setMetaData(metaData);
+
+        final ClusterResponse res = new ClusterResponse();
+        res.setMetaData(metaData);
 
         try {
             req.readExternal(in);
         } catch (IOException e) {
             res.setFailure(e);
-            sendErrorResponse("Cannot read ClusterRequest", e, res, out);
-            throw e;
+            return res;
         } catch (ClassNotFoundException e) {
-            res.setFailure(e);
-            sendErrorResponse("Cannot read ClusterRequest", e, res, out);
-            throw (IOException) new IOException().initCause(e);
+            res.setFailure(new IOException().initCause(e));
+            return res;
         }
 
-        ClusterMetaData currentClusterMetaData = data.current();
+        final ClusterMetaData currentClusterMetaData = data.current();
 
-        if (req.getClusterMetaDataVersion() < currentClusterMetaData.getVersion()){
+        if (req.getClusterMetaDataVersion() < currentClusterMetaData.getVersion()) {
             if (logger.isDebugEnabled()) {
-                URI[] locations = currentClusterMetaData.getLocations();
+                final URI[] locations = currentClusterMetaData.getLocations();
                 if (locations.length < 10) {
                     logger.debug("Sending client updated cluster locations: [" + Join.join(", ", locations) + "]");
                 } else {
@@ -81,32 +91,41 @@ public class ClusterRequestHandler imple
             res.setCurrent();
         }
 
-        try {
-            res.writeExternal(out);
-        } catch (IOException e) {
-            logger.error("Failed to write to ClusterResponse", e);
-            throw e;
-        }
+        return res;
     }
 
-    private void sendErrorResponse(String message, Throwable t, ClusterResponse res, ObjectOutputStream out) throws IOException {
-        logger.fatal(message, t);
-        t = new IOException("The server has encountered a fatal error: " + message + " " + t).initCause(t);
-        try {
-            res.writeExternal(out);
-        } catch (IOException ie) {
-            String m = "Failed to write to ClusterResponse";
-            logger.error(m, ie);
-            throw Exceptions.newIOException(m, ie);
+    @Override
+    public String getName() {
+        return "Cluster";
+    }
+
+    @Override
+    public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+        if (null != response) {
+
+            if (ClusterResponse.class.isInstance(response)) {
+
+                final ClusterResponse res = ClusterResponse.class.cast(response);
+
+                try {
+                    res.setMetaData(metaData);
+                    res.writeExternal(out);
+                } catch (IOException e) {
+                    logger.error("Failed to write to ClusterResponse", e);
+                    throw e;
+                }
+            } else {
+                logger.error("ClusterRequestHandler cannot process an instance of: " + response.getClass().getName());
+            }
         }
     }
 
+    @Override
     public void serviceAdded(final URI uri) {
         try {
-            URI type = uri;
-            URI service = unwrap(type);
+            final URI service = unwrap(uri);
 
-            if ("ejb".equals(type.getScheme())) {
+            if ("ejb".equals(uri.getScheme())) {
                 logger.info("Peer discovered: " + service.toString());
                 data.add(service);
             }
@@ -115,17 +134,16 @@ public class ClusterRequestHandler imple
         }
     }
 
-    private URI unwrap(URI uri) throws URISyntaxException {
+    private URI unwrap(final URI uri) throws URISyntaxException {
         return new URI(uri.getSchemeSpecificPart());
     }
 
-
+    @Override
     public void serviceRemoved(final URI uri) {
         try {
-            URI type = uri;
-            URI service = unwrap(type);
+            final URI service = unwrap(uri);
 
-            if ("ejb".equals(type.getScheme())) {
+            if ("ejb".equals(uri.getScheme())) {
                 logger.info("Peer removed: " + service.toString());
                 data.remove(service);
             }
@@ -135,59 +153,76 @@ public class ClusterRequestHandler imple
     }
 
     private static class Data {
-        private ClusterMetaData current;
-        private ReadWriteLock sync = new ReentrantReadWriteLock();
+
+        private final AtomicReference<ClusterMetaData> current = new AtomicReference<ClusterMetaData>();
+        private final ReadWriteLock sync = new ReentrantReadWriteLock();
         private final java.util.Set set = new LinkedHashSet();
 
         public Data() {
-            this.current = new ClusterMetaData(0);
+            this.current.set(new ClusterMetaData(0));
         }
 
-        public boolean add(URI o) {
-            Lock lock = sync.writeLock();
+        @SuppressWarnings("unchecked")
+        public boolean add(final URI o) {
+
+            final Lock lock = sync.writeLock();
             lock.lock();
-            ClusterMetaData nextVersion = null;
+
             try {
-                if (set.add(o)) {
-                    nextVersion = newClusterMetaData(set, current);
-                    return true;
-                } else {
-                    return false;
+                ClusterMetaData nextVersion = null;
+                try {
+                    if (set.add(o)) {
+                        nextVersion = newClusterMetaData(set, current.get());
+                        return true;
+                    } else {
+                        return false;
+                    }
+                } finally {
+                    if (nextVersion != null) {
+                        current.set(nextVersion);
+                    }
                 }
             } finally {
-                if (nextVersion != null) current = nextVersion;
+
                 lock.unlock();
             }
         }
 
-        public boolean remove(Object o) {
-            Lock lock = sync.writeLock();
+        public boolean remove(final Object o) {
+            final Lock lock = sync.writeLock();
             lock.lock();
-            ClusterMetaData nextVersion = null;
+
             try {
-                if (set.remove(o)) {
-                    nextVersion = newClusterMetaData(set, current);
-                    return true;
-                } else {
-                    return false;
+                ClusterMetaData nextVersion = null;
+                try {
+                    if (set.remove(o)) {
+                        nextVersion = newClusterMetaData(set, current.get());
+                        return true;
+                    } else {
+                        return false;
+                    }
+                } finally {
+                    if (nextVersion != null) {
+                        current.set(nextVersion);
+                    }
                 }
             } finally {
-                if (nextVersion != null) current = nextVersion;
+
                 lock.unlock();
             }
         }
 
-        private static ClusterMetaData newClusterMetaData(Set set, ClusterMetaData current) {
-            URI[] locations = new URI[set.size()];
+        private static ClusterMetaData newClusterMetaData(final Set set, final ClusterMetaData current) {
+            final URI[] locations = new URI[set.size()];
             set.toArray(locations);
             return new ClusterMetaData(System.currentTimeMillis(), locations);
         }
 
         public ClusterMetaData current() {
-            Lock lock = sync.readLock();
+            final Lock lock = sync.readLock();
             lock.lock();
             try {
-                return current;
+                return current.get();
             } finally {
                 lock.unlock();
             }

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=1511348&r1=1511347&r2=1511348&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 Wed Aug  7 15:06:21 2013
@@ -19,11 +19,13 @@ package org.apache.openejb.server.ejbd;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.ProxyInfo;
+import org.apache.openejb.client.ClusterResponse;
 import org.apache.openejb.client.EJBRequest;
 import org.apache.openejb.client.EjbObjectInputStream;
 import org.apache.openejb.client.FlushableGZIPOutputStream;
 import org.apache.openejb.client.ProtocolMetaData;
 import org.apache.openejb.client.RequestType;
+import org.apache.openejb.client.Response;
 import org.apache.openejb.client.ServerMetaData;
 import org.apache.openejb.client.serializer.EJBDSerializer;
 import org.apache.openejb.loader.SystemInstance;
@@ -32,6 +34,7 @@ import org.apache.openejb.server.context
 import org.apache.openejb.server.stream.CountingInputStream;
 import org.apache.openejb.server.stream.CountingOutputStream;
 import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.util.Exceptions;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
@@ -50,15 +53,16 @@ import java.util.zip.GZIPInputStream;
 
 public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
 
-    private static final ProtocolMetaData PROTOCOL_VERSION = new ProtocolMetaData("4.6"); // aligned with org.apache.openejb.client.EJBRequest.readExternal(java.io.ObjectInput)() and org.apache.openejb.client.Client.PROTOCOL_VERSION
+    //This is used to tell the clients which protocol we understand
+    private static final ProtocolMetaData PROTOCOL_VERSION = new ProtocolMetaData(); // aligned with org.apache.openejb.client.EJBRequest.readExternal(java.io.ObjectInput)() and org.apache.openejb.client.Client.PROTOCOL_VERSION
 
     static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources");
 
     private ClientObjectFactory clientObjectFactory;
     //    DeploymentIndex deploymentIndex;
-    private EjbRequestHandler ejbHandler;
-    private JndiRequestHandler jndiHandler;
-    private AuthRequestHandler authHandler;
+    private RequestHandler ejbHandler;
+    private RequestHandler jndiHandler;
+    private RequestHandler authHandler;
     private ClusterRequestHandler clusterHandler;
 
     private ContainerSystem containerSystem;
@@ -153,14 +157,7 @@ public class EjbDaemon implements org.ap
     }
 
     public void service(final InputStream rawIn, final OutputStream rawOut) throws IOException {
-        final ProtocolMetaData protocolMetaData = new ProtocolMetaData();
-
-        final CountingInputStream in = new CountingInputStream(rawIn);
-        final CountingOutputStream out = new CountingOutputStream(rawOut);
-
-        final RequestInfos.RequestInfo info = RequestInfos.info();
-        info.inputStream = in;
-        info.outputStream = out;
+        final ProtocolMetaData clientMetaData = new ProtocolMetaData();
 
         ObjectInputStream ois = null;
         ObjectOutputStream oos = null;
@@ -169,12 +166,12 @@ public class EjbDaemon implements org.ap
 
         try {
 
-            // Read Protocol Version
-            protocolMetaData.readExternal(in);
-            PROTOCOL_VERSION.writeExternal(out);
+            final RequestInfos.RequestInfo info = RequestInfos.info();
+            info.inputStream = new CountingInputStream(rawIn);
 
-            ois = new EjbObjectInputStream(in);
-            oos = new ObjectOutputStream(out);
+            // Read client Protocol Version
+            clientMetaData.readExternal(info.inputStream);
+            ois = new EjbObjectInputStream(info.inputStream);
 
             // Read ServerMetaData
             final ServerMetaData serverMetaData = new ServerMetaData();
@@ -182,18 +179,39 @@ public class EjbDaemon implements org.ap
             ClientObjectFactory.serverMetaData.set(serverMetaData);
 
             // Read request type
-            requestTypeByte = (byte) ois.read();
+            requestTypeByte = ois.readByte();
             requestType = RequestType.valueOf(requestTypeByte);
 
             if (requestType == RequestType.NOP_REQUEST) {
                 return;
             }
 
+            ClusterResponse clusterResponse = null;
+
             if (requestType == RequestType.CLUSTER_REQUEST) {
-                processClusterRequest(ois, oos);
+                clusterResponse = clusterHandler.processRequest(ois, clientMetaData);
+
+                //Check for immediate failure
+                final Throwable failure = clusterResponse.getFailure();
+                if (null != clusterResponse && null != failure) {
+
+                    clusterHandler.getLogger().debug("Failed to write to ClusterResponse", failure);
+
+                    try {
+                        oos = new ObjectOutputStream(info.outputStream);
+                        clusterResponse.setMetaData(clientMetaData);
+                        clusterResponse.writeExternal(oos);
+                    } catch (IOException ie) {
+                        final String m = "Failed to write to ClusterResponse";
+                        clusterHandler.getLogger().error(m, ie);
+                        throw Exceptions.newIOException(m, ie);
+                    }
+
+                    throw failure;
+                }
             }
 
-            requestTypeByte = (byte) ois.read();
+            requestTypeByte = ois.readByte();
             requestType = RequestType.valueOf(requestTypeByte);
 
             if (requestType == RequestType.NOP_REQUEST) {
@@ -203,36 +221,59 @@ public class EjbDaemon implements org.ap
             // Exceptions should not be thrown from these methods
             // They should handle their own exceptions and clean
             // things up with the client accordingly.
+            final Response response;
             switch (requestType) {
                 case EJB_REQUEST:
-                    processEjbRequest(ois, oos, protocolMetaData);
+                    response = processEjbRequest(ois, clientMetaData);
                     break;
                 case JNDI_REQUEST:
-                    processJndiRequest(ois, oos);
+                    response = processJndiRequest(ois, clientMetaData);
                     break;
                 case AUTH_REQUEST:
-                    processAuthRequest(ois, oos);
+                    response = processAuthRequest(ois, clientMetaData);
                     break;
                 default:
-                    logger.error("\"" + requestType + " " + protocolMetaData.getSpec() + "\" FAIL \"Unknown request type " + requestType);
+                    logger.error("\"" + requestType + " " + clientMetaData.getSpec() + "\" FAIL \"Unknown request type " + requestType);
+                    return;
+            }
+
+            info.outputStream = new CountingOutputStream(rawOut);
+            PROTOCOL_VERSION.writeExternal(info.outputStream);
+            oos = new ObjectOutputStream(info.outputStream);
+
+            clusterHandler.processResponse(clusterResponse, oos, clientMetaData);
+
+            switch (requestType) {
+                case EJB_REQUEST:
+                    processEjbResponse(response, oos, clientMetaData);
                     break;
+                case JNDI_REQUEST:
+                    processJndiResponse(response, oos, clientMetaData);
+                    break;
+                case AUTH_REQUEST:
+                    processAuthResponse(response, oos, clientMetaData);
+                    break;
+                default:
+                    //Should never get here...
+                    logger.error("\"" + requestType + " " + clientMetaData.getSpec() + "\" FAIL \"Unknown response type " + requestType);
             }
+
         } catch (IllegalArgumentException iae) {
-            final String msg = "\"" + protocolMetaData.getSpec() + "\" FAIL \"Unknown request type " + requestTypeByte;
+            final String msg = "\"" + clientMetaData.getSpec() + "\" FAIL \"Unknown request type " + requestTypeByte;
             if (logger.isDebugEnabled()) {
                 logger.debug(msg, iae);
             } else {
                 logger.warning(msg + " - Debug for StackTrace");
             }
         } catch (SecurityException e) {
-            final String msg = "\"" + requestType + " " + protocolMetaData.getSpec() + "\" FAIL \"Security error - " + e.getMessage() + "\"";
+            final String msg = "\"" + requestType + " " + clientMetaData.getSpec() + "\" FAIL \"Security error - " + e.getMessage() + "\"";
             if (logger.isDebugEnabled()) {
                 logger.debug(msg, e);
             } else {
                 logger.warning(msg + " - Debug for StackTrace");
             }
         } catch (Throwable e) {
-            final String msg = "\"" + requestType + " " + protocolMetaData.getSpec() + "\" FAIL \"Unexpected error - " + e.getMessage() + "\"";
+            final String msg = "\"" + requestType + " " + clientMetaData.getSpec() + "\" FAIL \"Unexpected error - " + e.getMessage() + "\"";
             if (logger.isDebugEnabled()) {
                 logger.debug(msg, e);
             } else {
@@ -268,10 +309,6 @@ public class EjbDaemon implements org.ap
         }
     }
 
-    private void processClusterRequest(final ObjectInputStream in, final ObjectOutputStream out) throws IOException {
-        clusterHandler.processRequest(in, out);
-    }
-
     protected BeanContext getDeployment(final EJBRequest req) throws RemoteException {
         final String deploymentId = req.getDeploymentId();
         final BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
@@ -281,16 +318,28 @@ public class EjbDaemon implements org.ap
         return beanContext;
     }
 
-    public void processEjbRequest(final ObjectInputStream in, final ObjectOutputStream out, final ProtocolMetaData metaData) {
-        ejbHandler.processRequest(in, out, metaData);
+    public Response processEjbRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+        return ejbHandler.processRequest(in, metaData);
     }
 
-    public void processJndiRequest(final ObjectInputStream in, final ObjectOutputStream out) throws Exception {
-        jndiHandler.processRequest(in, out);
+    public Response processJndiRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+        return jndiHandler.processRequest(in, metaData);
     }
 
-    public void processAuthRequest(final ObjectInputStream in, final ObjectOutputStream out) {
-        authHandler.processRequest(in, out);
+    public Response processAuthRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+        return authHandler.processRequest(in, metaData);
+    }
+
+    public void processEjbResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+        ejbHandler.processResponse(response, out, metaData);
+    }
+
+    public void processJndiResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+        jndiHandler.processResponse(response, out, metaData);
+    }
+
+    public void processAuthResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+        authHandler.processResponse(response, out, metaData);
     }
 
     @Override
@@ -332,6 +381,7 @@ public class EjbDaemon implements org.ap
     }
 
     private static class ContextualSerializer implements EJBDSerializer {
+
         private final String classname;
 
         public ContextualSerializer(final String serializer) {

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=1511348&r1=1511347&r2=1511348&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 Wed Aug  7 15:06:21 2013
@@ -26,6 +26,7 @@ import org.apache.openejb.client.EJBRequ
 import org.apache.openejb.client.EJBResponse;
 import org.apache.openejb.client.JNDIContext;
 import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
 import org.apache.openejb.client.ResponseCodes;
 import org.apache.openejb.client.ThrowableArtifact;
 import org.apache.openejb.client.serializer.EJBDSerializer;
@@ -47,20 +48,18 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-class EjbRequestHandler {
+class EjbRequestHandler extends RequestHandler {
 
     public static final ServerSideResolver SERVER_SIDE_RESOLVER = new ServerSideResolver();
 
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("ejb"), "org.apache.openejb.server.util.resources");
-    private final EjbDaemon daemon;
 
     private final ClusterableRequestHandler clusterableRequestHandler;
 
     private final Map<String, AtomicBoolean> asynchronousInvocationCancelMap = new ConcurrentHashMap<String, AtomicBoolean>();
 
-    EjbRequestHandler(final EjbDaemon daemon) {
-        this.daemon = daemon;
-
+    protected EjbRequestHandler(final EjbDaemon daemon) {
+        super(daemon);
         clusterableRequestHandler = newClusterableRequestHandler();
     }
 
@@ -68,7 +67,18 @@ class EjbRequestHandler {
         return new BasicClusterableRequestHandler();
     }
 
-    public void processRequest(final ObjectInputStream in, final ObjectOutputStream out, final ProtocolMetaData metaData) {
+    @Override
+    public Logger getLogger() {
+        return logger;
+    }
+
+    @Override
+    public String getName() {
+        return "EJB";
+    }
+
+    @Override
+    public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
 
         // Setup the client proxy replacement to replace
         // the proxies with the IntraVM proxy implementations
@@ -76,16 +86,18 @@ class EjbRequestHandler {
         EJBObjectProxyHandle.resolver.set(SERVER_SIDE_RESOLVER);
 
         final EJBRequest req = new EJBRequest();
+        req.setMetaData(metaData);
         byte version = req.getVersion();
-        final EJBResponse res = new EJBResponse();
 
+        final EJBResponse res = new EJBResponse();
+        res.setMetaData(metaData);
         res.start(EJBResponse.Time.TOTAL);
+        res.setRequest(req);
 
         try {
             req.readExternal(in);
         } catch (Throwable t) {
-            replyWithFatalError(version, out, t, "Bad request");
-            return;
+            return setResponseError(res, version, t, "Bad request");
         }
 
         final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
@@ -99,9 +111,8 @@ class EjbRequestHandler {
                     securityService.associate(clientIdentity);
                 }
             } catch (LoginException t) {
-                replyWithFatalError(version, out, t, "Client identity is not valid - " + req);
                 failed = true;
-                return;
+                return setResponseError(res, version, t, "Client identity is not valid - " + req);
             }
 
             final BeanContext di;
@@ -109,13 +120,11 @@ class EjbRequestHandler {
             try {
                 di = this.daemon.getDeployment(req);
             } catch (RemoteException e) {
-                replyWithFatalError(version, out, e, "No such deployment");
                 failed = true;
-                return;
+                return setResponseError(res, version, e, "No such deployment");
             } catch (Throwable t) {
-                replyWithFatalError(version, out, t, "Unkown error occured while retrieving deployment: " + req);
                 failed = true;
-                return;
+                return setResponseError(res, version, t, "Unkown error occured while retrieving deployment: " + req);
             }
 
             try {
@@ -126,16 +135,15 @@ class EjbRequestHandler {
 
                 res.start(EJBResponse.Time.DESERIALIZATION);
 
-                req.getBody().readExternal(in, metaData);
+                req.getBody().readExternal(in);
 
                 //Client version retrieved from body
                 version = req.getVersion();
 
                 res.stop(EJBResponse.Time.DESERIALIZATION);
             } catch (Throwable t) {
-                replyWithFatalError(version, out, t, "Error caught during request body deserialization: " + req);
                 failed = true;
-                return;
+                return setResponseError(res, version, t, "Error caught during request body deserialization: " + req);
             }
 
             try {
@@ -143,9 +151,8 @@ class EjbRequestHandler {
                 call.setEJBRequest(req);
                 call.setBeanContext(di);
             } catch (Throwable t) {
-                replyWithFatalError(version, out, t, "Unable to set the thread call context for this request: " + req);
                 failed = true;
-                return;
+                return setResponseError(res, version, t, "Unable to set the thread call context for this request: " + req);
             }
 
         } finally {
@@ -155,7 +162,6 @@ class EjbRequestHandler {
         }
 
         res.start(EJBResponse.Time.CONTAINER);
-        boolean respond = true;
 
         Object securityToken = null;
         try {
@@ -255,12 +261,12 @@ class EjbRequestHandler {
             logger.error("System error in container for request: " + req, e);
         } catch (Throwable t) {
 
-            replyWithFatalError(version, out, t, "Unknown error in container");
-            respond = false;
+            return setResponseError(res, version, t, "Unknown error in container");
 
         } finally {
             if (securityToken != null) {
                 try {
+                    //noinspection unchecked
                     securityService.logout(securityToken);
                 } catch (final LoginException e) {
                     // no-op
@@ -281,24 +287,43 @@ class EjbRequestHandler {
                     //Ignore
                 }
             }
+        }
 
-            if (respond) {
+        return res;
+    }
+
+    @Override
+    public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+        if (EJBResponse.class.isInstance(response)) {
+
+            final EJBResponse res = EJBResponse.class.cast(response);
+
+            try {
+                res.setMetaData(metaData);
+                res.writeExternal(out);
+            } catch (Throwable t) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Failed to write EjbResponse", t);
+                } else if (logger.isInfoEnabled()) {
+                    logger.info("Failed to write EjbResponse - Debug for stacktrace: " + t);
+                }
+            } finally {
                 try {
-                    res.writeExternal(out);
+                    SystemInstance.get().getComponent(SecurityService.class).disassociate();
                 } catch (Throwable t) {
-                    logger.error("Failed to write EjbResponse", t);
+                    logger.warning("Failed to disassociate security", t);
                 }
-            }
 
-            try {
-                securityService.disassociate();
-            } catch (Throwable t) {
-                logger.warning("Failed to disassociate security", t);
-            }
+                final CallContext call = CallContext.getCallContext();
+                if (null != call) {
+                    call.reset();
+                }
 
-            call.reset();
-            EJBHomeProxyHandle.resolver.set(null);
-            EJBObjectProxyHandle.resolver.set(null);
+                EJBHomeProxyHandle.resolver.set(null);
+                EJBObjectProxyHandle.resolver.set(null);
+            }
+        } else {
+            logger.error("EjbRequestHandler cannot process an instance of: " + response.getClass().getName());
         }
     }
 
@@ -554,7 +579,7 @@ class EjbRequestHandler {
         res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, null);
     }
 
-    private void replyWithFatalError(final byte version, final ObjectOutputStream out, final Throwable error, final String message) {
+    private EJBResponse setResponseError(final EJBResponse res, final byte version, final Throwable error, final String message) {
 
         //This is fatal for the client, but not the server.
         if (logger.isInfoEnabled()) {
@@ -564,17 +589,7 @@ class EjbRequestHandler {
         }
 
         final RemoteException re = new RemoteException(message, error);
-        final EJBResponse res = new EJBResponse();
         res.setResponse(version, ResponseCodes.EJB_ERROR, new ThrowableArtifact(re));
-
-        try {
-            res.writeExternal(out);
-        } catch (Throwable t) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Failed to write EjbResponse", t);
-            } else if (logger.isInfoEnabled()) {
-                logger.info("Failed to write EjbResponse - Debug for stacktrace: " + t);
-            }
-        }
+        return res;
     }
 }

Modified: tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java?rev=1511348&r1=1511347&r2=1511348&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java (original)
+++ tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java Wed Aug  7 15:06:21 2013
@@ -29,6 +29,8 @@ import org.apache.openejb.client.JNDIReq
 import org.apache.openejb.client.JNDIResponse;
 import org.apache.openejb.client.NameClassPairEnumeration;
 import org.apache.openejb.client.PortRefMetaData;
+import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
 import org.apache.openejb.client.ResponseCodes;
 import org.apache.openejb.client.ThrowableArtifact;
 import org.apache.openejb.client.WsMetaData;
@@ -75,7 +77,7 @@ import java.util.Set;
 
 import static org.apache.openejb.server.ejbd.ClientObjectFactory.convert;
 
-class JndiRequestHandler {
+class JndiRequestHandler extends RequestHandler {
 
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("jndi"), "org.apache.openejb.server.util.resources");
 
@@ -89,6 +91,7 @@ class JndiRequestHandler {
     private Context rootContext;
 
     JndiRequestHandler(final EjbDaemon daemon) throws Exception {
+        super(daemon);
         final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
         ejbJndiTree = (Context) containerSystem.getJNDIContext().lookup("openejb/remote");
         deploymentsJndiTree = (Context) containerSystem.getJNDIContext().lookup("openejb/Deployment");
@@ -107,11 +110,25 @@ class JndiRequestHandler {
         return new BasicClusterableRequestHandler();
     }
 
-    public void processRequest(final ObjectInputStream in, final ObjectOutputStream out) {
+    @Override
+    public Logger getLogger() {
+        return logger;
+    }
+
+    @Override
+    public String getName() {
+        return "JNDI";
+    }
+
+    @Override
+    public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) {
+
+        final JNDIRequest req = new JNDIRequest();
         final JNDIResponse res = new JNDIResponse();
-        JNDIRequest req = null;
+        res.setRequest(req);
+
         try {
-            req = new JNDIRequest();
+            req.setMetaData(metaData);
             req.readExternal(in);
         } catch (Throwable e) {
             res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
@@ -126,50 +143,66 @@ class JndiRequestHandler {
                     // no-op
                 }
             }
-
-            try {
-                res.writeExternal(out);
-            } catch (java.io.IOException ie) {
-                logger.fatal("Couldn't write JndiResponse to output stream", ie);
-            }
         }
+        return res;
+    }
 
-        try {
-            if (req.getRequestString().startsWith("/")) {
-                req.setRequestString(req.getRequestString().substring(1));
-            }
-            final String prefix = getPrefix(req);
+    @Override
+    public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
 
-            switch (req.getRequestMethod()) {
-                case JNDI_LOOKUP:
-                    doLookup(req, res, prefix);
-                    break;
-                case JNDI_LIST:
-                    doList(req, res, prefix);
-                    break;
-            }
+        if (JNDIResponse.class.isInstance(response)) {
 
-        } catch (Throwable e) {
-            res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
-            final NamingException namingException = new NamingException("Unknown error in container");
-            namingException.setRootCause(e);
-            res.setResult(new ThrowableArtifact(namingException));
-        } finally {
+            final JNDIResponse res = JNDIResponse.class.cast(response);
+            final JNDIRequest req = res.getRequest();
 
             try {
-                res.writeExternal(out);
+
+                //Only process if 'processRequest' was ok...
+                final Object result = res.getResult();
+                if (null == result || !ThrowableArtifact.class.isInstance(result)) {
+
+                    if (req.getRequestString().startsWith("/")) {
+                        req.setRequestString(req.getRequestString().substring(1));
+                    }
+
+                    final String prefix = getPrefix(req);
+
+                    switch (req.getRequestMethod()) {
+                        case JNDI_LOOKUP:
+                            doLookup(req, res, prefix);
+                            break;
+                        case JNDI_LIST:
+                            doList(req, res, prefix);
+                            break;
+                    }
+                }
+
             } catch (Throwable e) {
-                logger.fatal("Couldn't write JndiResponse to output stream", e);
-            }
+                res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
+                final NamingException namingException = new NamingException("Unknown error in container");
+                namingException.setRootCause(e);
+                res.setResult(new ThrowableArtifact(namingException));
+            } finally {
 
-            if (logger.isDebugEnabled()) {
                 try {
-                    out.flush(); // force it to as correct as possible response size
-                    logRequestResponse(req, res);
-                } catch (Exception ignore) {
-                    // no-op
+                    res.setMetaData(metaData);
+                    res.writeExternal(out);
+                } catch (Throwable e) {
+                    logger.fatal("Could not write JndiResponse to output stream", e);
+                }
+
+                if (logger.isDebugEnabled()) {
+                    try {
+                        out.flush(); // force it to as correct as possible response size
+                        logRequestResponse(req, res);
+                    } catch (Exception ignore) {
+                        // no-op
+                    }
                 }
             }
+
+        } else {
+            logger.error("JndiRequestHandler cannot process an instance of: " + response.getClass().getName());
         }
     }
 

Added: tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/RequestHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/RequestHandler.java?rev=1511348&view=auto
==============================================================================
--- tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/RequestHandler.java (added)
+++ tomee/tomee/trunk/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/RequestHandler.java Wed Aug  7 15:06:21 2013
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.server.ejbd;
+
+import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
+import org.apache.openejb.util.Logger;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public abstract class RequestHandler {
+
+    final EjbDaemon daemon;
+
+    protected RequestHandler(final EjbDaemon daemon) {
+        this.daemon = daemon;
+    }
+
+    public EjbDaemon getDaemon() {
+        return daemon;
+    }
+
+    public abstract String getName();
+
+    public abstract Logger getLogger();
+
+    public abstract Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception;
+
+    public abstract void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception;
+}



Mime
View raw message