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:io.fourfinanceit.homework.controller.ClientController.java

@RequestMapping(value = "/client/{id}", method = RequestMethod.DELETE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Client> deleteGreeting(@PathVariable("id") Long id, @RequestBody Client client) {

    if (clientRepository.findOne(id) != null) {

        clientRepository.delete(id);//  www  . ja va  2 s . c  o m
        return new ResponseEntity<Client>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        return new ResponseEntity<Client>(HttpStatus.NO_CONTENT);
    }

}

From source file:com.sapient.product.resource.ProductResource.java

@GET
@Produces(value = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> listProducts() {
    ViewResult result = couchbaseService.findAllBeers(1, 100);
    if (!result.success()) {
        //TODO maybe detect type of error and change error code accordingly
        return new ResponseEntity<String>(result.error().toString(), HttpStatus.INTERNAL_SERVER_ERROR);
    } else {//from ww  w  .  j  a v  a  2  s .c  o m
        JsonArray keys = JsonArray.create();
        Iterator<ViewRow> iter = result.rows();
        while (iter.hasNext()) {
            ViewRow row = iter.next();
            JsonObject beer = JsonObject.create();
            beer.put("name", row.key());
            beer.put("id", row.id());
            keys.add(beer);
        }
        return new ResponseEntity<String>(keys.toString(), HttpStatus.OK);
    }
}

From source file:gateway.test.AlertTriggerTests.java

/**
 * Test POST /trigger// w w w  . j  a  v a 2 s.  c o m
 * 
 * @throws JsonProcessingException
 */
@Test
public void testCreateTrigger() throws JsonProcessingException {
    // Mock Response
    when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn(any(String.class));

    // Test
    ResponseEntity<?> response = alertTriggerController.createTrigger(new Trigger(), user);

    // Verify
    assertTrue(response.getStatusCode().equals(HttpStatus.CREATED));

    // Test Exception
    when(restTemplate.postForObject(anyString(), any(), eq(String.class)))
            .thenThrow(new RestClientException("Trigger Error"));
    response = alertTriggerController.createTrigger(new Trigger(), user);
    assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR));
    assertTrue(response.getBody() instanceof ErrorResponse);
    assertTrue(((ErrorResponse) response.getBody()).message.contains("Trigger Error"));
}

From source file:com.miserablemind.butter.apps.butterApp.controller.ControllerExceptionHandler.java

/**
 * Handles "Internal Server Error" scenario and renders a 500 page.
 *
 * @param request   http request used for getting the URL and wiring config into model
 * @param exception exception that was thrown, in this case {@link com.miserablemind.butter.apps.butterApp.exception.HTTPBadRequestException} or {@link DataAccessException}
 * @return logical name of a view to render
 */// w  w  w . j  a v  a2  s  .c  o m
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 500
@ExceptionHandler({ DataAccessException.class, HTTPInternalServerErrorException.class })
public String handleInternalServerError(HttpServletRequest request, Exception exception) {
    logger.error("[500] Request: " + request.getRequestURL() + " raised " + exception, exception);
    request.setAttribute("configApp", this.config);
    if (Utilities.getAuthUserId() == 0)
        return "guest/errors/500";
    return "errors/500";
}

From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationTests.java

@Test
public void testError() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/error",
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(entity.getBody()).contains("<html>").contains("<body>")
            .contains("Please contact the operator with the above information");
}

From source file:com.sms.server.controller.ImageController.java

