< prev index next >

test/java/rmi/Naming/UnderscoreHost.java

Print this page


   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   */


  63             throws IOException  {
  64             if (this.host == null) {
  65                 // Only set it the first time, subsequent DGC dirty calls
  66                 // will be local host
  67                 this.host = host;
  68             }
  69             return new Socket("localhost", port);
  70         }
  71         public ServerSocket createServerSocket(int port) throws IOException {
  72             return new ServerSocket(port);
  73         }
  74     }
  75 
  76     public UnderscoreHost() throws RemoteException {};
  77 
  78     public static void main(String args[]) {
  79         UnderscoreHost t = null;
  80         try {
  81             HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
  82             RMISocketFactory.setSocketFactory(hvf);
  83             Registry r = TestLibrary.createRegistryOnUnusedPort();
  84             int port = TestLibrary.getRegistryPort(r);
  85             t = new UnderscoreHost();
  86             r.rebind(NAME, t);
  87             Naming.lookup("rmi://" + HOSTNAME +
  88                           ":" + port + "/" + NAME);
  89             /*
  90              * This test is coded to pass whether java.net.URI obeys
  91              * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
  92              *
  93              * If java.net.URI obeys RFC 3986, so host names may
  94              * contain underscores, then the Naming.lookup invocation
  95              * should succeed-- but the host actually connected to
  96              * must equal HOSTNAME.
  97              */
  98             if (!hvf.host.equals(HOSTNAME)) {
  99                 throw new RuntimeException(
 100                     "java.rmi.Naming Parsing error:" +
 101                     hvf.host + ":" + HOSTNAME);
 102             }
 103         } catch (MalformedURLException e) {
   1  /*
   2   * Copyright (c) 2005, 2016, 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   */


  63             throws IOException  {
  64             if (this.host == null) {
  65                 // Only set it the first time, subsequent DGC dirty calls
  66                 // will be local host
  67                 this.host = host;
  68             }
  69             return new Socket("localhost", port);
  70         }
  71         public ServerSocket createServerSocket(int port) throws IOException {
  72             return new ServerSocket(port);
  73         }
  74     }
  75 
  76     public UnderscoreHost() throws RemoteException {};
  77 
  78     public static void main(String args[]) {
  79         UnderscoreHost t = null;
  80         try {
  81             HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
  82             RMISocketFactory.setSocketFactory(hvf);
  83             Registry r = TestLibrary.createRegistryOnEphemeralPort();
  84             int port = TestLibrary.getRegistryPort(r);
  85             t = new UnderscoreHost();
  86             r.rebind(NAME, t);
  87             Naming.lookup("rmi://" + HOSTNAME +
  88                           ":" + port + "/" + NAME);
  89             /*
  90              * This test is coded to pass whether java.net.URI obeys
  91              * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
  92              *
  93              * If java.net.URI obeys RFC 3986, so host names may
  94              * contain underscores, then the Naming.lookup invocation
  95              * should succeed-- but the host actually connected to
  96              * must equal HOSTNAME.
  97              */
  98             if (!hvf.host.equals(HOSTNAME)) {
  99                 throw new RuntimeException(
 100                     "java.rmi.Naming Parsing error:" +
 101                     hvf.host + ":" + HOSTNAME);
 102             }
 103         } catch (MalformedURLException e) {
< prev index next >