[teiid-commits] teiid SVN: r653 - in trunk: client/src/main/java/com/metamatrix/common/comm/platform/socket/client and 10 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Mar 25 12:01:36 EDT 2009


Author: shawkins
Date: 2009-03-25 12:01:36 -0400 (Wed, 25 Mar 2009)
New Revision: 653

Added:
   trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java
   trunk/client/src/test/java/com/metamatrix/common/comm/exception/
   trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java
   trunk/client/src/test/resources/test.jar
Removed:
   trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java
   trunk/common-core/src/main/java/com/metamatrix/common/util/exception/SQLExceptionUnroller.java
   trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixCoreException.java
   trunk/common-core/src/test/java/com/metamatrix/common/util/exception/TestSQLExceptionUnroller.java
Modified:
   trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
   trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java
   trunk/client/src/main/resources/com/metamatrix/common/comm/platform/i18n.properties
   trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java
   trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java
   trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java
Log:
TEIID-431 changed the approach exception serialization to prevent client class def not found exceptions.

Deleted: trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -1,78 +0,0 @@
-package com.metamatrix.common.comm.exception;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.comm.platform.CommPlatformPlugin;
-
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-public class ExceptionHolder implements Externalizable {
-	
-	private String message;
-	private String className;
-	private boolean isProcessingException;
-	private Throwable exception;
-	
-	public ExceptionHolder() {
-	}
-	
-	public ExceptionHolder(Throwable exception) {
-		this.exception = exception;
-		this.isProcessingException = exception instanceof MetaMatrixProcessingException;
-		this.className = exception.getClass().getName();
-		this.message = exception.getMessage();
-	}
-	
-	@Override
-	public void readExternal(ObjectInput in) throws IOException,
-			ClassNotFoundException {
-		this.className = (String)in.readObject();
-		this.isProcessingException = in.readBoolean();
-		this.message = (String)in.readObject();
-		this.exception = (Throwable)in.readObject();
-	}
-	
-	@Override
-	public void writeExternal(ObjectOutput out) throws IOException {
-		out.writeObject(this.className);
-		out.writeBoolean(this.isProcessingException);
-		out.writeObject(this.message);
-		out.writeObject(this.exception);
-	}
-	
-	public Throwable convertException() {
-		if (exception != null) {
-			return exception;
-		}
-		if (isProcessingException) {
-			return new MetaMatrixProcessingException(CommPlatformPlugin.Util.getString("ExceptionHolder.converted_exception", this.className, this.message));
-		}
-		return new MetaMatrixComponentException(CommPlatformPlugin.Util.getString("ExceptionHolder.converted_exception", this.className, this.message));
-	}
-	
-}

