@Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {
      if (!HttpServer.isInstrumentationAccessAllowed(getServletContext(), request, response)) {
        return;
      }
      String jsonpcb = null;
      PrintWriter writer = null;
      JSONBean.Writer beanWriter = null;
      try {
        jsonpcb = checkCallbackName(request.getParameter(CALLBACK_PARAM));
        writer = response.getWriter();

        // "callback" parameter implies JSONP outpout
        if (jsonpcb != null) {
          response.setContentType("application/javascript; charset=utf8");
          writer.write(jsonpcb + "(");
        } else {
          response.setContentType("application/json; charset=utf8");
        }
        beanWriter = this.jsonBeanWriter.open(writer);
        // Should we output description on each attribute and bean?
        boolean description = "true".equals(request.getParameter(INCLUDE_DESCRIPTION));

        // query per mbean attribute
        String getmethod = request.getParameter("get");
        if (getmethod != null) {
          List<String> splitStrings = Splitter.onPattern("\\:\\:").splitToList(getmethod);
          if (splitStrings.size() != 2) {
            beanWriter.write("result", "ERROR");
            beanWriter.write("message", "query format is not as expected.");
            beanWriter.flush();
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return;
          }
          Iterator<String> i = splitStrings.iterator();
          if (
            beanWriter.write(this.mBeanServer, new ObjectName(i.next()), i.next(), description) != 0
          ) {
            beanWriter.flush();
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
          }
          return;
        }

        // query per mbean
        String qry = request.getParameter("qry");
        if (qry == null) {
          qry = "*:*";
        }
        String excl = request.getParameter("excl");
        ObjectName excluded = excl == null ? null : new ObjectName(excl);

        if (
          beanWriter.write(this.mBeanServer, new ObjectName(qry), null, description, excluded) != 0
        ) {
          beanWriter.flush();
          response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        }
      } finally {
        if (beanWriter != null) {
          beanWriter.close();
        }
        if (jsonpcb != null) {
          writer.write(");");
        }
        if (writer != null) {
          writer.close();
        }
      }
    } catch (IOException e) {
      LOG.error("Caught an exception while processing JMX request", e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (MalformedObjectNameException e) {
      LOG.error("Caught an exception while processing JMX request", e);
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
  }
Process a GET request for the specified resource. The servlet request we are processing The
servlet response we are creating
hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java