public static void main(String[] args) {

    RMID rmid = null;

    System.out.println("\nRegression test for bug 4510355\n");

    try {
      TestLibrary.suggestSecurityManager("java.lang.SecurityManager");

      /*
       * Install group class file in codebase.
       */
      System.err.println("install class file in codebase");
      URL groupURL = TestLibrary.installClassInCodebase("MyActivationGroupImpl", "group");
      System.err.println("class file installed");

      /*
       * Start rmid.
       */
      RMID.removeLog();
      rmid = RMID.createRMID();
      String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none";
      rmid.addOptions(new String[] {execPolicyOption});
      rmid.start();

      /*
       * Create and register descriptors for custom group and an
       * activatable object in that group.
       */
      System.err.println("register group");

      Properties p = new Properties();
      p.put("java.security.policy", TestParams.defaultGroupPolicy);

      ActivationGroupDesc groupDesc =
          new ActivationGroupDesc(
              "MyActivationGroupImpl", groupURL.toExternalForm(), null, p, null);
      ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc);

      System.err.println("register activatable object");
      ActivationDesc desc = new ActivationDesc(groupID, "DownloadActivationGroup", null, null);
      Ping obj = (Ping) Activatable.register(desc);

      /*
       * Start group (by calling ping).
       */
      System.err.println("ping object (forces download of group's class)");
      obj.ping();
      System.err.println("TEST PASSED: group's class downloaded successfully");
      System.err.println("shutdown object");
      obj.shutdown();
      System.err.println("TEST PASSED");

    } catch (Exception e) {
      TestLibrary.bomb(e);
    } finally {
      rmid.cleanup();
    }
  }
Exemple #2
0
  public static void main(String[] args) {
    Ping obj = null;
    Registry registry = null;

    try {
      /*
       * create registry
       */
      TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");

      System.err.println("creating Registry...");

      registry = TestLibrary.createRegistryOnUnusedPort();
      int port = TestLibrary.getRegistryPort(registry);
      /*
       * create object with custom ref and bind in registry
       */
      System.err.println("creating UseCustomRef...");
      UseCustomRef cr = new UseCustomRef();
      RemoteRef ref = cr.getRef();
      if (!(ref instanceof CustomServerRef)) {
        TestLibrary.bomb("test failed: reference not " + "instanceof CustomServerRef");
      }

      String name = "//:" + port + "/UseCustomRef";
      //      String name = "UseCustomRef";
      System.err.println("binding object in registry...");
      Naming.rebind(name, cr);

      /*
       * look up object and invoke its ping method
       */
      System.err.println("ping object...");
      obj = (Ping) Naming.lookup(name);
      obj.ping();

      /*
       * pass object with custom ref in remote call
       */
      System.err.println("pass object in remote call...");
      obj.receiveAndPing(cr);

      /*
       * write remote object with custom ref to output stream
       */
      System.err.println("writing remote object to stream...");
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      out.writeObject(cr);
      out.flush();
      out.close();

      /*
       * read back remote object from output stream
       */
      System.err.println("reading remote object from stream...");
      ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
      cr = (UseCustomRef) in.readObject();

      /*
       * re-export object and ping
       */
      System.err.println("re-export object read...");
      cr.exportObject();
      System.err.println("look up object again...");
      Naming.rebind(name, cr);
      System.err.println("ping object read...");
      obj = (Ping) Naming.lookup(name);
      obj.ping();
      System.err.println("TEST PASSED");
      Naming.unbind(name);
      cr = null;

    } catch (Exception e) {
      TestLibrary.bomb("test failed with exception: ", e);
    } finally {
      TestLibrary.unexport(obj);
      TestLibrary.unexport(registry);

      registry = null;
      obj = null;
    }
  }
Exemple #3
0
 public void receiveAndPing(Ping p) throws RemoteException {
   p.ping();
 }