Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/transport/tcp/DisableRMIOverHttp/DisableRMIOverHTTPTest.java
38867 views
1
/*
2
* Copyright (c) 2018, 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 8158963
26
*
27
* @summary Disable RMI over HTTP by default
28
*
29
* @library ../../../../../java/rmi/testlibrary
30
* @build TestIface TestImpl
31
* @run main/othervm/timeout=60 DisableRMIOverHTTPTest
32
* @run main/othervm/timeout=60 -Dsun.rmi.server.disableIncomingHttp=false DisableRMIOverHTTPTest
33
*/
34
35
/*
36
* This test is an adaptation of ../blockAccept/BlockAcceptTest.java
37
*
38
* This test:
39
* 1. Creates an object and exports it.
40
* 2. Makes a regular call, using HTTP tunnelling.
41
* 3. Either throws an exception if RMI over HTTP is disabled or completes
42
* execution if not.
43
*/
44
45
import java.rmi.*;
46
import java.rmi.server.RMISocketFactory;
47
import java.io.*;
48
import java.net.*;
49
50
import sun.rmi.transport.proxy.RMIMasterSocketFactory;
51
import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory;
52
53
public class DisableRMIOverHTTPTest
54
{
55
public static void main(String[] args)
56
throws Exception
57
{
58
// HTTP direct to the server port
59
System.setProperty("http.proxyHost", "127.0.0.1");
60
boolean incomingHttpDisabled =
61
Boolean.valueOf(
62
System.getProperty(
63
"sun.rmi.server.disableIncomingHttp", "true")
64
.equalsIgnoreCase("true"));
65
66
// Set the socket factory.
67
System.err.println("(installing HTTP-out socket factory)");
68
HttpOutFactory fac = new HttpOutFactory();
69
RMISocketFactory.setSocketFactory(fac);
70
71
// Create remote object
72
TestImpl impl = new TestImpl();
73
74
// Export and get which port.
75
System.err.println("(exporting remote object)");
76
TestIface stub = impl.export();
77
try {
78
int port = fac.whichPort();
79
80
// Sanity
81
if (port == 0)
82
throw new Error("TEST FAILED: export didn't reserve a port(?)");
83
84
// The test itself: make a remote call and see if it's blocked or
85
// if it works
86
//Thread.sleep(2000);
87
System.err.println("(making RMI-through-HTTP call)");
88
String result = stub.testCall("dummy load");
89
System.err.println(" => " + result);
90
91
if ("OK".equals(result)) {
92
if (incomingHttpDisabled) {
93
throw new Error(
94
"TEST FAILED: should not receive result if incoming http is disabled");
95
}
96
} else {
97
if (!incomingHttpDisabled) {
98
throw new Error("TEST FAILED: result not OK");
99
}
100
}
101
System.err.println("Test passed.");
102
} catch (UnmarshalException e) {
103
if (!incomingHttpDisabled) {
104
throw e;
105
} else {
106
System.err.println("Test passed.");
107
}
108
} finally {
109
try {
110
impl.unexport();
111
} catch (Throwable unmatter) {
112
}
113
}
114
115
// Should exit here
116
}
117
118
private static class HttpOutFactory
119
extends RMISocketFactory
120
{
121
private int servport = 0;
122
123
public Socket createSocket(String h, int p)
124
throws IOException
125
{
126
return ((new RMIHttpToPortSocketFactory()).createSocket(h, p));
127
}
128
129
/** Create a server socket and remember which port it's on.
130
* Aborts if createServerSocket(0) is called twice, because then
131
* it doesn't know whether to remember the first or second port.
132
*/
133
public ServerSocket createServerSocket(int p)
134
throws IOException
135
{
136
ServerSocket ss;
137
ss = (new RMIMasterSocketFactory()).createServerSocket(p);
138
if (p == 0) {
139
if (servport != 0) {
140
System.err.println("TEST FAILED: " +
141
"Duplicate createServerSocket(0)");
142
throw new Error("Test aborted (createServerSocket)");
143
}
144
servport = ss.getLocalPort();
145
}
146
return (ss);
147
}
148
149
/** Return which port was reserved by createServerSocket(0).
150
* If the return value was 0, createServerSocket(0) wasn't called.
151
*/
152
public int whichPort() {
153
return (servport);
154
}
155
} // end class HttpOutFactory
156
}
157
158