< prev index next >

test/jdk/javax/naming/module/src/test/test/StoreFruit.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -27,31 +27,38 @@
  * third-party module. The Fruit object implements javax.naming.Referenceable.
  */
 
 package test;
 
+import java.io.PrintStream;
 import java.net.*;
 import java.util.*;
 import javax.naming.*;
 import javax.naming.directory.*;
 
 import org.example.fruit.Fruit;
 
 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")))) {
 
             System.err.println("\nUsage:   StoreFruit <ldapurl>\n");

@@ -62,12 +69,12 @@
         }
 
         /*
          * Launch the LDAP server with the StoreFruit.ldap capture file
          */
-
-        serverSocket = new ServerSocket(0);
+        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);

@@ -148,10 +155,11 @@
             return;
         }
 
         cleanup(ctx, dn, dn2);
     }
+    }
 
     /*
      * Remove objects from the LDAP directory
      */
     private static void cleanup(DirContext ctx, String... dns)
< prev index next >