@Test public void testDoGet() throws Exception { Server server = Help.getServer(LogLevelServlet.class); server.start(); try { String[] levels = {"DEBUG", "INFO", "WARN", "WARNING", "ERROR", "FATAL"}; for (String level : levels) { String url = String.format("http: Help.Res r = Help.sendPut(url, ""); assertEquals(200, r.getCode()); r = Help.doGet(String.format("http: assertEquals(200, r.getCode()); JSONObject jo = new JSONObject(r.getText()); assertEquals(jo.optString("level"), "WARNING".equals(level)?"WARN":level); } } finally { server.stop(); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("getting log level"); synchronized (mutex) { try { String currentLevel = LogManager.getRootLogger().getLevel().toString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(String.format("{\"level\":\"%s\"}",Encode.forHtmlContent(currentLevel))); } catch (IOException e) { logger.error("IOException in log level"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } }
LogLevelServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("getting log level"); synchronized (mutex) { try { String currentLevel = LogManager.getRootLogger().getLevel().toString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(String.format("{\"level\":\"%s\"}",Encode.forHtmlContent(currentLevel))); } catch (IOException e) { logger.error("IOException in log level"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } }
LogLevelServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("getting log level"); synchronized (mutex) { try { String currentLevel = LogManager.getRootLogger().getLevel().toString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(String.format("{\"level\":\"%s\"}",Encode.forHtmlContent(currentLevel))); } catch (IOException e) { logger.error("IOException in log level"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } }  }
LogLevelServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("getting log level"); synchronized (mutex) { try { String currentLevel = LogManager.getRootLogger().getLevel().toString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(String.format("{\"level\":\"%s\"}",Encode.forHtmlContent(currentLevel))); } catch (IOException e) { logger.error("IOException in log level"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } }  @Override String getServletInfo(); }
LogLevelServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("getting log level"); synchronized (mutex) { try { String currentLevel = LogManager.getRootLogger().getLevel().toString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(String.format("{\"level\":\"%s\"}",Encode.forHtmlContent(currentLevel))); } catch (IOException e) { logger.error("IOException in log level"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } }  @Override String getServletInfo();  }