[jboss-svn-commits] JBL Code SVN: r15576 - in labs/jbossesb/trunk/product/rosetta/src/org/jboss: internal/soa/esb/message/format/xml/body/content and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 4 07:06:21 EDT 2007


Author: kevin.conner at jboss.com
Date: 2007-10-04 07:06:21 -0400 (Thu, 04 Oct 2007)
New Revision: 15576

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ContextObjectInputStream.java
Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/body/content/BytesBodyImpl.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/body/content/BytesBodyImpl.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java
Log:
Fixed deserialisation for JBESB-1130

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/body/content/BytesBodyImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/body/content/BytesBodyImpl.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/body/content/BytesBodyImpl.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -11,6 +11,7 @@
 import org.jboss.soa.esb.message.body.content.IncompatibleModeException;
 import org.jboss.soa.esb.message.body.content.InvalidPayloadException;
 import org.jboss.soa.esb.message.body.content.Payload;
+import org.jboss.soa.esb.util.ContextObjectInputStream;
 
 /*
  * JBoss, Home of Professional Open Source
@@ -230,7 +231,7 @@
 			throw new IOException();
 		
 		_mode = READ_MODE;
-		_inputStream = new ObjectInputStream(new ByteArrayInputStream((byte[]) super
+		_inputStream = new ContextObjectInputStream(new ByteArrayInputStream((byte[]) super
 				.get(BytesBody.BYTES_LOCATION)));
 		_outputStream = null;
 		_byteStream = null;

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/body/content/BytesBodyImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/body/content/BytesBodyImpl.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/body/content/BytesBodyImpl.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -11,6 +11,7 @@
 import org.jboss.soa.esb.message.body.content.IncompatibleModeException;
 import org.jboss.soa.esb.message.body.content.InvalidPayloadException;
 import org.jboss.soa.esb.message.body.content.Payload;
+import org.jboss.soa.esb.util.ContextObjectInputStream;
 
 /*
  * JBoss, Home of Professional Open Source
@@ -228,7 +229,7 @@
 			throw new IOException();
 		
 		_mode = READ_MODE;
-		_inputStream = new ObjectInputStream(new ByteArrayInputStream((byte[]) super
+		_inputStream = new ContextObjectInputStream(new ByteArrayInputStream((byte[]) super
 				.get(BytesBody.BYTES_LOCATION)));
 		_outputStream = null;
 		_byteStream = null;

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -1,5 +1,7 @@
 package org.jboss.internal.soa.esb.thirdparty;
 
+import org.jboss.soa.esb.util.ContextObjectInputStream;
+
 /**
  * Encodes and decodes to and from Base64 notation.
  *
@@ -785,7 +787,7 @@
         try
         {
             bais = new java.io.ByteArrayInputStream( objBytes );
-            ois  = new java.io.ObjectInputStream( bais );
+            ois  = new ContextObjectInputStream( bais );
         
             obj = ois.readObject();
         }   // end try

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -46,6 +46,7 @@
 import org.jboss.soa.esb.addressing.util.DefaultReplyTo;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.ContextObjectInputStream;
 import org.jboss.soa.esb.util.Util;
 import org.xml.sax.SAXException;
 
@@ -138,7 +139,7 @@
 			try
 			{
 				reader = new FileInputStream(from);
-				serial = (Serializable) new ObjectInputStream(reader).readObject();
+				serial = (Serializable) new ContextObjectInputStream(reader).readObject();
 				return Util.deserialize(serial);
 			}
 			catch (StreamCorruptedException ex)

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -221,7 +221,7 @@
      * The priority dictates the order in which the resources will be asked to cleanup,
      * lower priorities being asked to cleanup before higher priorities.
      */
