changeset 52981:e25291a90cba

8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java Reviewed-by: dfuchs
author chegar
date Tue, 09 Oct 2018 11:44:00 +0100
parents 6ee9500fe653
children 7ecbaece746f
files test/jdk/javax/naming/module/RunBasic.java test/jdk/javax/naming/module/src/test/test/ConnectWithAuthzId.java test/jdk/javax/naming/module/src/test/test/ConnectWithFoo.java test/jdk/javax/naming/module/src/test/test/ReadByUrl.java test/jdk/javax/naming/module/src/test/test/StoreFruit.java test/jdk/javax/naming/module/src/test/test/StoreObject.java test/jdk/javax/naming/module/src/test/test/StorePerson.java test/jdk/javax/naming/module/src/test/test/StoreRemote.java
diffstat 8 files changed, 561 insertions(+), 492 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/javax/naming/module/RunBasic.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/RunBasic.java	Tue Oct 09 11:44:00 2018 +0100
@@ -27,8 +27,10 @@
 import jdk.test.lib.process.ProcessTools;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.time.Duration;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -65,6 +67,8 @@
 
     private static final List<String> JAVA_CMDS;
 
+    static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName();
+
     static {
         String javaPath = JDKToolFinder.getJDKTool("java");
 
@@ -85,6 +89,8 @@
         prepareModule("test", "--module-source-path",
                 Path.of(TEST_SRC, "src").toString());
 
+        System.out.println("Hostname: [" + HOST_NAME + "]");
+
         // run tests
         runTest("java.desktop", "test.StoreObject");
         runTest("person", "test.StorePerson");
@@ -98,9 +104,12 @@
     private static void prepareModule(String mod, String... opts)
             throws IOException {
         System.out.println("Preparing the '" + mod + "' module...");
+        long start = System.nanoTime();
         makeDir("mods", mod);
         CompilerUtils.compile(Path.of(TEST_SRC, "src", mod),
                 Path.of("mods", (mod.equals("test") ? "" : mod)), opts);
+        Duration duration = Duration.ofNanos(System.nanoTime() - start);
+        System.out.println("completed: duration - " + duration );
     }
 
     private static void makeDir(String first, String... more)
@@ -111,7 +120,7 @@
     private static void runTest(String desc, String clsName) throws Throwable {
         System.out.println("Running with the '" + desc + "' module...");
         runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,
-                "ldap://localhost/dc=ie,dc=oracle,dc=com");
+                "ldap://" + HOST_NAME + "/dc=ie,dc=oracle,dc=com");
     }
 
     private static void runJava(String... opts) throws Throwable {
--- a/test/jdk/javax/naming/module/src/test/test/ConnectWithAuthzId.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/ConnectWithAuthzId.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -40,12 +41,18 @@
 
 public class ConnectWithAuthzId {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") +
         "/src/test/test/ConnectWithAuthzId.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -68,67 +75,69 @@
          * Launch the LDAP server with the ConnectWithAuthzId.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
-            }
-        }).start();
-
-        /*
-         * Connect to the LDAP directory
-         */
-
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-            "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
-        }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        env.put(Context.SECURITY_AUTHENTICATION, "simple");
-        env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=ie,dc=oracle,dc=com");
-        env.put(Context.SECURITY_CREDENTIALS, "changeit");
-        env.put(LdapContext.CONTROL_FACTORIES,
-            "org.example.authz.AuthzIdResponseControlFactory");
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        System.out.println("ConnectWithAuthzId: connecting to " + ldapUri);
-        LdapContext ctx = null;
-        Control[] connectionControls = { new AuthzIdRequestControl(false) };
-
-        try {
-            ctx = new InitialLdapContext(env, connectionControls);
-            System.out.println("ConnectWithAuthzId: connected");
-            // Retrieve the response controls
-            Control[] responseControls = ctx.getResponseControls();
-            if (responseControls != null) {
-                for (Control responseControl : responseControls) {
-                    System.out.println("ConnectWithAuthzId: received response" +
-                        " control: " + responseControl.getID());
-                    if (responseControl instanceof AuthzIdResponseControl) {
-                        AuthzIdResponseControl authzId =
-                            (AuthzIdResponseControl)responseControl;
-                        System.out.println("ConnectWithAuthzId: identity is  " +
-                            authzId.getIdentity());
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
                     }
                 }
+            }).start();
+
+            /*
+             * Connect to the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        } catch (NamingException e) {
-            System.err.println("ConnectWithAuthzId: error connecting " + e);
-        } finally {
-            if (ctx != null) {
-                ctx.close();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            env.put(Context.SECURITY_AUTHENTICATION, "simple");
+            env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=ie,dc=oracle,dc=com");
+            env.put(Context.SECURITY_CREDENTIALS, "changeit");
+            env.put(LdapContext.CONTROL_FACTORIES,
+                    "org.example.authz.AuthzIdResponseControlFactory");
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
+
+            System.out.println("ConnectWithAuthzId: connecting to " + ldapUri);
+            LdapContext ctx = null;
+            Control[] connectionControls = { new AuthzIdRequestControl(false) };
+
+            try {
+                ctx = new InitialLdapContext(env, connectionControls);
+                System.out.println("ConnectWithAuthzId: connected");
+                // Retrieve the response controls
+                Control[] responseControls = ctx.getResponseControls();
+                if (responseControls != null) {
+                    for (Control responseControl : responseControls) {
+                        System.out.println("ConnectWithAuthzId: received response" +
+                                " control: " + responseControl.getID());
+                        if (responseControl instanceof AuthzIdResponseControl) {
+                            AuthzIdResponseControl authzId =
+                                    (AuthzIdResponseControl)responseControl;
+                            System.out.println("ConnectWithAuthzId: identity is  " +
+                                    authzId.getIdentity());
+                        }
+                    }
+                }
+            } catch (NamingException e) {
+                System.err.println("ConnectWithAuthzId: error connecting " + e);
+            } finally {
+                if (ctx != null) {
+                    ctx.close();
+                }
             }
         }
     }
--- a/test/jdk/javax/naming/module/src/test/test/ConnectWithFoo.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/ConnectWithFoo.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -38,11 +39,17 @@
 
 public class ConnectWithFoo {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/ConnectWithFoo.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -65,48 +72,50 @@
          * Launch the LDAP server with the ConnectWithFoo.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+
+            /*
+             * Connect to the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Connect to the LDAP directory
-         */
+            System.out.println("ConnectWithFoo: connecting to " + ldapUri);
+            LdapContext ctx = null;
+            Control[] connectionControls = { new FooControl(false) };
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-            "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
-        }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        System.out.println("ConnectWithFoo: connecting to " + ldapUri);
-        LdapContext ctx = null;
-        Control[] connectionControls = { new FooControl(false) };
-
-        try {
-            ctx = new InitialLdapContext(env, connectionControls);
-            System.out.println("ConnectWithFoo: connected");
-        } catch (NamingException e) {
-            System.err.println("ConnectWithFoo: error connecting " + e);
-        } finally {
-            if (ctx != null) {
-                ctx.close();
+            try {
+                ctx = new InitialLdapContext(env, connectionControls);
+                System.out.println("ConnectWithFoo: connected");
+            } catch (NamingException e) {
+                System.err.println("ConnectWithFoo: error connecting " + e);
+            } finally {
+                if (ctx != null) {
+                    ctx.close();
+                }
             }
         }
     }
