@Test public void testHeadersAreSet() throws Exception { servlet.doGet(mockRequest, mockResponse); verify(mockResponse, times(1)).setContentType("application/json"); verify(mockResponse, times(1)).setHeader(eq("Cache-Control"), anyString()); }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS)); String[] tags = tagsStr.split("[, ;]+"); String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true"); HealthCheckExecutionOptions options = new HealthCheckExecutionOptions(); options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr)); options.setForceInstantExecution(true); List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags); boolean allOk = true; for(HealthCheckExecutionResult result : results) { if(!result.getHealthCheckResult().isOk()) { allOk = false; break; } } if(!allOk) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { response.setStatus(HttpServletResponse.SC_OK); } JSONObject resultJson = new JSONObject(); try { generateResponse(results, resultJson); } catch(JSONException ex) { logger.error("Could not serialize result into JSON", ex); } response.getWriter().write(resultJson.toString()); }
HealthCheckExecutorServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS)); String[] tags = tagsStr.split("[, ;]+"); String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true"); HealthCheckExecutionOptions options = new HealthCheckExecutionOptions(); options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr)); options.setForceInstantExecution(true); List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags); boolean allOk = true; for(HealthCheckExecutionResult result : results) { if(!result.getHealthCheckResult().isOk()) { allOk = false; break; } } if(!allOk) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { response.setStatus(HttpServletResponse.SC_OK); } JSONObject resultJson = new JSONObject(); try { generateResponse(results, resultJson); } catch(JSONException ex) { logger.error("Could not serialize result into JSON", ex); } response.getWriter().write(resultJson.toString()); } }
HealthCheckExecutorServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS)); String[] tags = tagsStr.split("[, ;]+"); String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true"); HealthCheckExecutionOptions options = new HealthCheckExecutionOptions(); options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr)); options.setForceInstantExecution(true); List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags); boolean allOk = true; for(HealthCheckExecutionResult result : results) { if(!result.getHealthCheckResult().isOk()) { allOk = false; break; } } if(!allOk) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { response.setStatus(HttpServletResponse.SC_OK); } JSONObject resultJson = new JSONObject(); try { generateResponse(results, resultJson); } catch(JSONException ex) { logger.error("Could not serialize result into JSON", ex); } response.getWriter().write(resultJson.toString()); }  }
HealthCheckExecutorServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS)); String[] tags = tagsStr.split("[, ;]+"); String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true"); HealthCheckExecutionOptions options = new HealthCheckExecutionOptions(); options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr)); options.setForceInstantExecution(true); List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags); boolean allOk = true; for(HealthCheckExecutionResult result : results) { if(!result.getHealthCheckResult().isOk()) { allOk = false; break; } } if(!allOk) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { response.setStatus(HttpServletResponse.SC_OK); } JSONObject resultJson = new JSONObject(); try { generateResponse(results, resultJson); } catch(JSONException ex) { logger.error("Could not serialize result into JSON", ex); } response.getWriter().write(resultJson.toString()); }   }
HealthCheckExecutorServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS)); String[] tags = tagsStr.split("[, ;]+"); String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true"); HealthCheckExecutionOptions options = new HealthCheckExecutionOptions(); options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr)); options.setForceInstantExecution(true); List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags); boolean allOk = true; for(HealthCheckExecutionResult result : results) { if(!result.getHealthCheckResult().isOk()) { allOk = false; break; } } if(!allOk) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { response.setStatus(HttpServletResponse.SC_OK); } JSONObject resultJson = new JSONObject(); try { generateResponse(results, resultJson); } catch(JSONException ex) { logger.error("Could not serialize result into JSON", ex); } response.getWriter().write(resultJson.toString()); }    }