169N/A/*
5266N/A * Copyright (c) 1998, 2012, 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 4127826
0N/A *
0N/A * @summary synopsis: need to download factories for use with custom socket
169N/A * types
0N/A * @author Ann Wollrath
0N/A *
0N/A * @library ../../../../testlibrary
5551N/A * @build TestLibrary RMID JavaVM Echo EchoImpl EchoImpl_Stub
0N/A * @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.server.*;
0N/Aimport java.rmi.registry.*;
0N/A
0N/Apublic class UseCustomSocketFactory {
0N/A
0N/A public static void main(String[] args) {
169N/A
5266N/A int registryPort = -1;
5266N/A
169N/A String[] protocol = new String[] { "", "compress", "xor" };
169N/A
169N/A System.out.println("\nRegression test for bug 4127826\n");
0N/A
169N/A TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
0N/A
169N/A try {
5266N/A Registry registry = TestLibrary.createRegistryOnUnusedPort();
5266N/A registryPort = TestLibrary.getRegistryPort(registry);
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("creating registry", e);
169N/A }
0N/A
169N/A for (int i = 0; i < protocol.length; i++) {
0N/A
169N/A System.err.println("test policy: " +
169N/A TestParams.defaultPolicy);
0N/A
169N/A JavaVM serverVM = new JavaVM("EchoImpl",
169N/A "-Djava.security.policy=" +
5266N/A TestParams.defaultPolicy +
5266N/A " -Drmi.registry.port=" +
5266N/A registryPort,
169N/A protocol[i]);
169N/A System.err.println("\nusing protocol: " +
169N/A (protocol[i] == "" ? "none" : protocol[i]));
169N/A
169N/A try {
169N/A /* spawn VM for EchoServer */
169N/A serverVM.start();
0N/A
169N/A /* lookup server */
169N/A int tries = 8;
169N/A Echo obj = null;
169N/A do {
169N/A try {
5266N/A obj = (Echo) Naming.lookup("//:" + registryPort +
169N/A "/EchoServer");
169N/A break;
169N/A } catch (NotBoundException e) {
169N/A try {
169N/A Thread.sleep(2000);
169N/A } catch (Exception ignore) {
169N/A }
169N/A continue;
169N/A }
169N/A } while (--tries > 0);
0N/A
169N/A if (obj == null)
169N/A TestLibrary.bomb("server not bound in 8 tries", null);
0N/A
169N/A /* invoke remote method and print result*/
169N/A System.err.println("Bound to " + obj);
169N/A byte[] data = ("Greetings, citizen " +
169N/A System.getProperty("user.name") + "!"). getBytes();
169N/A byte[] result = obj.echoNot(data);
169N/A for (int j = 0; j < result.length; j++)
169N/A result[j] = (byte) ~result[j];
169N/A System.err.println("Result: " + new String(result));
169N/A
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("test failed", e);
169N/A
169N/A } finally {
169N/A serverVM.destroy();
169N/A try {
5266N/A Naming.unbind("//:" + registryPort +
169N/A "/EchoServer");
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("unbinding EchoServer", e);
169N/A
169N/A }
169N/A }
169N/A }
0N/A }
0N/A}