Added: trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java	                        (rev 0)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -0,0 +1,111 @@
+package com.metamatrix.common.comm.exception;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.metamatrix.common.comm.platform.CommPlatformPlugin;
+import com.metamatrix.common.comm.platform.socket.ObjectInputStreamWithClassloader;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.ReflectionHelper;
+
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+public class ExceptionHolder implements Externalizable {
+	
+	private Throwable exception;
+	
+	public ExceptionHolder() {
+	}
+	
+	public ExceptionHolder(Throwable exception) {
+		this.exception = exception;
+	}
+	
+	@Override
+	public void readExternal(ObjectInput in) throws IOException,
+			ClassNotFoundException {
+		List<String> classNames = (List<String>)in.readObject();
+		String message = (String)in.readObject();
+		StackTraceElement[] stackTrace = (StackTraceElement[])in.readObject();
+		byte[] serializedException = (byte[])in.readObject();
+		ByteArrayInputStream bais = new ByteArrayInputStream(serializedException);
+		ObjectInputStream ois = new ObjectInputStreamWithClassloader(bais, Thread.currentThread().getContextClassLoader());
+		try {
+			this.exception = (Throwable)ois.readObject();
+		} catch (ClassNotFoundException e) {
+			List<String> args = Arrays.asList(CommPlatformPlugin.Util.getString("ExceptionHolder.converted_exception", message, classNames)); //$NON-NLS-1$
+			
+			for (String className : classNames) {
+				try {
+					Throwable result = (Throwable)ReflectionHelper.create(className, args, Thread.currentThread().getContextClassLoader());
+					result.initCause(e);
+					result.setStackTrace(stackTrace);
+					this.exception = result;
+					break;
+				} catch (MetaMatrixCoreException e1) {
+					//
+				}
+			}
+			if (this.exception == null) {
+				throw new MetaMatrixRuntimeException(exception, args.get(0));
+			}
+		}
+	}
+	
+	@Override
+	public void writeExternal(ObjectOutput out) throws IOException {
+		List<String> classNames = new ArrayList<String>();
+		Class<?> clazz = exception.getClass();
+		while (clazz != null) {
+			if (clazz == Throwable.class || clazz == Exception.class) {
+				break;
+			}
+			classNames.add(clazz.getName());
+			clazz = clazz.getSuperclass();
+		}
+		out.writeObject(classNames);
+		out.writeObject(exception.getMessage());
+		out.writeObject(exception.getStackTrace());
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(this.exception);
+        oos.flush();
+        oos.close();
+		out.writeObject(baos.toByteArray());
+	}
+	
+	public Throwable getException() {
+		return exception;
+	}
+		
+}

Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -264,7 +264,7 @@
 						try {
 							Object result = getCryptor().unsealObject((Serializable) super.convertResult());
 							if (result instanceof ExceptionHolder) {
-								throw new ExecutionException(((ExceptionHolder)result).convertException());
+								throw new ExecutionException(((ExceptionHolder)result).getException());
 							}
 							if (result instanceof Throwable) {
 								throw new ExecutionException((Throwable)result);

Modified: trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -34,6 +34,7 @@
 
 import com.metamatrix.api.exception.MetaMatrixException;
 import com.metamatrix.common.batch.BatchSerializer;
+import com.metamatrix.common.comm.exception.ExceptionHolder;
 import com.metamatrix.core.util.ExternalizeUtil;
 
 /**
@@ -339,11 +340,18 @@
         // Plan Descriptions
         planDescription = ExternalizeUtil.readMap(in);
 
-        exception = (MetaMatrixException)ExternalizeUtil.readThrowable(in);
+        ExceptionHolder holder = (ExceptionHolder)in.readObject();
+        if (holder != null) {
+        	this.exception = (MetaMatrixException)holder.getException();
+        }
+        List<ExceptionHolder> holderList = (List<ExceptionHolder>)in.readObject();
+        if (holderList != null) {
+        	this.warnings = new ArrayList<Exception>(holderList.size());
+        	for (ExceptionHolder exceptionHolder : holderList) {
+        		this.warnings.add((Exception)exceptionHolder.getException());
+			}
+        }
 
-        //Warnings
-        warnings = ExternalizeUtil.readList(in);
-
         //Schemas
         schemas = ExternalizeUtil.readList(in);
 
@@ -375,9 +383,20 @@
         // Plan descriptions
         ExternalizeUtil.writeMap(out, planDescription);
 
-        ExternalizeUtil.writeThrowable(out, exception);
-        // Warnings
-        ExternalizeUtil.writeList(out, warnings);
+        if (exception != null) {
+        	out.writeObject(new ExceptionHolder(exception));
+        } else {
+        	out.writeObject(exception);
+        }
+        if (this.warnings != null) {
+        	List<ExceptionHolder> replcement = new ArrayList<ExceptionHolder>(this.warnings.size());
+        	for (Exception warning : warnings) {
+				replcement.add(new ExceptionHolder(warning));
+			}
+        	out.writeObject(replcement);
+        } else {
+        	out.writeObject(this.warnings);
+        }
 
         //Schemas
         ExternalizeUtil.writeCollection(out, schemas);

Modified: trunk/client/src/main/resources/com/metamatrix/common/comm/platform/i18n.properties
===================================================================
--- trunk/client/src/main/resources/com/metamatrix/common/comm/platform/i18n.properties	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/client/src/main/resources/com/metamatrix/common/comm/platform/i18n.properties	2009-03-25 16:01:36 UTC (rev 653)
@@ -115,7 +115,7 @@
 
 SocketServerConnection.closed=Server connection is closed
 
-ExceptionHolder.converted_exception=Remote exception of type {0} occurred with message {1}
+ExceptionHolder.converted_exception=Remote exception: {0} ... Original type hierarchy {1}.
 
 SocketHelper.keystore_not_found=Key store ''{0}'' was not found.
 

Added: trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java
===================================================================
--- trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java	                        (rev 0)
+++ trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -0,0 +1,43 @@
+package com.metamatrix.common.comm.exception;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URL;
+
+import org.junit.Test;
+
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.classloader.NonDelegatingClassLoader;
+import com.metamatrix.core.util.ReflectionHelper;
+import com.metamatrix.core.util.UnitTestUtil;
+
+public class TestExceptionHolder {
+		
+	@SuppressWarnings("all")
+	public static class BadException extends MetaMatrixProcessingException {
+		private Object obj;
+		public BadException(Object obj) {
+			this.obj = obj;
+		}
+	}
+	
+	@Test public void testDeserializationUnknownException() throws Exception {
+		ClassLoader cl = new NonDelegatingClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
+		Object obj = ReflectionHelper.create("Test", null, cl); //$NON-NLS-1$
+		
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(new ExceptionHolder(new BadException(obj)));
+        oos.flush();
+        
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        ExceptionHolder holder = (ExceptionHolder)ois.readObject();
+        assertTrue(holder.getException() instanceof MetaMatrixProcessingException);
+        assertEquals("Remote exception: null ... Original type hierarchy [com.metamatrix.common.comm.exception.TestExceptionHolder$BadException, com.metamatrix.api.exception.MetaMatrixProcessingException, com.metamatrix.api.exception.MetaMatrixException, com.metamatrix.core.MetaMatrixCoreException].", holder.getException().getMessage()); //$NON-NLS-1$
+	}
+
+}


Property changes on: trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/client/src/test/resources/test.jar
===================================================================
(Binary files differ)


Property changes on: trunk/client/src/test/resources/test.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/exception/SQLExceptionUnroller.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/exception/SQLExceptionUnroller.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/exception/SQLExceptionUnroller.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/*
- * Date: Mar 5, 2003
- * Time: 5:24:57 PM
- */
-package com.metamatrix.common.util.exception;
-
-import java.sql.SQLException;
-
-/**
- * SQLExceptionUnroller.
- * <br>A utility to unroll a chained <code>SQLException</code>.</br>
- * <p>This utility is used to replace proprietary exceptions that may
- * not unmarshall in other VMs that do not have the proprietary libraries.</p>
- * 
- * TODO: test causes and next exceptions for non-Java then unroll
- */
-public class SQLExceptionUnroller {
-
-    /**
-     * Unroll a chain of possibly proprietary <code>SQLException</code>s
-     * and create a chain of of generic {@link java.sql.SQLException SQLExceptions}
-     * with the original message (reason), SQLState, and vendorCode of the
-     * <code>SQLException</code>s in the chain.
-     * @param theException The original <code>SQLException</code> possibly
-     * with a chain of child exceptions.
-     * @return A <code>SQLException</code> mirroring the original
-     * exception chain.
-     */
-    public static SQLException unRollException(final SQLException theException) {
-        // Get msg, SQLState and vendorCode from top-level exception
-        String SQLState = theException.getSQLState();
-        int vendorCode = theException.getErrorCode();
-        final SQLException outException = new SQLException(
-				(SQLException.class != theException.getClass() ? (theException.getClass().getName() + ": ") : ("")) + theException.getMessage(), SQLState, vendorCode); //$NON-NLS-1$ //$NON-NLS-2$
-        outException.setStackTrace(theException.getStackTrace());
-        
-        // Continue with any chained exceptions
-        SQLException ei = theException.getNextException();
-        if (ei != null) {
-        	outException.setNextException(unRollException(ei));
-        }
-        return outException;
-    }
-    
-}

Modified: trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -22,14 +22,8 @@
 
 package com.metamatrix.core;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.sql.SQLException;
 
-import com.metamatrix.common.util.exception.SQLExceptionUnroller;
 
-
 /**
  * Exception which occurs if an error occurs within the server that is not
  * business-related.  For instance, if a service or bean is not available
@@ -37,8 +31,6 @@
  */
 public class MetaMatrixCoreException extends Exception {
 	
-	private transient Throwable realCause;
-
     public MetaMatrixCoreException() {
     }
 
@@ -51,41 +43,7 @@
     }
 
     public MetaMatrixCoreException(Throwable e, String message) {
-        super(message);
-        this.realCause = e;
+        super(message, e);
     }
     
-    @Override
-    public Throwable getCause() {
-    	return this.realCause;
-    }
-    
-    @Override
-    public synchronized Throwable initCause(Throwable cause) {
-    	if (this.realCause != null)
-            throw new IllegalStateException("Can't overwrite cause"); //$NON-NSL-1$
-        if (cause == this)
-            throw new IllegalArgumentException("Self-causation not permitted"); //$NON-NSL-1$
-        this.realCause = cause;
-        return this;
-    }
-    
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-    	in.defaultReadObject();
-    	try {
-    		realCause = (Throwable)in.readObject();
-    	} catch (ClassNotFoundException cnfe) {
-    		realCause = new MetaMatrixCoreException(cnfe, CorePlugin.Util.getString("MetaMatrixException.deserialization_exception")); //$NON-NSL-1$
-    	}
-    }
-    
-    private void writeObject(ObjectOutputStream out) throws IOException {
-    	getStackTrace();
-    	out.defaultWriteObject();
-    	if (realCause != this && realCause instanceof SQLException) {
-    		out.writeObject(SQLExceptionUnroller.unRollException((SQLException)realCause));
-    	} else {
-    		out.writeObject(realCause);
-    	}
-    }
 }

