You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/01/23 04:48:43 UTC

svn commit: r126185 - in geronimo/trunk/modules: axis-builder/src/java/org/apache/geronimo/axis/builder axis-builder/src/test/org/apache/geronimo/axis/builder j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment jetty-builder/src/java/org/apache/geronimo/jetty/deployment jetty/src/java/org/apache/geronimo/jetty kernel/src/java/org/apache/geronimo/gbean/runtime naming/src/java/org/apache/geronimo/naming/reference

Author: djencks
Date: Sat Jan 22 19:48:42 2005
New Revision: 126185

URL: http://svn.apache.org/viewcvs?view=rev&rev=126185
Log:
Add DeserializingReference and modify web services deployment to use it. Really simple ws clients seem to work
Added:
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/DeserializingReference.java
Modified:
   geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java
   geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java
   geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java
   geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java?view=diff&rev=126185&p1=geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java&r1=126184&p2=geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java	(original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java	Sat Jan 22 19:48:42 2005
@@ -17,8 +17,10 @@
 package org.apache.geronimo.axis.builder;
 
 import java.beans.Introspector;
-import java.io.File;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
@@ -30,7 +32,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import javax.naming.Reference;
+import java.util.jar.JarFile;
 import javax.wsdl.Binding;
 import javax.wsdl.BindingInput;
 import javax.wsdl.BindingOperation;
@@ -78,8 +80,9 @@
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.j2ee.deployment.ServiceReferenceBuilder;
 import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.ServiceReferenceBuilder;
+import org.apache.geronimo.naming.reference.DeserializingReference;
 import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingDocument;
 import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
 import org.apache.xmlbeans.XmlException;
@@ -113,16 +116,17 @@
     }
 
     public Object createService(Class serviceInterface, URI wsdlURI, URI jaxrpcMappingURI, QName serviceQName, Map portComponentRefMap, List handlers, DeploymentContext deploymentContext, Module module, ClassLoader classLoader) throws DeploymentException {
-        String wsdlFile = null;
+        JarFile moduleFile = module.getModuleFile();
+        InputStream wsdlInputStream = null;
         try {
-            wsdlFile = deploymentContext.getTargetFile(module.getTargetPathURI().resolve(wsdlURI)).toURL().toString();
-        } catch (MalformedURLException e) {
-            throw new DeploymentException("Could not resolve wsdlfile", e);
+            wsdlInputStream = moduleFile.getInputStream(moduleFile.getEntry(wsdlURI.toString()));
+        } catch (IOException e) {
+            throw new DeploymentException("Could not open stream to wsdl file", e);
         }
         //TODO trying to read in the doc from the wsdlFile directly doesn't work in running geronimo, but does work in
         //unit tests.  You get a java.net.UnknownServiceException with message "no content-type".  Perhaps something
         //is wrong with the geronimo url handler??
-        InputSource is = new InputSource(wsdlFile);
+        InputSource inputSource = new InputSource(wsdlInputStream);
         WSDLFactory wsdlFactory = null;
         try {
             wsdlFactory = WSDLFactory.newInstance();
@@ -133,15 +137,20 @@
         wsdlReader.setFeature("javax.wsdl.importDocuments", false);
         Definition definition = null;
         try {
-            definition = wsdlReader.readWSDL(null, is);
+            definition = wsdlReader.readWSDL(null, inputSource);
         } catch (WSDLException e) {
             throw new DeploymentException("Failed to read wsdl document", e);
         }
 
-        File jaxrpcMappingFile = deploymentContext.getTargetFile(module.getTargetPathURI().resolve(jaxrpcMappingURI));
+        InputStream jaxrpcInputStream = null;
+        try {
+            jaxrpcInputStream = moduleFile.getInputStream(moduleFile.getEntry(jaxrpcMappingURI.toString()));
+        } catch (IOException e) {
+            throw new DeploymentException("Could not open stream to jaxrpc mapping document", e);
+        }
         JavaWsdlMappingDocument mappingDocument = null;
         try {
-            mappingDocument = JavaWsdlMappingDocument.Factory.parse(jaxrpcMappingFile);
+            mappingDocument = JavaWsdlMappingDocument.Factory.parse(jaxrpcInputStream);
         } catch (XmlException e) {
             throw new DeploymentException("Could not parse jaxrpc mapping document", e);
         } catch (IOException e) {
@@ -149,7 +158,19 @@
         }
         JavaWsdlMappingType mapping = mappingDocument.getJavaWsdlMapping();
 
-        return createService(serviceInterface, definition, mapping, serviceQName, SOAP_VERSION, deploymentContext, module, classLoader);
+        Object service =  createService(serviceInterface, definition, mapping, serviceQName, SOAP_VERSION, deploymentContext, module, classLoader);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = null;
+        try {
+            oos = new ObjectOutputStream(baos);
+            oos.writeObject(service);
+            oos.flush();
+        } catch (IOException e) {
+            throw new DeploymentException("Could not create serialize service", e);
+        }
+        byte[] bytes = baos.toByteArray();
+        DeserializingReference reference = new DeserializingReference(bytes);
+        return reference;
     }
 
     public javax.xml.rpc.Service createService(Class serviceInterface, Definition definition, JavaWsdlMappingType mapping, QName serviceQName, SOAPConstants soapVersion, DeploymentContext context, Module module, ClassLoader classloader) throws DeploymentException {

Modified: geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java?view=diff&rev=126185&p1=geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java&r1=126184&p2=geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java	(original)
+++ geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java	Sat Jan 22 19:48:42 2005
@@ -16,15 +16,7 @@
  */
 package org.apache.geronimo.axis.builder;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URL;
@@ -34,8 +26,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
 import javax.wsdl.Binding;
 import javax.wsdl.BindingInput;
 import javax.wsdl.BindingOperation;
@@ -76,12 +66,14 @@
 import org.apache.geronimo.axis.client.ServiceReference;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.util.UnpackedJarFile;
+import org.apache.geronimo.j2ee.deployment.EJBModule;
+import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+import org.apache.geronimo.naming.reference.DeserializingReference;
 import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingDocument;
 import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
 import org.apache.geronimo.xbeans.j2ee.PackageMappingType;
-import org.apache.geronimo.j2ee.deployment.Module;
-import org.apache.geronimo.j2ee.deployment.EJBModule;
 
 /**
  * @version $Rev:  $ $Date:  $
@@ -95,8 +87,10 @@
     private DeploymentContext context;
     private ClassLoader isolatedCl = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
     private final String operationName = "doMockOperation";
+    private final File wsdlDir = new File(basedir, "src/test-resources/interop");
+    private final File wsdlFile = new File(wsdlDir, "interop.wsdl");
 
-    private final Module module = new EJBModule(true, configID, null, null, "ejb", null, null, null);
+    private Module module;
 
     private boolean runExternalWSTest;
 
@@ -106,6 +100,10 @@
         tmpbasedir.mkdirs();
         context = new DeploymentContext(tmpbasedir, configID, ConfigurationModuleType.CAR, null, "foo", "geronimo", null);
 
+        File moduleLocation = new File(tmpbasedir, "ejb");
+        moduleLocation.mkdirs();
+        module = new EJBModule(true, configID, null, new UnpackedJarFile(moduleLocation), "ejb", null, null, null);
+
         runExternalWSTest = System.getProperty("geronimo.run.external.webservicetest", "false").equals("true");
     }
 
@@ -193,10 +191,9 @@
     }
 
     public void testBuildInteropProxy() throws Exception {
-        File wsdl = new File(basedir, "src/test-resources/interop/interop.wsdl");
         WSDLFactory factory = WSDLFactory.newInstance();
         WSDLReader reader = factory.newWSDLReader();
-        Definition definition = reader.readWSDL(wsdl.toURI().toString());
+        Definition definition = reader.readWSDL(wsdlFile.toURI().toString());
         File jaxrpcMapping = new File(basedir, "src/test-resources/interop/interop-jaxrpcmapping.xml");
         JavaWsdlMappingDocument mappingDocument = JavaWsdlMappingDocument.Factory.parse(jaxrpcMapping);
         JavaWsdlMappingType mapping = mappingDocument.getJavaWsdlMapping();
@@ -217,22 +214,22 @@
     }
 
     public void testBuildInteropProxyFromURIs() throws Exception {
-        File wsdldir = new File(basedir, "src/test-resources/interop");
         //ejb is from the EJBModule "ejb" targetPath.
-        context.addFile(new URI("ejb/META-INF/wsdl/interop.wsdl"), new File(wsdldir, "interop.wsdl"));
-        context.addFile(new URI("ejb/META-INF/wsdl/interop-jaxrpcmapping.xml"), new File(wsdldir, "interop-jaxrpcmapping.xml"));
+        context.addFile(new URI("ejb/META-INF/wsdl/interop.wsdl"), wsdlFile);
+        context.addFile(new URI("ejb/META-INF/wsdl/interop-jaxrpcmapping.xml"), new File(wsdlDir, "interop-jaxrpcmapping.xml"));
         ClassLoader cl = context.getClassLoader(null);
-                //new URLClassLoader(new URL[]{wsdldir.toURL()}, isolatedCl);
+        //new URLClassLoader(new URL[]{wsdldir.toURL()}, isolatedCl);
         URI wsdlURI = new URI("META-INF/wsdl/interop.wsdl");
         URI jaxrpcmappingURI = new URI("META-INF/wsdl/interop-jaxrpcmapping.xml");
         QName serviceQName = new QName("http://tempuri.org/4s4c/1/3/wsdl/def/interopLab", "interopLab");
         AxisBuilder builder = new AxisBuilder();
         Map portComponentRefMap = null;
         List handlers = null;
-        Object proxy = builder.createService(InteropLab.class, wsdlURI, jaxrpcmappingURI, serviceQName, portComponentRefMap, handlers, context, module, cl);
-        assertNotNull(proxy);
+        DeserializingReference reference = (DeserializingReference) builder.createService(InteropLab.class, wsdlURI, jaxrpcmappingURI, serviceQName, portComponentRefMap, handlers, context, module, cl);
         ClassLoader contextCl = context.getClassLoader(null);
-        proxy = reserialize(proxy, contextCl);
+        reference.setClassLoader(contextCl);
+        Object proxy = reference.getContent();
+        assertNotNull(proxy);
         assertTrue(proxy instanceof InteropLab);
         InteropTestPortType interopTestPort = ((InteropLab) proxy).getinteropTestPort();
         assertNotNull(interopTestPort);
@@ -242,40 +239,6 @@
             assertEquals(result, 1);
         } else {
             System.out.println("Skipping external ws test");
-        }
-    }
-
-    private Object reserialize(Object object, ClassLoader cl) throws Exception {
-        if (!(object instanceof Serializable)) {
-            fail("object is not serializable, " + object);
-        }
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream(baos);
-        oos.writeObject(object);
-        oos.flush();
-        byte[] bytes = baos.toByteArray();
-        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-        ObjectInputStream ois = new ConfigInputStream(bais, cl);
-        Object result = ois.readObject();
-        return result;
-    }
-
-    private static class ConfigInputStream extends ObjectInputStream {
-        private final ClassLoader cl;
-
-        public ConfigInputStream(InputStream in, ClassLoader cl) throws IOException {
-            super(in);
-            this.cl = cl;
-        }
-
-        protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
-            try {
-                return cl.loadClass(desc.getName());
-            } catch (ClassNotFoundException e) {
-                // let the parent try
-                return super.resolveClass(desc);
-            }
         }
     }
 

Modified: geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java?view=diff&rev=126185&p1=geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java&r1=126184&p2=geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java	(original)
+++ geronimo/trunk/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/WebModule.java	Sat Jan 22 19:48:42 2005
@@ -52,6 +52,7 @@
 
     public void addClass(URI location, String fqcn, byte[] bytes, DeploymentContext context) throws IOException, URISyntaxException {
         context.addClass(location, fqcn, bytes, false);
+//        addToWebClasspath(new URI("../" + location.toString()));
         addToWebClasspath(location);
     }
 

Modified: geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java?view=diff&rev=126185&p1=geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java&r1=126184&p2=geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java	(original)
+++ geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java	Sat Jan 22 19:48:42 2005
@@ -945,7 +945,7 @@
         // check for a classes dir
         File classesDir = new File(webInfDir, "classes");
         if (classesDir.isDirectory()) {
-            webModule.addToWebClasspath(URI.create("WEB-INF/classes/"));
+            webModule.addToWebClasspath(webModule.getTargetPathURI().resolve(URI.create("WEB-INF/classes/")));
         }
 
         // add all of the libs
@@ -960,7 +960,7 @@
             if (libs != null) {
                 for (int i = 0; i < libs.length; i++) {
                     File lib = libs[i];
-                    webModule.addToWebClasspath(URI.create("WEB-INF/lib/" + lib.getName()));
+                    webModule.addToWebClasspath(webModule.getTargetPathURI().resolve(URI.create("WEB-INF/lib/" + lib.getName())));
                 }
             }
         }

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java?view=diff&rev=126185&p1=geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java&r1=126184&p2=geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java	(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java	Sat Jan 22 19:48:42 2005
@@ -66,7 +66,7 @@
 public class JettyWebAppContext extends WebApplicationContext implements GBeanLifecycle, JettyServletRegistration {
     private static Log log = LogFactory.getLog(JettyWebAppContext.class);
 
-    private final ClassLoader classLoader;
+    private final ClassLoader webClassLoader;
     private final JettyContainer jettyContainer;
 
     private final URI webAppRoot;
@@ -81,7 +81,7 @@
      * @deprecated never use this... this is only here because Jetty WebApplicationContext is externalizable
      */
     public JettyWebAppContext() {
-        classLoader = null;
+        webClassLoader = null;
         jettyContainer = null;
         webAppRoot = null;
         handler = null;
@@ -147,11 +147,11 @@
         URL[] urls = new URL[webClassPath.length];
         for (int i = 0; i < webClassPath.length; i++) {
             URI classPathEntry = webClassPath[i];
-            classPathEntry = webAppRoot.resolve(classPathEntry);
+            classPathEntry = root.resolve(classPathEntry);
             urls[i] = classPathEntry.toURL();
         }
-        this.classLoader = new JettyClassLoader(urls, classLoader, contextPriorityClassLoader);
-        setClassLoader(this.classLoader);
+        this.webClassLoader = new JettyClassLoader(urls, classLoader, contextPriorityClassLoader);
+        setClassLoader(this.webClassLoader);
 
         handler = new WebApplicationHandler();
         addHandler(handler);
@@ -174,14 +174,14 @@
 
         if (componentContext != null) {
             componentContext.setKernel(kernel);
-            componentContext.setClassLoader(classLoader);
+            componentContext.setClassLoader(this.webClassLoader);
         }
 
         int index = 0;
         BeforeAfter interceptor = new InstanceContextBeforeAfter(null, index++, unshareableResources, applicationManagedSecurityResources, trackedConnectionAssociator);
         interceptor = new TransactionContextBeforeAfter(interceptor, index++, index++, transactionContextManager);
         interceptor = new ComponentContextBeforeAfter(interceptor, index++, componentContext);
-        interceptor = new ThreadClassloaderBeforeAfter(interceptor, index++, index++, this.classLoader);
+        interceptor = new ThreadClassloaderBeforeAfter(interceptor, index++, index++, this.webClassLoader);
         interceptor = new WebApplicationContextBeforeAfter(interceptor, index++, this);
 //JACC
         if (securityConfig != null) {
@@ -217,7 +217,7 @@
 
     public void doStart() throws WaitingException, Exception {
         // reset the classsloader... jetty likes to set it to null when stopping
-        setClassLoader(classLoader);
+        setClassLoader(webClassLoader);
 
         // merge Geronimo and Jetty Lifecycles
         if (!isStarting()) {

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?view=diff&rev=126185&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java&r1=126184&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java&r2=126185
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java	Sat Jan 22 19:48:42 2005
@@ -763,7 +763,6 @@
                 target = constructor.newInstance(parameters);
             } catch (InvocationTargetException e) {
                 Throwable targetException = e.getTargetException();
-                if (targetException instanceof Exception) {
                     throw (Exception) targetException;
                 } else if (targetException instanceof Error) {
                     throw (Error) targetException;

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/DeserializingReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/DeserializingReference.java?view=auto&rev=126185
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/DeserializingReference.java	Sat Jan 22 19:48:42 2005
@@ -0,0 +1,75 @@
+/**
+ *
+ * Copyright 2003-2004 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.apache.geronimo.naming.reference;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectStreamClass;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class DeserializingReference extends SimpleAwareReference {
+
+    private final byte[] bytes;
+    private transient Object content;
+
+    public DeserializingReference(byte[] bytes) {
+        this.bytes = bytes;
+    }
+
+    public Object getContent() {
+        return content;
+    }
+
+    public void setClassLoader(ClassLoader classLoader) {
+        super.setClassLoader(classLoader);
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        try {
+            ObjectInputStream is = new ConfigInputStream(bais, classLoader);
+            try {
+                content = is.readObject();
+            } finally {
+                is.close();
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Could not deserialize content", e);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException("Could not deserialize content", e);
+        }
+    }
+
+    private static class ConfigInputStream extends ObjectInputStream {
+        private final ClassLoader cl;
+
+        public ConfigInputStream(InputStream in, ClassLoader cl) throws IOException {
+            super(in);
+            this.cl = cl;
+        }
+
+        protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+            try {
+                return cl.loadClass(desc.getName());
+            } catch (ClassNotFoundException e) {
+                // let the parent try
+                return super.resolveClass(desc);
+            }
+        }
+    }
+}