Commit 951e5ae4 authored by yanzg's avatar yanzg

修复异常提醒,从而正确的跟踪异常信息

parent fb618e70
......@@ -2,6 +2,7 @@ package com.yanzuoguang.util;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.CodeTargetException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.exception.RuntimeCodeException;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -51,10 +52,11 @@ public class YzgErrorData {
/**
* 获取全编码
*
* @param code 原编码
* @return 返回值
*/
public String getFullCode(String code){
public String getFullCode(String code) {
return TAG + code;
}
......@@ -142,7 +144,7 @@ public class YzgErrorData {
try {
message = String.format(message, args);
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(YzgErrorData.class, e);
}
}
return message;
......
......@@ -171,7 +171,7 @@ public class ObjectHelper {
}
} catch (Exception ex) {
System.err.println("字段" + field + "读取错误");
ex.printStackTrace();
ExceptionHelper.PrintError(ObjectHelper.class, ex);
}
return null;
}
......
package com.yanzuoguang.util.exception;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.ResponseResult;
......@@ -89,4 +90,17 @@ public class ExceptionHelper {
return ResponseResult.error(code, msg);
}
}
public static void PrintError(Class<?> cls, Throwable ex) {
if (ex == null) {
return;
}
if (ex instanceof RuntimeCodeException) {
RuntimeCodeException rce = (RuntimeCodeException) ex;
String log = String.format("%s:%s %s target: %s ", cls.getName(), rce.getCode(), rce.getMessage(), JsonHelper.serialize(rce.getTarget()));
System.err.println(log);
} else {
ex.printStackTrace();
}
}
}
......@@ -2,6 +2,7 @@ package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -231,7 +232,7 @@ public final class CheckerHelper {
* 检测是否符合时间类型
*
* @param paramName 参数名称
* @param paramVal 值
* @param paramVal
* @param queryType 格式类型
* @return
*/
......@@ -388,14 +389,14 @@ public final class CheckerHelper {
try {
Date date = getDate(paramVal, formatStr);
String dateResult = DateHelper.getDateTimeString(formatStr, date);
if (!dateResult.startsWith(paramVal)){
String formatTo = StringHelper.getFirst(formatStr,DateHelper.FORMAT_SECOND_STRING);
if (!dateResult.startsWith(paramVal)) {
String formatTo = StringHelper.getFirst(formatStr, DateHelper.FORMAT_SECOND_STRING);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatTo);
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
String formatTo = StringHelper.getFirst(formatStr,DateHelper.FORMAT_SECOND_STRING);
ExceptionHelper.PrintError(CheckerHelper.class, e);
String formatTo = StringHelper.getFirst(formatStr, DateHelper.FORMAT_SECOND_STRING);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatTo);
this.setValid(false);
}
......@@ -434,7 +435,7 @@ public final class CheckerHelper {
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
ExceptionHelper.PrintError(CheckerHelper.class, e);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatStr);
this.setValid(false);
}
......@@ -464,7 +465,7 @@ public final class CheckerHelper {
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
ExceptionHelper.PrintError(CheckerHelper.class, e);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatStr);
this.setValid(false);
}
......
......@@ -101,7 +101,6 @@ public class DateHelper {
}
return initMillSecond(to, initMillSecond);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(DateHelper.class, ex, from);
}
return null;
......@@ -550,7 +549,7 @@ public class DateHelper {
c.set(Calendar.DATE, 1);
now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(DateHelper.class, e);
}
return now;
}
......@@ -617,7 +616,7 @@ public class DateHelper {
SimpleDateFormat format = new SimpleDateFormat(FORMAT_DAY_STRING);
return format.format(dateFrom).equals(format.format(dateTo));
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(DateHelper.class, e);
}
return false;
}
......@@ -689,8 +688,7 @@ public class DateHelper {
long fromMill = cal.getTimeInMillis();
cal.setTime(to);
long toMill = cal.getTimeInMillis();
long mill = toMill - fromMill;
return mill;
return toMill - fromMill;
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
......@@ -854,7 +852,7 @@ public class DateHelper {
*/
public static String getDateTimeString(String format, Date date) {
if (date != null) {
String formatTo = StringHelper.getFirst(format,FORMAT_SECOND_STRING);
String formatTo = StringHelper.getFirst(format, FORMAT_SECOND_STRING);
return new SimpleDateFormat(formatTo).format(date);
}
return StringHelper.EMPTY;
......
......@@ -2,6 +2,7 @@ package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.contants.SystemContants;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
......@@ -33,6 +34,7 @@ public class DesHelper {
byte[] to = processCipher(from, getSecretKey(key), Cipher.ENCRYPT_MODE, ALGORITHM_DES);
return RsaHelper.encodeBase64(to);
} catch (UnsupportedEncodingException ex) {
ExceptionHelper.PrintError(DesHelper.class, ex);
throw new CodeException("加密失败:" + ex.getMessage(), ex);
}
}
......@@ -50,6 +52,7 @@ public class DesHelper {
byte[] to = processCipher(from, getSecretKey(key), Cipher.DECRYPT_MODE, ALGORITHM_DES);
return new String(to, SystemContants.UTF8);
} catch (UnsupportedEncodingException ex) {
ExceptionHelper.PrintError(DesHelper.class, ex);
throw new CodeException("解密失败:" + ex.getMessage(), ex);
}
}
......@@ -64,10 +67,9 @@ public class DesHelper {
try {
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
SecretKeyFactory instance = SecretKeyFactory.getInstance(ALGORITHM_DES);
SecretKey secretKey = instance.generateSecret(desKeySpec);
return secretKey;
return instance.generateSecret(desKeySpec);
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(DesHelper.class, e);
}
return null;
......@@ -92,7 +94,7 @@ public class DesHelper {
cipher.init(opsMode, key, secureRandom);
return cipher.doFinal(processData);
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(DesHelper.class, e);
}
return null;
}
......
......@@ -7,6 +7,7 @@ import java.util.HashMap;
/**
* 字符串和枚举进行转换
*
* @author 颜佐光
*/
public class EnumHelper {
......@@ -22,7 +23,6 @@ public class EnumHelper {
result = Enum.valueOf(vType, vStr);
}
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(EnumHelper.class, ex, vStr);
}
return result;
......@@ -41,7 +41,6 @@ public class EnumHelper {
result = (T) Enum.valueOf((Class) vType, vStr);
}
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(EnumHelper.class, ex, vStr);
}
if (result == null && vDefault == null) {
......@@ -71,7 +70,6 @@ public class EnumHelper {
}
}
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(EnumHelper.class, ex, i);
}
return result;
......
......@@ -3,6 +3,7 @@ package com.yanzuoguang.util.helper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yanzuoguang.util.exception.ExceptionHelper;
/**
* JSON序列化的处理
......@@ -40,7 +41,6 @@ public class JsonHelper {
* @param type 对象的类型
* @param <T> 转换后的结果的类型
* @return 转换后的结果
* @throws Exception 转换结果发生异常
*/
public static <T> T to(Object from, Class<T> type) {
String json = serialize(from);
......@@ -54,7 +54,6 @@ public class JsonHelper {
* @param type 对象的类型
* @param <T> 转换后的结果的类型
* @return 转换后的结果
* @throws Exception 转换结果发生异常
*/
public static <T> T to(Object from, TypeReference<T> type) {
String json = serialize(from);
......@@ -81,7 +80,6 @@ public class JsonHelper {
* @param type 对象的类型
* @param <T> 转换后的结果的类型
* @return 转换后的结果
* @throws Exception 转换结果发生异常
*/
public static <T> T deserialize(String json, Class<T> type) {
if (isException) {
......@@ -90,7 +88,7 @@ public class JsonHelper {
try {
return JSON.parseObject(json, type);
} catch (RuntimeException ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(JsonHelper.class, ex);
return null;
}
}
......@@ -103,7 +101,6 @@ public class JsonHelper {
* @param type 对象的类型
* @param <T> 转换后的结果的类型
* @return 转换后的结果
* @throws Exception 转换结果发生异常
*/
public static <T> T deserialize(String json, TypeReference<T> type) {
if (isException) {
......@@ -112,7 +109,7 @@ public class JsonHelper {
try {
return JSON.parseObject(json, type);
} catch (RuntimeException ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(JsonHelper.class, ex);
return null;
}
}
......@@ -127,7 +124,7 @@ public class JsonHelper {
* @return 返回数组
*/
public static <T> T deserializeArray(String json, TypeReference<T> type) {
if (json == null || json.length() < 1) {
if (json == null || json.isEmpty()) {
return null;
}
json = json.trim();
......@@ -140,7 +137,7 @@ public class JsonHelper {
try {
return JSON.parseObject(json, type);
} catch (RuntimeException ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(JsonHelper.class, ex);
return null;
}
}
......@@ -151,7 +148,6 @@ public class JsonHelper {
*
* @param value 需要序列化的对象
* @return JSON结果
* @throws Exception 抛出的异常信息
*/
public static String serialize(Object value) {
return JSON.toJSONString(value);
......@@ -163,7 +159,6 @@ public class JsonHelper {
* @param value 需要序列化的对象
* @param isLine 是否需要换行
* @return JSON结果
* @throws Exception 抛出的异常信息
*/
public static String serialize(Object value, boolean isLine) {
return JSON.toJSONString(value, isLine);
......
......@@ -2,6 +2,7 @@ package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
/**
......@@ -43,11 +44,9 @@ public class RunHelper {
ex = null;
break;
} catch (RuntimeException e) {
e.printStackTrace();
if (i < size) {
// 间隔100ms,防止服务器重启时请求失败
ThreadHelper.sleep(sleep);
}
ExceptionHelper.PrintError(RunHelper.class, e);
// 间隔100ms,防止服务器重启时请求失败
ThreadHelper.sleep(sleep);
ex = e;
}
}
......
......@@ -1051,7 +1051,7 @@ public class StringHelper {
}
return hex.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
ExceptionHelper.PrintError(StringHelper.class, e);
}
return StringHelper.EMPTY;
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.contants.SystemContants;
import com.yanzuoguang.util.exception.ExceptionHelper;
import java.net.*;
import java.util.*;
......@@ -92,7 +93,7 @@ public class UrlHelper {
}
}
} catch (SocketException e) {
e.printStackTrace();
ExceptionHelper.PrintError(UrlHelper.class,e);
}
return ipList;
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.thread.ThreadHelper;
......@@ -99,7 +100,7 @@ public class YzgTimeout {
try {
runItem();
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(YzgTimeout.class,ex);
}
ThreadHelper.sleep(200);
}
......@@ -127,7 +128,7 @@ public class YzgTimeout {
poll.setTimeMax(poll.getTimeMax() + poll.getTimeOutTip());
ThreadHelper.runThread(() -> poll.getHeart().heart(time));
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(YzgTimeout.class, ex);
}
}
if (!poll.isRun()) {
......
package com.yanzuoguang.util.log;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.extend.ConfigBase;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -27,8 +28,8 @@ public class Log {
* 写入错误消息
*
* @param cls 类
* @param msg
* @param args
* @param msg 消息内容
* @param args 参数信息
*/
public static void error(Class<?> cls, String msg, Object... args) {
String toMsg = getFormat(msg, args);
......@@ -38,9 +39,11 @@ public class Log {
/**
* 写入错误信息
*
* @param ex
* @param cls 类
* @param ex 错误信息
*/
public static void error(Class<?> cls, Throwable ex) {
ExceptionHelper.PrintError(cls,ex);
add(new LogInfo(cls, new Date(), ex != null, ex, StringHelper.EMPTY));
}
......@@ -52,6 +55,7 @@ public class Log {
* @param args 错误消息
*/
public static void error(Class<?> cls, Throwable ex, String msg, Object... args) {
ExceptionHelper.PrintError(cls,ex);
String toMsg = getFormat(msg, args);
add(new LogInfo(cls, new Date(), ex != null, ex, toMsg));
}
......@@ -59,8 +63,9 @@ public class Log {
/**
* 警告信息
*
* @param msg
* @param args
* @param cls 类
* @param msg 消息
* @param args 参数信息
*/
public static void info(Class<?> cls, String msg, Object... args) {
String toMsg = getFormat(msg, args);
......@@ -70,8 +75,10 @@ public class Log {
/**
* 警告信息
*
* @param msg
* @param args
* @param cls 类
* @param tag 标签信息
* @param msg 消息
* @param args 参数信息
*/
public static void infoTag(Class<?> cls, String tag, String msg, Object... args) {
String toMsg = getFormat(msg, args);
......@@ -89,7 +96,6 @@ public class Log {
// 获取当前线程编号
String threadId = getThreadId();
info.setThreadId(threadId);
// 判断当前线程日志是否需要特殊处理
LogDate date;
synchronized (Log.class) {
......@@ -127,7 +133,7 @@ public class Log {
/**
* 当前县城日志对象
*
* @return
* @return 返回日志信息
*/
public static LogDate threadCurrent() {
String threadId = getThreadId();
......@@ -136,6 +142,8 @@ public class Log {
/**
* 当前线程结束处理特殊异常
*
* @return 返回日志信息
*/
public static LogDate threadCommit() {
String threadId = getThreadId();
......@@ -147,7 +155,7 @@ public class Log {
/**
* 获取当前线程编号
*
* @return
* @return 返回日志信息
*/
private static String getThreadId() {
return String.valueOf(Thread.currentThread().getId());
......@@ -156,16 +164,15 @@ public class Log {
/**
* 将异常消息格式化
*
* @param msg
* @param args
* @return
* @param msg 消息
* @param args 参数信息
* @return 结果字符串
*/
private static String getFormat(String msg, Object... args) {
if (args != null && args.length > 0) {
try {
msg = String.format(msg, args);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(Log.class, ex);
}
}
......
package com.yanzuoguang.util.log;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -65,9 +66,6 @@ public class LogDefault implements RunnableLog {
sb.append(ex.getMessage());
}
System.err.println(sb);
if (ex != null) {
ex.printStackTrace();
}
} else {
System.out.println(sb);
}
......
package com.yanzuoguang.util.sfz;
import com.yanzuoguang.util.exception.ExceptionHelper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -36,7 +38,7 @@ public class SfzHandle15 implements SfzHandle {
try {
birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2));
} catch (ParseException e) {
e.printStackTrace();
ExceptionHelper.PrintError(SfzHandle15.class, e);
}
Calendar cal = Calendar.getInstance();
if (birthDate != null)
......@@ -94,7 +96,7 @@ public class SfzHandle15 implements SfzHandle {
try {
birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
} catch (ParseException e) {
e.printStackTrace();
ExceptionHelper.PrintError(SfzHandle15.class, e);
}
Calendar cal = Calendar.getInstance();
if (birthDate != null) {
......
package com.yanzuoguang.util.sfz;
import com.yanzuoguang.util.exception.ExceptionHelper;
import static com.yanzuoguang.util.sfz.SfzHandle15.CHINA_ID_MIN_LENGTH;
import static com.yanzuoguang.util.sfz.SfzHandleUtil.cityCodes;
......@@ -113,7 +115,7 @@ public class SfzHandle18 implements SfzHandle {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
e.printStackTrace();
ExceptionHelper.PrintError(SfzHandle18.class, e);
}
return iArr;
}
......
......@@ -5,6 +5,7 @@ import com.yanzuoguang.util.log.Log;
/**
* 进度数据
*
* @author 颜佐光
*/
public class ProcessData {
......@@ -75,7 +76,6 @@ public class ProcessData {
try {
runProcess.execute(this);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(HttpHelper.class, ex);
}
}
......
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.helper.Event;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.Event;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -102,7 +101,6 @@ public class RunPlan {
}
millSeconds = (now - item.getDate());
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(ThreadHelper.class, ex);
}
// 未到执行时间
......@@ -118,7 +116,6 @@ public class RunPlan {
this.triggerEvent(this.onItemExecuted);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(RunPlan.class, ex);
}
item.initDate();
......
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.Date;
......@@ -142,7 +143,6 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
this.code.run();
} catch (Exception ex) {
ex.printStackTrace();
this.handleException(ex);
} finally {
this.count++;
......@@ -156,6 +156,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
* @param ex
*/
private void handleException(Throwable ex) {
ExceptionHelper.PrintError(RunnableListAutoItem.class, ex);
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
......
......@@ -75,13 +75,11 @@ public class ThreadHelper {
try {
timeout.run(true, -1);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(ThreadHelper.class, ex);
}
try {
interval.run(false, -1);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.handleException(ThreadHelper.class, ex);
}
if (timeout.getCount() == 0 && interval.getCount() == 0) {
......
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
......@@ -61,7 +62,7 @@ public class ThreadNext {
try {
isPause = next.next();
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(ThreadNext.class,ex);
boolean isNewEx = frontEx == null || !(frontEx.getClass() == ex.getClass() &&
StringHelper.compare(frontEx.getMessage(), ex.getMessage()));
if (isNewEx || System.currentTimeMillis() - newErrorTime > 5L * 60L * 1000L) {
......@@ -75,7 +76,7 @@ public class ThreadNext {
int max = Math.max(next.getNextTime(), 100);
Thread.sleep(max);
} catch (InterruptedException e) {
e.printStackTrace();
ExceptionHelper.PrintError(ThreadNext.class,e);
}
} else {
break;
......
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.extend.ConfigBase;
import com.yanzuoguang.util.log.Log;
......@@ -54,7 +55,7 @@ public class ThreadWait {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
ExceptionHelper.PrintError(ThreadWait.class,e);
}
this.stopPrint();
}
......
package com.yanzuoguang.util.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import java.io.Serializable;
......@@ -24,7 +25,7 @@ public class BaseVo implements Serializable {
MapRow rowThat = JsonHelper.to(that, MapRow.class);
return rowThis.equals(rowThat);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(BaseVo.class, ex);
return super.equals(that);
}
}
......@@ -35,7 +36,7 @@ public class BaseVo implements Serializable {
MapRow row = JsonHelper.to(this, MapRow.class);
return row.hashCode();
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(BaseVo.class, ex);
return super.hashCode();
}
}
......@@ -45,7 +46,7 @@ public class BaseVo implements Serializable {
try {
return JsonHelper.serialize(this, false);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(BaseVo.class, ex);
return super.toString();
}
}
......
package helper;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.BaiduHelper;
import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.JsonHelper;
......@@ -120,7 +121,7 @@ public class HttpHelperTest {
try {
String s = HttpHelper.get(req.url);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(HttpHelperTest.class, ex);
isError = true;
} finally {
long end = System.currentTimeMillis();
......
package helper;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
......@@ -57,7 +58,7 @@ public class TestDateHelper {
Date date = DateHelper.getDateTime("00:00:00");
System.out.println("日期转换时间是否相等:" + (date != null));
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(TestDateHelper.class, ex);
}
}
......
......@@ -2,6 +2,7 @@ package helper;
import base.DemoVo;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.SfzhUtil;
......@@ -218,7 +219,7 @@ public class TestSfzUtil {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
e.printStackTrace();
ExceptionHelper.PrintError(TestSfzUtil.class, e);
}
return iArr;
}
......
......@@ -90,7 +90,7 @@ public class AspectLogResult {
Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
logLocal.result(log, responseResult.getCode(), json, isError);
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(AspectLogResult.class, e);
} finally {
if (logFlag) {
Log.threadCommit();
......
......@@ -3,6 +3,7 @@ package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.cloud.CloudConfig;
import com.yanzuoguang.cloud.aop.log.LogLocal;
import com.yanzuoguang.log.LogCountTime;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.LogVo;
import org.springframework.stereotype.Component;
......@@ -52,7 +53,7 @@ public class AspectLogStart {
Log.info(cls, " %s [ %s ] request: %s", tag, url, body);
}
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(AspectLogStart.class, ex);
}
}
......
......@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop.log;
import com.yanzuoguang.cloud.CloudConfig;
import com.yanzuoguang.cloud.aop.LogFeign;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.thread.ThreadNext;
import com.yanzuoguang.util.vo.LogVo;
import org.springframework.beans.factory.InitializingBean;
......@@ -89,7 +90,7 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
try {
logFeign.save(item);
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(LogBase.class, ex);
}
}
return true;
......
......@@ -5,6 +5,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
......@@ -38,9 +39,8 @@ public class YzgEnvironmentPostProcessor implements EnvironmentPostProcessor {
environment.getPropertySources().addLast(propertySource);
System.out.println("====加载外部配置文件" + property + "完毕====");
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(YzgEnvironmentPostProcessor.class,e);
}
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ package com.yanzuoguang.cloud.excel;
import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.excel.*;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -132,7 +133,7 @@ public class ExcelHttp<T> extends ExcelConsole<T> {
// 等待下载模式,下载文件
excel.down(response);
} catch (IOException e) {
e.printStackTrace();
ExceptionHelper.PrintError(ExcelConsole.class, e);
throw YzgError.getRuntimeException(e, "045", e.getMessage());
} finally {
// 删除生成的临时文件
......
......@@ -4,6 +4,7 @@ import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.CheckerHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -533,7 +534,7 @@ public class ExcelConsole<T> implements DbRow<T> {
workbook.write(out);
out.flush();
} catch (IOException e) {
e.printStackTrace();
ExceptionHelper.PrintError(ExcelConsole.class, e);
throw YzgError.getRuntimeException("035");
}
// 判断临时文件是否存在
......
......@@ -66,10 +66,8 @@ public class YzgFileConsumer implements InitializingBean {
try {
fileService.removeTempFolder(tempFolder);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.removeTempFolder(tempFolder);
} finally {
......@@ -90,10 +88,8 @@ public class YzgFileConsumer implements InitializingBean {
YzgFileMoveReqVo req = JsonHelper.deserialize(json, YzgFileMoveReqVo.class);
fileService.moveFile(req);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.moveFile(json, 60 * 1000);
} finally {
......@@ -129,10 +125,8 @@ public class YzgFileConsumer implements InitializingBean {
fileProcedure.convertImage(req);
}
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.convertImage(json, 60 * 1000);
} finally {
......@@ -168,10 +162,8 @@ public class YzgFileConsumer implements InitializingBean {
fileProcedure.convertVideo(req);
}
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.convertVideo(json, 60 * 1000);
} finally {
......@@ -196,10 +188,8 @@ public class YzgFileConsumer implements InitializingBean {
}
excelService.fileCreate(json, fileReq);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.fileCreateDelay(json);
} finally {
......@@ -223,10 +213,8 @@ public class YzgFileConsumer implements InitializingBean {
}
excelService.updateStatus(fileReq);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgFileConsumer.class, ex);
fileProcedure.fileStatus(json);
} finally {
......
package com.yanzuoguang.media;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
......@@ -168,7 +169,7 @@ public class HlsDownloader {
content.append("\n");
}
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(HlsDownloader.class,e);
}
return content.toString();
}
......@@ -213,7 +214,7 @@ public class HlsDownloader {
HttpHelper.downToLocal(serverTsUrl, localTs);
} catch (Exception e) {
// 判断文件是否下载失败
e.printStackTrace();
ExceptionHelper.PrintError(HlsDownloader.class,e);
}
}
......
......@@ -2,6 +2,7 @@ package com.yanzuoguang.media;
import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
......@@ -118,7 +119,7 @@ public class MediaFirst {
break;
}
} catch (Exception ex) {
ex.printStackTrace();
ExceptionHelper.PrintError(MediaFirst.class, ex);
}
ThreadHelper.sleep(res.getSplit());
} while (!isFinish(req));
......
......@@ -68,7 +68,6 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem
System.out.println("丢失消息:" + ack + " msg:" + cause);
}
} catch (Exception ex) {
ex.printStackTrace();
Log.error(MqConfigurable.class, ex);
}
}
......@@ -94,7 +93,6 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem
// 写入数据库
messageSendService.onError(messageVo);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(MqConfigurable.class, ex);
}
}
......
......@@ -8,6 +8,7 @@ import com.yanzuoguang.mq.vo.MessagePlan;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.log.Log;
import org.springframework.amqp.core.Message;
......@@ -38,9 +39,9 @@ public class YzgMqConsumer {
/**
* MQ回调
*
* @param json
* @param message
* @param channel
* @param json 字符串
* @param message 消息
* @param channel 频道
*/
@RabbitListener(queues = {YzgMqProcedure.YZG_MQ_SYSTEM_QUEUE}, concurrency = "10")
public void yzgMqSystemQueue(String json, Message message, Channel channel) {
......@@ -49,10 +50,8 @@ public class YzgMqConsumer {
req = JsonHelper.deserialize(json, MessageVo.class);
yzgMqProcedure.send(req, true);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
// 等待100ms再次执行
yzgMqProcedure.sendDelay(req, 100);
......@@ -65,9 +64,9 @@ public class YzgMqConsumer {
/**
* MQ回调
*
* @param json
* @param message
* @param channel
* @param json 字符串
* @param message 消息
* @param channel 频道
*/
@RabbitListener(queues = {YzgMqProcedure.YZG_MQ_SYSTEM_QUEUE_PLAN}, concurrency = "10")
public void yzgMqSystemQueuePlan(String json, Message message, Channel channel) {
......@@ -76,10 +75,8 @@ public class YzgMqConsumer {
req = JsonHelper.deserialize(json, MessagePlan.class);
yzgMqProcedure.sendDelay(req);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
// 等待100ms再次执行
yzgMqProcedure.sendDelay(req, 100);
......@@ -91,9 +88,9 @@ public class YzgMqConsumer {
/**
* 删除token回调
*
* @param json
* @param message
* @param channel
* @param json 字符串
* @param message 消息
* @param channel 频道
*/
@RabbitListener(queues = {YzgMqProcedure.YZG_MQ_CLEAR_TOKEN_QUEUE})
public void yzgMqClearTokenQueue(String json, Message message, Channel channel) {
......@@ -101,10 +98,8 @@ public class YzgMqConsumer {
RegisterServerTokenReqVo req = JsonHelper.deserialize(json, RegisterServerTokenReqVo.class);
messageServerService.removeServerToken(req);
} catch (CodeException ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(YzgMqConsumer.class, ex);
// 等待100ms再次执行
yzgMqProcedure.sendRemove(json, 100);
......@@ -116,9 +111,9 @@ public class YzgMqConsumer {
/**
* 删除日期
*
* @param day
* @param message
* @param channel
* @param day 日期
* @param message 消息
* @param channel 频道
*/
@RabbitListener(queues = {YzgMqProcedure.YZG_CLEAR_LOG})
public void yzgClearLog(String day, Message message, Channel channel) {
......
......@@ -149,7 +149,6 @@ public class MessageSendServiceImpl implements MessageSendService {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
} catch (IOException e) {
e.printStackTrace();
Log.error(MessageSendServiceImpl.class, e);
}
}
......
......@@ -192,7 +192,6 @@ public class MessageServeServiceImpl implements MessageServerService, Initializi
});
sendServerMessage(msg);
} catch (Exception ex) {
ex.printStackTrace();
Log.error(MessageServeServiceImpl.class, ex);
} finally {
messageSendService.basicAck(message, channel);
......@@ -264,7 +263,6 @@ public class MessageServeServiceImpl implements MessageServerService, Initializi
}
} catch (Exception ex) {
Log.error(MessageServeServiceImpl.class, ex);
ex.printStackTrace();
}
if (sendQueueName.isEmpty()) {
......
......@@ -132,10 +132,8 @@ public class MqServiceImpl implements MqService {
try {
consumerMessage.accept(message);
} catch (CodeException e) {
e.printStackTrace();
Log.error(MqServiceImpl.class, e);
} catch (Exception e) {
e.printStackTrace();
Log.error(MqServiceImpl.class, e);
if (StringHelper.isEmpty(exchangeName, routeKey)) {
return;
......
......@@ -3,6 +3,7 @@ package com.yanzuoguang.mq.service.impl;
import com.yanzuoguang.mq.dao.BeanDao;
import com.yanzuoguang.mq.service.QueueService;
import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.stereotype.Component;
......@@ -97,7 +98,7 @@ public class QueueServiceImpl implements QueueService {
}
} catch (Exception ex) {
this.queue.add(vo);
ex.printStackTrace();
ExceptionHelper.PrintError(QueueServiceImpl.class, ex);
ThreadHelper.sleep(5000);
}
}
......
package com.yanzuoguang.wxxcx.utils;
import com.yanzuoguang.util.exception.ExceptionHelper;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Base64;
......@@ -58,7 +59,7 @@ public class WeChatUtil {
// 初始化cipher
cipher = Cipher.getInstance(ALGORITHM_STR, "BC");
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(WeChatUtil.class,e);
}
}
......@@ -77,7 +78,7 @@ public class WeChatUtil {
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivs));
encryptedText = cipher.doFinal(encryptedData);
} catch (Exception e) {
e.printStackTrace();
ExceptionHelper.PrintError(WeChatUtil.class,e);
}
return encryptedText;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment