Java Code Examples for org.springframework.http.HttpStatus#INTERNAL_SERVER_ERROR

The following examples show how to use org.springframework.http.HttpStatus#INTERNAL_SERVER_ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ErrorController.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuilder sb = new StringBuilder();
    sb.append("Exception during execution of Spring Security application!   ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append(" root cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
Example 2
Source File: ErrorController.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuffer sb = new StringBuffer();
    sb.append("Exception during execution of Spring Security application!  ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append("\n\nroot cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
Example 3
Source File: RestaurantController.java    From Mastering-Microservices-with-Java-9-Second-Edition with MIT License 6 votes vote down vote up
/**
 * Fetch restaurants with the specified name. A partial case-insensitive
 * match is supported. So <code>http://.../restaurants/rest</code> will find
 * any restaurants with upper or lower case 'rest' in their name.
 *
 * @param name
 * @return A non-null, non-empty collection of restaurants.
 */
@HystrixCommand(fallbackMethod = "defaultRestaurants")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Collection<Restaurant>> findByName(@RequestParam("name") String name) {
    logger.info(String.format("restaurant-service findByName() invoked:{} for {} ", restaurantService.getClass().getName(), name));
    name = name.trim().toLowerCase();
    Collection<Restaurant> restaurants;
    try {
        restaurants = restaurantService.findByName(name);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception raised findByName REST Call", ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return restaurants.size() > 0 ? new ResponseEntity<>(restaurants, HttpStatus.OK)
            : new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
 
Example 4
Source File: ErrorController.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuilder sb = new StringBuilder();
    sb.append("Exception during execution of Spring Security application!   ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append(" root cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
Example 5
Source File: LoginServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
/**
 * 校验验证码
 * @param pd 页面请求对象
 * @return
 */
public ResponseEntity<String> validate(IPageData pd){

    logger.debug("校验验证码参数:{}",pd.toString());
    ResponseEntity<String> verifyResult = null;
    Assert.jsonObjectHaveKey(pd.getReqData(),"validateCode","请求报文中未包含 validateCode节点"+pd.toString());

    String code = CommonCache.getValue(pd.getSessionId()+"_validateCode");

    if(JSONObject.parseObject(pd.getReqData()).getString("validateCode").toLowerCase().equals(code)){
        verifyResult = new ResponseEntity<>("成功", HttpStatus.OK);
    }else{
        pd.setToken("");
        verifyResult = new ResponseEntity<>("验证码错误或已失效", HttpStatus.INTERNAL_SERVER_ERROR);
    }


    return verifyResult;
}
 
Example 6
Source File: ErrorController.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuffer sb = new StringBuffer();
    sb.append("Exception during execution of Spring Security application!   ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append(" root cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
Example 7
Source File: PrivilegeApi.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
@RequestMapping(path = "/deletePrivilegeFromPrivilegeGroup",method= RequestMethod.POST)
@ApiOperation(value="从权限组删除权限", notes="test: 返回 200 表示服务受理成功,其他表示失败")
@ApiImplicitParam(paramType="query", name = "privilegeInfo", value = "权限信息", required = true, dataType = "String")
public ResponseEntity<String> deletePrivilegeFromPrivilegeGroup(@RequestBody String privilegeInfo,HttpServletRequest request){
    ResponseEntity<String> responseEntity = null;

    try {
        responseEntity = privilegeSMOImpl.deletePrivilegeToPrivilegeGroup(privilegeInfo);
    }catch (Exception e){
        logger.error("请求订单异常",e);
        responseEntity =  new ResponseEntity<String>("请求中心服务发生异常,"+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }finally {
        logger.debug("订单服务返回报文为: {}",responseEntity);
        return responseEntity;
    }
}
 
Example 8
Source File: ErrorController.java    From NoteBlog with MIT License 5 votes vote down vote up
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        String code = request.getParameter("errorCode");
        statusCode = code == null ? null : Integer.valueOf(code);
    }
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    try {
        return HttpStatus.valueOf(statusCode);
    } catch (Exception ex) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
}
 
Example 9
Source File: PrivilegeSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 删除用户权限
 *
 * @param privilegeInfo
 * @return
 */
@Override
public ResponseEntity<String> deleteUserAllPrivilege(String privilegeInfo) {
    Assert.isJsonObject(privilegeInfo, "请求报文不是有效的json格式");

    Assert.jsonObjectHaveKey(privilegeInfo, "userId", "请求报文中未包含userId节点");

    JSONObject privilegeObj = JSONObject.parseObject(privilegeInfo);
    if (privilegeDAOImpl.deleteUserAllPrivilege(privilegeObj)) {
        return new ResponseEntity<String>("成功", HttpStatus.OK);
    }

    return new ResponseEntity<String>("未知异常", HttpStatus.INTERNAL_SERVER_ERROR);
}
 
Example 10
Source File: WebConfig.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500");
            container.addErrorPages(error404Page);
            container.addErrorPages(error500Page);
        }
    };
}
 
Example 11
Source File: AbstractWebController.java    From org.openwms with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(Exception.class)
protected ResponseEntity<Response<?>> handleException(Exception ex) {
    EXC_LOGGER.error("[P] Presentation Layer Exception: " + ex.getLocalizedMessage(), ex);
    return new ResponseEntity<>(Response.newBuilder()
            .withMessage(ex.getMessage())
            .withMessageKey(ExceptionCodes.TECHNICAL_RT_ERROR)
            .withHttpStatus(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()))
            .build(),
            HttpStatus.INTERNAL_SERVER_ERROR
    );
}
 
Example 12
Source File: GlobalExceptionHandler.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
@ExceptionHandler(MultipartException.class)
public Wrapper multipartException(Throwable t) {
	log.error("上传文件, 出现错误={}", t.getMessage(), t);
	return WrapMapper.wrap(Wrapper.ERROR_CODE, "文件超过限制");
}
 
Example 13
Source File: RestExceptionHandler.java    From metron with Apache License 2.0 5 votes vote down vote up
private HttpStatus getStatus(HttpServletRequest request) {
  Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
  if (statusCode == null) {
    return HttpStatus.INTERNAL_SERVER_ERROR;
  }
  return HttpStatus.valueOf(statusCode);
}
 
Example 14
Source File: GlobalExceptionHandler.java    From WebStack-Guns with MIT License 5 votes vote down vote up
/**
 * 拦截业务异常
 */
@ExceptionHandler(ServiceException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ErrorResponseData bussiness(ServiceException e) {
    LogManager.me().executeLog(LogTaskFactory.exceptionLog(ShiroKit.getUser().getId(), e));
    getRequest().setAttribute("tip", e.getMessage());
    log.error("业务异常:", e);
    return new ErrorResponseData(e.getCode(), e.getMessage());
}
 
Example 15
Source File: GlobalExceptionHand.java    From spring-boot-shiro with Apache License 2.0 5 votes vote down vote up
/**
 * 500 - Internal Server Error
 */
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public Response handleException(Exception e) {
    String msg = "服务内部异常!" + e.getMessage();
    log.error(msg, e);
    return new Response().failure(msg);
}
 
Example 16
Source File: BaseAppController.java    From Juice with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 用于处理通用异常
 *
 * @return
 */
@ResponseBody
@ExceptionHandler({ RuntimeException.class })
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result exception(RuntimeException e) throws IOException {
    //log.warn("got a Exception",e);

    Integer status = HttpStatus.BAD_REQUEST.value();
    String message = e.getMessage();

    return handleValue(status, message);
}
 
Example 17
Source File: CtrlExceptionHandler.java    From jcalaBlog with MIT License 5 votes vote down vote up
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public String handleIOException(Exception e, Model model) {
    if (e != null) {
        log.warn(e.getMessage());
        model.addAttribute("errorMsg", e.getLocalizedMessage());
    }
    return "/error";
}
 
Example 18
Source File: QueryServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
@Override
public void commonQueryService(DataQuery dataQuery) throws BusinessException {
    //查询缓存查询 对应处理的ServiceSql
    ResponseEntity<String> responseEntity = null;
    try {
        ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode());
        if (currentServiceSql == null) {
            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "未提供该服务 serviceCode = " + dataQuery.getServiceCode());
        }
        if ("".equals(currentServiceSql.getQueryModel())) {
            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员");
        }
        //请求参数校验
        List<String> sysParams = currentServiceSql.getParamList();
        for (String param : sysParams) {
            if (!dataQuery.getRequestParams().containsKey(param)) {
                //2019-04-10 这里修改为不抛出异常而是写为空字符串
                //throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,"请求参数错误,请求报文中未包含参数 " + param + " 信息");
                dataQuery.getRequestParams().put(param, "");
            }
        }
        dataQuery.setServiceSql(currentServiceSql);
        if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) {
            doExecuteSql(dataQuery);
        } else if (CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())) {
            doExecuteJava(dataQuery);
        } else {
            doExecuteProc(dataQuery);
        }
        responseEntity = new ResponseEntity<String>(dataQuery.getResponseInfo().toJSONString(), HttpStatus.OK);
    } catch (BusinessException e) {
        logger.error("公用查询异常:", e);
        /*dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR,
                e.getMessage()));*/
        responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    } finally {
        dataQuery.setResponseEntity(responseEntity);
    }


}
 
Example 19
Source File: Advice.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(MyException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Bar handleMyException(MyException ex, WebRequest request) {
	return new Bar();
}
 
Example 20
Source File: ExceptionAdvice.java    From ShiroJwt with MIT License 2 votes vote down vote up
/**
 * 捕捉其他所有异常
 * @param request
 * @param ex
 * @return
 */
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public ResponseBean globalException(HttpServletRequest request, Throwable ex) {
    return new ResponseBean(this.getStatus(request).value(), ex.toString() + ": " + ex.getMessage(), null);
}