Title: [2439] trunk/openejb3/server/openejb-server: Split client and server and core apart.
Revision
2439
Author
dblevins
Date
2006-02-11 02:01:19 -0500 (Sat, 11 Feb 2006)

Log Message

Split client and server and core apart.

core is not dependent on server or client
client is not dependent on core or server
server is dependent on both client and core

All code was designed to be separated so this was more or less just some selective moving.  The client module was dependent on a few core excpetion classes, though.  Cleaning this up required finally writing the clever exception serializing code that i've had in my head for a couple years.  That should be backported to openejb 2 and 1.

Improved the exception handling of the container builder.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/assembler/classic/ContainerBuilder.java (2438 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/assembler/classic/ContainerBuilder.java	2006-02-10 22:23:25 UTC (rev 2438)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/assembler/classic/ContainerBuilder.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -1,21 +1,18 @@
 package org.openejb.assembler.classic;
 
+import org.apache.xbean.recipe.ConstructionException;
+import org.apache.xbean.recipe.ObjectRecipe;
+import org.apache.xbean.recipe.StaticRecipe;
 import org.openejb.Container;
 import org.openejb.OpenEJBException;
 import org.openejb.RpcContainer;
-import org.openejb.spi.SecurityService;
-import org.openejb.loader.SystemInstance;
 import org.openejb.core.DeploymentInfo;
+import org.openejb.loader.SystemInstance;
+import org.openejb.spi.SecurityService;
 import org.openejb.util.Logger;
-import org.openejb.util.SafeToolkit;
-import org.apache.xbean.recipe.ObjectRecipe;
-import org.apache.xbean.recipe.StaticRecipe;
-import org.apache.xbean.recipe.ConstructionException;
 
 import javax.transaction.TransactionManager;
 import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -94,27 +91,28 @@
         String containerName = containerInfo.containerName;
         ContainerInfo service = containerInfo;
 
-            Properties systemProperties = System.getProperties();
-            synchronized (systemProperties) {
-                String userDir = systemProperties.getProperty("user.dir");
-                try {
-                    File base = SystemInstance.get().getBase().getDirectory();
-                    systemProperties.setProperty("user.dir", base.getAbsolutePath());
+        Properties systemProperties = System.getProperties();
+        synchronized (systemProperties) {
+            String userDir = systemProperties.getProperty("user.dir");
+            try {
+                File base = SystemInstance.get().getBase().getDirectory();
+                systemProperties.setProperty("user.dir", base.getAbsolutePath());
 
-                    ObjectRecipe containerRecipe = new ObjectRecipe(service.className, service.constructorArgs, null);
-                    containerRecipe.setAllProperties(service.properties);
-                    containerRecipe.setProperty("id", new StaticRecipe(containerName) );
-                    containerRecipe.setProperty("transactionManager", new StaticRecipe(props.get(TransactionManager.class.getName())) );
-                    containerRecipe.setProperty("securityService", new StaticRecipe(props.get(SecurityService.class.getName())) );
-                    containerRecipe.setProperty("deployments", new StaticRecipe(deploymentsList) );
+                ObjectRecipe containerRecipe = new ObjectRecipe(service.className, service.constructorArgs, null);
+                containerRecipe.setAllProperties(service.properties);
+                containerRecipe.setProperty("id", new StaticRecipe(containerName));
+                containerRecipe.setProperty("transactionManager", new StaticRecipe(props.get(TransactionManager.class.getName())));
+                containerRecipe.setProperty("securityService", new StaticRecipe(props.get(SecurityService.class.getName())));
+                containerRecipe.setProperty("deployments", new StaticRecipe(deploymentsList));
 
-                    return (Container) containerRecipe.create();
-                } catch (Exception e) {
-                    throw new OpenEJBException(AssemblerTool.messages.format("as0002", containerName, e.getMessage()), e);
-                } finally {
-                    systemProperties.setProperty("user.dir", userDir);
-                }
+                return (Container) containerRecipe.create();
+            } catch (Exception e) {
+                Throwable cause = (e.getCause() != null) ? e.getCause() : e;
+                throw new OpenEJBException(AssemblerTool.messages.format("as0002", containerName, cause.getMessage()), cause);
+            } finally {
+                systemProperties.setProperty("user.dir", userDir);
             }
+        }
     }
 
     private Container wrapContainer(Container container) {

Copied: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client (from rev 2429, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client) ( => )

Added: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ApplicationException.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/ApplicationException.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ApplicationException.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,30 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.openejb.client;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class ApplicationException extends Exception {
+    public ApplicationException(ThrowableArtifact cause) {
+        super(cause.getThrowable());
+    }
+
+    public ApplicationException(Throwable cause) {
+        super(cause);
+    }
+}

Added: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ArrayEnumeration.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/ArrayEnumeration.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ArrayEnumeration.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,86 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.openejb.client;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.NoSuchElementException;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public final class ArrayEnumeration implements Enumeration, Externalizable {
+    static final long serialVersionUID = -1194966576855523042L;
+
+    private Object[] elements;
+    private int elementsIndex;
+
+    public ArrayEnumeration(Vector elements) {
+        this.elements = new Object[elements.size()];
+        elements.copyInto(this.elements);
+    }
+
+    public ArrayEnumeration(java.util.List list) {
+        this.elements = new Object[list.size()];
+        list.toArray(this.elements);
+    }
+
+    public ArrayEnumeration() {
+    }
+
+    public Object get(int index) {
+        return elements[index];
+    }
+
+    public void set(int index, Object o) {
+        elements[index] = o;
+    }
+
+    public int size() {
+        return elements.length;
+    }
+
+    public boolean hasMoreElements() {
+        return (elementsIndex < elements.length);
+    }
+
+    public Object nextElement() {
+        if (!hasMoreElements()) throw new NoSuchElementException("No more elements exist");
+        return elements[elementsIndex++];
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(elements.length);
+        out.writeInt(elementsIndex);
+        for (int i = 0; i < elements.length; i++) {
+            out.writeObject(elements[i]);
+        }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        elements = new Object[in.readInt()];
+        elementsIndex = in.readInt();
+        for (int i = 0; i < elements.length; i++) {
+            elements[i] = in.readObject();
+        }
+    }
+
+}

Modified: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EJBHomeHandler.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/EJBHomeHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EJBHomeHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -127,9 +127,12 @@
 
             }
 
-        } catch (org.openejb.SystemException se) {
+        } catch (SystemException se) {
             invalidateReference();
-            throw new RemoteException("Container has suffered a SystemException", se.getRootCause());
+            throw new RemoteException("Container has suffered a SystemException", se.getCause());
+        } catch (SystemError se) {
+            invalidateReference();
+            throw new RemoteException("Container has suffered a SystemException", se.getCause());
         }
 
     }
