From fe55285e9c9fef5e80c2d6e827e92ef5545e7546 Mon Sep 17 00:00:00 2001 From: Rivers-Shall Date: Tue, 20 Aug 2019 20:53:57 +0800 Subject: [PATCH] Replace native method invoke with `methodInvoke` --- .../custom/SentinelProtectInterceptor.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java index fd91016e..7b370264 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java @@ -69,19 +69,9 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor sentinelRestTemplate.urlCleanerClass(), sentinelRestTemplate.urlCleaner()); if (urlCleanerMethod != null) { - try { - hostWithPathResource = (String) urlCleanerMethod.invoke(null, - hostWithPathResource); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + hostWithPathResource = (String) methodInvoke(urlCleanerMethod, + hostWithPathResource); } - System.out.println("hostWithPathResource: " + hostWithPathResource); - System.out.println("entryWithPath: " + entryWithPath); Entry hostEntry = null, hostWithPathEntry = null; ClientHttpResponse response = null; @@ -123,7 +113,7 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor Method fallbackMethod = extractFallbackMethod(sentinelRestTemplate.fallback(), sentinelRestTemplate.fallbackClass()); if (fallbackMethod != null) { - return methodInvoke(fallbackMethod, args); + return (ClientHttpResponse) methodInvoke(fallbackMethod, args); } else { return new SentinelClientHttpResponse(); @@ -134,16 +124,16 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor sentinelRestTemplate.blockHandler(), sentinelRestTemplate.blockHandlerClass()); if (blockHandler != null) { - return methodInvoke(blockHandler, args); + return (ClientHttpResponse) methodInvoke(blockHandler, args); } else { return new SentinelClientHttpResponse(); } } - private ClientHttpResponse methodInvoke(Method method, Object... args) { + private Object methodInvoke(Method method, Object... args) { try { - return (ClientHttpResponse) method.invoke(null, args); + return method.invoke(null, args); } catch (IllegalAccessException e) { throw new RuntimeException(e);