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.trustedanalytics.examples.hbase.api.ExceptionHandlerAdvice.java

@ExceptionHandler
public ResponseEntity<String> handleGeneric(Exception ex) {
    LOG.error("Handling generic exception", ex);
    HttpStatus responseStatus = resolveAnnotatedResponseStatus(ex);
    if (responseStatus == null) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }//  w w w  .  j  a v a 2 s  . c o  m
    return new ResponseEntity<>(ex.getMessage(), responseStatus);
}

From source file:org.frat.common.exception.ExceptionResolver.java

@Override
public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) {
    if (WebUtil.isAjaxRequest(request)) {
        try {/*from  www. ja v  a2s .  c om*/
            String formId = request.getHeader(ApplicationConstant.X_FORM_ID);
            Locale locale = request.getLocale();
            ObjectMapper objectMapper = new ObjectMapper();
            response.setContentType("application/json;charset=UTF-8");
            ResultDto error = getErrorDto(ex, handler, formId, locale);
            if (error.isNonBizError()) {
                response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            } else {
                response.setStatus(HttpStatus.OK.value());
            }
            PrintWriter writer = response.getWriter();
            objectMapper.writeValue(response.getWriter(), error);
            writer.flush();
        } catch (IOException ie) {
            LOGGER.error("Failed to serialize the object to json for exception handling.", ie);
        }
        return new ModelAndView();
    } else {
        response.setContentType("text/html;charset=UTF-8");
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorMessage", ExceptionUtils.getStackTrace(ex));
        if (ex instanceof AuthorizationException) {
            LOGGER.warn("AuthorizationException handled (non-ajax style):", ex);
            mav.setViewName("error/access_denied");
        } else {
            LOGGER.error("Unknown exception handled (non-ajax style):", ex);
            mav.setViewName("error/404");
        }
        return mav;
    }
}

From source file:com.hp.autonomy.frontend.find.core.beanconfiguration.AppConfiguration.java

@SuppressWarnings("ReturnOfInnerClass")
@Bean//ww w.j  a v a2  s.c o  m
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(final ConfigurableEmbeddedServletContainer container) {

            final ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED,
                    DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
            final ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN,
                    DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
            final ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND,
                    DispatcherServletConfiguration.NOT_FOUND_ERROR_PATH);
            final ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,
                    DispatcherServletConfiguration.SERVER_ERROR_PATH);

            container.addErrorPages(error401Page, error403Page, error404Page, error500Page);
        }
    };
}

From source file:net.bluewizardhat.tfa.web.controller.AbstractBaseController.java

/**
 * General exceptions.//from  w w  w .j  a  v  a 2 s. c o  m
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "Error occured on server")
public void handleException(Exception e) {
    log.warn("Unhandled exception occured", e);
}

From source file:org.trustedanalytics.kafka.adminapi.api.ExceptionHandlerAdvice.java

/**
 * This is a generic exception handler.//from   w ww.  j  a  v  a 2 s . c o  m
 * It tries to resolve a response status based on the ResponseStatus annotation
 * applied on a class of an object passed as an argument.
 * It looks recursively at the the exception class and exception root causes.
 * If no such ResponseStatus annotation is found anywhere then HttpStatus.INTERNAL_SERVER_ERROR is returned.
 * @param ex The exception object
 * @return The response entity
 */
@ExceptionHandler
public ResponseEntity<String> handleGenericException(Exception ex) {
    LOG.error("Handling generic exception", ex);
    HttpStatus responseStatus = resolveAnnotatedResponseStatus(ex);
    if (responseStatus == null) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return new ResponseEntity<>(ex.getMessage(), responseStatus);
}

From source file:de.steilerdev.myVerein.server.controller.user.DivisionController.java

@RequestMapping(value = "sync", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<List<Division>> syncUserDivision(@CurrentUser User currentUser) {
    logger.trace("[" + currentUser + "] Syncing division");
    List<Division> divisions = currentUser.getDivisions();
    if (divisions == null) {
        logger.warn("[" + currentUser + "] No divisions found");
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {//from  w w  w. j  a  va  2  s  .  co m
        divisions.replaceAll(Division::getSendingObjectOnlyId);
        logger.info("[" + currentUser + "] Returning user divisions");
        return new ResponseEntity<>(divisions, HttpStatus.OK);
    }
}

From source file:com.example.spring.controller.AppErrorController.java

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode != null) {
        try {/*  ww w .j  av a  2s. com*/
            return HttpStatus.valueOf(statusCode);
        } catch (Exception ex) {
        }
    }
    return HttpStatus.INTERNAL_SERVER_ERROR;
}

