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:org.osiam.resources.exception.OsiamExceptionHandler.java

@ExceptionHandler(OsiamBackendFailureException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody//from w  ww. j a v  a 2s. com
public ErrorResponse handleBackendFailure(OsiamBackendFailureException e) {
    return produceErrorResponse("An internal error occurred", HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:net.maritimecloud.identityregistry.controllers.CertificateController.java

/**
 * Returns info about the device identified by the given ID
 * //from  w  w w .  j  ava  2 s  .  com
 * @return a reply...
 */
@RequestMapping(value = "/api/certificates/crl", method = RequestMethod.GET, produces = "application/x-pem-file;charset=UTF-8")
@ResponseBody
public ResponseEntity<?> getCRL() {
    List<Certificate> revokedCerts = this.certificateService.listRevokedCertificate();
    X509CRL crl = certUtil.generateCRL(revokedCerts);
    try {
        String pemCrl = CertificateUtil.getPemFromEncoded("X509 CRL", crl.getEncoded());
        return new ResponseEntity<>(pemCrl, HttpStatus.OK);
    } catch (CRLException e) {
        log.error("Unable to get Pem from bytes", e);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }

}

From source file:fi.helsinki.opintoni.config.WebConfigurer.java

@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return (container -> {
        ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, "/errors/403.html");
        ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/errors/404.html");
        ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/errors/500.html");

        container.addErrorPages(error403Page, error404Page, error500Page);
    });/*from   w ww .  ja v  a 2 s.c o  m*/
}

From source file:com.alexshabanov.springrestapi.support.ProfileController.java

@ExceptionHandler(UnsupportedOperationException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody/*from  w w w  .ja  v  a2  s . c o m*/
public ErrorDesc handleUnsupportedOperationException() {
    throw new AssertionError();
}

From source file:alfio.controller.api.admin.AdditionalServiceApiController.java

@ExceptionHandler({ Exception.class })
public ResponseEntity<String> handleError(Exception e) {
    log.error("error", e);
    return new ResponseEntity<>("internal server error", HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:org.aksw.gerbil.web.FileUploadController.java

@RequestMapping(value = "upload", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<UploadFileContainer> upload(MultipartHttpServletRequest request,
        HttpServletResponse response) {//  ww w  . j a va2 s.c o  m

    if (path == null) {
        logger.error("Path must be not null");
        return new ResponseEntity<UploadFileContainer>(HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LinkedList<FileMeta> files = new LinkedList<FileMeta>();
    MultipartFile mpf = null;

    for (Iterator<String> it = request.getFileNames(); it.hasNext();) {
        mpf = request.getFile(it.next());
        logger.debug("{} uploaded", mpf.getOriginalFilename());

        FileMeta fileContainer = new FileMeta();
        fileContainer.setName(mpf.getOriginalFilename());
        fileContainer.setSize(mpf.getSize() / 1024 + "Kb");
        fileContainer.setFileType(mpf.getContentType());

        try {
            fileContainer.setBytes(mpf.getBytes());
            createFolderIfNotExists();
            FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream(path + mpf.getOriginalFilename()));

        } catch (IOException e) {
            logger.error("Error during file upload", e);
            fileContainer.setError(e.getMessage());
        }
        files.add(fileContainer);
    }

    UploadFileContainer uploadFileContainer = new UploadFileContainer(files);
    return new ResponseEntity<UploadFileContainer>(uploadFileContainer, HttpStatus.OK);
}

From source file:com.ns.retailmgr.controller.ShopController.java

@ApiOperation(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "POST", value = "", response = String.class, notes = "Save the shop details")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> saveShop(@RequestBody ShopDetails shopDetails) {
    LOGGER.info("Started endpoint method {}, params - {}", "saveShop");
    try {/* w  w  w  .  j av a2s  .  c  o  m*/
        ShopDetails newShopDetails = shopService.addShop(shopDetails);
        if (newShopDetails == null) {
            return new ResponseEntity<Object>(
                    "Unable to find latitude and logitude for shop details provided, please check and resubmit again",
                    HttpStatus.BAD_REQUEST);
        }
        if (newShopDetails.getStatus() != null)
            return new ResponseEntity<Object>(HttpStatus.CREATED);
        else
            return new ResponseEntity<Object>(newShopDetails, HttpStatus.OK);
    } catch (Exception e) {
        LOGGER.error("Exception {}", e);
        return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }

}

From source file:org.ow2.proactive.procci.rest.MixinRest.java

@RequestMapping(value = "{mixinTitle}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<MixinRendering> getMixin(@PathVariable("mixinTitle") String mixinTitle) {
    logger.debug("Getting Mixin " + mixinTitle);

    try {//from  w  w  w  .  java2 s  .c  om
        return new ResponseEntity(mixinService.getMixinByTitle(mixinTitle).getRendering(), HttpStatus.OK);
    } catch (ClientException ex) {
        return new ResponseEntity(ex.getJsonError(), HttpStatus.BAD_REQUEST);
    } catch (ServerException exception) {
        return new ResponseEntity(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:it.polimi.diceH2020.launcher.controller.rest.RestFilesController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity<BaseResponseBody> multipleSave(@RequestParam("file[]") List<MultipartFile> files,
        @RequestParam("scenario") String scenarioStringRepresentation) {
    BaseResponseBody body = new BaseResponseBody();
    PendingSubmission submission = new PendingSubmission();

    Scenario scenario = Scenario.generateScenario(scenarioStringRepresentation);
    body.setScenario(scenario);//from   w  ww. j  av  a  2s.  c  om
    submission.setScenario(scenario);

    body.setAcceptedFiles(new LinkedList<>());
    ResponseEntity<BaseResponseBody> response = new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);

    boolean good_status = true;
    List<String> additionalFileNames = new LinkedList<>();
    List<File> allSavedFiles = new LinkedList<>();

    if (files == null || files.isEmpty()) {
        String message = "No files to process!";
        logger.error(message);
        body.setMessage(message);
        response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
        good_status = false;
    } else {
        Iterator<MultipartFile> multipartFileIterator = files.iterator();

        while (good_status && multipartFileIterator.hasNext()) {
            MultipartFile multipartFile = multipartFileIterator.next();
            String fileName = new File(multipartFile.getOriginalFilename()).getName();
            logger.trace("Analyzing file " + fileName);
            File savedFile = null;
            try {
                savedFile = saveFile(multipartFile, fileName);
                allSavedFiles.add(savedFile);
            } catch (FileNameClashException e) {
                String message = String.format("'%s' already exists", fileName);
                logger.error(message, e);
                body.setMessage(message);
                response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
                good_status = false;
            } catch (IOException e) {
                String message = String.format("Error handling '%s'", fileName);
                logger.error(message, e);
                body.setMessage(message);
                response = new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);
                good_status = false;
            }

            if (good_status) {
                if (fileName.contains(".json")) {
                    Optional<InstanceDataMultiProvider> idmp = validator
                            .readInstanceDataMultiProvider(savedFile.toPath());
                    if (idmp.isPresent()) {
                        if (idmp.get().validate()) {
                            submission.setInstanceData(savedFile.getPath());
                            body.getAcceptedFiles().add(savedFile.getName());
                        } else {
                            logger.error(idmp.get().getValidationError());
                            body.setMessage(idmp.get().getValidationError());
                            response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
                            good_status = false;
                        }
                    } else {
                        String message = "You have submitted an invalid json!";
                        logger.error(message);
                        body.setMessage(message);
                        response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
                        good_status = false;
                    }
                } else if (fileName.contains(".txt") || fileName.contains(".jsimg") || fileName.contains(".def")
                        || fileName.contains(".net") || fileName.contains(".stat")) {
                    additionalFileNames.add(savedFile.getPath());
                    body.getAcceptedFiles().add(savedFile.getName());
                }
            }
        }
    }

    if (good_status) {
        body.setMessage("Successful file upload");

        submission.setPaths(additionalFileNames);
        diceService.updateSubmission(submission);

        body.setSubmissionId(submission.getId());
        Link submissionLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder
                .methodOn(RestLaunchAnalysisController.class).submitById(submission.getId())).withRel("submit");
        body.add(submissionLink);

        logger.info(body);
        response = new ResponseEntity<>(body, HttpStatus.OK);
    } else {
        if (fileUtility.delete(allSavedFiles)) {
            logger.debug("Deleted the files created during a failed submission");
        }
    }

    return response;
}