169N/A/*
5740N/A * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4115683
0N/A * @summary Endpoint hostnames should always be fully qualified or
0N/A * should be an ip address. When references to remote
0N/A * objects are passed outside of the local domain their
0N/A * endpoints may contain hostnames that are not fully
0N/A * qualified. Hence remote clients won't be able to contact
0N/A * the referenced remote obect.
0N/A *
0N/A * @author Laird Dornin
0N/A *
0N/A * @library ../../testlibrary
5551N/A * @build TestLibrary CheckFQDNClient CheckFQDN_Stub TellServerName
169N/A * @run main/othervm/timeout=120 CheckFQDN
0N/A */
0N/A
169N/A/**
0N/A * Get the hostname used by rmi using different rmi properities:
0N/A *
0N/A * if set java.rmi.server.hostname, hostname should equal this
0N/A * property.
169N/A *
0N/A * if set java.rmi.server.useLocalHostname, hostname must contain a '.'
0N/A *
0N/A * if set no properties hostname should be an ipaddress.
0N/A *
0N/A * if set java.rmi.server.hostname, hostname should equal this
0N/A * property even if set java.rmi.server.useLocalHostname is true.
0N/A *
0N/A */
0N/A
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.registry.*;
0N/Aimport java.rmi.server.*;
0N/Aimport java.io.*;
0N/A
0N/A/**
169N/A * Export a remote object through which the exec'ed client vm can
0N/A * inform the main test what its host name is.
0N/A */
169N/Apublic class CheckFQDN extends UnicastRemoteObject
0N/A implements TellServerName {
5266N/A public static int REGISTRY_PORT =-1;
0N/A static String propertyBeingTested = null;
0N/A static String propertyBeingTestedValue = null;
0N/A
0N/A public static void main(String args[]) {
0N/A
169N/A Object dummy = new Object();
169N/A CheckFQDN checkFQDN = null;
169N/A try {
169N/A checkFQDN = new CheckFQDN();
169N/A
169N/A System.err.println
169N/A ("\nRegression test for bug/rfe 4115683\n");
169N/A
5266N/A Registry registry = TestLibrary.createRegistryOnUnusedPort();
5266N/A REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
169N/A registry.bind("CheckFQDN", checkFQDN);
0N/A
169N/A /* test the host name scheme in different environments.*/
169N/A testProperty("java.rmi.server.useLocalHostname", "true", "");
169N/A testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest", "");
169N/A testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest",
169N/A " -Djava.rmi.server.useLocalHostname=true ");
169N/A testProperty("", "", "");
0N/A
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb(e);
169N/A } finally {
169N/A if (checkFQDN != null) {
169N/A TestLibrary.unexport(checkFQDN);
169N/A }
169N/A }
169N/A System.err.println("\nTest for bug/ref 4115683 passed.\n");
0N/A }
0N/A
169N/A /**
0N/A * Spawn a vm and feed it a property which sets the client's rmi
0N/A * hostname.
0N/A */
169N/A public static void testProperty(String property,
169N/A String propertyValue,
169N/A String extraProp)
0N/A {
169N/A try {
169N/A String propOption = "";
169N/A String equal = "";
169N/A if (!property.equals("")) {
169N/A propOption = " -D";
169N/A equal = "=";
169N/A }
0N/A
5740N/A // create a client to tell checkFQDN what its rmi name is.
169N/A JavaVM jvm = new JavaVM("CheckFQDNClient",
169N/A propOption + property +
169N/A equal +
5266N/A propertyValue + extraProp +
5266N/A " -Drmi.registry.port=" +
5266N/A REGISTRY_PORT,
169N/A "");
169N/A
169N/A propertyBeingTested=property;
169N/A propertyBeingTestedValue=propertyValue;
0N/A
5740N/A if (jvm.execute() != 0) {
169N/A TestLibrary.bomb("Test failed, error in client.");
169N/A }
169N/A
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb(e);
169N/A }
0N/A }
0N/A
0N/A CheckFQDN() throws RemoteException { }
0N/A
169N/A /**
169N/A * Remote method to allow client vm to tell the main test what its
0N/A * host name is .
0N/A */
169N/A public void tellServerName(String serverName)
169N/A throws RemoteException {
0N/A
169N/A if (propertyBeingTested.equals("java.rmi.server.hostname")) {
169N/A if ( !propertyBeingTestedValue.equals(serverName)) {
169N/A TestLibrary.bomb(propertyBeingTested +
169N/A ":\n Client rmi server name does " +
169N/A "not equal the one specified " +
169N/A "by java.rmi.server.hostname: " +
169N/A serverName +" != " +
169N/A propertyBeingTestedValue);
169N/A }
0N/A
169N/A /** use local host name, must contain a '.' */
169N/A } else if (propertyBeingTested.equals
169N/A ("java.rmi.server.useLocalHostname")) {
169N/A if (serverName.indexOf('.') < 0) {
169N/A TestLibrary.bomb(propertyBeingTested +
169N/A ":\nThe client servername contains no '.'");
169N/A }
169N/A } else {
169N/A // no propety set, must be ip address
169N/A if ((serverName.indexOf('.') < 0) ||
169N/A (!Character.isDigit(serverName.charAt(0)))) {
169N/A TestLibrary.bomb("Default name scheme:\n"+
169N/A " The client servername contains no '.'"+
169N/A "or is not an ip address");
169N/A }
169N/A }
169N/A System.err.println("Servername used: " + serverName);
0N/A }
0N/A}