View | Details | Raw Unified | Return to bug 51647
Collapse All | Expand All

(-)container/modules/cluster/src/share/org/apache/catalina/cluster/session/ReplicationStream.java (+39 lines)
Lines 22-27 Link Here
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.io.ObjectInputStream;
23
import java.io.ObjectInputStream;
24
import java.io.ObjectStreamClass;
24
import java.io.ObjectStreamClass;
25
import java.lang.reflect.Modifier;
26
import java.lang.reflect.Proxy;
25
27
26
/**
28
/**
27
 * Custom subclass of <code>ObjectInputStream</code> that loads from the
29
 * Custom subclass of <code>ObjectInputStream</code> that loads from the
Lines 86-91 Link Here
86
        }
88
        }
87
    }
89
    }
88
    
90
    
91
    /**
92
     * ObjectInputStream.resolveProxyClass has some funky way of using 
93
     * the incorrect class loader to resolve proxy classes, let's do it our way instead
94
     */
95
    protected Class resolveProxyClass(String[] interfaces)
96
        throws IOException, ClassNotFoundException {
97
        
98
        ClassLoader latestLoader = classLoader;
99
        ClassLoader nonPublicLoader = null;
100
        boolean hasNonPublicInterface = false;
101
102
        // define proxy in class loader of non-public interface(s), if any
103
        Class[] classObjs = new Class[interfaces.length];
104
        for (int i = 0; i < interfaces.length; i++) {
105
            Class cl = this.findWebappClass(interfaces[i]);
106
            if (latestLoader == null) latestLoader = cl.getClassLoader();
107
            if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
108
                if (hasNonPublicInterface) {
109
                    if (nonPublicLoader != cl.getClassLoader()) {
110
                        throw new IllegalAccessError(
111
                            "conflicting non-public interface class loaders");
112
                    }
113
                } else {
114
                    nonPublicLoader = cl.getClassLoader();
115
                    hasNonPublicInterface = true;
116
                }
117
            }
118
            classObjs[i] = cl;
119
        }
120
        try {
121
            return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader
122
                    : latestLoader, classObjs);
123
        } catch (IllegalArgumentException e) {
124
            throw new ClassNotFoundException(null, e);
125
        }
126
    }
127
89
    public Class findReplicationClass(String name)
128
    public Class findReplicationClass(String name)
90
        throws ClassNotFoundException, IOException {
129
        throws ClassNotFoundException, IOException {
91
        return Class.forName(name, false, getClass().getClassLoader());
130
        return Class.forName(name, false, getClass().getClassLoader());
(-)container/modules/groupcom/src/share/org/apache/catalina/tribes/io/ReplicationStream.java (-11 / +58 lines)
Lines 22-27 Link Here
22
import java.io.InputStream;
22
import java.io.InputStream;
23
import java.io.ObjectInputStream;
23
import java.io.ObjectInputStream;
24
import java.io.ObjectStreamClass;
24
import java.io.ObjectStreamClass;
25
import java.lang.reflect.Modifier;
26
import java.lang.reflect.Proxy;
25
27
26
/**
28
/**
27
 * Custom subclass of <code>ObjectInputStream</code> that loads from the
29
 * Custom subclass of <code>ObjectInputStream</code> that loads from the
Lines 71-93 Link Here
71
    public Class resolveClass(ObjectStreamClass classDesc)
73
    public Class resolveClass(ObjectStreamClass classDesc)
72
        throws ClassNotFoundException, IOException {
74
        throws ClassNotFoundException, IOException {
73
        String name = classDesc.getName();
75
        String name = classDesc.getName();
74
        boolean tryRepFirst = name.startsWith("org.apache.catalina.tribes");
75
        try {
76
        try {
76
            try
77
            return resolveClass(name);
77
            {
78
                if ( tryRepFirst ) return findReplicationClass(name);
79
                else return findExternalClass(name);
80
            }
81
            catch ( Exception x )
82
            {
83
                if ( tryRepFirst ) return findExternalClass(name);
84
                else return findReplicationClass(name);
85
            }
86
        } catch (ClassNotFoundException e) {
78
        } catch (ClassNotFoundException e) {
87
            return super.resolveClass(classDesc);
79
            return super.resolveClass(classDesc);
88
        }
80
        }
89
    }
81
    }
90
    
82
    
83
    public Class resolveClass(String name)
84
        throws ClassNotFoundException, IOException {
85
    
86
        boolean tryRepFirst = name.startsWith("org.apache.catalina.tribes");
87
            try {
88
            if (tryRepFirst)
89
                return findReplicationClass(name);
90
            else
91
                return findExternalClass(name);
92
        } catch (Exception x) {
93
            if (tryRepFirst)
94
                return findExternalClass(name);
95
            else
96
                return findReplicationClass(name);
97
        }
98
    }
99
100
    /**
101
     * ObjectInputStream.resolveProxyClass has some funky way of using 
102
     * the incorrect class loader to resolve proxy classes, let's do it our way instead
103
     */
104
    protected Class resolveProxyClass(String[] interfaces)
105
            throws IOException, ClassNotFoundException {
106
        
107
        ClassLoader latestLoader = (classLoaders!=null && classLoaders.length==0)?null:classLoaders[0];
108
        ClassLoader nonPublicLoader = null;
109
        boolean hasNonPublicInterface = false;
110
111
        // define proxy in class loader of non-public interface(s), if any
112
        Class[] classObjs = new Class[interfaces.length];
113
        for (int i = 0; i < interfaces.length; i++) {
114
            Class cl = this.resolveClass(interfaces[i]);
115
            if (latestLoader==null) latestLoader = cl.getClassLoader();
116
            if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
117
                if (hasNonPublicInterface) {
118
                    if (nonPublicLoader != cl.getClassLoader()) {
119
                        throw new IllegalAccessError(
120
                                "conflicting non-public interface class loaders");
121
                    }
122
                } else {
123
                    nonPublicLoader = cl.getClassLoader();
124
                    hasNonPublicInterface = true;
125
                }
126
            }
127
            classObjs[i] = cl;
128
        }
129
        try {
130
            return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader
131
                    : latestLoader, classObjs);
132
        } catch (IllegalArgumentException e) {
133
            throw new ClassNotFoundException(null, e);
134
        }
135
    }
136
137
    
91
    public Class findReplicationClass(String name)
138
    public Class findReplicationClass(String name)
92
        throws ClassNotFoundException, IOException {
139
        throws ClassNotFoundException, IOException {
93
        Class clazz = Class.forName(name, false, getClass().getClassLoader());
140
        Class clazz = Class.forName(name, false, getClass().getClassLoader());

Return to bug 51647