0N/A/*
2362N/A * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4149366
0N/A * @summary The class loader used to load classes for parameter types sent in
0N/A * an RMI call to an activatable object should delegate to the class loader
0N/A * that loaded the class of the activatable object itself, to maximize the
0N/A * likelihood of type compatibility between downloaded parameter types and
0N/A * supertypes shared with the activatable object.
0N/A * @author Peter Jones (much code taken from Ann Wollrath's activation tests)
0N/A *
0N/A * @library ../../../testlibrary
0N/A * @build TestLibrary RMID ActivationLibrary
5551N/A * Foo FooReceiverImpl FooReceiverImpl_Stub Bar
0N/A * @run main/othervm/policy=security.policy/timeout=240 DownloadParameterClass
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.activation.*;
0N/Aimport java.rmi.server.*;
0N/Aimport java.rmi.registry.*;
0N/A
0N/Apublic class DownloadParameterClass {
0N/A
0N/A public interface FooReceiver extends Remote {
0N/A
0N/A /*
0N/A * The interface can't actually declare that the method takes a
0N/A * Foo, because then Foo would have to be in the test's CLASSPATH,
0N/A * which might get propagated to the group VM's CLASSPATH, which
0N/A * would nullify the test (the Foo supertype must be loaded in the
0N/A * group VM only through the class loader that loaded the
0N/A * activatable object).
0N/A */
0N/A public void receiveFoo(Object obj) throws RemoteException;
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A System.err.println("\nRegression test for bug 4149366\n");
0N/A
0N/A /*
0N/A * Install classes to be seen by the activatable object's class
0N/A * loader in the "codebase1" subdirectory of working directory, and
0N/A * install the subtype to be downloaded into the activatable object
0N/A * into the "codebase2" subdirectory.
0N/A */
0N/A URL codebase1 = null;
0N/A URL codebase2 = null;
0N/A try {
0N/A codebase1 = TestLibrary.installClassInCodebase("FooReceiverImpl", "codebase1");
0N/A TestLibrary.installClassInCodebase("FooReceiverImpl_Stub", "codebase1");
0N/A TestLibrary.installClassInCodebase("Foo", "codebase1");
0N/A codebase2 = TestLibrary.installClassInCodebase("Bar", "codebase2");
0N/A } catch (MalformedURLException e) {
0N/A TestLibrary.bomb("failed to install test classes", e);
0N/A }
0N/A
0N/A TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
0N/A
0N/A RMID rmid = null;
0N/A
0N/A try {
0N/A RMID.removeLog();
0N/A rmid = RMID.createRMID();
0N/A rmid.start();
0N/A
0N/A /* Cause activation groups to have a security policy that will
0N/A * allow security managers to be downloaded and installed
0N/A */
0N/A Properties p = new Properties();
0N/A // this test must always set policies/managers in its
0N/A // activation groups
0N/A p.put("java.security.policy",
0N/A TestParams.defaultGroupPolicy);
0N/A p.put("java.security.manager",
0N/A TestParams.defaultSecurityManager);
0N/A
0N/A /*
0N/A * Create and register descriptors for activatable object in a
0N/A * group other than this VM's group, so that another VM will be
0N/A * spawned with the object is activated.
0N/A */
0N/A System.err.println("Creating descriptors");
0N/A ActivationGroupDesc groupDesc =
0N/A new ActivationGroupDesc(p, null);
0N/A ActivationGroupID groupID =
0N/A ActivationGroup.getSystem().registerGroup(groupDesc);
0N/A ActivationDesc objDesc =
0N/A new ActivationDesc(groupID, "FooReceiverImpl",
0N/A codebase1.toString(), null, false);
0N/A
0N/A System.err.println("Registering descriptors");
0N/A FooReceiver obj = (FooReceiver) Activatable.register(objDesc);
0N/A
0N/A /*
0N/A * Create an instance of the subtype to be downloaded by the
0N/A * activatable object. The codebase must be a path including
0N/A * "codebase1" as well as "codebase2" because the supertype
0N/A * must be visible here as well; the supertype cannot be
0N/A * installed in both codebases (like it would be in a typical
0N/A * setup) because of the trivial installation mechanism used
0N/A * below, and see the comment above for why it can't be in
0N/A * the test's CLASSPATH.
0N/A */
0N/A Class subtype = RMIClassLoader.loadClass(
0N/A codebase2 + " " + codebase1, "Bar");
0N/A Object subtypeInstance = subtype.newInstance();
0N/A
0N/A obj.receiveFoo(subtypeInstance);
0N/A
0N/A System.err.println("\nTEST PASSED\n");
0N/A
0N/A } catch (Exception e) {
0N/A TestLibrary.bomb("test failed", e);
0N/A } finally {
0N/A ActivationLibrary.rmidCleanup(rmid);
0N/A }
0N/A }
0N/A}