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/13 12:06:51 UTC

[incubator-shenyu] branch master updated: [ISSUE 3523] task6 aop test case for motan (#3545)

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 e265be8f5 [ISSUE 3523] task6 aop test case for motan (#3545)
e265be8f5 is described below

commit e265be8f50ff0d2477699a919b70ea8f57e585b4
Author: sunshujie1990 <tj...@163.com>
AuthorDate: Mon Jun 13 20:06:46 2022 +0800

    [ISSUE 3523] task6 aop test case for motan (#3545)
---
 .../shenyu-examples-motan-service/pom.xml          |  4 ++
 .../shenyu/examples/motan/service/aop/Log.java     | 30 ++++++++++++++
 .../examples/motan/service/aop/LogInterceptor.java | 48 ++++++++++++++++++++++
 .../motan/service/impl/MotanDemoServiceImpl.java   |  2 +
 4 files changed, 84 insertions(+)

diff --git a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/pom.xml b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/pom.xml
index f3dc09252..fec742eef 100644
--- a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/pom.xml
+++ b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/pom.xml
@@ -37,6 +37,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
diff --git a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/aop/Log.java b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/aop/Log.java
new file mode 100644
index 000000000..b4f3a7a8a
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/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.motan.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 {
+}
\ No newline at end of file
diff --git a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/aop/LogInterceptor.java b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/aop/LogInterceptor.java
new file mode 100644
index 000000000..896978073
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/aop/LogInterceptor.java
@@ -0,0 +1,48 @@
+/*
+ * 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.motan.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.motan.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-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
index 2598d0b4d..fb07cf611 100644
--- a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
@@ -20,6 +20,7 @@ package org.apache.shenyu.examples.motan.service.impl;
 import com.weibo.api.motan.config.springsupport.annotation.MotanService;
 import org.apache.shenyu.client.motan.common.annotation.ShenyuMotanClient;
 import org.apache.shenyu.examples.motan.service.MotanDemoService;
+import org.apache.shenyu.examples.motan.service.aop.Log;
 
 /**
  * Motan demo service.
@@ -30,6 +31,7 @@ public class MotanDemoServiceImpl implements MotanDemoService {
 
     @Override
     @ShenyuMotanClient("/hello")
+    @Log
     public String hello(final String name) {
         return "hello " + name;
     }