@@ -150,12 +153,12 @@
         EJBResponse res = request(req);
 
         switch (res.getResponseCode()) {
+            case EJB_ERROR:
+                throw new SystemError((ThrowableArtifact) res.getResult());
             case EJB_SYS_EXCEPTION:
-                throw (Throwable) res.getResult();
+                throw new SystemException((ThrowableArtifact) res.getResult());
             case EJB_APP_EXCEPTION:
-                throw (Throwable) res.getResult();
-            case EJB_ERROR:
-                throw (Throwable) res.getResult();
+                throw new ApplicationException((ThrowableArtifact) res.getResult());
             case EJB_OK:
 
                 Object primKey = res.getResult();

Modified: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EJBObjectHandler.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/EJBObjectHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EJBObjectHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -129,28 +129,24 @@
                 throw new UnsupportedOperationException("Unkown method: " + m);
             }
 
-            /*
-            * The ire is thrown by the container system and propagated by
-            * the server to the stub.
-            */
-        } catch (org.openejb.InvalidateReferenceException ire) {
+        } catch (SystemException e) {
             invalidateAllHandlers(getRegistryId());
-            return ire.getRootCause();
+            throw e.getCause();
             /*
             * Application exceptions must be reported dirctly to the client. They
             * do not impact the viability of the proxy.
             */
-        } catch (org.openejb.ApplicationException ae) {
-            throw ae.getRootCause();
+        } catch (ApplicationException ae) {
+            throw ae.getCause();
             /*
             * A system exception would be highly unusual and would indicate a sever
             * problem with the container system.
             */
-        } catch (org.openejb.SystemException se) {
+        } catch (SystemError se) {
             invalidateReference();
-            throw new RemoteException("Container has suffered a SystemException", se.getRootCause());
-        } catch (org.openejb.OpenEJBException oe) {
-            throw new RemoteException("Unknown Container Exception", oe.getRootCause());
+            throw new RemoteException("Container has suffered a SystemException", se.getCause());
+        } catch (Throwable oe) {
+            throw new RemoteException("Unknown Container Exception", oe.getCause());
         }
         return retValue;
     }
@@ -201,18 +197,16 @@
 //        }
         switch (res.getResponseCode()) {
             case EJB_ERROR:
-//            System.out.println("ERROR "+res.getResult());
-                throw (Throwable) res.getResult();
+                throw new SystemError((ThrowableArtifact) res.getResult());
             case EJB_SYS_EXCEPTION:
-//            System.out.println("SYS EXEPTION "+res.getResult());
-                throw (Throwable) res.getResult();
+                throw new SystemException((ThrowableArtifact) res.getResult());
             case EJB_APP_EXCEPTION:
-//            System.out.println("APP EXEPTION "+res.getResult());
-                throw (Throwable) res.getResult();
+                throw new ApplicationException((ThrowableArtifact) res.getResult());
             case EJB_OK:
                 return res.getResult();
             default:
                 throw new RemoteException("Received invalid response code from server: " + res.getResponseCode());
         }
     }
+
 }

Modified: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EntityEJBHomeHandler.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/EntityEJBHomeHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EntityEJBHomeHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -33,11 +33,11 @@
 
         switch (res.getResponseCode()) {
             case EJB_ERROR:
-                throw (Throwable) res.getResult();
+                throw new SystemError((ThrowableArtifact) res.getResult());
             case EJB_SYS_EXCEPTION:
-                throw (Throwable) res.getResult();
+                throw new SystemException((ThrowableArtifact) res.getResult());
             case EJB_APP_EXCEPTION:
-                throw (Throwable) res.getResult();
+                throw new ApplicationException((ThrowableArtifact) res.getResult());
 
             case EJB_OK_FOUND:
                 primKey = res.getResult();
@@ -69,7 +69,8 @@
                     registerHandler(ejb.deploymentID + ":" + primKey, handler);
                     primaryKeys[i] = handler.createEJBObjectProxy();
                 }
-                return new org.openejb.util.ArrayEnumeration(java.util.Arrays.asList(primaryKeys));
+
+                return new ArrayEnumeration(java.util.Arrays.asList(primaryKeys));
             default:
                 throw new RemoteException("Received invalid response code from server: " + res.getResponseCode());
         }

