13256
|
1 |
/*
|
|
2 |
* Copyright (c) 2005, 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 |
*/
|
2
|
23 |
|
13256
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 5083594
|
|
27 |
* @summary Ensure that Naming.java correctly parses host names with '_' in
|
|
28 |
* them.
|
|
29 |
* @author Vinod Johnson
|
|
30 |
*
|
|
31 |
* @library ../testlibrary
|
14778
|
32 |
* @build TestLibrary UnderscoreHost_Stub
|
13256
|
33 |
* @run main/othervm UnderscoreHost
|
2
|
34 |
*/
|
|
35 |
|
|
36 |
import java.io.IOException;
|
|
37 |
import java.net.MalformedURLException;
|
|
38 |
import java.net.ServerSocket;
|
|
39 |
import java.net.Socket;
|
|
40 |
import java.rmi.Naming;
|
|
41 |
import java.rmi.Remote;
|
|
42 |
import java.rmi.RemoteException;
|
|
43 |
import java.rmi.registry.LocateRegistry;
|
|
44 |
import java.rmi.registry.Registry;
|
|
45 |
import java.rmi.server.RMISocketFactory;
|
|
46 |
import java.rmi.server.UnicastRemoteObject;
|
|
47 |
|
|
48 |
public class UnderscoreHost extends UnicastRemoteObject implements Remote {
|
|
49 |
private static final String HOSTNAME = "foo_bar";
|
|
50 |
private static final String NAME = "name";
|
|
51 |
/*
|
|
52 |
* The socket factory captures the host name of the parsed URL, and
|
|
53 |
* then connects to the local host.
|
|
54 |
*/
|
|
55 |
private static class HostVerifyingSocketFactory extends RMISocketFactory {
|
|
56 |
String host;
|
|
57 |
|
|
58 |
public synchronized Socket createSocket(String host, int port)
|
|
59 |
throws IOException {
|
|
60 |
if (this.host == null) {
|
|
61 |
// Only set it the first time, subsequent DGC dirty calls
|
|
62 |
// will be local host
|
|
63 |
this.host = host;
|
|
64 |
}
|
|
65 |
return new Socket("localhost", port);
|
|
66 |
}
|
|
67 |
public ServerSocket createServerSocket(int port) throws IOException {
|
|
68 |
return new ServerSocket(port);
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
public UnderscoreHost() throws RemoteException {};
|
|
73 |
|
|
74 |
public static void main(String args[]) {
|
|
75 |
UnderscoreHost t = null;
|
|
76 |
try {
|
|
77 |
HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
|
|
78 |
RMISocketFactory.setSocketFactory(hvf);
|
13256
|
79 |
Registry r = TestLibrary.createRegistryOnUnusedPort();
|
|
80 |
int port = TestLibrary.getRegistryPort(r);
|
2
|
81 |
t = new UnderscoreHost();
|
|
82 |
r.rebind(NAME, t);
|
|
83 |
Naming.lookup("rmi://" + HOSTNAME +
|
13256
|
84 |
":" + port + "/" + NAME);
|
2
|
85 |
/*
|
|
86 |
* This test is coded to pass whether java.net.URI obeys
|
|
87 |
* RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
|
|
88 |
*
|
|
89 |
* If java.net.URI obeys RFC 3986, so host names may
|
|
90 |
* contain underscores, then the Naming.lookup invocation
|
|
91 |
* should succeed-- but the host actually connected to
|
|
92 |
* must equal HOSTNAME.
|
|
93 |
*/
|
|
94 |
if (!hvf.host.equals(HOSTNAME)) {
|
|
95 |
throw new RuntimeException(
|
|
96 |
"java.rmi.Naming Parsing error:" +
|
|
97 |
hvf.host + ":" + HOSTNAME);
|
|
98 |
}
|
|
99 |
} catch (MalformedURLException e) {
|
|
100 |
/*
|
|
101 |
* If java.net.URI obeys RFC 2396, so host names must not
|
|
102 |
* contain underscores, then the Naming.lookup invocation
|
|
103 |
* should throw MalformedURLException-- so this is OK.
|
|
104 |
*/
|
|
105 |
} catch (IOException ioe) {
|
|
106 |
TestLibrary.bomb(ioe);
|
|
107 |
} catch (java.rmi.NotBoundException nbe) {
|
|
108 |
TestLibrary.bomb(nbe);
|
|
109 |
} finally {
|
|
110 |
TestLibrary.unexport(t);
|
|
111 |
}
|
|
112 |
|
|
113 |
}
|
|
114 |
}
|