Search in sources :

Example 16 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class WebExceptionResolver method resolveException.

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    logger.error("WebExceptionResolver:{}", ex);
    // if json
    boolean isJson = false;
    HandlerMethod method = (HandlerMethod) handler;
    ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
    if (responseBody != null) {
        isJson = true;
    }
    // error result
    ReturnT<String> errorResult = new ReturnT<String>(ReturnT.FAIL_CODE, ex.toString().replaceAll("\n", "<br/>"));
    // response
    ModelAndView mv = new ModelAndView();
    if (isJson) {
        try {
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().print(JacksonUtil.writeValueAsString(errorResult));
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
        return mv;
    } else {
        mv.addObject("exceptionMsg", errorResult.getMsg());
        mv.setViewName("/common/common.exception");
        return mv;
    }
}
Also used : ReturnT(com.xxl.job.core.biz.model.ReturnT) ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) HandlerMethod(org.springframework.web.method.HandlerMethod) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ReturnT (com.xxl.job.core.biz.model.ReturnT)16 XxlJobInfo (com.xxl.job.admin.core.model.XxlJobInfo)7 Date (java.util.Date)7 ExecutorBiz (com.xxl.job.core.biz.ExecutorBiz)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)3 SchedulerException (org.quartz.SchedulerException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 XxlJobGroup (com.xxl.job.admin.core.model.XxlJobGroup)2 TriggerParam (com.xxl.job.core.biz.model.TriggerParam)2 ExecutorBlockStrategyEnum (com.xxl.job.core.enums.ExecutorBlockStrategyEnum)2 JobThread (com.xxl.job.core.thread.JobThread)2 ExecutorFailStrategyEnum (com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum)1 XxlJobLogGlue (com.xxl.job.admin.core.model.XxlJobLogGlue)1 ExecutorRouteStrategyEnum (com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum)1 HandleCallbackParam (com.xxl.job.core.biz.model.HandleCallbackParam)1 LogResult (com.xxl.job.core.biz.model.LogResult)1 GlueTypeEnum (com.xxl.job.core.glue.GlueTypeEnum)1 IJobHandler (com.xxl.job.core.handler.IJobHandler)1 GlueJobHandler (com.xxl.job.core.handler.impl.GlueJobHandler)1