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.coffeebeans.services.controller.base.BaseController.java

@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
ErrorResponse handleException(Exception e) {
    return new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), "Internal Error",
            null);//  w  w  w .j  ava2 s  . co  m
}

From source file:com.culturedear.chord.ChordAnalyzerController.java

@RequestMapping("/analyze")
public ResponseEntity<Object> identifyChordByNotes(@RequestParam(value = "notes") String notes) {
    Chord jfugueChord = null;//from w  w w.ja va  2 s .  c o m
    musicChord = null;
    try {
        jfugueChord = Chord.fromNotes(notes);
        musicChord = new MusicChord(Note.getToneStringWithoutOctave(jfugueChord.getRoot().getValue()),
                jfugueChord.getChordType().toLowerCase(),
                Note.getToneStringWithoutOctave(jfugueChord.getBassNote().getValue()),
                jfugueChord.getInversion(), jfugueChord.isMajor(), jfugueChord.isMinor(),
                jfugueChord.toString());
    } catch (Exception e) {
        System.out.println("Exception encountered in ChordAnalyzerController#identifyChordByNotes: " + e);
    }
    return Optional.ofNullable(musicChord).map(mc -> new ResponseEntity<>((Object) mc, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Could not analyze the chord", HttpStatus.INTERNAL_SERVER_ERROR));

}

From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java

@Override
public String getBedAvailablityHAVE(String hospitalname) {

    String hospitalstatushave;//from  w w w  .  ja v a 2 s  .c  o m
    BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname);
    HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats);

    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter sw = new StringWriter();
        //marshal the envelope 
        jaxbMarshaller.marshal(hospitalStatus, sw);
        hospitalstatushave = sw.toString();

    } catch (JAXBException e) {
        e.printStackTrace();
        return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR;
    }

    return hospitalstatushave;

}

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

/**
 * Build a preview for a previewable/*  w w  w .  ja va2s . c  o  m*/
 */
public <T extends Previewable & Identifiable> ResponseEntity<String> render(String id, Repository<T> repository,
        HttpServletRequest httpServletRequest) {
    if (isBlank(id)) {
        throw new IllegalArgumentException("Need to specify the id of the page to preview.");
    }

    try {
        String html = generator.generateHtml(getResourceContext(httpServletRequest), repository.get(id));
        return new ResponseEntity<>(html, HttpStatus.OK);
    } catch (GenerationException e) {
        LOGGER.error("Error during page generation", e);
        return new ResponseEntity<>("Error during page generation", HttpStatus.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        return new ResponseEntity<>("Page <" + id + "> not found", HttpStatus.NOT_FOUND);
    }
}

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

@RequestMapping(value = "/{id}/cover/{scale}", method = RequestMethod.GET, produces = "image/jpeg")
@ResponseBody//from ww  w .  j  a  v a2 s  . co  m
public ResponseEntity getCoverArt(@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 cover art
    image = imageService.getCoverArt(mediaElement, scale);

    // Check if we were able to retrieve a cover
    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.fede.calculator.web.controller.InvestmentController.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String errorHandler(Exception ex) {
    LOG.log(Level.SEVERE, "errorHandler", ex);

    return "redirect:/secure/";
}

From source file:be.dnsbelgium.rdap.IPController.java

private IPNetwork getNetwork(String ipAddress) throws RDAPError {
    IPNetwork ipNetwork;/*  ww  w .  ja va  2s  .c  om*/
    try {
        ipNetwork = ipService.getIPNetwork(CIDR.of(ipAddress));
        if (ipNetwork == null) {
            logger.debug("IP result for {} is null. Throwing IPNotFound Error", ipAddress);
            throw RDAPError.ipNotFound(ipAddress);
        }
    } catch (RDAPError e) {
        throw e;
    } catch (Exception e) {
        logger.error("Some errors not handled", e);
        throw new RDAPError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Internal server error");
    }
    return ipNetwork;
}

From source file:com.wisemapping.rest.BaseController.java

@ExceptionHandler(ImportUnexpectedException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody/*from w  ww. j a  v a2s . c om*/
public RestErrors handleImportErrors(@NotNull ImportUnexpectedException ex,
        @NotNull HttpServletRequest request) {
    final User user = Utils.getUser();
    notificationService.reportJavaException(ex, user, new String(ex.getFreemindXml()), request);
    return new RestErrors(ex.getMessage(), Severity.SEVERE);
}

From source file:eu.cloudwave.wp5.feedbackhandler.controller.AbstractBaseUiController.java

/**
 * Is called whenever an {@link Exception} in a controller method is thrown.
 * /*from   www  .ja  v a  2  s  .co  m*/
 * @param exception
 *          the exception that arose
 * @param request
 *          the request that caused the exception
 * @return an error message
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public final ModelAndView handleException(final Exception exception, final HttpServletRequest request) {
    LogManager.getLogger(getClass()).error(String.format(EXCEPTION_MESSAGE, request.getRequestURI()),
            exception);
    return htmlErrorPage(exception.getMessage());
}

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

@Test
public void testRestApiExceptionWithException() {
    RuntimeException runtimeException = new RuntimeException("Runtime exception message");
    RestApiException apiException = new RestApiException(runtimeException);

    Assert.assertEquals(apiException.getCause(), runtimeException);
    Assert.assertEquals(apiException.getMessage(), "java.lang.RuntimeException: Runtime exception message");
    Assert.assertEquals(apiException.getAppErrorCode(), "FAILURE");
    Assert.assertEquals(apiException.getHttpStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR);
}