You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by da...@apache.org on 2012/09/18 15:55:52 UTC
svn commit: r1387166 -
/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java
Author: davsclaus
Date: Tue Sep 18 13:55:52 2012
New Revision: 1387166
URL: http://svn.apache.org/viewvc?rev=1387166&view=rev
Log:
AMQ-2488: Unable to access Serializable class when receiving ObjectMessage in OSGi environment
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java?rev=1387166&r1=1387165&r2=1387166&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java Tue Sep 18 13:55:52 2012
@@ -34,13 +34,16 @@ public class ClassLoadingAwareObjectInpu
*/
private static final HashMap<String, Class> primClasses = new HashMap<String, Class>(8, 1.0F);
+ private final ClassLoader inLoader;
+
public ClassLoadingAwareObjectInputStream(InputStream in) throws IOException {
super(in);
+ inLoader = in.getClass().getClassLoader();
}
protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return load(classDesc.getName(), cl);
+ return load(classDesc.getName(), cl, inLoader);
}
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
@@ -54,25 +57,35 @@ public class ClassLoadingAwareObjectInpu
return Proxy.getProxyClass(cl, cinterfaces);
} catch (IllegalArgumentException e) {
try {
- return Proxy.getProxyClass(FALLBACK_CLASS_LOADER, cinterfaces);
+ return Proxy.getProxyClass(inLoader, cinterfaces);
} catch (IllegalArgumentException e1) {
+ // ignore
+ }
+ try {
+ return Proxy.getProxyClass(FALLBACK_CLASS_LOADER, cinterfaces);
+ } catch (IllegalArgumentException e2) {
+ // ignore
}
throw new ClassNotFoundException(null, e);
}
}
- private Class<?> load(String className, ClassLoader cl) throws ClassNotFoundException {
- try {
- return Class.forName(className, false, cl);
- } catch (ClassNotFoundException e) {
- final Class<?> clazz = (Class<?>) primClasses.get(className);
- if (clazz != null) {
- return clazz;
- } else {
- return Class.forName(className, false, FALLBACK_CLASS_LOADER);
+ private Class<?> load(String className, ClassLoader... cl) throws ClassNotFoundException {
+ for (ClassLoader loader : cl) {
+ try {
+ return Class.forName(className, false, loader);
+ } catch (ClassNotFoundException e) {
+ // ignore
}
}
+ // fallback
+ final Class<?> clazz = (Class<?>) primClasses.get(className);
+ if (clazz != null) {
+ return clazz;
+ } else {
+ return Class.forName(className, false, FALLBACK_CLASS_LOADER);
+ }
}
static {