From source file:de.petendi.ethereum.secure.proxy.controller.SecureController.java

@ResponseBody
@RequestMapping(method = RequestMethod.POST, value = "/{fingerprint}")
public ResponseEntity<EncryptedMessage> post(@PathVariable("fingerprint") String fingerPrint,
        @RequestBody EncryptedMessage encryptedMessage) {

    IO.UnencryptedResponse unencryptedResponse = new IO.UnencryptedResponse() {
        @Override/*w  w w  .ja va2  s  .co m*/
        public byte[] getUnencryptedResponse(byte[] bytes, String s, String s1) {
            return SecureController.this.dispatch(bytes).getBytes();
        }
    };
    try {
        EncryptedMessage encrypted = seccoco.io().dispatch(fingerPrint, encryptedMessage, unencryptedResponse);
        return new ResponseEntity<EncryptedMessage>(encrypted, HttpStatus.OK);
    } catch (IO.RequestException e) {
        HttpStatus status;
        if (e instanceof IO.CertificateNotFoundException) {
            status = HttpStatus.FORBIDDEN;
        } else if (e instanceof IO.SignatureCheckFailedException) {
            status = HttpStatus.UNAUTHORIZED;
        } else if (e instanceof IO.InvalidInputException) {
            status = HttpStatus.BAD_REQUEST;
        } else {
            status = HttpStatus.INTERNAL_SERVER_ERROR;
        }
        return new ResponseEntity<EncryptedMessage>(status);
    }
}

From source file:cn.org.once.cstack.config.RestHandlerException.java

@ExceptionHandler(value = { ServiceException.class, JsonMappingException.class })
protected ResponseEntity<Object> handleServiceException(Exception ex, WebRequest request) {
    ex.printStackTrace();//from   w  w w.ja  v a2s  .  c o  m
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    return handleExceptionInternal(ex, new HttpErrorServer(ex.getLocalizedMessage()), headers,
            HttpStatus.INTERNAL_SERVER_ERROR, request);
}

From source file:org.openwms.core.http.AbstractWebController.java

/**
 * All general exceptions thrown by services are caught here and translated into http conform responses with a status code {@code 500
 * Internal Server Error}./*from w w w.  j  a v a  2 s. c o  m*/
 *
 * @param ex The exception occurred
 * @return A response object wraps the server result
 */
@ExceptionHandler(Exception.class)
public ResponseEntity<Response<Serializable>> handleException(Exception ex) {
    EXC_LOGGER.error("[P] Presentation Layer Exception: " + ex.getLocalizedMessage(), ex);
    if (ex instanceof BehaviorAwareException) {
        BehaviorAwareException bae = (BehaviorAwareException) ex;
        return bae.toResponse(bae.getData());
    }
    if (ex instanceof BusinessRuntimeException) {
        BusinessRuntimeException bre = (BusinessRuntimeException) ex;
        return new ResponseEntity<>(new Response<>(ex.getMessage(), bre.getMsgKey(),
                HttpStatus.INTERNAL_SERVER_ERROR.toString(), new String[] { bre.getMsgKey() }),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
    if (ex instanceof HttpBusinessException) {
        HttpBusinessException e = (HttpBusinessException) ex;
        return new ResponseEntity<>(new Response<>(ex.getMessage(), e.getHttpStatus().toString()),
                e.getHttpStatus());
    }
    if (ex instanceof ValidationException) {
        return new ResponseEntity<>(new Response<>(ex.getMessage(), HttpStatus.BAD_REQUEST.toString()),
                HttpStatus.BAD_REQUEST);
    }
    if (ex instanceof TechnicalRuntimeException) {
        TechnicalRuntimeException be = (TechnicalRuntimeException) ex;
        return new ResponseEntity<>(new Response<>(ex.getMessage(), HttpStatus.BAD_GATEWAY.toString()),
                HttpStatus.BAD_GATEWAY);
    }
    return new ResponseEntity<>(new Response<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.toString()),
            HttpStatus.INTERNAL_SERVER_ERROR);
}