J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1999-2000 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4117427 |
| 26 | * @summary When marshalling an object that implements java.rmi.Remote, |
| 27 | * but is not a RemoteStub and its corresponding stub class is not known |
| 28 | * by the RMI runtime, RMI's MarshalOutputStream should assume that the |
| 29 | * object is a proxy of some sort (like an RMI/IIOP stub) and simply |
| 30 | * allow the object to be serialized. |
| 31 | * @author Ann Wollrath |
| 32 | * |
| 33 | * @library ../../../../../java/rmi/testlibrary |
| 34 | * @build TestLibrary |
| 35 | * @build TestFailedException |
| 36 | * @build MarshalForeignStub |
| 37 | * @build Receiver |
| 38 | * @build MarshalForeignStub_Stub |
| 39 | * @run main/othervm/policy=security.policy MarshalForeignStub |
| 40 | */ |
| 41 | |
| 42 | import java.io.Serializable; |
| 43 | import java.rmi.*; |
| 44 | import java.rmi.server.*; |
| 45 | |
| 46 | public class MarshalForeignStub |
| 47 | extends UnicastRemoteObject |
| 48 | implements Receiver |
| 49 | { |
| 50 | |
| 51 | public static class ForeignStub implements Remote, Serializable { |
| 52 | } |
| 53 | |
| 54 | public MarshalForeignStub() throws RemoteException { |
| 55 | } |
| 56 | |
| 57 | public void receive(Object obj) { |
| 58 | System.err.println("+ receive(): received object " + obj); |
| 59 | } |
| 60 | |
| 61 | public static void main(String[] args) { |
| 62 | |
| 63 | System.err.println("\nRegression test for bug 4117427\n"); |
| 64 | |
| 65 | TestLibrary.suggestSecurityManager(null); |
| 66 | |
| 67 | System.err.println("Creating remote object."); |
| 68 | MarshalForeignStub obj = null; |
| 69 | try { |
| 70 | obj = new MarshalForeignStub(); |
| 71 | } catch (RemoteException e) { |
| 72 | TestLibrary.bomb(e); |
| 73 | } |
| 74 | |
| 75 | try { |
| 76 | Receiver stub = (Receiver) RemoteObject.toStub(obj); |
| 77 | |
| 78 | /* |
| 79 | * Pass an instance of ForeignStub to the remote object. |
| 80 | * This should succeed, because MarshalOutputStream now |
| 81 | * allows objects that implement Remote, but not RemoteStub |
| 82 | * to be serialized in an RMI call. |
| 83 | */ |
| 84 | System.err.println( |
| 85 | "Passing a foreign stub to remote object."); |
| 86 | stub.receive(new ForeignStub()); |
| 87 | |
| 88 | System.err.println("TEST SUCCEEDED"); |
| 89 | } catch (Exception e) { |
| 90 | System.err.println("TEST FAILED: "); |
| 91 | e.printStackTrace(); |
| 92 | throw new RuntimeException("TEST FAILED: " + e.toString()); |
| 93 | } finally { |
| 94 | try { |
| 95 | UnicastRemoteObject.unexportObject(obj, true); |
| 96 | } catch (Throwable e) { |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |