public boolean hasChildren(Object node) {
   NameClassPair ncp = (NameClassPair) node;
   String nm = ncp.getName();
   if (nm.equals("")) // root node
   return true;
   return ncp.getClassName().equals(CLASS_WITH_CHILDREN);
 }
예제 #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("");
        }
      }
    }
  }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String infoString = "";
    String listString = "";
    logger.info("zzzzzzzzzzzzzzzzzzzzzzzzzzz beginning run");

    try {
      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      Object oo = envCtx.lookup("jms/ConnectionFactory");
      if (oo != null) {
        infoString += "<h4>Sample lookup: " + oo.getClass().getName() + "</h4>";
      }
      NamingEnumeration<NameClassPair> nameInfo = envCtx.list("jms");
      while (nameInfo.hasMore()) {
        NameClassPair n = nameInfo.next();
        listString += "<li>" + n.getClassName() + " -- " + n.getName() + "</li>";
      }
      Queue tomcatQueue = (Queue) envCtx.lookup("jms/TomcatQueue");
      infoString += "<h4>Tomcat queue: " + tomcatQueue.getQueueName() + "</h4>";
      ActiveMQQueue aQueue = (ActiveMQQueue) tomcatQueue;
      infoString += "<h4>Apache queue: " + aQueue.getDestinationTypeAsString() + "</h4>";

    } catch (Exception ex) {
      String exI = "Error: " + ex.getClass().getName() + "-- " + ex.getMessage();
      logger.error(exI);
      infoString += "Error: <b>" + exI + "</b>";
    }

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet JmsTestServlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>List of items at java:comp/env/jms</h1>");
    out.println("<p>" + infoString + "</p>");
    out.println("<ol>" + listString + "</ol>");
    out.println("</body>");
    out.println("</html>");
  }
예제 #4
0
  /**
   * Recursively display the naming context information into the buffer.
   *
   * @param ctx
   * @param indent
   * @param buffer
   * @param verbose
   */
  public static void list(Context ctx, String indent, StringBuffer buffer, boolean verbose) {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    try {
      NamingEnumeration ne = ctx.list("");
      while (ne.hasMore()) {
        NameClassPair pair = (NameClassPair) ne.next();

        String name = pair.getName();
        String className = pair.getClassName();
        boolean recursive = false;
        boolean isLinkRef = false;
        boolean isProxy = false;
        Class c = null;
        try {
          c = loader.loadClass(className);

          if (Context.class.isAssignableFrom(c)) recursive = true;
          if (LinkRef.class.isAssignableFrom(c)) isLinkRef = true;

          isProxy = Proxy.isProxyClass(c);
        } catch (ClassNotFoundException cnfe) {
          // If this is a $Proxy* class its a proxy
          if (className.startsWith("$Proxy")) {
            isProxy = true;
            // We have to get the class from the binding
            try {
              Object p = ctx.lookup(name);
              c = p.getClass();
            } catch (NamingException e) {
              Throwable t = e.getRootCause();
              if (t instanceof ClassNotFoundException) {
                // Get the class name from the exception msg
                String msg = t.getMessage();
                if (msg != null) {
                  // Reset the class name to the CNFE class
                  className = msg;
                }
              }
            }
          }
        }

        buffer.append(indent + " +- " + name);

        // Display reference targets
        if (isLinkRef) {
          // Get the
          try {
            Object obj = ctx.lookupLink(name);

            LinkRef link = (LinkRef) obj;
            buffer.append("[link -> ");
            buffer.append(link.getLinkName());
            buffer.append(']');
          } catch (Throwable t) {
            buffer.append("invalid]");
          }
        }

        // Display proxy interfaces
        if (isProxy) {
          buffer.append(" (proxy: " + pair.getClassName());
          if (c != null) {
            Class[] ifaces = c.getInterfaces();
            buffer.append(" implements ");
            for (int i = 0; i < ifaces.length; i++) {
              buffer.append(ifaces[i]);
              buffer.append(',');
            }
            buffer.setCharAt(buffer.length() - 1, ')');
          } else {
            buffer.append(" implements " + className + ")");
          }
        } else if (verbose) {
          buffer.append(" (class: " + pair.getClassName() + ")");
        }

        buffer.append('\n');
        if (recursive) {
          try {
            Object value = ctx.lookup(name);
            if (value instanceof Context) {
              Context subctx = (Context) value;
              list(subctx, indent + " |  ", buffer, verbose);
            } else {
              buffer.append(indent + " |   NonContext: " + value);
              buffer.append('\n');
            }
          } catch (Throwable t) {
            buffer.append("Failed to lookup: " + name + ", errmsg=" + t.getMessage());
            buffer.append('\n');
          }
        }
      }
      ne.close();
    } catch (NamingException ne) {
      buffer.append("error while listing context " + ctx.toString() + ": " + ne.toString(true));
      formatException(buffer, ne);
    }
  }