test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4127826
  26  *
  27  * @summary synopsis: need to download factories for use with custom socket
  28  * types
  29  * @author Ann Wollrath
  30  *
  31  * @library ../../../../testlibrary
  32  * @build TestLibrary RMID JavaVM Echo EchoImpl EchoImpl_Stub
  33  * @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory
  34  */
  35 
  36 import java.io.*;

  37 import java.rmi.*;
  38 import java.rmi.server.*;
  39 import java.rmi.registry.*;
  40 
  41 public class UseCustomSocketFactory {
  42 
  43     public static void main(String[] args) {
  44 
  45         int registryPort = -1;
  46 
  47         String[] protocol = new String[] { "", "compress", "xor" };
  48 
  49         System.out.println("\nRegression test for bug 4127826\n");
  50 
  51         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
  52 
  53         try {
  54             Registry registry = TestLibrary.createRegistryOnUnusedPort();
  55             registryPort = TestLibrary.getRegistryPort(registry);
  56         } catch (Exception e) {
  57             TestLibrary.bomb("creating registry", e);
  58         }
  59 
  60         for (int i = 0; i < protocol.length; i++) {
  61 
  62             System.err.println("test policy: " +
  63                                TestParams.defaultPolicy);
  64 
  65             JavaVM serverVM = new JavaVM("EchoImpl",
  66                                          "-Djava.security.policy=" +
  67                                          TestParams.defaultPolicy +
  68                                          " -Drmi.registry.port=" +
  69                                          registryPort,
  70                                          protocol[i]);
  71             System.err.println("\nusing protocol: " +
  72                                (protocol[i] == "" ? "none" : protocol[i]));
  73 
  74             try {
  75                 /* spawn VM for EchoServer */
  76                 serverVM.start();
  77 
  78                 /* lookup server */
  79                 int tries = 8;
  80                 Echo obj = null;


  81                 do {
  82                     try {
  83                         obj = (Echo) Naming.lookup("//:" + registryPort +
  84                                                    "/EchoServer");
  85                         break;
  86                     } catch (NotBoundException e) {
  87                         try {
  88                             Thread.sleep(2000);
  89                         } catch (Exception ignore) {
  90                         }
  91                         continue;
  92                     }
  93                 } while (--tries > 0);
  94 
  95                 if (obj == null)
  96                     TestLibrary.bomb("server not bound in 8 tries", null);
  97 
  98                 /* invoke remote method and print result*/
  99                 System.err.println("Bound to " + obj);
 100                 byte[] data = ("Greetings, citizen " +
 101                                System.getProperty("user.name") + "!"). getBytes();
 102                 byte[] result = obj.echoNot(data);
 103                 for (int j = 0; j < result.length; j++)
 104                     result[j] = (byte) ~result[j];
 105                 System.err.println("Result: " + new String(result));
 106 
 107             } catch (Exception e) {
 108                 TestLibrary.bomb("test failed", e);
 109 
 110             } finally {
 111                 serverVM.destroy();
 112                 try {
 113                     Naming.unbind("//:" + registryPort +
 114                                   "/EchoServer");
 115                 } catch (Exception e) {
 116                     TestLibrary.bomb("unbinding EchoServer", e);
 117 
 118                 }
 119             }
 120         }
 121     }
 122 }


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4127826
  26  *
  27  * @summary synopsis: need to download factories for use with custom socket
  28  * types
  29  * @author Ann Wollrath
  30  *
  31  * @library ../../../../testlibrary
  32  * @build TestLibrary RMID JavaVM Echo EchoImpl EchoImpl_Stub
  33  * @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory
  34  */
  35 
  36 import java.io.IOException;
  37 import java.net.MalformedURLException;
  38 import java.rmi.*;

  39 import java.rmi.registry.*;
  40 
  41 public class UseCustomSocketFactory {
  42 
  43     public static void main(String[] args) {
  44 
  45         int registryPort = -1;
  46 
  47         String[] protocols = new String[] { "", "compress", "xor" };
  48 
  49         System.out.println("\nRegression test for bug 4127826\n");
  50 
  51         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
  52 
  53         try {
  54             Registry registry = TestLibrary.createRegistryOnUnusedPort();
  55             registryPort = TestLibrary.getRegistryPort(registry);
  56         } catch (RemoteException e) {
  57             TestLibrary.bomb("creating registry", e);
  58         }
  59         for (String protocol : protocols) {


  60             System.err.println("test policy: " +
  61                     TestParams.defaultPolicy);
  62             JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" +


  63                     TestParams.defaultPolicy +
  64                     " -Drmi.registry.port=" +
  65                     registryPort, protocol);

  66             System.err.println("\nusing protocol: " + 
  67                     ("".equals(protocol) ? "none" : protocol));

  68             try {
  69                 /* spawn VM for EchoServer */
  70                 serverVM.start();
  71 
  72                 /* lookup server */

  73                 Echo obj = null;
  74                 // 16 seconds timeout
  75                 long stopTime = System.currentTimeMillis() + 16000;
  76                 do {
  77                     try {
  78                         obj = (Echo) Naming.lookup("//:" + registryPort +
  79                                                    "/EchoServer");
  80                         break;
  81                     } catch (NotBoundException e) {
  82                         try {
  83                             Thread.sleep(200);
  84                         } catch (InterruptedException ignore) {
  85                         }

  86                     }
  87                 } while (System.currentTimeMillis() < stopTime);
  88 
  89                 if (obj == null)
  90                     TestLibrary.bomb("server not bound in 8 tries", null);
  91 
  92                 /* invoke remote method and print result*/
  93                 System.err.println("Bound to " + obj);
  94                 byte[] data = ("Greetings, citizen " +
  95                         System.getProperty("user.name") + "!"). getBytes();
  96                 byte[] result = obj.echoNot(data);
  97                 for (int j = 0; j < result.length; j++)
  98                     result[j] = (byte) ~result[j];
  99                 System.err.println("Result: " + new String(result));
 100 
 101             } catch (IOException e) {
 102                 TestLibrary.bomb("test failed", e);
 103 
 104             } finally {
 105                 serverVM.destroy();
 106                 try {
 107                     Naming.unbind("//:" + registryPort +
 108                             "/EchoServer");
 109                 } catch (RemoteException | NotBoundException | MalformedURLException e) {
 110                     TestLibrary.bomb("unbinding EchoServer", e);
 111 
 112                 }
 113             }
 114         }
 115     }
 116 }