1 17 18 package org.apache.catalina.util; 19 20 import java.io.InputStream ; 21 import java.io.IOException ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectStreamClass ; 24 import java.lang.reflect.Proxy ; 25 26 35 36 public final class CustomObjectInputStream 37 extends ObjectInputStream { 38 39 40 43 private ClassLoader classLoader = null; 44 45 46 54 public CustomObjectInputStream(InputStream stream, 55 ClassLoader classLoader) 56 throws IOException { 57 58 super(stream); 59 this.classLoader = classLoader; 60 } 61 62 63 72 public Class resolveClass(ObjectStreamClass classDesc) 73 throws ClassNotFoundException , IOException { 74 try { 75 return Class.forName(classDesc.getName(), false, classLoader); 76 } catch (ClassNotFoundException e) { 77 return super.resolveClass(classDesc); 79 } 80 } 81 82 83 88 protected Class resolveProxyClass(String [] interfaces) 89 throws IOException , ClassNotFoundException { 90 91 Class [] cinterfaces = new Class [interfaces.length]; 92 for (int i = 0; i < interfaces.length; i++) 93 cinterfaces[i] = classLoader.loadClass(interfaces[i]); 94 95 try { 96 return Proxy.getProxyClass(classLoader, cinterfaces); 97 } catch (IllegalArgumentException e) { 98 throw new ClassNotFoundException (null, e); 99 } 100 } 101 102 } 103 | Popular Tags |