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 4115696
0N/A
0N/A * @summary synopsis: cannot use socket factories with Activatable objects
0N/A * @author Ann Wollrath
0N/A *
0N/A * @library ../../../../testlibrary
5551N/A * @build TestLibrary Echo EchoImpl EchoImpl_Stub
0N/A * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.activation.*;
0N/Aimport java.rmi.server.*;
0N/Aimport java.rmi.registry.*;
0N/A
0N/Apublic class UseCustomSocketFactory {
5266N/A static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
0N/A
0N/A static String[] protocol = new String[] { "", "compress", "xor" };
169N/A
0N/A public static void main(String[] args) {
0N/A
169N/A System.out.println("\nRegression test for bug 4115696\n");
169N/A
169N/A TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
0N/A
169N/A try {
169N/A LocateRegistry.createRegistry(REGISTRY_PORT);
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("creating registry", e);
169N/A }
169N/A
169N/A RMID rmid = null;
0N/A
169N/A try {
169N/A rmid = RMID.createRMID(true);
169N/A rmid.addArguments(new String[] {
169N/A "-C-Djava.security.policy=" +
169N/A TestParams.defaultGroupPolicy +
169N/A " -C-Djava.security.manager=java.rmi.RMISecurityManager "});
169N/A rmid.start();
0N/A
5266N/A Echo[] echo = spawnAndTest(rmid.getPort());
169N/A reactivateAndTest(echo);
169N/A } catch (IOException e) {
169N/A TestLibrary.bomb("creating rmid", e);
169N/A } finally {
169N/A if (rmid != null)
169N/A rmid.destroy();
169N/A }
0N/A }
0N/A
5266N/A private static Echo[] spawnAndTest(int rmidPort) {
169N/A
169N/A System.err.println("\nCreate Test-->");
169N/A
169N/A Echo[] echo = new Echo[protocol.length];
169N/A
169N/A for (int i = 0; i < protocol.length; i++) {
169N/A JavaVM serverVM = new JavaVM("EchoImpl",
169N/A "-Djava.security.policy=" +
5266N/A TestParams.defaultPolicy +
5266N/A " -Drmi.registry.port=" +
5266N/A REGISTRY_PORT +
5266N/A " -Djava.rmi.activation.port=" +
5266N/A rmidPort,
169N/A protocol[i]);
0N/A
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 = 12; // need enough tries for slow machine.
169N/A echo[i] = null;
169N/A do {
169N/A try {
169N/A echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT +
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 (echo[i] == null)
169N/A TestLibrary.bomb("server not bound in 12 tries", null);
0N/A
169N/A /* invoke remote method and print result*/
169N/A System.err.println("Bound to " + echo[i]);
169N/A byte[] data = ("Greetings, citizen " +
169N/A System.getProperty("user.name") + "!"). getBytes();
169N/A byte[] result = echo[i].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 echo[i].shutdown();
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 {
169N/A Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("unbinding EchoServer", e);
169N/A
169N/A }
169N/A }
169N/A }
169N/A return echo;
0N/A }
0N/A
0N/A
0N/A private static void reactivateAndTest(Echo[] echo) {
0N/A
169N/A System.err.println("\nReactivate Test-->");
0N/A
169N/A for (int i = 0; i < echo.length; i++) {
169N/A try {
169N/A System.err.println("\nusing protocol: " +
169N/A (protocol[i] == "" ? "none" : protocol[i]));
169N/A byte[] data = ("Greetings, citizen " +
169N/A System.getProperty("user.name") + "!").getBytes();
169N/A byte[] result = echo[i].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 echo[i].shutdown();
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("activating EchoServer for protocol " + protocol[i], e);
169N/A }
169N/A }
0N/A }
0N/A}