@Test public void whenNoParamsSpecifiedReturnsOnlyAlerts() throws JsonProcessingException, UnsupportedEncodingException, ActionException { ByteArrayOutputStream responseBody = new ByteArrayOutputStream(); ActionParameters params = new ActionParameters(); params.setRequest(mockHttpServletRequest()); params.setResponse(mockHttpServletResponse(responseBody)); handler.handleAction(params); String actual = responseBody.toString("UTF-8"); String expected = "{'backendstatus':[" + "{'maplayer_id':4,'status':'DOWN','statusjson':null,'infourl':'http: + "]}"; expected = expected.replace('\'', '"'); assertEquals(expected, actual); }
public void handleAction(ActionParameters params) throws ActionException { boolean alert = isRequestOnlyForLayersWithAlerts(params); List<BackendStatus> statuses; if (alert) { statuses = service.findAllWithAlert(); } else { statuses = modifyErrorsWithUnknownMessageToUnknown(service.findAll()); } statuses = modifyErrorsWithUnknownMessageToUnknown(statuses); LOG.debug("BackendStatus list size: " + statuses.size()); try { byte[] b = serialize(om, statuses); ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, b); } catch (JsonProcessingException e) { LOG.warn(e, "Failed to write JSON!"); throw new ActionException("Failed to serialize response to JSON!", e); } }
GetBackendStatusHandler extends ActionHandler { public void handleAction(ActionParameters params) throws ActionException { boolean alert = isRequestOnlyForLayersWithAlerts(params); List<BackendStatus> statuses; if (alert) { statuses = service.findAllWithAlert(); } else { statuses = modifyErrorsWithUnknownMessageToUnknown(service.findAll()); } statuses = modifyErrorsWithUnknownMessageToUnknown(statuses); LOG.debug("BackendStatus list size: " + statuses.size()); try { byte[] b = serialize(om, statuses); ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, b); } catch (JsonProcessingException e) { LOG.warn(e, "Failed to write JSON!"); throw new ActionException("Failed to serialize response to JSON!", e); } } }
GetBackendStatusHandler extends ActionHandler { public void handleAction(ActionParameters params) throws ActionException { boolean alert = isRequestOnlyForLayersWithAlerts(params); List<BackendStatus> statuses; if (alert) { statuses = service.findAllWithAlert(); } else { statuses = modifyErrorsWithUnknownMessageToUnknown(service.findAll()); } statuses = modifyErrorsWithUnknownMessageToUnknown(statuses); LOG.debug("BackendStatus list size: " + statuses.size()); try { byte[] b = serialize(om, statuses); ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, b); } catch (JsonProcessingException e) { LOG.warn(e, "Failed to write JSON!"); throw new ActionException("Failed to serialize response to JSON!", e); } } GetBackendStatusHandler();  GetBackendStatusHandler(BackendStatusService service, ObjectMapper om); }
GetBackendStatusHandler extends ActionHandler { public void handleAction(ActionParameters params) throws ActionException { boolean alert = isRequestOnlyForLayersWithAlerts(params); List<BackendStatus> statuses; if (alert) { statuses = service.findAllWithAlert(); } else { statuses = modifyErrorsWithUnknownMessageToUnknown(service.findAll()); } statuses = modifyErrorsWithUnknownMessageToUnknown(statuses); LOG.debug("BackendStatus list size: " + statuses.size()); try { byte[] b = serialize(om, statuses); ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, b); } catch (JsonProcessingException e) { LOG.warn(e, "Failed to write JSON!"); throw new ActionException("Failed to serialize response to JSON!", e); } } GetBackendStatusHandler();  GetBackendStatusHandler(BackendStatusService service, ObjectMapper om); void handleAction(ActionParameters params); }
GetBackendStatusHandler extends ActionHandler { public void handleAction(ActionParameters params) throws ActionException { boolean alert = isRequestOnlyForLayersWithAlerts(params); List<BackendStatus> statuses; if (alert) { statuses = service.findAllWithAlert(); } else { statuses = modifyErrorsWithUnknownMessageToUnknown(service.findAll()); } statuses = modifyErrorsWithUnknownMessageToUnknown(statuses); LOG.debug("BackendStatus list size: " + statuses.size()); try { byte[] b = serialize(om, statuses); ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, b); } catch (JsonProcessingException e) { LOG.warn(e, "Failed to write JSON!"); throw new ActionException("Failed to serialize response to JSON!", e); } } GetBackendStatusHandler();  GetBackendStatusHandler(BackendStatusService service, ObjectMapper om); void handleAction(ActionParameters params);  }