author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 14778 | 5947768d173d |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
14778
diff
changeset
|
2 |
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 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 |
|
14778 | 31 |
* @build TestLibrary ClientStackTrace MyRemoteObject_Stub |
2 | 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 |
} |