public RMIConnection createConnection() {
    RMIServerManager serverManager = null;
    Context initialNamingContext = null;
    try {
      initialNamingContext = new InitialContext();
    } catch (NamingException exception) {
      System.out.println("Naming Exception " + exception.toString());
    }
    ;
    // Set the client security manager
    try {
      System.setSecurityManager(new RMISecurityManager());
    } catch (Exception exception) {
      System.out.println("Security violation " + exception.toString());
    }

    // Get the remote factory object from the Registry
    try {
      serverManager = (RMIServerManager) initialNamingContext.lookup("SERVER-MANAGER");
    } catch (Exception exception) {
      throw new TestProblemException(exception.toString());
    }

    RMIConnection rmiConnection = null;
    try {
      rmiConnection = new RMIConnection(serverManager.createRemoteSessionController());
    } catch (RemoteException exception) {
      System.out.println("Error in invocation " + exception.toString());
    }

    return rmiConnection;
  }
Example #2
0
  public static void main(String[] args) {
    try {
      Properties p = new Properties();

      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.PROVIDER_URL, "10.10.10.13:1100,10.10.10.14:1100");
      // p.put(Context.PROVIDER_URL, "localhost:1100");
      p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      InitialContext ctx = new InitialContext(p);

      StatelessSessionHome statelessSessionHome =
          (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
      EnterpriseEntityHome cmpHome = (EnterpriseEntityHome) ctx.lookup("nextgen.EnterpriseEntity");
      StatelessSession statelessSession = statelessSessionHome.create();
      EnterpriseEntity cmp = null;
      try {
        cmp = cmpHome.findByPrimaryKey("bill");
      } catch (Exception ex) {
        cmp = cmpHome.create("bill");
      }
      int count = 0;
      while (true) {
        System.out.println(statelessSession.callBusinessMethodB());
        try {
          cmp.setOtherField(count++);
        } catch (Exception ex) {
          System.out.println("exception, trying to create it: " + ex);
          cmp = cmpHome.create("bill");
          cmp.setOtherField(count++);
        }
        System.out.println("Entity: " + cmp.getOtherField());
        Thread.sleep(2000);
      }
    } catch (NamingException nex) {
      if (nex.getRootCause() != null) {
        nex.getRootCause().printStackTrace();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }