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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Apr 2 21:31:23 EDT 2009


Author: rareddy
Date: 2009-04-02 21:31:23 -0400 (Thu, 02 Apr 2009)
New Revision: 697

Added:
   trunk/common-core/src/main/java/com/metamatrix/api/exception/ExceptionHolder.java
   trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java
   trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java
   trunk/common-core/src/test/resources/test.jar
Removed:
   trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java
   trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectInputStreamWithClassloader.java
   trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java
   trunk/client/src/test/resources/test.jar
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/api/exception/MultipleException.java
   trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
   trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java
Log:
TEIID-297: making changes to exception holder to be resilient to unknown classes in the class loader. This will send cause of exception along with original exception, and in case exception is was not able to construct in original form then the cause will be bubbled up, otherwise it will create one of exceptions in chain  of its hierarchy. Reviewed by SH.

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-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -1,111 +0,0 @@
-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;
-	}
-		
-}

Deleted: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectInputStreamWithClassloader.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectInputStreamWithClassloader.java	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectInputStreamWithClassloader.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -1,50 +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.comm.platform.socket;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamClass;
-
-public final class ObjectInputStreamWithClassloader extends
-		ObjectInputStream {
-	private final ClassLoader cl;
-
-	public ObjectInputStreamWithClassloader(InputStream in,
-			ClassLoader cl) throws IOException {
-		super(in);
-		this.cl = cl;
-	}
-
-	@Override
-	protected Class<?> resolveClass(ObjectStreamClass desc)
-			throws IOException, ClassNotFoundException {
-		//see java bug id 6434149
-		try {
-			return Class.forName(desc.getName(), false, cl);
-		} catch (ClassNotFoundException e) {
-			return super.resolveClass(desc);
-		}
-	}
-}
\ No newline at end of file

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-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -44,12 +44,12 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import com.metamatrix.api.exception.ExceptionHolder;
 import com.metamatrix.client.ExceptionUtil;
 import com.metamatrix.common.api.HostInfo;
 import com.metamatrix.common.comm.api.Message;
 import com.metamatrix.common.comm.api.ResultsReceiver;
 import com.metamatrix.common.comm.exception.CommunicationException;
-import com.metamatrix.common.comm.exception.ExceptionHolder;
 import com.metamatrix.common.comm.exception.SingleInstanceCommunicationException;
 import com.metamatrix.common.comm.platform.CommPlatformPlugin;
 import com.metamatrix.common.comm.platform.socket.Handshake;

Modified: trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -32,9 +32,9 @@
 import java.util.List;
 import java.util.Map;
 
+import com.metamatrix.api.exception.ExceptionHolder;
 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;
 
 /**
@@ -55,7 +55,7 @@
     private MetaMatrixException exception;
 
     /** Warning could be schema validation errors or partial results warnings */
-    private List<Exception> warnings;
+    private List<Throwable> warnings;
 
     /** Schemas associated with xml results. */
     private Collection schemas;
@@ -262,7 +262,7 @@
     /**
      * @param list
      */
-    public void setWarnings(List<Exception> list) {
+    public void setWarnings(List<Throwable> list) {
         warnings = list;
     }
 
@@ -346,10 +346,7 @@
         }
         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());
-			}
+        	this.warnings = ExceptionHolder.toThrowables(holderList);
         }
 
         //Schemas
@@ -389,11 +386,7 @@
         	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);
+        	out.writeObject(ExceptionHolder.toExceptionHolders(this.warnings));
         } else {
         	out.writeObject(this.warnings);
         }

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-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/main/resources/com/metamatrix/common/comm/platform/i18n.properties	2009-04-03 01:31:23 UTC (rev 697)
@@ -115,8 +115,6 @@
 
 SocketServerConnection.closed=Server connection is closed
 
