/** * 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); }
/** * 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); }
/** * Load the class. The method uses class loaders from the call stact first. If * this fails, the further behaviour depends on the System Property * "java.rmi.server.useCodebaseOnly" with default value "false". * * <ul> * <li>Try the current thread context class loader first.</li> * <li>If remoteCodebase is non-null and useCodebaseOnly is "false" then call * java.rmi.server.RMIClassLoader.loadClass (remoteCodebase, className)</li> * <li> If remoteCodebase is null or useCodebaseOnly is true then call * java.rmi.server.RMIClassLoader.loadClass(className)</li> * <li>If a class is still not successfully loaded and the loader != null * then try Class.forName(className, false, loader). </li> * </ul> * * @param className the name of the class. * @param remoteCodebase the codebase. * @param loader the class loader. * @return the loaded class. * * @throws ClassNotFoundException of the class cannot be loaded. */ public Class loadClass(String className, String remoteCodebase, ClassLoader loader) throws ClassNotFoundException { if (loader == null) loader = VMStackWalker.firstNonNullClassLoader(); String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly"); boolean useCodebaseOnly = p_useCodebaseOnly != null && p_useCodebaseOnly.trim().equalsIgnoreCase("true"); if (useCodebaseOnly) remoteCodebase = null; try { return RMIClassLoader.loadClass(remoteCodebase, className, loader); } catch (MalformedURLException x) { throw new ClassNotFoundException(className, x); } }
/** * 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); }
/** * Returns the Remote Stub for the given activatable class. */ public static RemoteStub getStub(ActivationDesc desc, ActivationID aid) throws StubNotFoundException { String cn = desc.getClassName(); String stubName = ""; //$NON-NLS-1$ try { Class cl = RMIClassLoader.loadClass(desc.getLocation(), cn); Class rcl = RMIUtil.getRemoteClass(cl); stubName = rcl.getName() + "_Stub"; //$NON-NLS-1$ Class stubClass = RMIClassLoader.loadClass((String) null, stubName); Constructor constructor = stubClass.getConstructor(new Class[] { RemoteRef.class }); RemoteStub stub = (RemoteStub) constructor.newInstance(new Object[] { new ActivatableRef(aid, null) }); return stub; } catch (Exception ex) { // rmi.68=Stub {0} not found. throw new StubNotFoundException(Messages.getString("rmi.68", stubName), //$NON-NLS-1$ //$NON-NLS-2$ ex); } }
/** * Returns the Class that corresponds to the desc argument. * * @param desc * the descriptor of the needed Class * @return the Class for the desc descriptor */ @SuppressWarnings("deprecation") @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { Class<?> ret = null; Object obj = this.readObject(); try { ret = Class.forName(desc.getName(), true, Thread.currentThread() .getContextClassLoader()); } catch (ClassNotFoundException e) { if ((obj != null && obj instanceof String) && (!useCodebaseOnly)) { ret = RMIClassLoader.loadClass((String) obj, desc.getName()); } else { ret = RMIClassLoader.loadClass(desc.getName()); } } return ret; }
private void LoadClassStringString(String clase, boolean url) { SecurityManager smOld = System.getSecurityManager(); System.setSecurityManager(new RMISecurityManager() { public void checkPermission(Permission perm) { } }); try { if (url) { RMIClassLoader.loadClass(new URL("file://" + pathOwnClass), clase); } else { RMIClassLoader.loadClass("file://" + pathOwnClass, clase); } } catch (Throwable e) { fail("Failed with: " + e); } finally { System.setSecurityManager(smOld); } }
public final void testLoadClassStringStringClassLoader006() { SecurityManager smOld = System.getSecurityManager(); System.setSecurityManager(new RMISecurityManager() { public void checkPermission(Permission perm) { } }); try { RMIClassLoader .loadClass( "file://" + pathOwnClass, "ar.org.fitc.test.rmi.server.testclasses.LoaderClassTest001", null); } catch (Throwable e) { fail("Should not raise an exception but raised: " + e); } finally { System.setSecurityManager(smOld); } }
/** * Modify the above method to test loadClass, loadClass(String, String) for * coverage. */ public void testLoadClassCodebaseOrder5() throws Exception { SecurityManager previous = System.getSecurityManager(); System.setSecurityManager(new SecurityManager() { @Override public void checkPermission(Permission perm) { /* * Override checkPermission to allow everything. Specifically, * we want to allow the SecurityManager to be set to null at the * end of the test and we want to allow the 'testClass.jar' file * to be allowed to load. */ return; } }); try { Class<?> c = RMIClassLoader.loadClass("TestClass"); fail(); } catch (ClassNotFoundException e) { // expected } finally { // reset the security manager back to null state System.setSecurityManager(previous); } }
@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); }
/** * 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; }
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"); }
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); } }