@RequestMapping(value = "/{id}/fanart/{scale}", method = RequestMethod.GET, produces = "image/jpeg")
@ResponseBody// ww w. j av  a 2  s.  co  m
public ResponseEntity getFanArt(@PathVariable("id") Long id, @PathVariable("scale") Integer scale) {
    MediaElement mediaElement;
    BufferedImage image;

    // Get corresponding media element
    mediaElement = mediaDao.getMediaElementByID(id);

    if (mediaElement == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Get scaled fan art
    image = imageService.getFanArt(mediaElement, scale);

    // Check if we were able to retrieve fan art
    if (image == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Convert image to bytes to send
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        byte[] imageBytes = baos.toByteArray();

        // Return cover art if found
        return new ResponseEntity(imageBytes, HttpStatus.OK);

    } catch (IOException ex) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.springsource.sinspctr.rest.SInspctrController.java

@ResponseBody
@RequestMapping(value = "/**/*.xml", method = RequestMethod.POST)
public ResponseEntity<String> saveConfig(HttpServletRequest request, @RequestParam("xml") String xml) {
    ResponseEntity<String> response;
    HttpHeaders headers = new HttpHeaders();
    headers.add("content-type", "application/json");
    try {//from  w  w w .j  a  va  2 s.  c om
        //"META-INF/spring/integration/spring-integration-context.xml"
        String servletPath = request.getServletPath();
        if (servletPath.startsWith("/sinspctr/configs")) {
            servletPath = servletPath.substring("/sinspctr/configs".length(), servletPath.length());
        }
        File siConfigFile = ResourceLocator.getClasspathRelativeFile(servletPath);
        FileCopyUtils.copy(siConfigFile, createBackupFile(siConfigFile));
        siConfigFile.delete();
        FileCopyUtils.copy(xml.getBytes(), siConfigFile);
        response = new ResponseEntity<String>("{\"status\":\"success\"}", HttpStatus.OK);
        return response;
    } catch (Exception e) {
        return new ResponseEntity<String>("{\"error\":\"" + e.getMessage() + "\"}", headers,
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:de.steilerdev.myVerein.server.controller.ContentController.java

/**
 * This function gathers the club logo either from the database or the classpath, depending if the user uploaded a custom logo. The function is invoked by GETting the URI /content/clubLogo.
 * @param defaultLogo If this parameter is present the method will return the default logo, without searching through the database.
 * @return The current club logo as byte array.
 *//*from   ww  w. j  ava 2  s . c om*/
@RequestMapping(value = "clubLogo", produces = "image/png", method = RequestMethod.GET)
@ResponseBody
ResponseEntity<byte[]> getClubLogo(@RequestParam(required = false) String defaultLogo) {
    logger.trace("Loading club logo");
    GridFSDBFile clubLogo = null;
    if (defaultLogo == null) {
        //Loading file only from database if the request did not state the fact to use the default logo.
        clubLogo = gridFSRepository.findClubLogo();
    } else {
        logger.info("Directly loading default club logo");
    }

    if (clubLogo == null) {
        if (defaultLogo == null) {
            logger.info("No club logo found, using default logo");
        }

        try {
            return new ResponseEntity<>(
                    IOUtils.toByteArray(new ClassPathResource("content/Logo.png").getInputStream()),
                    HttpStatus.OK);
        } catch (IOException e) {
            logger.warn("Unable to load default logo: " + e.getMessage());
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    } else {
        logger.debug("Loading club logo from database");
        try {
            return new ResponseEntity<>(IOUtils.toByteArray(clubLogo.getInputStream()), HttpStatus.OK);
        } catch (IOException e) {
            logger.warn("Unable to load club logo from database: " + e.getMessage());
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:io.fourfinanceit.homework.controller.LoanControler.java

@RequestMapping(value = "/loan/{id}", method = RequestMethod.DELETE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<LoanApplication> deleteGreeting(@PathVariable("id") Long id,
        @RequestBody LoanApplication loanApplication) {

    if (loanApplicationRepository.findOne(id) != null) {

        loanApplicationRepository.delete(id);
        return new ResponseEntity<LoanApplication>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {//www  .  ja va  2 s  .  c  o  m
        return new ResponseEntity<LoanApplication>(HttpStatus.NO_CONTENT);
    }

}

From source file:org.appverse.web.framework.backend.frontfacade.rest.remotelog.services.presentation.RemoteLogServiceFacadeImpl.java

/**
 * Writes a remote log// w ww  . j  a  v a  2s  . c  o m
 * @param remoteLogRequestVO
 * @return
 */
@RequestMapping(value = "${appverse.frontfacade.rest.remoteLogEndpoint.path:/remotelog/log}", method = RequestMethod.POST)
public ResponseEntity<Void> writeRemoteLog(@RequestBody RemoteLogRequestVO remoteLogRequestVO) {
    RemoteLogResponseVO remoteLogResponseVO = null;
    try {
        remoteLogResponseVO = remoteLogManager.writeLog(remoteLogRequestVO);
        if (!(remoteLogResponseVO.getErrorVO().getCode() == 0)) {
            // Error related to client call
            return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
            //return Response.status(Response.Status.BAD_REQUEST).build();
        }
    } catch (Exception e) {
        // Server error
        // return Response.serverError().build();
        return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    // return Response.ok().build();
    return new ResponseEntity<Void>(HttpStatus.OK);
}