-ExceptionHolder.converted_exception=Remote exception: {0} ... Original type hierarchy {1}.
-
 SocketHelper.keystore_not_found=Key store ''{0}'' was not found.
 
 MMURL.INVALID_FORMAT=The required url format is {0}
\ No newline at end of file

Deleted: trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java
===================================================================
--- trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -1,43 +0,0 @@
-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$
-	}
-
-}

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

Copied: trunk/common-core/src/main/java/com/metamatrix/api/exception/ExceptionHolder.java (from rev 682, trunk/client/src/main/java/com/metamatrix/common/comm/exception/ExceptionHolder.java)
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/api/exception/ExceptionHolder.java	                        (rev 0)
+++ trunk/common-core/src/main/java/com/metamatrix/api/exception/ExceptionHolder.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -0,0 +1,184 @@
+package com.metamatrix.api.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.Collection;
+import java.util.List;
+
+import com.metamatrix.core.CorePlugin;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.ObjectInputStreamWithClassloader;
+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;
+	private boolean nested = false;
+	
+	public ExceptionHolder() {
+	}
+	
+	public ExceptionHolder(Throwable exception) {
+		this.exception = exception;
+	}
+
+	public ExceptionHolder(Throwable exception, boolean nested) {
+		this.exception = exception;
+		this.nested = nested;
+	}
+	
+	
+	@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();
+		ExceptionHolder causeHolder = (ExceptionHolder)in.readObject();
+		byte[] serializedException = (byte[])in.readObject();
+		
+		this.exception = readFromByteArray(serializedException);
+
+		if (this.exception == null) {
+			Throwable t = buildException(classNames, message, stackTrace);
+			if (t == null) {
+				if (causeHolder != null) {
+					this.exception = causeHolder.exception;
+				}
+			}
+			else {
+				if (causeHolder != null) {
+					t.initCause(causeHolder.exception);
+				}
+				this.exception = t;
+			}
+		}
+
+		if (this.exception == null) {
+			this.exception = new MetaMatrixRuntimeException(message);
+			this.exception.setStackTrace(stackTrace);
+		}
+	}
+	
+	@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());
+		
+		// specify that this cause is nested exception; not top level
+		if (this.exception.getCause() != null) {
+			out.writeObject(new ExceptionHolder(this.exception.getCause(), true));
+		}
+		else {
+			out.writeObject(null);
+		}
+		
+		// only for the top level exception write the serialized block for the object
+		if (!nested) {
+			out.writeObject(writeAsByteArray(this.exception));
+		}
+		else {
+			out.writeObject(null);
+		}
+	}
+	
+	public Throwable getException() {
+		return exception;
+	}
+		
+	private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace) {
+		List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, classNames)); //$NON-NLS-1$
+		
+		Throwable result = null;
+		for (String className : classNames) {
+			try {
+				result = (Throwable)ReflectionHelper.create(className, args, Thread.currentThread().getContextClassLoader());
+				result.setStackTrace(stackTrace);
+				break;
+			} catch (MetaMatrixCoreException e1) {
+				//
+			}
+		}
+		return result;
+	}
+	
+	private byte[] writeAsByteArray(Throwable t) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(t);
+        oos.flush();
+        oos.close();		
+        return baos.toByteArray();
+	}
+	
+	private Throwable readFromByteArray(byte[] contents) throws IOException {
+		// only for top level we would have the contents as not null.
+		if (contents != null) {
+			ByteArrayInputStream bais = new ByteArrayInputStream(contents);
+			ObjectInputStream ois = new ObjectInputStreamWithClassloader(bais, Thread.currentThread().getContextClassLoader());
+			try {
+				return (Throwable)ois.readObject();
+			} catch (ClassNotFoundException e) {
+				// 
+			}
+		}
+		return null;
+	}
+	
+	public static List<ExceptionHolder> toExceptionHolders(List<? extends Throwable> throwables){
+    	List<ExceptionHolder> list = new ArrayList();
+    	for (Throwable t: throwables) {
+    		list.add(new ExceptionHolder(t));
+    	}
+    	return list;
+	}
+	
+    public static List<Throwable> toThrowables(List<ExceptionHolder> exceptionHolders) {
+    	List<Throwable> list = new ArrayList();
+    	for(ExceptionHolder e: exceptionHolders) {
+    		list.add(e.getException());
+    	}
+    	return list;
+    }
+
+}

