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.n52.aviation.aviationfx.spring.ExceptionHandlerImpl.java

@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
    return createModelAndView(e, req);
}

From source file:org.nebula.service.exception.NebulaExceptionHandler.java

@ExceptionHandler({ Exception.class })
protected ResponseEntity<Object> exceptions(Exception ex, WebRequest request) {
    String bodyOfResponse = "Internal Server Error";

    ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(),
            HttpStatus.INTERNAL_SERVER_ERROR, request);

    logger.error("Exception:" + response.toString(), ex);

    return response;
}

From source file:com.oneops.cms.ws.rest.AbstractRestController.java

/**
 * Generic Exception handler for unknown Exception
 * @param e UnknownException/*w  w  w.  j  a  va2  s. c  o  m*/
 * @param response ErrorResponse
 * @throws IOException
 */
@ExceptionHandler(Exception.class)
public void handleException(Exception e, HttpServletResponse response) throws IOException {
    logger.error("Exception serving request ", e);
    CmsBaseException ce = new CmsBaseException(CmsError.RUNTIME_EXCEPTION, e.getMessage());
    ErrorResponse error = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ce);
    response.setStatus(error.getCode());
    response.getWriter().write(gson.toJson(error));
}

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

@ApiOperation(hidden = true, value = "Reports a bug")
@RequestMapping(value = "/api/report-bug", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody//from   w  w w.ja  va2s  .  c  o m
public ResponseEntity<?> reportBug(HttpServletRequest request, @RequestBody BugReport report)
        throws McBasicRestException {
    try {
        emailUtil.sendBugReport(report);
    } catch (MessagingException e) {
        throw new McBasicRestException(HttpStatus.INTERNAL_SERVER_ERROR,
                MCIdRegConstants.BUG_REPORT_CREATION_FAILED, request.getServletPath());
    }
    return new ResponseEntity<>(HttpStatus.OK);
}

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

/**
 * Handles the given exception and generates a response with error code and message description.
 *
 * @param e/* w  w  w  .  ja v  a 2 s.  c om*/
 *            Given exception
 * @param request
 *            The http request
 * @param response
 *            The http response
 * @return The model view with the error response
 */
@SuppressWarnings("nls")
public ModelAndView createApiErrorResponse(final Exception e, final HttpServletRequest request,
        final HttpServletResponse response) {
    LOGGER.error(e.getMessage(), e);
    response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    RestApiErrorResponse restApiErrorResponse = new RestApiErrorResponse();

    if (e instanceof RestApiException) {
        RestApiException restEx = (RestApiException) e;
        response.setStatus(restEx.getHttpStatusCode().value());
        restApiErrorResponse.setErrorMessage(restEx.getMessage());
        restApiErrorResponse.setErrorCode(restEx.getAppErrorCode());
    } else if (IllegalArgumentException.class.isAssignableFrom(e.getClass())) {
        // Illegal argument exceptions mapped to 400 errors by default
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        restApiErrorResponse.setErrorMessage(e.getMessage());
    } else if (UntrustedIssuerException.class.isAssignableFrom(e.getClass())
            || SecurityException.class.isAssignableFrom(e.getClass())) {
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
        restApiErrorResponse.setErrorMessage(e.getMessage());
    } else if (HttpMessageNotReadableException.class.isAssignableFrom(e.getClass())) {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        restApiErrorResponse.setErrorMessage("Malformed JSON syntax. " + e.getLocalizedMessage());
    }

    return new ModelAndView(new MappingJackson2JsonView(), "ErrorDetails", restApiErrorResponse);
}

From source file:com.opensearchserver.hadse.cluster.ClusterController.java

/**
 * //  w  w  w. j  a  v  a 2 s .c  o  m
 * Add a node to the cluster
 * 
 * @param addresse
 * @return
 */
@RequestMapping(method = RequestMethod.PUT, value = "/_cluster")
@ResponseBody
public HttpEntity<?> add(@RequestParam(value = "addr", required = true) String... addresses) {
    try {
        List<String> adressList = new ArrayList<String>(addresses.length);
        for (String ad : addresses)
            adressList.add(ad);
        return ClusterCatalog.add(adressList);
    } catch (Throwable t) {
        return new ResponseEntity<String>(t.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.trustedanalytics.utils.errorhandling.RestErrorHandler.java

@ExceptionHandler(Exception.class)
public void handleException(Exception e, HttpServletResponse response) throws Exception {
    // Generate error reference id (to be used both in logs and in error sent from the service)
    long errorId = ErrorIdGenerator.getNewId();

    // If the exception is annotated with @ResponseStatus rethrow it and let
    // the framework handle it - like the OrderNotFoundException example
    // at the start of this post.
    // AnnotationUtils is a Spring Framework utility class.
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        ErrorLogger.logError("Controller error, reference id: " + errorId, e);
        response.sendError(responseStatus.value().value(),
                ErrorFormatter.formatErrorMessage(responseStatus.reason(), errorId));
        return;/* ww  w  .  j a  va 2s.  co  m*/
    }

    HttpStatus errorStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    ErrorLogger.logError("Unhandled controller error, reference id: " + errorId, e);
    response.sendError(errorStatus.value(), ErrorFormatter.formatErrorMessage(errorStatus, errorId));
}

From source file:com.opensearchserver.hadse.index.IndexController.java

@RequestMapping(method = RequestMethod.PUT, value = "/{index_name}")
@ResponseBody//from w  w w .  j  a  v a2  s .com
public HttpEntity<?> createIndex(@PathVariable String index_name,
        @RequestParam(value = "shards", required = false, defaultValue = "5") Integer shards,
        @RequestParam(value = "replicats", required = false, defaultValue = "1") Integer replicas) {
    try {
        return IndexCatalog.create(index_name, shards, replicas);
    } catch (Throwable e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:technology.tikal.gae.service.template.RestControllerTemplate.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public BasicErrorMessage handleException(Exception ex, HttpServletRequest request,
        HttpServletResponse response) {/*from  ww  w.j a va 2  s  . co m*/
    if (this.logger.isInfoEnabled()) {
        ex.printStackTrace();
    }
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
    BasicErrorMessage result = new BasicErrorMessage();
    String[] msg = new String[] { ex.getMessage() };
    result.setType(ex.getClass().getSimpleName());
    result.setMessage(msg);
    return result;
}

From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java

@Test
public void throwsResponseWrappedInException() throws IOException {
    final ClientHttpResponse expectedResponse = new MockClientHttpResponse(new byte[] { 0x13, 0x37 },
            HttpStatus.INTERNAL_SERVER_ERROR);

    exception.expect(AlreadyConsumedResponseException.class);
    exception.expect(hasFeature("response", AlreadyConsumedResponseException::getResponse,
            statusCode(HttpStatus.INTERNAL_SERVER_ERROR)));

    unit.handleError(expectedResponse);//from ww w. ja  va 2 s  .  c  o m
}