java.rmi.server.RMIClassLoader Java Examples

The following examples show how to use java.rmi.server.RMIClassLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarshalInputStream.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #2
Source File: MarshalInputStream.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    StreamChecker checker = streamChecker;
    if (checker != null) {
        checker.checkProxyInterfaceNames(interfaces);
    }

    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #3
Source File: MarshalInputStream.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    StreamChecker checker = streamChecker;
    if (checker != null) {
        checker.checkProxyInterfaceNames(interfaces);
    }

    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #4
Source File: MarshalInputStream.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #5
Source File: MarshalInputStream.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #6
Source File: MarshalInputStream.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #7
Source File: MarshalInputStream.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    StreamChecker checker = streamChecker;
    if (checker != null) {
        checker.checkProxyInterfaceNames(interfaces);
    }

    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #8
Source File: MarshalInputStream.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #9
Source File: MarshalInputStream.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #10
Source File: MarshalInputStream.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * resolveProxyClass is extended to acquire (if present) the location
 * to determine the class loader to define the proxy class in.
 */
protected Class<?> resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException
{
    StreamChecker checker = streamChecker;
    if (checker != null) {
        checker.checkProxyInterfaceNames(interfaces);
    }

    /*
     * Always read annotation written by MarshalOutputStream.
     */
    Object annotation = readLocation();

    ClassLoader defaultLoader =
        skipDefaultResolveClass ? null : latestUserDefinedLoader();

    String codebase = null;
    if (!useCodebaseOnly && annotation instanceof String) {
        codebase = (String) annotation;
    }

    return RMIClassLoader.loadProxyClass(codebase, interfaces,
                                         defaultLoader);
}
 
Example #11
Source File: LoadProxyClasses.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #12
Source File: CodebaseAwareObjectInputStream.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
		throws IOException, ClassNotFoundException {

	// If codebaseUrl is set, try to load the class with the RMIClassLoader.
	// Else, propagate the ClassNotFoundException.
	if (this.codebaseUrl == null) {
		throw ex;
	}
	return RMIClassLoader.loadClass(this.codebaseUrl, className);
}
 
Example #13
Source File: DefaultProperty.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #14
Source File: DefaultProperty.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #15
Source File: ClassLoading.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeatedly load a class not found in classpath through RMIClassLoader.
 * Arguments: <# reps>
 */
public long run(String[] args) throws Exception {
    int reps = Integer.parseInt(args[0]);
    CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
    String url = "jar:" + csrc.getLocation().toString() + ALTROOT;

    long start = System.currentTimeMillis();
    for (int i = 0; i < reps; i++)
        RMIClassLoader.loadClass(url, CLASSNAME);
    long time = System.currentTimeMillis() - start;

    return time;
}
 
Example #16
Source File: ClassLoading.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeatedly load a class not found in classpath through RMIClassLoader.
 * Arguments: <# reps>
 */
public long run(String[] args) throws Exception {
    int reps = Integer.parseInt(args[0]);
    CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
    String url = "jar:" + csrc.getLocation().toString() + ALTROOT;

    long start = System.currentTimeMillis();
    for (int i = 0; i < reps; i++)
        RMIClassLoader.loadClass(url, CLASSNAME);
    long time = System.currentTimeMillis() - start;

    return time;
}
 
Example #17
Source File: ClassLoading.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeatedly load a class not found in classpath through RMIClassLoader.
 * Arguments: <# reps>
 */
public long run(String[] args) throws Exception {
    int reps = Integer.parseInt(args[0]);
    CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
    String url = "jar:" + csrc.getLocation().toString() + ALTROOT;

    long start = System.currentTimeMillis();
    for (int i = 0; i < reps; i++)
        RMIClassLoader.loadClass(url, CLASSNAME);
    long time = System.currentTimeMillis() - start;

    return time;
}
 
Example #18
Source File: LoadProxyClasses.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #19
Source File: DefaultProperty.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #20
Source File: LoadProxyClasses.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #21
Source File: LoadProxyClasses.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #22
Source File: LoadProxyClasses.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #23
Source File: LoadProxyClasses.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #24
Source File: ClassLoading.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeatedly load a class not found in classpath through RMIClassLoader.
 * Arguments: <# reps>
 */
public long run(String[] args) throws Exception {
    int reps = Integer.parseInt(args[0]);
    CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
    String url = "jar:" + csrc.getLocation().toString() + ALTROOT;

    long start = System.currentTimeMillis();
    for (int i = 0; i < reps; i++)
        RMIClassLoader.loadClass(url, CLASSNAME);
    long time = System.currentTimeMillis() - start;

    return time;
}
 
Example #25
Source File: DefaultProperty.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #26
Source File: DefaultProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #27
Source File: DefaultProperty.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServiceConfiguration.installServiceConfigurationFile();

        System.setProperty(
            "java.rmi.server.RMIClassLoaderSpi", "default");

        String classname = "Foo";

        URL codebaseURL = null;
        try {
            codebaseURL = TestLibrary.installClassInCodebase(
                classname, "remote_codebase");
        } catch (MalformedURLException e) {
            TestLibrary.bomb(e);
        }

        TestLibrary.suggestSecurityManager(null);

        Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
        if (!fooClass.getName().equals(classname)) {
            throw new RuntimeException(
                "wrong class name, expected: " + classname +
                ", received: " + fooClass.getName());
        }

        String annotation = RMIClassLoader.getClassAnnotation(fooClass);
        if (!annotation.equals(codebaseURL.toString())) {
            throw new RuntimeException(
                "wrong class annotation, expected: " + codebaseURL.toString() +
                ", received: " + annotation);
        }

        System.err.println("TEST PASSED");
    }
 
Example #28
Source File: LoadProxyClasses.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
    ClassLoader proxyLoader = proxy.getClass().getClassLoader();

    String proxyAnnotation =
        RMIClassLoader.getClassAnnotation(proxy.getClass());

    if ((proxyAnnotation == null) ||
        !proxyAnnotation.equals(publicUrl.toString()))
    {
        TestLibrary.bomb("proxy class had incorrect annotation: " +
                         proxyAnnotation);
    } else {
        System.err.println("proxy class had correct annotation: " +
                           proxyAnnotation);
    }

    boolean proxyOk = false;

    if (boomerangSemantics) {
        ClassLoader ctxLoader =
            Thread.currentThread().getContextClassLoader();
        if (proxyLoader == ctxLoader) {
            proxyOk = true;
        }
    } else if (proxyLoader.getClass().
               getName().indexOf("sun.rmi") >= 0)
    {
        proxyOk = true;
    }

    if (proxyOk) {
        System.err.println("\ncase5: proxy loaded from" +
                           " correct loader: " + proxyLoader);
    } else {
        TestLibrary.bomb("case5: proxy interface loaded from " +
                         "incorrect loader: " + proxyLoader);
    }
}
 
Example #29
Source File: CodebaseAwareObjectInputStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
		throws IOException, ClassNotFoundException {

	// If codebaseUrl is set, try to load the class with the RMIClassLoader.
	// Else, propagate the ClassNotFoundException.
	if (this.codebaseUrl == null) {
		throw ex;
	}
	return RMIClassLoader.loadClass(this.codebaseUrl, className);
}
 
Example #30
Source File: CodebaseAwareObjectInputStream.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
		throws IOException, ClassNotFoundException {

	// If codebaseUrl is set, try to load the class with the RMIClassLoader.
	// Else, propagate the ClassNotFoundException.
	if (this.codebaseUrl == null) {
		throw ex;
	}
	return RMIClassLoader.loadClass(this.codebaseUrl, className);
}