Esempio n. 1
2
  /**
   * Sets the java.security.policy system property to point at the location of the security policy
   * file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to
   * match operating system). the security manager is then started. This method must be called
   * before starting the class server.
   */
  private void configSecurityManager() {
    // file.separator is "\" in Windows and "/" in Unix/Linux/Mac.
    String sep = System.getProperty("file.separator");

    System.setProperty(
        "java.security.policy", "provided" + sep + "rmiUtils" + sep + "server.policy");
    outputCmd.apply("java.security.policy: " + System.getProperty("java.security.policy"));

    // Start the security manager
    if (System.getSecurityManager() == null) {
      outputCmd.apply("Installing new Security Manager...\n");
      System.setSecurityManager(new SecurityManager());
      outputCmd.apply("Security Manager = " + System.getSecurityManager());
    }
  }
Esempio n. 2
1
  /**
   * Sets the java.rmi.server.hostname and java.rmi.server.codebase system properties which control
   * the automatic remote dynamic class loading. This must be called before starting the class
   * server.
   *
   * @param classServerPort The port the class server will use.
   */
  private void configRMIProperties(int classServerPort) {
    // Logs all RMI activity to System.err
    System.setProperty("java.rmi.server.logCalls", "true");

    try {
      // Try to get figure out this server's IP address and save it as the
      // RMI server hostname.
      System.setProperty("java.rmi.server.hostname", getLocalAddress());

      System.setProperty(
          "java.rmi.server.codebase",
          "http://" + System.getProperty("java.rmi.server.hostname") + ":" + classServerPort + "/");
      System.setProperty(
          "java.rmi.server.useCodebaseOnly",
          "false"); // Must be false to allow remote class dynamic loading (defaults to true for JDK
                    // 1.7+)
      outputCmd.apply(
          "java.rmi.server.hostname: " + System.getProperty("java.rmi.server.hostname") + "\n",
          "java.rmi.server.codebase: " + System.getProperty("java.rmi.server.codebase") + "\n",
          "java.rmi.server.useCodebaseOnly: "
              + System.getProperty("java.rmi.server.useCodebaseOnly")
              + "\n");

    } catch (Exception e) {
      outputCmd.apply("Error getting local host address: " + e + "\n");
    }
  }
Esempio n. 3
0
  public static void main(String[] args) throws NamingException, RemoteException {
    System.setProperty("java.security.policy", "client.policy");
    System.setSecurityManager(new SecurityManager());
    Context namingContext = new InitialContext();

    System.out.print("RMI registry bindings: ");
    NamingEnumeration<NameClassPair> e = namingContext.list("rmi://localhost/");
    while (e.hasMore()) System.out.println(e.next().getName());

    String url = "rmi://localhost/central_warehouse";
    Warehouse centralWarehouse = (Warehouse) namingContext.lookup(url);

    Scanner in = new Scanner(System.in);
    System.out.print("Enter keywords: ");
    List<String> keywords = Arrays.asList(in.nextLine().split("\\s+"));
    Product prod = centralWarehouse.getProduct(keywords);

    System.out.println(prod.getDescription() + ": " + prod.getPrice());
  }
  public static void main(String[] args) {

    //        System.setProperty("java.net.preferIPv4Stack", "true");

    String ip =
        //                "localhost";
        "52.21.170.190";
    //                "50.248.80.131";

    //        System.out.println("Enter IP (default: 52.4.225.209): ");
    //        Scanner reader = new Scanner(System.in);
    //        String input = reader.nextLine();
    if (args.length == 1) {
      ip = args[0];
    }

    System.setProperty("java.rmi.server.hostname", ip);
    makeStub();

    ServerWatcher w = new ServerWatcher(t3);
    Thread t = new Thread(w);
    t.start();
  }