Modified: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EntityEJBObjectHandler.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/EntityEJBObjectHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/EntityEJBObjectHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -51,11 +51,11 @@
 
         switch (res.getResponseCode()) {
             case EJB_ERROR:
-                throw (Throwable) res.getResult();
+                throw new SystemError((ThrowableArtifact) res.getResult());
             case EJB_SYS_EXCEPTION:
-                throw (Throwable) res.getResult();
+                throw new SystemException((ThrowableArtifact) res.getResult());
             case EJB_APP_EXCEPTION:
-                throw (Throwable) res.getResult();
+                throw new ApplicationException((ThrowableArtifact) res.getResult());
             case EJB_OK:
                 invalidateAllHandlers(getRegistryId());
                 return null;

Deleted: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/LocalInitialContextFactory.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/LocalInitialContextFactory.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/LocalInitialContextFactory.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -1,56 +0,0 @@
-package org.openejb.client;
-
-import org.openejb.loader.OpenEJBInstance;
-import org.openejb.loader.SystemInstance;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-import java.util.Hashtable;
-import java.util.Properties;
-
-public class LocalInitialContextFactory implements javax.naming.spi.InitialContextFactory {
-
-    static Context intraVmContext;
-    private static OpenEJBInstance openejb;
-
-    public Context getInitialContext(Hashtable env) throws javax.naming.NamingException {
-        if (intraVmContext == null) {
-            try {
-                Properties properties = new Properties();
-                properties.putAll(env);
-                init(properties);
-            } catch (Exception e) {
-                throw (NamingException) new NamingException("Attempted to load OpenEJB. " + e.getMessage()).initCause(e);
-            }
-            intraVmContext = getIntraVmContext(env);
-        }
-        return intraVmContext;
-    }
-
-    public void init(Properties properties) throws Exception {
-        if (openejb != null) return;
-        SystemInstance.init(properties);
-        openejb = new OpenEJBInstance();
-        if (openejb.isInitialized()) return;
-        openejb.init(properties);
-    }
-
-    private Context getIntraVmContext(Hashtable env) throws javax.naming.NamingException {
-        Context context = null;
-        try {
-            InitialContextFactory factory = null;
-            ClassLoader cl = SystemInstance.get().getClassLoader();
-            Class ivmFactoryClass = Class.forName("org.openejb.core.ivm.naming.InitContextFactory", true, cl);
-
-            factory = (InitialContextFactory) ivmFactoryClass.newInstance();
-            context = factory.getInitialContext(env);
-        } catch (Exception e) {
-            throw new javax.naming.NamingException("Cannot instantiate an IntraVM InitialContext. Exception: "
-                    + e.getClass().getName() + " " + e.getMessage());
-        }
-
-        return context;
-    }
-}
-

Modified: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/StatelessEJBObjectHandler.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/StatelessEJBObjectHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/StatelessEJBObjectHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -23,10 +23,7 @@
     }
 
     public Object getRegistryId() {
-//      if(registryId== null)
-//          registryId= createRegistryId(primaryKey, deploymentID, container);
-//      return registryId;
-        return null;
+        return this.ejb.deploymentID;
     }
 
     protected Object getPrimaryKey(Method method, Object[] args, Object proxy) throws Throwable {

Added: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/SystemError.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/SystemError.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/SystemError.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,29 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.openejb.client;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class SystemError extends Error {
+    public SystemError(ThrowableArtifact cause) {
+        super(cause.getThrowable());
+    }
+    public SystemError(Throwable cause) {
+        super(cause);
+    }
+}

Added: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/SystemException.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/SystemException.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/SystemException.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,29 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.openejb.client;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class SystemException extends Exception {
+    public SystemException(ThrowableArtifact cause) {
+        super(cause.getThrowable());
+    }
+    public SystemException(Throwable cause) {
+        super(cause);
+    }
+}

Added: trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ThrowableArtifact.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/ThrowableArtifact.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-client/src/main/java/org/openejb/client/ThrowableArtifact.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,95 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.openejb.client;
+
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.util.Stack;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class ThrowableArtifact implements Externalizable {
+
+    private Throwable throwable;
+
+    public ThrowableArtifact(Throwable throwable) {
+        this.throwable = throwable;
+    }
+
+    public ThrowableArtifact() {
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        Stack<MockThrowable> stack = new Stack<MockThrowable>();
+
+        for (Throwable cause = throwable; cause != null; cause = cause.getCause()) {
+            stack.add(new MockThrowable(cause));
+        }
+
+        out.writeObject(stack);
+        try {
+            out.writeObject(throwable);
+        } catch (IOException dontCare) {
+        }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        Stack<MockThrowable> stack = (Stack<MockThrowable>) in.readObject();
+        try {
+            throwable = (Throwable) in.readObject();
+        } catch (Exception e) {
+            throwable = createMockThrowable(stack); // recreate exception
+        }
+    }
+
+    private Throwable createMockThrowable(Stack<MockThrowable> stack) {
+        Throwable throwable = stack.pop();
+
+        while (!stack.isEmpty()){
+            throwable = stack.pop().initCause(throwable);
+        }
+
+        return new RuntimeException("The exception sent could not be serialized or deserialized.  This is a mock recreation:\n"+throwable, throwable);
+    }
+
+    public Throwable getThrowable() {
+        return throwable;
+    }
+
+    private static class MockThrowable extends Throwable {
+        private final String classType;
+
+        public MockThrowable(Throwable t){
+            this(t.getMessage(),t.getClass().getName(), t.getStackTrace());
+        }
+
+        public MockThrowable(String message, String classType, StackTraceElement[] stackTrace) {
+            super(message);
+            this.classType = classType;
+            this.setStackTrace(stackTrace);
+        }
+
+        public String toString() {
+            String s = classType;
+            String message = getLocalizedMessage();
+            return (message != null) ? (s + ": " + message) : s;
+        }
+    }
+}

Added: trunk/openejb3/server/openejb-client/src/test/java/org/openejb/client/ThrowableArtifactTest.java (2438 => 2439)

--- trunk/openejb3/server/openejb-client/src/test/java/org/openejb/client/ThrowableArtifactTest.java	2006-02-10 22:23:25 UTC (rev 2438)
+++ trunk/openejb3/server/openejb-client/src/test/java/org/openejb/client/ThrowableArtifactTest.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -0,0 +1,74 @@
+package org.openejb.client;
+/**
+ * @version $Revision$ $Date$
+ */
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.rmi.MarshalledObject;
+
+public class ThrowableArtifactTest extends TestCase {
+
+    public void testThrowableArtifact() throws Throwable {
+        Throwable exception = new NullPointerException("ONE");
+        exception = throwCatchReturn(exception);
+
+        exception = new IllegalArgumentException("TWO", exception);
+        exception = throwCatchReturn(exception);
+
+        exception = new UnsupportedOperationException("THREE", exception);
+        exception = throwCatchReturn(exception);
+
+        exception = new IllegalStateException("FOUR", exception);
+        exception = throwCatchReturn(exception);
+
+        exception = new BadException("FIVE", exception);
+        exception = throwCatchReturn(exception);
+
+        String expectedStackTrace = getPrintedStackTrace(exception);
+
+        ThrowableArtifact artifact = marshal(new ThrowableArtifact(exception));
+        exception = throwCatchReturn(artifact.getThrowable().getCause());
+
+        String actualStackTrace = getPrintedStackTrace(exception);
+
+        assertEquals("stackTrace", expectedStackTrace, actualStackTrace);
+    }
+
+    private String getPrintedStackTrace(Throwable exception) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        PrintStream printStream = new PrintStream(baos);
+        exception.printStackTrace(printStream);
+        printStream.flush();
+        String stackTrace = new String(baos.toByteArray());
+        return stackTrace;
+    }
+
+    private Throwable throwCatchReturn(Throwable exception) {
+        try {
+            throw exception;
+        } catch (Throwable e) {
+            return exception;
+        }
+    }
+
+    private ThrowableArtifact marshal(ThrowableArtifact artifact) throws IOException, ClassNotFoundException {
+        MarshalledObject marshalledObject = new MarshalledObject(artifact);
+        artifact = (ThrowableArtifact) marshalledObject.get();
+        return artifact;
+    }
+
+    public static class BadException extends Exception {
+        private final Object data = "" NotSerializableObject();
+
+        public BadException(String message, Throwable throwable) {
+            super(message, throwable);
+        }
+    }
+
+    public static class NotSerializableObject {
+    }
+}
\ No newline at end of file

