J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1998-1999 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 4010355 |
| 26 | * @summary RemoteException should have server's stack trace |
| 27 | * |
| 28 | * @author Laird Dornin |
| 29 | * |
| 30 | * @library ../../testlibrary |
| 31 | * @build ClientStackTrace MyRemoteObject_Stub TestLibrary TestParams |
| 32 | * @run main/othervm/policy=security.policy/timeout=120 ClientStackTrace |
| 33 | */ |
| 34 | |
| 35 | /* |
| 36 | * This test ensures that the stack trace in a caught server side |
| 37 | * remote exception contains the string "exceptionReceivedFromServer". |
| 38 | */ |
| 39 | |
| 40 | import java.rmi.*; |
| 41 | import java.rmi.server.*; |
| 42 | import sun.rmi.transport.StreamRemoteCall; |
| 43 | import java.io.ByteArrayOutputStream; |
| 44 | import java.io.PrintStream; |
| 45 | |
| 46 | interface MyRemoteInterface extends Remote { |
| 47 | void ping() throws RemoteException; |
| 48 | } |
| 49 | |
| 50 | class MyRemoteObject extends UnicastRemoteObject |
| 51 | implements MyRemoteInterface { |
| 52 | |
| 53 | public MyRemoteObject () throws RemoteException {} |
| 54 | |
| 55 | public void ping () throws RemoteException { |
| 56 | throw new RemoteException("This is a test remote exception"); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public class ClientStackTrace { |
| 61 | Object dummy = new Object(); |
| 62 | |
| 63 | public static void main(String[] args) { |
| 64 | |
| 65 | TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
| 66 | |
| 67 | Object dummy = new Object(); |
| 68 | MyRemoteObject myRobj = null; |
| 69 | MyRemoteInterface myStub = null; |
| 70 | |
| 71 | try { |
| 72 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 73 | PrintStream ps = new PrintStream(bos); |
| 74 | |
| 75 | System.err.println("\nRegression test for bug 4010355\n"); |
| 76 | |
| 77 | myRobj = new MyRemoteObject(); |
| 78 | |
| 79 | /* cause a remote exception to occur. */ |
| 80 | try { |
| 81 | myStub = (MyRemoteInterface) RemoteObject.toStub(myRobj); |
| 82 | myStub.ping(); |
| 83 | |
| 84 | } catch (RemoteException re) { |
| 85 | re.printStackTrace(ps); |
| 86 | String trace = bos.toString(); |
| 87 | |
| 88 | if (trace.indexOf("exceptionReceivedFromServer") <0 ) { |
| 89 | throw new RuntimeException("No client stack trace on " + |
| 90 | "thrown remote exception"); |
| 91 | } else { |
| 92 | System.err.println("test passed with stack trace: " + |
| 93 | trace); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | deactivate(myRobj); |
| 98 | |
| 99 | } catch (Exception e) { |
| 100 | e.printStackTrace(); |
| 101 | System.err.println("test failed"); |
| 102 | throw new RuntimeException(e.getMessage()); |
| 103 | } finally { |
| 104 | myRobj = null; |
| 105 | myStub = null; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // make sure that the remote object goes away. |
| 110 | static void deactivate(RemoteServer r) { |
| 111 | // make sure that the object goes away |
| 112 | try { |
| 113 | System.err.println("deactivating object."); |
| 114 | UnicastRemoteObject.unexportObject(r, true); |
| 115 | } catch (Exception e) { |
| 116 | e.getMessage(); |
| 117 | e.printStackTrace(); |
| 118 | } |
| 119 | } |
| 120 | } |