Modified: trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -22,15 +22,10 @@
 
 package com.metamatrix.core;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
-import java.sql.SQLException;
 
 import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.common.util.exception.SQLExceptionUnroller;
 import com.metamatrix.core.util.MetaMatrixExceptionUtil;
 
 /**
@@ -69,7 +64,6 @@
 
     /** An error code. */
     private String code;
-	private transient Throwable realCause;
 
     //############################################################################################################################
     //# Constructors                                                                                                             #
@@ -143,8 +137,7 @@
      * @param message The error message or a resource bundle key
      */
     public MetaMatrixRuntimeException(final Throwable e, final int code, final String message) {
-        super(message);
-        this.realCause = e;
+        super(message, e);
         // The following setCode call should be executed after setting the message 
         setCode(code);
     }
@@ -241,38 +234,4 @@
         super.printStackTrace(output);
     }
     
-    @Override
-    public Throwable getCause() {
-    	return this.realCause;
-    }
-    
-    @Override
-    public synchronized Throwable initCause(Throwable cause) {
-    	if (this.realCause != this)
-            throw new IllegalStateException("Can't overwrite cause"); //$NON-NSL-1$
-        if (cause == this)
-            throw new IllegalArgumentException("Self-causation not permitted"); //$NON-NSL-1$
-        this.realCause = cause;
-        return this;
-    }
-    
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-    	in.defaultReadObject();
-    	try {
-    		realCause = (Throwable)in.readObject();
-    	} catch (ClassNotFoundException cnfe) {
-    		realCause = new MetaMatrixRuntimeException(cnfe, CorePlugin.Util.getString("MetaMatrixException.deserialization_exception")); //$NON-NSL-1$
-    	}
-    }
-    
-    private void writeObject(ObjectOutputStream out) throws IOException {
-    	getStackTrace();
-    	out.defaultWriteObject();
-    	if (realCause != this && realCause instanceof SQLException) {
-    		out.writeObject(SQLExceptionUnroller.unRollException((SQLException)realCause));
-    	} else {
-    		out.writeObject(realCause);
-    	}
-    }
-
 }

