List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR
HttpStatus INTERNAL_SERVER_ERROR
To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.
Click Source Link
From source file:business.controllers.StatusController.java
@RequestMapping(value = "/status", method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> getStatus() { log.info("GET /status"); boolean ok = true; Map<String, Object> status = new HashMap<String, Object>(); try {//from ww w . java 2 s .c o m status.put("requests", requestPropertiesRepository.count()); } catch (Exception e) { status.put("requests", e.getMessage()); ok = false; } try { status.put("labrequests", labRequestRepository.count()); } catch (Exception e) { status.put("labrequests", e.getMessage()); ok = false; } try { status.put("pathologyitems", pathologyItemRepository.count()); } catch (Exception e) { status.put("pathologyitems", e.getMessage()); ok = false; } try { status.put("active_processes", runtimeService.createProcessInstanceQuery().active().count()); } catch (Exception e) { status.put("active_processes", e.getMessage()); ok = false; } try { status.put("active_tasks", taskService.createTaskQuery().active().count()); } catch (Exception e) { status.put("active_tasks", e.getMessage()); ok = false; } boolean fileServiceStatus = fileService.checkUploadPath(); ok = ok && fileServiceStatus; status.put("fileservice", fileServiceStatus); boolean mailServiceStatus = mailService.checkMailSender(); ok = ok && mailServiceStatus; status.put("mailservice", mailServiceStatus); HttpStatus code = (ok) ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR; return new ResponseEntity<Map<String, Object>>(status, code); }
From source file:reconf.server.services.property.ClientReadPropertyService.java
@RequestMapping(value = "/{prod}/{comp}/{prop}", method = RequestMethod.GET) @Transactional(readOnly = true)/*from w w w . ja v a2s.co m*/ public ResponseEntity<String> doIt(@PathVariable("prod") String product, @PathVariable("comp") String component, @PathVariable("prop") String property, @RequestParam(value = "instance", required = false, defaultValue = "unknown") String instance) { PropertyKey key = new PropertyKey(product, component, property); List<String> errors = DomainValidator.checkForErrors(key); Property reqProperty = new Property(key); HttpHeaders headers = new HttpHeaders(); if (!errors.isEmpty()) { addErrorHeader(headers, errors, reqProperty); return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST); } List<Property> dbProperties = properties .findByKeyProductAndKeyComponentAndKeyNameOrderByRulePriorityDescKeyRuleNameAsc(key.getProduct(), key.getComponent(), key.getName()); for (Property dbProperty : dbProperties) { try { if (isMatch(instance, dbProperty)) { addRuleHeader(headers, dbProperty); return new ResponseEntity<String>(dbProperty.getValue(), headers, HttpStatus.OK); } } catch (Exception e) { log.error("error applying rule", e); addRuleHeader(headers, dbProperty); addErrorHeader(headers, Collections.singletonList("rule error"), reqProperty); return new ResponseEntity<String>(headers, HttpStatus.INTERNAL_SERVER_ERROR); } } return new ResponseEntity<String>(HttpStatus.NOT_FOUND); }
From source file:cn.powerdash.libsystem.common.exception.ExceptionResolver.java
@Override public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { if (WebUtil.isAjaxRequest(request)) { try {//from w w w. j a v a 2 s .co m String formId = request.getHeader(ApplicationConstant.X_FORM_ID); Locale locale = request.getLocale(); ObjectMapper objectMapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); ResultDto<?> error = getErrorDto(ex, handler, formId, locale); if (error.isNonBizError()) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } else { response.setStatus(HttpStatus.OK.value()); } PrintWriter writer = response.getWriter(); objectMapper.writeValue(response.getWriter(), error); writer.flush(); } catch (IOException ie) { LOGGER.error("Failed to serialize the object to json for exception handling.", ie); } return new ModelAndView(); } else { response.setContentType("text/html;charset=UTF-8"); ModelAndView mav = new ModelAndView(); mav.addObject("errorMessage", ExceptionUtils.getStackTrace(ex)); if (ex instanceof AuthorizationException) { LOGGER.warn("AuthorizationException handled (non-ajax style):", ex); mav.setViewName("error/access_denied"); } else { LOGGER.error("Unknown exception handled (non-ajax style):", ex); mav.setViewName("error/404"); } return mav; } }
From source file:dk.nsi.haiba.epimibaimporter.status.StatusReporter.java
@RequestMapping(value = "/status") public ResponseEntity<String> reportStatus() { String manual = request.getParameter("manual"); if (manual == null || manual.trim().length() == 0) { // no value set, use default set in the import executor manual = "" + importExecutor.isManualOverride(); } else {/*from w w w .j a v a 2 s . c o m*/ // manual flag is set on the request if (manual.equalsIgnoreCase("true")) { importExecutor.setManualOverride(true); importExecutor.doProcess(true); } else { importExecutor.setManualOverride(false); } } HttpHeaders headers = new HttpHeaders(); String body = "OK"; HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; body = "OK"; try { if (!statusRepo.isHAIBADBAlive()) { body = "HAIBA Database is _NOT_ running correctly"; } else if (statusRepo.isOverdue()) { // last run information is applied to body later body = "Is overdue"; } else { status = HttpStatus.OK; } } catch (Exception e) { body = e.getMessage(); } body += "</br>"; body = addLastRunInformation(body); body += "</br>------------------</br>"; String importProgress = currentImportProgress.getStatus(); body += importProgress; body += "</br>------------------</br>"; String url = request.getRequestURL().toString(); body += "<a href=\"" + url + "?manual=true\">Manual start importer</a>"; body += "</br>"; body += "<a href=\"" + url + "?manual=false\">Scheduled start importer</a>"; body += "</br>"; if (manual.equalsIgnoreCase("true")) { body += "status: MANUAL"; } else { // default body += "status: SCHEDULED - " + cron; } headers.setContentType(MediaType.TEXT_HTML); return new ResponseEntity<String>(body, headers, status); }
From source file:org.osiam.addons.selfadministration.exception.OsiamExceptionHandler.java
@ExceptionHandler(RuntimeException.class) protected ModelAndView handleException(RuntimeException ex, HttpServletResponse response) { LOGGER.log(Level.WARNING, AN_EXCEPTION_OCCURED, ex); response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); modelAndView.addObject(KEY, "registration.exception.message"); setLoggingInformation(ex);//from w ww . java2 s . c o m return modelAndView; }
From source file:org.fede.calculator.web.controller.ChartController.java
@ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public CanvasJSChartDTO errorHandler(Exception ex) { LOG.log(Level.SEVERE, "errorHandler", ex); CanvasJSChartDTO dto = new CanvasJSChartDTO(); dto.setSuccessful(false);/*from w w w. j a va2s .com*/ return dto; }
From source file:com.orange.ngsi.client.NotifyContextRequestTest.java
@Test(expected = HttpServerErrorException.class) public void notifyContextRequestWith500() throws Exception { mockServer.expect(requestTo(baseUrl + "/ngsi10/notifyContext")).andExpect(method(HttpMethod.POST)) .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); ngsiClient.notifyContext(baseUrl, null, createNotifyContextTempSensor(0)).get(); }
From source file:com.orange.ngsi.client.QueryContextRequestTest.java
@Test(expected = HttpServerErrorException.class) public void queryContextRequestWith500() throws Exception { mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST)) .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature()).get(); }
From source file:com.ge.predix.acs.zone.management.ZoneController.java
@RequestMapping(method = PUT, value = V1 + AcsApiUriTemplates.ZONE_URL, consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Creates/Updates the zone.", hidden = true) public ResponseEntity<Zone> putZone(@RequestBody final Zone zone, @PathVariable("zoneName") final String zoneName) { validateAndSanitizeInputOrFail(zone, zoneName); try {/* w w w . jav a 2 s . c o m*/ boolean zoneCreated = this.service.upsertZone(zone); if (zoneCreated) { return created(false, V1 + AcsApiUriTemplates.ZONE_URL, "zoneName:" + zoneName); } return created(); } catch (ZoneManagementException e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e); } catch (Exception e) { String message = String.format( "Unexpected Exception " + "while upserting Zone with name %s and subdomain %s", zone.getName(), zone.getSubdomain()); throw new RestApiException(HttpStatus.INTERNAL_SERVER_ERROR, message, e); } }
From source file:com.mysample.springbootsample.config.WebConfig.java
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override/*from w w w .j a v a 2 s . c o m*/ public void customize(ConfigurableEmbeddedServletContainer container) { ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.html"); ErrorPage error505Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/505.html"); container.addErrorPages(error404Page, error505Page); } }; }