com.xxl.job.core.util.JacksonUtil Java Examples

The following examples show how to use com.xxl.job.core.util.JacksonUtil. 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: WebExceptionResolver.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@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;
	}
}
 
Example #2
Source File: TriggerCallbackThread.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
private void retryFailCallbackFile(){

        // load and clear file
        List<String> fileLines = FileUtil.loadFileLines(failCallbackFileName);
        FileUtil.deleteFile(failCallbackFileName);

        // parse
        List<HandleCallbackParam> failCallbackParamList = new ArrayList<>();
        if (fileLines!=null && fileLines.size()>0) {
            for (String line: fileLines) {
                List<HandleCallbackParam> failCallbackParamListTmp = JacksonUtil.readValue(line, List.class, HandleCallbackParam.class);
                if (failCallbackParamListTmp!=null && failCallbackParamListTmp.size()>0) {
                    failCallbackParamList.addAll(failCallbackParamListTmp);
                }
            }
        }

        // retry callback, 100 lines per page
        if (failCallbackParamList.size()>0) {
            int pagesize = 100;
            List<HandleCallbackParam> pageData = new ArrayList<>();
            for (int i = 0; i < failCallbackParamList.size(); i++) {
                pageData.add(failCallbackParamList.get(i));
                if (i>0 && i%pagesize == 0) {
                    doCallback(pageData);
                    pageData.clear();
                }
            }
            if (pageData.size() > 0) {
                doCallback(pageData);
            }
        }
    }
 
Example #3
Source File: WebExceptionResolver.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@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;
	}
}
 
Example #4
Source File: WebExceptionResolver.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #5
Source File: TriggerCallbackThread.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
private void retryFailCallbackFile() {

        // load and clear file
        List<String> fileLines = FileUtil.loadFileLines(failCallbackFileName);
        FileUtil.deleteFile(failCallbackFileName);

        // parse
        List<HandleCallbackParam> failCallbackParamList = new ArrayList<>();
        if (fileLines != null && fileLines.size() > 0) {
            for (String line : fileLines) {
                List<HandleCallbackParam> failCallbackParamListTmp = JacksonUtil.readValue(line, List.class, HandleCallbackParam.class);
                if (failCallbackParamListTmp != null && failCallbackParamListTmp.size() > 0) {
                    failCallbackParamList.addAll(failCallbackParamListTmp);
                }
            }
        }

        // retry callback, 100 lines per page
        if (failCallbackParamList != null && failCallbackParamList.size() > 0) {
            int pagesize = 100;
            List<HandleCallbackParam> pageData = new ArrayList<>();
            for (int i = 0; i < failCallbackParamList.size(); i++) {
                pageData.add(failCallbackParamList.get(i));
                if (i > 0 && i % pagesize == 0) {
                    doCallback(pageData);
                    pageData.clear();
                }
            }
            if (pageData.size() > 0) {
                doCallback(pageData);
            }
        }
    }
 
Example #6
Source File: WebExceptionResolver.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #7
Source File: TriggerCallbackThread.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private void retryFailCallbackFile() {

        // load and clear file
        List<String> fileLines = FileUtil.loadFileLines(failCallbackFileName);
        FileUtil.deleteFile(failCallbackFileName);

        // parse
        List<HandleCallbackParam> failCallbackParamList = new ArrayList<>();
        if (fileLines != null && fileLines.size() > 0) {
            for (String line : fileLines) {
                List<HandleCallbackParam> failCallbackParamListTmp = JacksonUtil.readValue(line, List.class, HandleCallbackParam.class);
                if (failCallbackParamListTmp != null && failCallbackParamListTmp.size() > 0) {
                    failCallbackParamList.addAll(failCallbackParamListTmp);
                }
            }
        }

        // retry callback, 100 lines per page
        if (failCallbackParamList != null && failCallbackParamList.size() > 0) {
            int pagesize = 100;
            List<HandleCallbackParam> pageData = new ArrayList<>();
            for (int i = 0; i < failCallbackParamList.size(); i++) {
                pageData.add(failCallbackParamList.get(i));
                if (i > 0 && i % pagesize == 0) {
                    doCallback(pageData);
                    pageData.clear();
                }
            }
            if (pageData.size() > 0) {
                doCallback(pageData);
            }
        }
    }
 
Example #8
Source File: TriggerCallbackThread.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
private void appendFailCallbackFile(List<HandleCallbackParam> callbackParamList){
    // append file
    String content = JacksonUtil.writeValueAsString(callbackParamList);
    FileUtil.appendFileLine(failCallbackFileName, content);
}
 
Example #9
Source File: TriggerCallbackThread.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
private void appendFailCallbackFile(List<HandleCallbackParam> callbackParamList) {
    // append file
    String content = JacksonUtil.writeValueAsString(callbackParamList);
    FileUtil.appendFileLine(failCallbackFileName, content);
}
 
Example #10
Source File: TriggerCallbackThread.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
private void appendFailCallbackFile(List<HandleCallbackParam> callbackParamList) {
    // append file
    String content = JacksonUtil.writeValueAsString(callbackParamList);
    FileUtil.appendFileLine(failCallbackFileName, content);
}