1 /*
2 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. 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 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.
22 */
23
24 /* @test
25 * @bug 4155894
26 *
27 * @summary remote references can't be downloaded
28 * @author Ann Wollrath
29 *
30 * test currently needs RMISecurityManager because of
31 * 4180392
32 *
33 * @library ../../testlibrary
34 * @build UseCustomRef
35 * @build Ping
36 * @build UseCustomRef_Stub
37 * @build UseCustomRef_Skel
38 * @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef
39 *
40 * This test was failing to run because the synthetic access
41 * control context used by the application class loader to find and define
42 * CustomServerRef does not have accessClassInPackage.sun.rmi.server runtime
43 * permission necessary to load its superclass sun.rmi.server.UnicastServerRef,
44 * even though this test's code is granted that permission in its policy file.
45 * That bug number is 4256530
46 */
47
48 import java.io.*;
49 import java.rmi.*;
50 import java.rmi.server.*;
51 import java.rmi.registry.*;
52 import sun.rmi.transport.LiveRef;
53
54 public class UseCustomRef
55 extends RemoteServer
56 implements Ping
57 {
67
68 public RemoteRef getRef() { return ref; }
69
70 public void ping() {}
71
72 public void receiveAndPing(Ping p) throws RemoteException {
73 p.ping();
74 }
75
76 public static void main(String[] args) {
77 Ping obj = null;
78 Registry registry = null;
79
80 try {
81 /*
82 * create registry
83 */
84 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
85
86 System.err.println("creating Registry...");
87 registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
88
89 /*
90 * create object with custom ref and bind in registry
91 */
92 System.err.println("creating UseCustomRef...");
93 UseCustomRef cr = new UseCustomRef();
94 RemoteRef ref = cr.getRef();
95 if (!(ref instanceof CustomServerRef)) {
96 TestLibrary.bomb("test failed: reference not " +
97 "instanceof CustomServerRef");
98 }
99
100 String name = "//:" + TestLibrary.REGISTRY_PORT + "/UseCustomRef";
101 // String name = "UseCustomRef";
102 System.err.println("binding object in registry...");
103 Naming.rebind(name, cr);
104
105 /*
106 * look up object and invoke its ping method
107 */
108 System.err.println("ping object...");
109 obj = (Ping) Naming.lookup(name);
110 obj.ping();
111
112 /*
113 * pass object with custom ref in remote call
114 */
115 System.err.println("pass object in remote call...");
116 obj.receiveAndPing(cr);
117
118 /*
119 * write remote object with custom ref to output stream
120 */
|
1 /*
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. 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 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.
22 */
23
24 /* @test
25 * @bug 4155894
26 *
27 * @summary remote references can't be downloaded
28 * @author Ann Wollrath
29 *
30 * test currently needs RMISecurityManager because of
31 * 4180392
32 *
33 * @library ../../testlibrary
34 * @build UseCustomRef
35 * @build Ping
36 * @build UseCustomRef_Stub
37 * @build UseCustomRef_Skel
38 * @build TestLibrary
39 * @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef
40 *
41 * This test was failing to run because the synthetic access
42 * control context used by the application class loader to find and define
43 * CustomServerRef does not have accessClassInPackage.sun.rmi.server runtime
44 * permission necessary to load its superclass sun.rmi.server.UnicastServerRef,
45 * even though this test's code is granted that permission in its policy file.
46 * That bug number is 4256530
47 */
48
49 import java.io.*;
50 import java.rmi.*;
51 import java.rmi.server.*;
52 import java.rmi.registry.*;
53 import sun.rmi.transport.LiveRef;
54
55 public class UseCustomRef
56 extends RemoteServer
57 implements Ping
58 {
68
69 public RemoteRef getRef() { return ref; }
70
71 public void ping() {}
72
73 public void receiveAndPing(Ping p) throws RemoteException {
74 p.ping();
75 }
76
77 public static void main(String[] args) {
78 Ping obj = null;
79 Registry registry = null;
80
81 try {
82 /*
83 * create registry
84 */
85 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
86
87 System.err.println("creating Registry...");
88
89 registry = TestLibrary.createRegistryOnUnusedPort();
90 int port = TestLibrary.getRegistryPort(registry);
91 /*
92 * create object with custom ref and bind in registry
93 */
94 System.err.println("creating UseCustomRef...");
95 UseCustomRef cr = new UseCustomRef();
96 RemoteRef ref = cr.getRef();
97 if (!(ref instanceof CustomServerRef)) {
98 TestLibrary.bomb("test failed: reference not " +
99 "instanceof CustomServerRef");
100 }
101
102 String name = "//:" + port + "/UseCustomRef";
103 // String name = "UseCustomRef";
104 System.err.println("binding object in registry...");
105 Naming.rebind(name, cr);
106
107 /*
108 * look up object and invoke its ping method
109 */
110 System.err.println("ping object...");
111 obj = (Ping) Naming.lookup(name);
112 obj.ping();
113
114 /*
115 * pass object with custom ref in remote call
116 */
117 System.err.println("pass object in remote call...");
118 obj.receiveAndPing(cr);
119
120 /*
121 * write remote object with custom ref to output stream
122 */
|