Modified: trunk/openejb3/server/openejb-ejbd/src/test/java/org/openejb/RemoteiTest.java (2438 => 2439)

--- trunk/openejb3/server/openejb-ejbd/src/test/java/org/openejb/RemoteiTest.java	2006-02-10 22:23:25 UTC (rev 2438)
+++ trunk/openejb3/server/openejb-ejbd/src/test/java/org/openejb/RemoteiTest.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -32,6 +32,10 @@
 import java.util.Properties;
 
 /**
+ * To run from intellij or another IDE add
+ *
+ * -Dopenejb.home=/Users/dblevins/work/openejb3/server/openejb-ejbd/target/test-classes
+ *
  * @version $Revision$ $Date$
  */
 public class RemoteiTest extends org.openejb.test.TestSuite {

Modified: trunk/openejb3/server/openejb-server/pom.xml (2438 => 2439)

--- trunk/openejb3/server/openejb-server/pom.xml	2006-02-10 22:23:25 UTC (rev 2438)
+++ trunk/openejb3/server/openejb-server/pom.xml	2006-02-11 07:01:19 UTC (rev 2439)
@@ -17,6 +17,11 @@
       <version>3.0-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.openejb</groupId>
+      <artifactId>openejb-client</artifactId>
+      <version>3.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>

Copied: trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server (from rev 2429, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/server) ( => )

Modified: trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server/ejbd/EjbRequestHandler.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/server/ejbd/EjbRequestHandler.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server/ejbd/EjbRequestHandler.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -16,6 +16,7 @@
 import org.openejb.client.EJBResponse;
 import org.openejb.client.RequestMethods;
 import org.openejb.client.ResponseCodes;
+import org.openejb.client.ThrowableArtifact;
 import org.openejb.spi.SecurityService;
 
 class EjbRequestHandler implements ResponseCodes, RequestMethods {
@@ -140,11 +141,11 @@
             }
 
         } catch (org.openejb.InvalidateReferenceException e) {
-            res.setResponse(EJB_SYS_EXCEPTION, e.getRootCause());
+            res.setResponse(EJB_SYS_EXCEPTION, new ThrowableArtifact(e.getRootCause()));
         } catch (org.openejb.ApplicationException e) {
-            res.setResponse(EJB_APP_EXCEPTION, e.getRootCause());
+            res.setResponse(EJB_APP_EXCEPTION, new ThrowableArtifact(e.getRootCause()));
         } catch (org.openejb.SystemException e) {
-            res.setResponse(EJB_ERROR, e.getRootCause());
+            res.setResponse(EJB_ERROR, new ThrowableArtifact(e.getRootCause()));
 
             this.daemon.logger.fatal(req + ": OpenEJB encountered an unknown system error in container: ", e);
         } catch (java.lang.Throwable t) {

Deleted: trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server/telnet/Lookup.java (2429 => 2439)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/server/telnet/Lookup.java	2006-02-08 02:59:57 UTC (rev 2429)
+++ trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server/telnet/Lookup.java	2006-02-11 07:01:19 UTC (rev 2439)
@@ -1,137 +0,0 @@
-package org.openejb.server.telnet;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-
-import javax.ejb.EJBHome;
-import javax.naming.Context;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingEnumeration;
-
-import org.openejb.ClassLoaderUtil;
-import org.openejb.loader.SystemInstance;
-import org.openejb.spi.ContainerSystem;
-import org.openejb.core.ivm.naming.IvmContext;
-
-public class Lookup extends Command {
-
-    javax.naming.Context ctx;
-
-    {
-        ContainerSystem containerSystem = (ContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
-        ctx = containerSystem.getJNDIContext();
-    }
-
-    public static void register() {
-        Lookup cmd = new Lookup();
-        Command.register("lookup", cmd);
-
-    }
-
-    static String PWD = "";
-
-    public void exec(Arguments args, DataInputStream in, PrintStream out) throws IOException {
-        try {
-            String name = "";
-            if (args == null || args.count() == 0) {
-                name = PWD;
-            } else {
-                name = args.get();
-            }
-
-            Object obj = null;
-            try {
-                obj = ctx.lookup(name);
-            }
-            catch (NameNotFoundException e) {
-                out.print("lookup: ");
-                out.print(name);
-                out.println(": No such object or subcontext");
-                return;
-            }
-            catch (Throwable e) {
-                out.print("lookup: error: ");
-                e.printStackTrace(new PrintStream(out));
-                return;
-            }
-
-            if (obj instanceof Context) {
-                list(name, in, out);
-                return;
-            }
-
-            out.println("" + obj);
-        }
-        catch (Exception e) {
-            e.printStackTrace(new PrintStream(out));
-        }
-    }
-
-    public void list(String name, DataInputStream in, PrintStream out) throws IOException {
-        try {
-            NamingEnumeration enum = null;
-            try {
-
-                enum = ctx.list(name);
-            }
-            catch (NameNotFoundException e) {
-                out.print("lookup: ");
-                out.print(name);
-                out.println(": No such object or subcontext");
-                return;
-            }
-            catch (Throwable e) {
-                out.print("lookup: error: ");
-                e.printStackTrace(new PrintStream(out));
-                return;
-            }
-
-            if (enum == null) {
-                return;
-            }
-
-            while (enum.hasMore()) {
-
-                NameClassPair entry = (NameClassPair) enum.next();
-                String eName = entry.getName();
-                Class eClass = null;
-
-                if (IvmContext.class.getName().equals(entry.getClassName())) {
-                    eClass = IvmContext.class;
-                } else {
-                    try {
-                        ClassLoader cl = ClassLoaderUtil.getContextClassLoader();
-                        eClass = Class.forName(entry.getClassName(), true, cl);
-                    }
-                    catch (Throwable t) {
-                        eClass = java.lang.Object.class;
-                    }
-                }
-
-                if (Context.class.isAssignableFrom(eClass)) {
-
-                    out.print(TextConsole.TTY_Bright);
-                    out.print(TextConsole.TTY_FG_Blue);
-                    out.print(entry.getName());
-                    out.print(TextConsole.TTY_Reset);
-                } else if (EJBHome.class.isAssignableFrom(eClass)) {
-
-                    out.print(TextConsole.TTY_Bright);
-                    out.print(TextConsole.TTY_FG_Green);
-                    out.print(entry.getName());
-                    out.print(TextConsole.TTY_Reset);
-                } else {
-
-                    out.print(entry.getName());
-                }
-                out.println();
-            }
-        }
-        catch (Exception e) {
-            e.printStackTrace(new PrintStream(out));
-        }
-    }
-}
-

Copied: trunk/openejb3/server/openejb-server/src/main/java/org/openejb/server/telnet/Lookup.java (from rev 2430, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/server/telnet/Lookup.java) ( => )



Reply via email to