Exemple #1
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());
  }
Exemple #2
0
  void exploreNext(int depth, DirContext ctx, String path) throws NamingException {
    NamingEnumeration<NameClassPair> names = ctx.list(path);

    while (names.hasMore()) {
      Object obj = names.next();
      NameClassPair ncp = (NameClassPair) obj;
      if (ncp.getClassName().equals("weblogic.jndi.internal.ServerNamingNode")) {
        System.out.println(createBlanks(depth) + ncp.getName());
        exploreNext(depth + 1, ctx, path + "/" + ncp.getName());
      } else {
        System.out.print(createBlanks(depth) + "[" + ncp.getName());
        System.out.print("] - ");
        try {
          // System.out.println(ctx.lookup(path+"/"+ncp.getName()));
          System.out.println(ncp.getClassName());
        } catch (Exception ex) {
          System.out.println("");
        }
      }
    }
  }
Exemple #3
0
 /**
  * Print Attributes to System.out
  *
  * @param attrs
  */
 private static void dump(Attributes attrs) {
   if (attrs == null) {
     System.out.println("No attributes");
   } else {
     /* Print each attribute */
     try {
       for (NamingEnumeration<? extends Attribute> ae = attrs.getAll(); ae.hasMore(); ) {
         Attribute attr = ae.next();
         System.out.println("attribute: " + attr.getID());
         /* print each value */
         for (NamingEnumeration<?> e = attr.getAll();
             e.hasMore();
             System.out.println("    value: " + e.next())) ;
       }
     } catch (NamingException e) {
       e.printStackTrace();
     }
   }
 } //	dump