Modified: trunk/common-core/src/main/java/com/metamatrix/api/exception/MultipleException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/api/exception/MultipleException.java	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/common-core/src/main/java/com/metamatrix/api/exception/MultipleException.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -22,27 +22,28 @@
 
 package com.metamatrix.api.exception;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.*;
 
 /**
  * Exception that represents the occurrence of multiple exceptions.
  */
-public class MultipleException extends Exception {
-    // =========================================================================
-    //                       C O N S T R U C T O R S
-    // =========================================================================
+public class MultipleException extends Exception implements Externalizable {
 
-//    private int attribute1;
-    /**
+	/**
      *The set of Throwable instances that make up this exception
      * @link aggregation
      * @associates <b>java.lang.Throwable</b>
      * @supplierCardinality 1..*
      */
-    private List throwablesList = new ArrayList();
+    private List throwablesList = null;
 
     /** An error code. */
     private String code;
+    
     /** Construct a default instance of this class. */
     public MultipleException() {
         super();
@@ -139,5 +140,17 @@
     public void setExceptions( Collection throwables ){
         this.throwablesList = new ArrayList(throwables);
     }
+
+	@Override
+	public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
+		this.code = (String)in.readObject();
+		this.throwablesList = ExceptionHolder.toThrowables((List<ExceptionHolder>)in.readObject());
+	}
+
+	@Override
+	public void writeExternal(ObjectOutput out) throws IOException {
+		out.writeObject(code);
+		out.writeObject(ExceptionHolder.toExceptionHolders(throwablesList));
+	}
 }
 

Copied: trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java (from rev 682, trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectInputStreamWithClassloader.java)
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java	                        (rev 0)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -0,0 +1,50 @@
+/*
+ * 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.core.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+public final class ObjectInputStreamWithClassloader extends
+		ObjectInputStream {
+	private final ClassLoader cl;
+
+	public ObjectInputStreamWithClassloader(InputStream in,
+			ClassLoader cl) throws IOException {
+		super(in);
+		this.cl = cl;
+	}
+
+	@Override
+	protected Class<?> resolveClass(ObjectStreamClass desc)
+			throws IOException, ClassNotFoundException {
+		//see java bug id 6434149
+		try {
+			return Class.forName(desc.getName(), false, cl);
+		} catch (ClassNotFoundException e) {
+			return super.resolveClass(desc);
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties
===================================================================
--- trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties	2009-04-03 01:31:23 UTC (rev 697)
@@ -406,3 +406,5 @@
 ERR.003.030.0179=Unable to load the JDBC driver class {0}
 ERR.003.030.0180=Driver {0} can not load {1}
 ERR.003.030.0181=Failed to connect to the Database at {0} check connection properties.
+
+ExceptionHolder.converted_exception=Remote exception: {0} ... Original type hierarchy {1}.

Copied: trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java (from rev 682, trunk/client/src/test/java/com/metamatrix/common/comm/exception/TestExceptionHolder.java)
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java	                        (rev 0)
+++ trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -0,0 +1,98 @@
+package com.metamatrix.api.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 java.sql.SQLException;
+import java.util.ArrayList;
+
+import org.junit.Test;
+
+import com.metamatrix.api.exception.ExceptionHolder;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.classloader.NonDelegatingClassLoader;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+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(String msg) {super(msg);}
+		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.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 BadException);
+        assertEquals("Remote exception: null ... Original type hierarchy [com.metamatrix.api.exception.TestExceptionHolder$BadException, com.metamatrix.api.exception.MetaMatrixProcessingException, com.metamatrix.api.exception.MetaMatrixException, com.metamatrix.core.MetaMatrixCoreException].", holder.getException().getMessage()); //$NON-NLS-1$
+	}
+
+
+	@SuppressWarnings("all")
+	public static class BadException2 extends MetaMatrixProcessingException {
+		public BadException2(String msg) {
+			super(msg);
+		}
+		public BadException2(Throwable e, String msg) {
+			super(e, msg);
+		}
+	}
+	
+	@Test public void testDeserializationUnknownChildException() throws Exception {
+		ClassLoader cl = new NonDelegatingClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
+		Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$
+		obj.initCause(new SQLException("something bad happended")); //$NON-NLS-1$
+		
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(new ExceptionHolder(new BadException2(obj, "I have foreign exception embedded in me"))); //$NON-NLS-1$
+        oos.flush();
+        
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        ExceptionHolder holder = (ExceptionHolder)ois.readObject();
+        Throwable e = holder.getException();
+        assertTrue(e instanceof BadException2);
+        assertEquals("Remote exception: I have foreign exception embedded in me ... Original type hierarchy [com.metamatrix.api.exception.TestExceptionHolder$BadException2, com.metamatrix.api.exception.MetaMatrixProcessingException, com.metamatrix.api.exception.MetaMatrixException, com.metamatrix.core.MetaMatrixCoreException].", e.getMessage()); //$NON-NLS-1$
+        
+        // now unknown exception is not found, so promote known SQL exception up
+        e = e.getCause();
+        assertTrue(e instanceof SQLException);
+        assertEquals("Remote exception: something bad happended ... Original type hierarchy [java.sql.SQLException].", e.getMessage()); //$NON-NLS-1$
+	}	
+	
+	@Test public void testDeserializationUnknownChildException2() throws Exception {
+		ClassLoader cl = new NonDelegatingClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
+		ArrayList<String> args = new ArrayList<String>();
+		args.add("Unknown Exception"); //$NON-NLS-1$
+		Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$ 
+		
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(new ExceptionHolder(obj));
+        oos.flush();
+        
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        ExceptionHolder holder = (ExceptionHolder)ois.readObject();
+        Throwable e = holder.getException();
+        assertTrue(e instanceof MetaMatrixRuntimeException);
+        assertEquals("Unknown Exception", e.getMessage()); //$NON-NLS-1$
+	}		
+}


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

Copied: trunk/common-core/src/test/resources/test.jar (from rev 682, trunk/client/src/test/resources/test.jar)
===================================================================
(Binary files differ)


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

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2009-04-02 16:09:56 UTC (rev 696)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -453,7 +453,7 @@
             response.setSchemas(this.schemas);
             
             // send any warnings with the response object
-            List<Exception> responseWarnings = new ArrayList<Exception>();
+            List<Throwable> responseWarnings = new ArrayList<Throwable>();
     		List<Exception> currentWarnings = processor.getAndClearWarnings();
     	    if (currentWarnings != null) {
     	    	responseWarnings.addAll(currentWarnings);

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-04-02 16:09:56 UTC (rev 696)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java	2009-04-03 01:31:23 UTC (rev 697)
@@ -36,10 +36,10 @@
 
 import com.metamatrix.admin.api.exception.AdminProcessingException;
 import com.metamatrix.api.exception.ComponentNotFoundException;
+import com.metamatrix.api.exception.ExceptionHolder;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.comm.ClientServiceRegistry;
 import com.metamatrix.common.comm.api.Message;
-import com.metamatrix.common.comm.exception.ExceptionHolder;
 import com.metamatrix.common.comm.platform.socket.SocketVMController;
 import com.metamatrix.common.comm.platform.socket.client.ServiceInvocationStruct;
 import com.metamatrix.common.log.LogManager;




More information about the teiid-commits mailing list