/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.82
 * Generated at: 2018-03-05 18:01:32 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.admin;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.TreeMap;
import java.util.Map;
import javax.management.AttributeList;
import java.util.Map.Entry;
import java.util.Hashtable;
import java.util.Iterator;
import javax.management.ObjectName;
import java.util.Set;
import javax.management.MBeanServerFactory;
import java.util.ArrayList;
import javax.management.MBeanServer;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

public final class mbeans_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private volatile javax.el.ExpressionFactory _el_expressionfactory;
  private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
    if (_el_expressionfactory == null) {
      synchronized (this) {
        if (_el_expressionfactory == null) {
          _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
        }
      }
    }
    return _el_expressionfactory;
  }

  public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
    if (_jsp_instancemanager == null) {
      synchronized (this) {
        if (_jsp_instancemanager == null) {
          _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
        }
      }
    }
    return _jsp_instancemanager;
  }

  public void _jspInit() {
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("application/json;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;



    TreeMap data = new TreeMap<String, String>();
    data.put("timestamp", Long.toString(System.currentTimeMillis()));
    MBeanServer mbserver = null;

    ArrayList mbservers = MBeanServerFactory.findMBeanServer(null);

    if (mbservers.size() > 0) {
        mbserver = (MBeanServer) mbservers.get(0);
    }
    if (mbserver != null) {
    } else {
        mbserver = MBeanServerFactory.createMBeanServer();
    }
    if (mbserver == null) {
        out.write("null ref<br>");
    } else {
        long totalsuccess = 0;
        long totalfailures = 0;
        String[] domains = mbserver.getDomains();
        for (int i = 0; i < domains.length; i++) {
            //              out.write(domains[i] + "<br>");
        }
        ObjectName juddi = new ObjectName("apache.juddi:counter=*");
        juddi.setMBeanServer(mbserver);
        Set<ObjectName> beans = mbserver.queryNames(juddi, null);
        Iterator<ObjectName> it = beans.iterator();
        while (it.hasNext()) {
            ObjectName n = it.next();
            //   out.write(n.getCanonicalName() + " ");
            //                out.write(n.getKeyPropertyListString() + "<Br>");
            Hashtable<String, String> props = n.getKeyPropertyList();
            Iterator<Entry<String, String>> it2 = props.entrySet().iterator();
            while (it2.hasNext()) {
                Entry<String, String> e = it2.next();
//                        out.write("key = " + e.getKey() + "<br>");
                //                      out.write("value = " + e.getValue() + "<br>");
            }
            AttributeList j = (AttributeList) mbserver.getAttributes(n, new String[]{"counter"});
            for (int k = 0; k < j.size(); k++) {
                String attr = j.get(k).toString();
                String[] kv = attr.split("=");
                //out.write("attr = " + kv[0] + " value = " + kv[1] + "<br>");
                data.put(kv[0], kv[1]);
                if (kv[0].toLowerCase().contains("success")) {
                   totalsuccess+= Long.parseLong(kv[1].trim());
                }
                  if (kv[0].toLowerCase().contains("fail")) {
                   totalfailures+= Long.parseLong(kv[1].trim());
                }
            }

            // out.write(j.getClass().getCanonicalName() + "<br>");
        }
        data.put("totalsuccess", totalsuccess);
        data.put("totalfailures", totalfailures);
    }
    //  out.write("<br>");
    //  out.write("<br>");
    //    out.write("<br>");
    //  List<MemoryPoolMXBean> memPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    // for (MemoryPoolMXBean mpb : memPoolBeans) {
    //    out.write("Memory Pool: " + mpb.getName() + "<br>");
    //}

    out.write(new org.json.JSONObject(data).toString());

    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            if (response.isCommitted()) {
              out.flush();
            } else {
              out.clearBuffer();
            }
          } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
