Browse Source

Merge branch 'wxz_feign_exception_show' into release_temp

# Conflicts:
#	epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/ExceptionUtils.java
master
wxz 4 years ago
parent
commit
7dde76735f
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/ExceptionUtils.java
  2. 4
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java
  3. 2
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBack.java
  4. 20
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBackFactory.java
  5. 7
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java
  6. 5
      epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/GovAccessFeignClient.java
  7. 2
      epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallBack.java
  8. 28
      epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallBackFactory.java

12
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/ExceptionUtils.java

@ -25,22 +25,16 @@ public class ExceptionUtils {
* @return 返回异常信息 * @return 返回异常信息
*/ */
public static String getErrorStackTrace(Exception ex){ public static String getErrorStackTrace(Exception ex){
return getErrorStackTraceOfThrowable(ex); return getThrowableErrorStackTrace(ex);
} }
/** public static String getThrowableErrorStackTrace(Throwable ex) {
* @Description Throwable级别的错误信息
* @return
* @author wxz
* @date 2021.07.07 14:37
*/
public static String getErrorStackTraceOfThrowable(Throwable t) {
StringWriter sw = null; StringWriter sw = null;
PrintWriter pw = null; PrintWriter pw = null;
try { try {
sw = new StringWriter(); sw = new StringWriter();
pw = new PrintWriter(sw, true); pw = new PrintWriter(sw, true);
t.printStackTrace(pw); ex.printStackTrace(pw);
}finally { }finally {
try { try {
if(pw != null) { if(pw != null) {

4
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java

@ -8,6 +8,7 @@ import com.epmet.dto.group.form.GroupStatsFormDTO;
import com.epmet.dto.screen.form.InitCustomerIndexForm; import com.epmet.dto.screen.form.InitCustomerIndexForm;
import com.epmet.dto.stats.form.CustomerIdAndDateIdFormDTO; import com.epmet.dto.stats.form.CustomerIdAndDateIdFormDTO;
import com.epmet.feign.impl.DataStatisticalOpenFeignClientFallBack; import com.epmet.feign.impl.DataStatisticalOpenFeignClientFallBack;
import com.epmet.feign.impl.DataStatisticalOpenFeignClientFallBackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -20,7 +21,8 @@ import org.springframework.web.bind.annotation.RequestBody;
* @author: jianjun liu * @author: jianjun liu
*/ */
//url="http://localhost:8108" //url="http://localhost:8108"
@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallback = DataStatisticalOpenFeignClientFallBack.class) //@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallback = DataStatisticalOpenFeignClientFallBack.class, url = "http://localhost:6666")
@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallbackFactory = DataStatisticalOpenFeignClientFallBackFactory.class)
public interface DataStatisticalOpenFeignClient { public interface DataStatisticalOpenFeignClient {
/** /**

2
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBack.java

@ -19,7 +19,7 @@ import org.springframework.stereotype.Component;
* @author: jianjun liu * @author: jianjun liu
* email:liujianjun@git.elinkit.com.cn * email:liujianjun@git.elinkit.com.cn
*/ */
@Component //@Component
public class DataStatisticalOpenFeignClientFallBack implements DataStatisticalOpenFeignClient { public class DataStatisticalOpenFeignClientFallBack implements DataStatisticalOpenFeignClient {
/** /**

20
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBackFactory.java

@ -0,0 +1,20 @@
package com.epmet.feign.impl;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DataStatisticalOpenFeignClientFallBackFactory implements FallbackFactory<DataStatisticalOpenFeignClient> {
private DataStatisticalOpenFeignClientFallBack fallback = new DataStatisticalOpenFeignClientFallBack();
@Override
public DataStatisticalOpenFeignClient create(Throwable cause) {
log.error(ExceptionUtils.getThrowableErrorStackTrace(cause));//自己写的工具类
return fallback;
}
}

7
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java

@ -8,8 +8,10 @@
package com.epmet.controller; package com.epmet.controller;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -24,10 +26,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("demo") @RequestMapping("demo")
@Api(tags="定时任务") @Api(tags="定时任务")
public class DemoController { public class DemoController {
@Autowired
private DataStatisticalOpenFeignClient client;
@GetMapping("testAlarm") @GetMapping("testAlarm")
public void testAlarm() { public void testAlarm() {
//for (int i = 0; i < 20; i++) { //for (int i = 0; i < 20; i++) {
log.error("测试消息"); log.error("测试消息");
//} //}
client.agencyGridIssueStats(null);
} }
} }

5
epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/GovAccessFeignClient.java

@ -4,7 +4,7 @@ import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.InitDefaultOperationsFormDTO; import com.epmet.dto.form.InitDefaultOperationsFormDTO;
import com.epmet.dto.form.ListOpePermsFormDTO; import com.epmet.dto.form.ListOpePermsFormDTO;
import com.epmet.feign.fallback.GovAccessFeignClientFallBack; import com.epmet.feign.fallback.GovAccessFeignClientFallBackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -12,7 +12,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import java.util.Set; import java.util.Set;
//@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallBack.class, url = "http://localhost:8099") //@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallBack.class, url = "http://localhost:8099")
@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallBack.class) //@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallBack.class)
@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallbackFactory = GovAccessFeignClientFallBackFactory.class)
public interface GovAccessFeignClient { public interface GovAccessFeignClient {
/** /**

2
epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallBack.java

@ -14,7 +14,7 @@ import java.util.Set;
* @Description * @Description
* @Author sun * @Author sun
*/ */
@Component //@Component
public class GovAccessFeignClientFallBack implements GovAccessFeignClient { public class GovAccessFeignClientFallBack implements GovAccessFeignClient {

28
epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallBackFactory.java

@ -0,0 +1,28 @@
package com.epmet.feign.fallback;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.feign.GovAccessFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @Description fallBackFactory用于抛出异常之后返回一个Fallback降级处理对象
* @author wxz
* @date 2021.07.15 09:54:14
*/
@Component
@Slf4j
public class GovAccessFeignClientFallBackFactory implements FallbackFactory<GovAccessFeignClient> {
/**
* 降级处理对象
*/
private GovAccessFeignClientFallBack fallBack = new GovAccessFeignClientFallBack();
@Override
public GovAccessFeignClient create(Throwable cause) {
log.error(ExceptionUtils.getThrowableErrorStackTrace(cause));
return fallBack;
}
}
Loading…
Cancel
Save