Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.metrics.reporting;
  
 
 public class AdminServlet extends HttpServlet {
     private static final long serialVersionUID = 1363903248255082791L;
 
     private static final String TEMPLATE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" +
                                            "        \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
                                            "<html>\n" +
                                            "<head>\n" +
                                            "  <title>Metrics</title>\n" +
                                            "</head>\n" +
                                            "<body>\n" +
                                            "  <h1>Operational Menu</h1>\n" +
                                            "  <ul>\n" +
                                            "    <li><a href=\"{0}{1}?pretty=true\">Metrics</a></li>\n" +
                                            "    <li><a href=\"{2}{3}\">Ping</a></li>\n" +
                                            "    <li><a href=\"{4}{5}\">Threads</a></li>\n" +
                                            "    <li><a href=\"{6}{7}\">Healthcheck</a></li>\n" +
                                            "  </ul>\n" +
                                            "</body>\n" +
                                            "</html>";
 
     public static final String DEFAULT_HEALTHCHECK_URI = "/healthcheck";
     public static final String DEFAULT_METRICS_URI = "/metrics";
     public static final String DEFAULT_PING_URI = "/ping";
     public static final String DEFAULT_THREADS_URI = "/threads";
     private static final String CONTENT_TYPE = "text/html";
 
     private final HealthCheckServlet healthCheckServlet;
     private final MetricsServlet metricsServlet;
     private final PingServlet pingServlet;
     private final ThreadDumpServlet threadDumpServlet;
 
 
     public AdminServlet() {
         this(new HealthCheckServlet(), new MetricsServlet(), new PingServlet(),
              new ThreadDumpServlet(), ,
              );
     }
 
     public AdminServlet(HealthCheckServlet healthCheckServlet,
                         MetricsServlet metricsServlet,
                         PingServlet pingServlet,
                         ThreadDumpServlet threadDumpServlet,
                         String healthcheckUri,
                         String metricsUri,
                         String pingUri,
                         String threadsUri) {
         this. = healthCheckServlet;
         this. = metricsServlet;
         this. = pingServlet;
         this. = threadDumpServlet;
 
         this. = metricsUri;
         this. = pingUri;
         this. = threadsUri;
         this. = healthcheckUri;
     }
 
     @Override
     public void init(ServletConfig configthrows ServletException {
         super.init(config);
         .init(config);
         .init(config);
         .init(config);
         .init(config);
 
         final ServletContext context = config.getServletContext();
         this. = context.getContextPath();
         this. = getParam(config.getInitParameter("metrics-uri"), this.);
         this. = getParam(config.getInitParameter("ping-uri"), this.);
         this. = getParam(config.getInitParameter("threads-uri"), this.);
         this. = getParam(config.getInitParameter("healthcheck-uri"), this.);
     }
 
     @Override
     protected void doGet(HttpServletRequest reqHttpServletResponse respthrows ServletExceptionIOException {
         resp.setHeader("Cache-Control""must-revalidate,no-cache,no-store");
         final String uri = req.getPathInfo();
         final String path = this. + req.getServletPath();
         if (uri == null || uri.equals("/")) {
             resp.setStatus(.);
             resp.setContentType();
             final PrintWriter writer = resp.getWriter();
             try {
                 writer.println(MessageFormat.format(pathpathpath,
                                                     path));
             } finally {
                writer.close();
            }
        } else if (uri.equals()) {
            .service(reqresp);
        } else if (uri.startsWith()) {
            .service(reqresp);
        } else if (uri.equals()) {
            .service(reqresp);
        } else if (uri.equals()) {
            .service(reqresp);
        } else {
            resp.sendError(.);
        }
    }
    private static String getParam(String initParamString defaultValue) {
        return initParam == null ? defaultValue : initParam;
    }
New to GrepCode? Check out our FAQ X