Example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Prototype

HttpStatus INTERNAL_SERVER_ERROR

To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Click Source Link

Document

500 Internal Server Error .

Usage

From source file:com.esri.geoportal.harvester.rest.ProcessController.java

/**
 * List all processes.//  w w w .  j a  va 2  s. c o  m
 * @return all processes
 */
@RequestMapping(value = "/rest/harvester/processes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ProcessResponse[]> listAllProcesses() {
    try {
        LOG.debug(String.format("GET /rest/harvester/processes"));
        return new ResponseEntity<>(filterProcesses(e -> true), HttpStatus.OK);
    } catch (DataProcessorException ex) {
        LOG.error(String.format("Error listing all processes"), ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:au.id.hazelwood.sos.web.controller.framework.GlobalExceptionHandlerUnitTest.java

@Test
public void testHandleAllUnknown() throws Exception {
    WebRequest webRequest = mock(WebRequest.class);
    RuntimeException ex = new RuntimeException("Runtime exception");

    ResponseEntity<Object> responseEntity = handler.handleAllUnknown(ex, webRequest);

    assertResponseEntity(responseEntity, HttpStatus.INTERNAL_SERVER_ERROR, "Runtime exception");
    verify(webRequest).setAttribute("javax.servlet.error.exception", ex, WebRequest.SCOPE_REQUEST);
    verifyNoMoreInteractions(webRequest);
}

From source file:org.bonitasoft.web.designer.controller.preview.PreviewerTest.java

@Test
public void should_return_error_response_when_error_occur_on_generation() throws Exception {
    when(pageRepository.get(page.getId())).thenReturn(page);
    when(generator.generateHtml("/runtime/", page))
            .thenThrow(new GenerationException("error", new Exception()));

    ResponseEntity<String> response = previewer.render(page.getId(), pageRepository, request);

    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(response.getBody()).isEqualTo("Error during page generation");
}

From source file:org.agatom.springatom.web.controller.SVDefaultController.java

@ResponseBody
@ExceptionHandler({ ControllerTierException.class, Exception.class })
public ResponseEntity<?> handleException(final Exception exp) {
    return this.errorResponse(exp, HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:org.easy.spring.web.ValidationSupport.java

/**
 * Has to be in one class as Spring seems to take a magic order in this handlers
 * as this is the last "method" the other handlers are takes before this fallback
 *//*  w  ww . jav a 2  s.  c  o m*/
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ErrorMessage onError(Exception e) {
    LOG.error(e.getMessage(), e);
    return new ErrorMessage(e.getMessage(), ExceptionUtils.getStackTrace(e));
}

From source file:org.mitre.openid.connect.view.JsonErrorView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {//from ww w .j  ava 2 s . com

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.INTERNAL_SERVER_ERROR; // default to 500
    }

    response.setStatus(code.value());

    try {

        Writer out = response.getWriter();

        String errorTitle = (String) model.get(ERROR);
        if (Strings.isNullOrEmpty(errorTitle)) {
            errorTitle = "mitreid_error";
        }
        String errorMessage = (String) model.get(ERROR_MESSAGE);
        JsonObject obj = new JsonObject();
        obj.addProperty("error", errorTitle);
        obj.addProperty("error_description", errorMessage);
        gson.toJson(obj, out);

    } catch (IOException e) {

        logger.error("IOException in JsonErrorView.java: ", e);

    }
}

From source file:fr.gmjgav.controller.BarController.java

@RequestMapping(value = "/beerType/{location:.+}/{type}", method = GET)
public ResponseEntity<?> getByBeerType(@PathVariable String location, @PathVariable String type) {
    List<Beer> beers = beerRepository.findByType(type);
    if (beers.isEmpty()) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }/*from   w  w  w.java 2s.  com*/

    List<Bar> barsForBeers = new ArrayList<>();
    for (Beer beer : beers) {
        List<Bar> tmpBarLst = beer.getBars();
        for (Bar tmpBar : tmpBarLst) {
            if (!barsForBeers.contains(tmpBar)) {
                barsForBeers.add(tmpBar);
            }
        }
    }
    ListAndStatus returnedBars = GooglePlacesManager.intersectBarsAndPlaces(barsForBeers, barRepository,
            new Coordinates(location));
    return new ResponseEntity<>(returnedBars.getList(), returnedBars.getResponseCode());
}

From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpoints.java

@RequestMapping(value = { "/Codes" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)/*from   w  ww.  j av  a  2 s  .c o  m*/
@ResponseBody
public ExpiringCode generateCode(@RequestBody ExpiringCode expiringCode) {
    try {
        return expiringCodeStore.generateCode(expiringCode.getData(), expiringCode.getExpiresAt());
    } catch (NullPointerException e) {
        throw new CodeStoreException("data and expiresAt are required.", HttpStatus.BAD_REQUEST);
    } catch (IllegalArgumentException e) {
        throw new CodeStoreException("expiresAt must be in the future.", HttpStatus.BAD_REQUEST);
    } catch (DataIntegrityViolationException e) {
        throw new CodeStoreException("Duplicate code generated.", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.javafxpert.wikibrowser.WikiIdLocatorController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> locatorEndpoint(
        @RequestParam(value = "name", defaultValue = "") String articleName,
        @RequestParam(value = "lang") String lang) {

    String language = wikiBrowserProperties.computeLang(lang);

    ItemInfo itemInfo = null;/*ww w. j a va  2  s  .  c o m*/
    if (!articleName.equals("")) {
        itemInfo = name2Id(articleName, language);
    }

    return Optional.ofNullable(itemInfo).map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Wikipedia query unsuccessful", HttpStatus.INTERNAL_SERVER_ERROR));
}

From source file:com.ge.predix.acs.commons.web.RestApiExceptionTest.java

@Test
public void testRestApiExceptionWithMessageException() {
    RuntimeException runtimeException = new RuntimeException();
    RestApiException apiException = new RestApiException("message", runtimeException);

    Assert.assertEquals(apiException.getCause(), runtimeException);
    Assert.assertEquals(apiException.getMessage(), "message");
    Assert.assertEquals(apiException.getAppErrorCode(), "FAILURE");
    Assert.assertEquals(apiException.getHttpStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR);
}