-    public void registerResource(final LifecycleResource<?> lifecycleResource,
+    void registerResource(final LifecycleResource<?> lifecycleResource,
         final ClassLoader classLoader, final int priority)
     {
         resourceLock.lock() ;
@@ -339,7 +339,7 @@
      * @param lifecycleResource The lifecycle resource.
      * @param classLoader The classloader associated with the factory.
      */
-    public void registerResource(final LifecycleResource<?> lifecycleResource,
+    void registerResource(final LifecycleResource<?> lifecycleResource,
         final ClassLoader classLoader)
     {
         registerResource(lifecycleResource, classLoader, Integer.MIN_VALUE) ;

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java	2007-10-04 10:59:57 UTC (rev 15575)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -24,6 +24,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Proxy;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -93,6 +94,50 @@
     }
     
     /**
+     * Resolve a proxy for the specified interfaces.
+     * @param interfaces The interfaces associated with the proxy.
+     * @param caller The class of the caller.
+     * @return The specified proxy class.
+     * @throws ClassNotFoundException If the class cannot be found.
+     */
+    public static Class resolveProxy(final String[] interfaces, final Class caller)
+        throws ClassNotFoundException
+    {
+        final int numInterfaces = (interfaces == null ? 0 : interfaces.length) ;
+        if (numInterfaces == 0)
+        {
+            throw new ClassNotFoundException("Cannot generate proxy with no interfaces") ;
+        }
+        
+        final Class[] interfaceClasses = new Class[numInterfaces] ;
+        for(int count = 0 ; count < numInterfaces ; count++)
+        {
+            interfaceClasses[count] = forName(interfaces[count], caller) ;
+        }
+        
+        final ClassLoader proxyClassLoader ;
+        final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader() ;
+        if (threadClassLoader != null)
+        {
+            proxyClassLoader = threadClassLoader ;
+        }
+        else
+        {
+            final ClassLoader classLoader = caller.getClassLoader() ;
+            if (classLoader != null)
+            {
+                proxyClassLoader = classLoader ;
+            }
+            else
+            {
+                proxyClassLoader = ClassLoader.getSystemClassLoader() ;
+            }
+        }
+        
+        return Proxy.getProxyClass(proxyClassLoader, interfaceClasses) ;
+    }
+    
+    /**
      * Get the specified resource as a stream.
      * @param resourceName The name of the class to load.
      * @param caller The class of the caller.

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ContextObjectInputStream.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ContextObjectInputStream.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ContextObjectInputStream.java	2007-10-04 11:06:21 UTC (rev 15576)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+/**
+ * Implementation of an object input stream that delegates class loading to the thread
+ * context classloader in preference.
+ * 
+ * @author kevin
+ */
+public class ContextObjectInputStream extends ObjectInputStream
+{
+    /**
+     * Construct a default instance of the context aware object input stream.
+     * @throws SecurityException if an active security manager prevents subclassing
+     * @throws IOException for IO errors.
+     */
+    protected ContextObjectInputStream()
+        throws IOException, SecurityException
+    {
+    }
+
+    /**
+     * Construct a context aware object input stream using the specified input stream.
+     * @param in The associated input stream.
+     * @throws IOException for IO errors reading from the stream.
+     */
+    public ContextObjectInputStream(final InputStream in)
+        throws IOException
+    {
+        super(in) ;
+    }
+    
+    /**
+     * Resolve the class using the active context.
+     * @param desc The object stream class description.
+     * @return The associated class.
+     * @throws ClassNotFoundException if the class cannot be found.
+     * @throws IOException for I/O Errors.
+     */
+    @Override
+    protected Class<?> resolveClass(final ObjectStreamClass desc)
+        throws IOException, ClassNotFoundException
+    {
+        return ClassUtil.forName(desc.getName(), ContextObjectInputStream.class) ;
+    }
+    
+    /**
+     * Resolve the proxy class using the active context.
+     * @param interfaces The interfaces associated with the proxy.
+     * @return The associated class.
+     * @throws ClassNotFoundException if an interface cannot be found.
+     * @throws IOException for I/O Errors.
+     */
+    @Override
+    protected Class<?> resolveProxyClass(String[] interfaces)
+            throws IOException, ClassNotFoundException
+    {
+        return ClassUtil.resolveProxy(interfaces, ContextObjectInputStream.class) ;
+    }
+}


Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ContextObjectInputStream.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list