You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2022/06/15 00:50:18 UTC

[incubator-shenyu] branch master updated: fix issue #3523 (#3563)

This is an automated email from the ASF dual-hosted git repository.

zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 297b8d53c fix issue #3523 (#3563)
297b8d53c is described below

commit 297b8d53ceedc75aaa8b7669442db7df2620fa7d
Author: ShawnSiao <xi...@qq.com>
AuthorDate: Wed Jun 15 08:50:09 2022 +0800

    fix issue #3523 (#3563)
---
 .../shenyu-examples-sofa-service/pom.xml           |  5 ++-
 .../shenyu/examples/sofa/service/aop/Log.java      | 30 +++++++++++++
 .../examples/sofa/service/aop/LogInterceptor.java  | 49 ++++++++++++++++++++++
 .../service/impl/SofaSingleParamServiceImpl.java   |  2 +
 4 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
index 61014c3f5..d6f37201a 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
@@ -102,7 +102,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.micrometer</groupId>
             <artifactId>micrometer-core</artifactId>
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/Log.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/Log.java
new file mode 100644
index 000000000..7cc2b27d3
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/Log.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.examples.sofa.service.aop;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Log {
+}
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/LogInterceptor.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/LogInterceptor.java
new file mode 100644
index 000000000..c6b52206c
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/aop/LogInterceptor.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.examples.sofa.service.aop;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+public class LogInterceptor {
+    
+    private static final Logger log = LoggerFactory.getLogger(LogInterceptor.class);
+    
+    @Pointcut("@annotation(org.apache.shenyu.examples.sofa.service.aop.Log)")
+    public void logPointcut() {
+        //just for pointcut
+    }
+    
+    @Around("logPointcut()")
+    public Object around(final ProceedingJoinPoint point) throws Throwable {
+        try {
+            log.info("before");
+            return point.proceed(point.getArgs());
+        } finally {
+            log.info("after");
+        }
+    }
+}
+
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
index 7e266aaf0..16399f897 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
@@ -20,6 +20,7 @@ package org.apache.shenyu.examples.sofa.service.impl;
 import org.apache.shenyu.client.sofa.common.annotation.ShenyuSofaClient;
 import org.apache.shenyu.examples.sofa.api.entity.SofaSimpleTypeBean;
 import org.apache.shenyu.examples.sofa.api.service.SofaSingleParamService;
+import org.apache.shenyu.examples.sofa.service.aop.Log;
 import org.springframework.stereotype.Service;
 
 import java.util.Random;
@@ -32,6 +33,7 @@ public class SofaSingleParamServiceImpl implements SofaSingleParamService {
 
     @Override
     @ShenyuSofaClient("/findById")
+    @Log
     public SofaSimpleTypeBean findById(final String id) {
         return new SofaSimpleTypeBean(id, "hello world shenyu Sofa, findById");
     }