Deleted: trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixCoreException.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixCoreException.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixCoreException.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -1,65 +0,0 @@
-package com.metamatrix.api.exception;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.sql.BatchUpdateException;
-import java.sql.SQLException;
-
-import javax.naming.OperationNotSupportedException;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.util.UnitTestUtil;
-
-public class TestMetaMatrixCoreException extends TestCase {
-	
-	public void testSQLExceptionUnrolling() throws Exception {
-		SQLException se = new BatchUpdateException("foo", new int[] {1}); //$NON-NLS-1$
-		MetaMatrixCoreException mmce = new MetaMatrixCoreException(se);
-		
-		mmce = UnitTestUtil.helpSerialize(mmce);
-		assertEquals(SQLException.class, mmce.getCause().getClass());
-		assertEquals("foo", mmce.getMessage()); //$NON-NLS-1$
-		assertEquals("java.sql.BatchUpdateException: foo", mmce.getCause().getMessage()); //$NON-NLS-1$
-	}
-	
-	public void testInitCause() throws Exception {
-		MetaMatrixCoreException mmce = new MetaMatrixCoreException();
-		mmce.initCause(new Exception());
-		try {
-			mmce.initCause(new Exception());
-			fail();
-		} catch (IllegalStateException e) {
-			
-		}
-	}
-	
-	public void defer_testDeserializationUnknownException() throws Exception {
-		MetaMatrixCoreException mmce = new MetaMatrixCoreException(new OperationNotSupportedException());
-		
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream(baos);
-        oos.writeObject(mmce);
-        oos.flush();
-        
-        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())) {
-        	@Override
-        	protected Class<?> resolveClass(ObjectStreamClass desc)
-        			throws IOException, ClassNotFoundException {
-        		if (desc.getName().equals(OperationNotSupportedException.class.getName())) {
-        			throw new ClassNotFoundException();
-        		}
-        		return super.resolveClass(desc);
-        	}
-        	
-        };
-        
-        mmce = (MetaMatrixComponentException)ois.readObject();
-	}
-
-}

Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/exception/TestSQLExceptionUnroller.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/exception/TestSQLExceptionUnroller.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/exception/TestSQLExceptionUnroller.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util.exception;
-
-import java.sql.SQLException;
-import java.util.Random;
-
-import junit.framework.TestCase;
-
-/**
- * @version 	1.0
- * @author
- */
-public class TestSQLExceptionUnroller extends TestCase {
-
-    /**
-     * Constructor for TestSQLExceptionUnroller.
-     * @param name
-     */
-    public TestSQLExceptionUnroller(String name) {
-        super(name);
-    }
-
-    //  ********* H E L P E R   M E T H O D S  *********
-
-    private void helpTestUnroll(SQLException sqlEx, SQLException mmEx) {
-        // Get the original SQLException chain
-        StringBuffer expectedResult = new StringBuffer(getSQLErrorMsg(sqlEx));
-        SQLException sqlChild = sqlEx.getNextException();
-        while ( sqlChild != null ) {
-            expectedResult.append("|" + getSQLErrorMsg(sqlChild)); //$NON-NLS-1$
-            sqlChild = sqlChild.getNextException();
-        }
-
-        // Get the "unrolled" chain
-        StringBuffer result = new StringBuffer(getSQLErrorMsg(mmEx));
-        sqlChild = mmEx.getNextException();
-        while ( sqlChild != null ) {
-            result.append("|" + getSQLErrorMsg(sqlChild)); //$NON-NLS-1$
-            sqlChild = sqlChild.getNextException();
-        }
-
-        assertEquals("Unexpected unroll result!\n", expectedResult.toString(), result.toString()); //$NON-NLS-1$
-    }
-
-    private static String getSQLErrorMsg(SQLException e) {
-        StringBuffer buf = new StringBuffer(e.getMessage());
-        buf.append("|" + e.getSQLState()); //$NON-NLS-1$
-        buf.append("|" + e.getErrorCode()); //$NON-NLS-1$
-        // DEBUG:
-//        System.out.println("Emsg: " + buf.toString());
-        return buf.toString();
-    }
-
-    private static SQLException helpTestRoll(int limit) {
-        String sqlState = "confusion %^D"; //$NON-NLS-1$
-        int vendorCode = -1;
-
-        // Create a chain of SQLExceptions
-        final SQLException e = new SQLException("Unroll 0", sqlState, vendorCode); //$NON-NLS-1$
-
-        Random gen = new Random();
-        for ( int i = 0; i < limit - 1; i++ ) {
-            sqlState = String.valueOf(gen.nextDouble());
-            vendorCode = gen.nextInt();
-            SQLException e2 = null;
-            if ( vendorCode % 2 == 0 ) {
-                e2 = new SQLException("Unroll " + (i + 1), sqlState, vendorCode); //$NON-NLS-1$
-            } else {
-                // No SQLState (null) or vendorCode (0) should appear
-                // in SQLException when vendorCode is odd.
-                e2 = new SQLException("Unroll " + (i + 1)); //$NON-NLS-1$
-            }
-            e.setNextException(e2);
-        }
-
-        return e;
-    }
-
-    //  ********* T E S T   S U I T E   M E T H O D S  *********
-
-    public void testUnroll_1() {
-        // Create a SQLException
-        final SQLException e = helpTestRoll(1);
-
-        // Unroll the exception
-        SQLException mmEx = SQLExceptionUnroller.unRollException(e);
-
-        // Make sure they're the same.
-        helpTestUnroll(e, mmEx);
-    }
-
-    public void testUnroll_10() {
-        // Create a SQLException
-        final SQLException e = helpTestRoll(10);
-
-        // Unroll the exception
-        SQLException mmEx = SQLExceptionUnroller.unRollException(e);
-
-        // Make sure they're the same.
-        helpTestUnroll(e, mmEx);
-    }
-}