--- a/test/jdk/javax/naming/module/src/test/test/ReadByUrl.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/ReadByUrl.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -36,11 +37,17 @@
 
 public class ReadByUrl {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/ReadByUrl.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -63,50 +70,52 @@
          * Launch the LDAP server with the ReadByUrl.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+
+            /*
+             * Connect to the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI("ldapv4", null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Connect to the LDAP directory
-         */
+            // URL context factory location for 'ldapv4://'
+            env.put(Context.URL_PKG_PREFIXES, "org.example");
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI("ldapv4", null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
-        }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
+            System.out.println("ReadByUrl: connecting to " + ldapUri);
+            DirContext ctx = null;
 
-        // URL context factory location for 'ldapv4://'
-        env.put(Context.URL_PKG_PREFIXES, "org.example");
-
-        System.out.println("ReadByUrl: connecting to " + ldapUri);
-        DirContext ctx = null;
-
-        try {
-            ctx = new InitialDirContext(env);
-            System.out.println("ReadByUrl: connected");
-            DirContext entry = (DirContext) ctx.lookup(ldapUri.toString());
-            entry.close();
-        } catch (NamingException e) {
-            System.err.println("ReadByUrl: error connecting " + e);
-        } finally {
-            if (ctx != null) {
-                ctx.close();
+            try {
+                ctx = new InitialDirContext(env);
+                System.out.println("ReadByUrl: connected");
+                DirContext entry = (DirContext) ctx.lookup(ldapUri.toString());
+                entry.close();
+            } catch (NamingException e) {
+                System.err.println("ReadByUrl: error connecting " + e);
+            } finally {
+                if (ctx != null) {
+                    ctx.close();
+                }
             }
         }
     }
--- a/test/jdk/javax/naming/module/src/test/test/StoreFruit.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/StoreFruit.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -38,18 +39,24 @@
 
 public class StoreFruit {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/StoreFruit.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
         /*
          * Process arguments
          */
-
         int argc = args.length;
         if ((argc < 1) ||
             ((argc == 1) && (args[0].equalsIgnoreCase("-help")))) {
@@ -58,97 +65,98 @@
             System.err.println("        <ldapurl> is the LDAP URL of the parent entry\n");
             System.err.println("example:");
             System.err.println("        java StoreFruit ldap://oasis/o=airius.com");
-    return;
+            return;
         }
 
         /*
          * Launch the LDAP server with the StoreFruit.ldap capture file
          */
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+            /*
+             * Store fruit objects in the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Store fruit objects in the LDAP directory
-         */
+            System.out.println("StoreFruit: connecting to " + ldapUri);
+            DirContext ctx = new InitialDirContext(env);
+            Fruit fruit = null;
+            String dn = "cn=myfruit";
+            String dn2 = "cn=myapple";
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-    "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
+            try {
+                fruit = new Fruit("orange");
+                ctx.bind(dn, fruit);
+                System.out.println("StoreFruit: created entry '" + dn + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StoreFruit: entry '" + dn +
+                        "' already exists");
+                cleanup(ctx, (String)null);
+                return;
+            }
+
+            try {
+                ctx.bind(dn2, new Fruit("apple"));
+                System.out.println("StoreFruit: created entry '" + dn2 + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StoreFruit: entry '" + dn2 +
+                        "' already exists");
+                cleanup(ctx, dn);
+                return;
+            }
+
+            /*
+             * Retrieve fruit objects from the LDAP directory
+             */
+
+            try {
+                Fruit fruit2 = (Fruit) ctx.lookup(dn);
+                System.out.println("StoreFruit: retrieved object: " + fruit2);
+            } catch (NamingException e) {
+                System.err.println("StoreFruit: error retrieving entry '" +
+                        dn + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            try {
+                Fruit fruit3 = (Fruit) ctx.lookup(dn2);
+                System.out.println("StoreFruit: retrieved object: " + fruit3);
+            } catch (NamingException e) {
+                System.err.println("StoreFruit: error retrieving entry '" +
+                        dn2 + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            cleanup(ctx, dn, dn2);
         }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        System.out.println("StoreFruit: connecting to " + ldapUri);
-        DirContext ctx = new InitialDirContext(env);
-        Fruit fruit = null;
-        String dn = "cn=myfruit";
-        String dn2 = "cn=myapple";
-
-        try {
-            fruit = new Fruit("orange");
-            ctx.bind(dn, fruit);
-            System.out.println("StoreFruit: created entry '" + dn + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StoreFruit: entry '" + dn +
-                "' already exists");
-            cleanup(ctx, (String)null);
-            return;
-        }
-
-        try {
-            ctx.bind(dn2, new Fruit("apple"));
-            System.out.println("StoreFruit: created entry '" + dn2 + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StoreFruit: entry '" + dn2 +
-                "' already exists");
-            cleanup(ctx, dn);
-            return;
-        }
-
-        /*
-         * Retrieve fruit objects from the LDAP directory
-         */
-
-        try {
-            Fruit fruit2 = (Fruit) ctx.lookup(dn);
-            System.out.println("StoreFruit: retrieved object: " + fruit2);
-        } catch (NamingException e) {
-            System.err.println("StoreFruit: error retrieving entry '" +
-                dn + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        try {
-            Fruit fruit3 = (Fruit) ctx.lookup(dn2);
-            System.out.println("StoreFruit: retrieved object: " + fruit3);
-        } catch (NamingException e) {
-            System.err.println("StoreFruit: error retrieving entry '" +
-                dn2 + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        cleanup(ctx, dn, dn2);
     }
 
     /*
--- a/test/jdk/javax/naming/module/src/test/test/StoreObject.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/StoreObject.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 package test;
 
 import java.awt.event.ActionEvent;
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -37,11 +38,17 @@
 
 public class StoreObject {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/StoreObject.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -64,89 +71,91 @@
          * Launch the LDAP server with the StoreObject.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+
+            /*
+             * Store objects in the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Store objects in the LDAP directory
-         */
+            System.out.println("StoreObject: connecting to " + ldapUri);
+            DirContext ctx = new InitialDirContext(env);
+            String dn = "cn=myevent";
+            String dn2 = "cn=myevent2";
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-            "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
+            try {
+                ctx.bind(dn, new ActionEvent("", 1, "Hello1"));
+                System.out.println("StoreObject: created entry '" + dn + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StoreObject: entry '" + dn +
+                        "' already exists");
+                cleanup(ctx, (String)null);
+                return;
+            }
+
+            try {
+                ctx.bind(dn2, new ActionEvent("", 2, "Hello2"));
+                System.out.println("StoreObject: created entry '" + dn2 + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StoreObject: entry '" + dn2 +
+                        "' already exists");
+                cleanup(ctx, dn);
+                return;
+            }
+
+            /*
+             * Retrieve objects from the LDAP directory
+             */
+
+            try {
+                ActionEvent b = (ActionEvent) ctx.lookup(dn);
+                System.out.println("StoreObject: retrieved object: " + b);
+            } catch (NamingException e) {
+                System.err.println("StoreObject: error retrieving entry '" +
+                        dn + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            try {
+                ActionEvent t = (ActionEvent) ctx.lookup(dn2);
+                System.out.println("StoreObject: retrieved object: " + t);
+            } catch (NamingException e) {
+                System.err.println("StoreObject: error retrieving entry '" +
+                        dn2 + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            cleanup(ctx, dn, dn2);
+            ctx.close();
         }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        System.out.println("StoreObject: connecting to " + ldapUri);
-        DirContext ctx = new InitialDirContext(env);
-        String dn = "cn=myevent";
-        String dn2 = "cn=myevent2";
-
-        try {
-            ctx.bind(dn, new ActionEvent("", 1, "Hello1"));
-            System.out.println("StoreObject: created entry '" + dn + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StoreObject: entry '" + dn +
-                "' already exists");
-            cleanup(ctx, (String)null);
-            return;
-        }
-
-        try {
-            ctx.bind(dn2, new ActionEvent("", 2, "Hello2"));
-            System.out.println("StoreObject: created entry '" + dn2 + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StoreObject: entry '" + dn2 +
-                "' already exists");
-            cleanup(ctx, dn);
-            return;
-        }
-
-        /*
-         * Retrieve objects from the LDAP directory
-         */
-
-        try {
-            ActionEvent b = (ActionEvent) ctx.lookup(dn);
-            System.out.println("StoreObject: retrieved object: " + b);
-        } catch (NamingException e) {
-            System.err.println("StoreObject: error retrieving entry '" +
-                dn + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        try {
-            ActionEvent t = (ActionEvent) ctx.lookup(dn2);
-            System.out.println("StoreObject: retrieved object: " + t);
-        } catch (NamingException e) {
-            System.err.println("StoreObject: error retrieving entry '" +
-                dn2 + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        cleanup(ctx, dn, dn2);
-        ctx.close();
     }
 
     /*
--- a/test/jdk/javax/naming/module/src/test/test/StorePerson.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/StorePerson.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
@@ -40,11 +41,17 @@
 
 public class StorePerson {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/StorePerson.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -67,115 +74,116 @@
          * Launch the LDAP server with the StorePerson.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+
+            /*
+             * Store Person objects in the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Store Person objects in the LDAP directory
-         */
+            // Specify the factory classname explicitly
+            env.put(Context.STATE_FACTORIES, "org.example.person.PersonFactory");
+            env.put(Context.OBJECT_FACTORIES, "org.example.person.PersonFactory");
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-    "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
+            System.out.println("StorePerson: connecting to " + ldapUri);
+            DirContext ctx = new InitialDirContext(env);
+            Person person = null;
+            String name = "John Smith";
+            String dn = "cn=" + name;
+
+            try {
+                person = new Person(name, "Smith");
+                person.setMailAddress("jsmith@smith.com");
+                ctx.bind(dn, person);
+                System.out.println("StorePerson: created entry '" + dn + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StorePerson: entry '" + dn +
+                        "' already exists");
+                cleanup(ctx, (String)null);
+                return;
+            }
+
+            name = "Jill Smyth";
+            String dn2 = "cn=" + name;
+            Person person2 = new Person(name, "Smyth");
+            person2.setMailAddress("jsmyth@smith.com");
+
+            try {
+                ctx.bind(dn2, person2);
+                System.out.println("StorePerson: created entry '" + dn2 + "'");
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StorePerson: entry '" + dn2 +
+                        "' already exists");
+                cleanup(ctx, dn);
+                return;
+            }
+
+            /*
+             * Retrieve Person objects from the LDAP directory
+             */
+
+            try {
+                Person person3 = (Person) ctx.lookup(dn);
+                System.out.println("StorePerson: retrieved object: " + person3);
+                if (person.getAttributes().equals(person3.getAttributes())) {
+                    System.out.println(
+                            "StorePerson: retrieved person matches original");
+                } else {
+                    System.out.println(
+                            "StorePerson: retrieved person does NOT match original");
+                }
+            } catch (NamingException e) {
+                System.err.println("StorePerson: error retrieving entry '" +
+                        dn + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            try {
+                Person person4 = (Person) ctx.lookup(dn2);
+                System.out.println("StorePerson: retrieved object: " + person4);
+                if (person2.getAttributes().equals(person4.getAttributes())) {
+                    System.out.println(
+                            "StorePerson: retrieved person matches original");
+                } else {
+                    System.out.println(
+                            "StorePerson: retrieved person does NOT match original");
+                }
+            } catch (NamingException e) {
+                System.err.println("StorePerson: error retrieving entry '" +
+                        dn2 + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn, dn2);
+                return;
+            }
+
+            cleanup(ctx, dn, dn2);
         }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        // Specify the factory classname explicitly
-        env.put(Context.STATE_FACTORIES, "org.example.person.PersonFactory");
-        env.put(Context.OBJECT_FACTORIES, "org.example.person.PersonFactory");
-
-        System.out.println("StorePerson: connecting to " + ldapUri);
-        DirContext ctx = new InitialDirContext(env);
-        Person person = null;
-        String name = "John Smith";
-        String dn = "cn=" + name;
-
-        try {
-            person = new Person(name, "Smith");
-            person.setMailAddress("jsmith@smith.com");
-            ctx.bind(dn, person);
-            System.out.println("StorePerson: created entry '" + dn + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StorePerson: entry '" + dn +
-                "' already exists");
-            cleanup(ctx, (String)null);
-            return;
-        }
-
-        name = "Jill Smyth";
-        String dn2 = "cn=" + name;
-        Person person2 = new Person(name, "Smyth");
-        person2.setMailAddress("jsmyth@smith.com");
-
-        try {
-            ctx.bind(dn2, person2);
-            System.out.println("StorePerson: created entry '" + dn2 + "'");
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StorePerson: entry '" + dn2 +
-                "' already exists");
-            cleanup(ctx, dn);
-            return;
-        }
-
-        /*
-         * Retrieve Person objects from the LDAP directory
-         */
-
-        try {
-            Person person3 = (Person) ctx.lookup(dn);
-            System.out.println("StorePerson: retrieved object: " + person3);
-            if (person.getAttributes().equals(person3.getAttributes())) {
-                System.out.println(
-                    "StorePerson: retrieved person matches original");
-            } else {
-                System.out.println(
-                    "StorePerson: retrieved person does NOT match original");
-            }
-        } catch (NamingException e) {
-            System.err.println("StorePerson: error retrieving entry '" +
-                dn + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        try {
-            Person person4 = (Person) ctx.lookup(dn2);
-            System.out.println("StorePerson: retrieved object: " + person4);
-            if (person2.getAttributes().equals(person4.getAttributes())) {
-                System.out.println(
-                    "StorePerson: retrieved person matches original");
-            } else {
-                System.out.println(
-                    "StorePerson: retrieved person does NOT match original");
-            }
-        } catch (NamingException e) {
-            System.err.println("StorePerson: error retrieving entry '" +
-                dn2 + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn, dn2);
-            return;
-        }
-
-        cleanup(ctx, dn, dn2);
-        return;
     }
 
     /*
--- a/test/jdk/javax/naming/module/src/test/test/StoreRemote.java	Tue Oct 02 17:17:43 2018 +0200
+++ b/test/jdk/javax/naming/module/src/test/test/StoreRemote.java	Tue Oct 09 11:44:00 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,11 +40,17 @@
 
 public class StoreRemote {
 
+    static {
+        final PrintStream out = new PrintStream(System.out, true);
+        final PrintStream err = new PrintStream(System.err, true);
+
+        System.setOut(out);
+        System.setErr(err);
+    }
+
     // LDAP capture file
     private static final String LDAP_CAPTURE_FILE =
         System.getProperty("test.src") + "/src/test/test/StoreRemote.ldap";
-    // LDAPServer socket
-    private static ServerSocket serverSocket;
 
     public static void main(String[] args) throws Exception {
 
@@ -67,77 +73,79 @@
          * Launch the LDAP server with the StoreRemote.ldap capture file
          */
 
-        serverSocket = new ServerSocket(0);
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
-               } catch (Exception e) {
-                   System.out.println("ERROR: unable to launch LDAP server");
-                   e.printStackTrace();
-               }
+        try (ServerSocket serverSocket = new ServerSocket()){
+            serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        new LDAPServer(serverSocket, LDAP_CAPTURE_FILE);
+                    } catch (Exception e) {
+                        System.out.println("ERROR: unable to launch LDAP server");
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+
+            /*
+             * Store a Remote object in the LDAP directory
+             */
+
+            Hashtable<String,Object> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
+            URI ldapUri = new URI(args[0]);
+            if (ldapUri.getPort() == -1) {
+                ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
+                        serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
             }
-        }).start();
+            env.put(Context.PROVIDER_URL, ldapUri.toString());
+            if (args[args.length - 1].equalsIgnoreCase("-trace")) {
+                env.put("com.sun.jndi.ldap.trace.ber", System.out);
+            }
 
-        /*
-         * Store a Remote object in the LDAP directory
-         */
+            System.out.println("StoreRemote: connecting to " + ldapUri);
+            DirContext ctx = new InitialDirContext(env);
+            String dn = "cn=myremote";
 
-        Hashtable<String,Object> env = new Hashtable<>();
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-            "com.sun.jndi.ldap.LdapCtxFactory");
-        URI ldapUri = new URI(args[0]);
-        if (ldapUri.getPort() == -1) {
-            ldapUri = new URI(ldapUri.getScheme(), null, ldapUri.getHost(),
-                serverSocket.getLocalPort(), ldapUri.getPath(), null, null);
+            try {
+                Hello hello = new HelloImpl();
+                ctx.bind(dn, hello);
+                System.out.println("StoreRemote: created entry '" + dn + "'");
+
+                // Explicitly release the RMI object
+                UnicastRemoteObject.unexportObject(hello, true);
+
+            } catch (NameAlreadyBoundException e) {
+                System.err.println("StoreRemote: entry '" + dn +
+                        "' already exists");
+                cleanup(ctx, (String)null);
+                return;
+            }
+
+            /*
+             * Retrieve the Remote object from the LDAP directory
+             */
+
+            try {
+                Hello obj = (Hello) ctx.lookup(dn);
+                System.out.println("StoreRemote: retrieved object: " + obj);
+                System.out.println("StoreRemote: calling Hello.sayHello()...\n" +
+                        obj.sayHello());
+
+                // Explicitly release the RMI object
+                UnicastRemoteObject.unexportObject(obj, true);
+
+            } catch (NamingException e) {
+                System.err.println("StoreRemote: error retrieving entry '" +
+                        dn + "' " + e);
+                e.printStackTrace();
+                cleanup(ctx, dn);
+                return;
+            }
+
+            cleanup(ctx, dn);
         }
-        env.put(Context.PROVIDER_URL, ldapUri.toString());
-        if (args[args.length - 1].equalsIgnoreCase("-trace")) {
-            env.put("com.sun.jndi.ldap.trace.ber", System.out);
-        }
-
-        System.out.println("StoreRemote: connecting to " + ldapUri);
-        DirContext ctx = new InitialDirContext(env);
-        String dn = "cn=myremote";
-
-        try {
-            Hello hello = new HelloImpl();
-            ctx.bind(dn, hello);
-            System.out.println("StoreRemote: created entry '" + dn + "'");
-
-            // Explicitly release the RMI object
-            UnicastRemoteObject.unexportObject(hello, true);
-
-        } catch (NameAlreadyBoundException e) {
-            System.err.println("StoreRemote: entry '" + dn +
-                "' already exists");
-            cleanup(ctx, (String)null);
-            return;
-        }
-
-        /*
-         * Retrieve the Remote object from the LDAP directory
-         */
-
-        try {
-            Hello obj = (Hello) ctx.lookup(dn);
-            System.out.println("StoreRemote: retrieved object: " + obj);
-            System.out.println("StoreRemote: calling Hello.sayHello()...\n" +
-                obj.sayHello());
-
-            // Explicitly release the RMI object
-            UnicastRemoteObject.unexportObject(obj, true);
-
-        } catch (NamingException e) {
-            System.err.println("StoreRemote: error retrieving entry '" +
-                dn + "' " + e);
-            e.printStackTrace();
-            cleanup(ctx, dn);
-            return;
-        }
-
-        cleanup(ctx, dn);
     }
 
     /*