Modified: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java	2009-03-25 15:33:18 UTC (rev 652)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java	2009-03-25 16:01:36 UTC (rev 653)
@@ -84,62 +84,51 @@
 		String service = null;
 		final boolean encrypt = message.getContents() instanceof SealedObject;
         try {
-        	/* Defect 15211
-    		 * If a CNFE occurred while deserializing the packet, the packet message should be a
-    		 * MessageHolder containing the exception. Since we can no longer continue processing,
-    		 * we should notify the client of the problem immediately.
-    		 */
-        	if (message.getContents() instanceof Throwable) {
-        		LogManager.logWarning(SocketVMController.SOCKET_CONTEXT, (Throwable)message.getContents(), 
-		                     "Exception while deserializing message packet."); //$NON-NLS-1$
-                result = message;
-            } else {
-	            message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
-	            
-				if (!(message.getContents() instanceof ServiceInvocationStruct)) {
-					throw new AssertionError("unknown message contents"); //$NON-NLS-1$
-				}
-				final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)message.getContents();
-				Object instance = server.getClientService(serviceStruct.targetClass);
-				if (instance == null) {
-					throw new ComponentNotFoundException(PlatformPlugin.Util.getString("ServerWorkItem.Component_Not_Found", serviceStruct.targetClass)); //$NON-NLS-1$
-				}
-				if (!(instance instanceof ILogon)) {
-					DQPWorkContext workContext = this.socketClientInstance.getWorkContext();
-					sessionService.validateSession(workContext.getSessionId());
-				}
-				service = serviceStruct.targetClass;
-				ReflectionHelper helper = new ReflectionHelper(instance.getClass());
-				Method m = helper.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
-				Object methodResult;
-				try {
-					methodResult = m.invoke(instance, serviceStruct.args);
-				} catch (InvocationTargetException e) {
-					throw e.getCause();
-				}
-				if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
-					ResultsFuture<Serializable> future = (ResultsFuture<Serializable>) methodResult;
-					future.addCompletionListener(new ResultsFuture.CompletionListener<Serializable>() {
+            message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
+            
+			if (!(message.getContents() instanceof ServiceInvocationStruct)) {
+				throw new AssertionError("unknown message contents"); //$NON-NLS-1$
+			}
+			final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)message.getContents();
+			Object instance = server.getClientService(serviceStruct.targetClass);
+			if (instance == null) {
+				throw new ComponentNotFoundException(PlatformPlugin.Util.getString("ServerWorkItem.Component_Not_Found", serviceStruct.targetClass)); //$NON-NLS-1$
+			}
+			if (!(instance instanceof ILogon)) {
+				DQPWorkContext workContext = this.socketClientInstance.getWorkContext();
+				sessionService.validateSession(workContext.getSessionId());
+			}
+			service = serviceStruct.targetClass;
+			ReflectionHelper helper = new ReflectionHelper(instance.getClass());
+			Method m = helper.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
+			Object methodResult;
+			try {
+				methodResult = m.invoke(instance, serviceStruct.args);
+			} catch (InvocationTargetException e) {
+				throw e.getCause();
+			}
+			if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
+				ResultsFuture<Serializable> future = (ResultsFuture<Serializable>) methodResult;
+				future.addCompletionListener(new ResultsFuture.CompletionListener<Serializable>() {
 
-								public void onCompletion(
-										ResultsFuture<Serializable> completedFuture) {
-									Message asynchResult = new Message();
-									try {
-										asynchResult.setContents(completedFuture.get());
-									} catch (InterruptedException e) {
-										asynchResult.setContents(processException(e, serviceStruct.targetClass));
-									} catch (ExecutionException e) {
-										asynchResult.setContents(processException(e.getCause(), serviceStruct.targetClass));
-									}
-									sendResult(asynchResult, encrypt);
+							public void onCompletion(
+									ResultsFuture<Serializable> completedFuture) {
+								Message asynchResult = new Message();
+								try {
+									asynchResult.setContents(completedFuture.get());
+								} catch (InterruptedException e) {
+									asynchResult.setContents(processException(e, serviceStruct.targetClass));
+								} catch (ExecutionException e) {
+									asynchResult.setContents(processException(e.getCause(), serviceStruct.targetClass));
 								}
+								sendResult(asynchResult, encrypt);
+							}
 
-							});
-				} else { // synch call
-					Message resultHolder = new Message();
-					resultHolder.setContents((Serializable)methodResult);
-					result = resultHolder;
-				}
+						});
+			} else { // synch call
+				Message resultHolder = new Message();
+				resultHolder.setContents((Serializable)methodResult);
+				result = resultHolder;
 			}
 		} catch (Throwable t) {
 			Message holder = new Message();




More information about the teiid-commits mailing list