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/12 13:28:11 UTC
[incubator-shenyu] branch master updated: add AOP test for shenyu-client-alibaba-dubbo (#3539)
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 b2b5f6f48 add AOP test for shenyu-client-alibaba-dubbo (#3539)
b2b5f6f48 is described below
commit b2b5f6f48ae0e9840b795e8e045a65b1f61b0836
Author: weihubeats <we...@163.com>
AuthorDate: Sun Jun 12 21:28:06 2022 +0800
add AOP test for shenyu-client-alibaba-dubbo (#3539)
---
.../alibaba/dubbo/service/annotation/aop/Log.java | 26 ++++++++++++
.../service/annotation/aop/LogInterceptor.java | 48 ++++++++++++++++++++++
.../annotation/impl/DubboTestServiceImpl.java | 2 +
.../examples/alibaba/dubbo/service/aop/Log.java | 26 ++++++++++++
.../alibaba/dubbo/service/aop/LogInterceptor.java | 48 ++++++++++++++++++++++
.../dubbo/service/impl/DubboTestServiceImpl.java | 2 +
.../cloud/dubbo/service/annotation/aop/Log.java | 26 ++++++++++++
.../service/annotation/aop/LogInterceptor.java | 48 ++++++++++++++++++++++
.../service/annotation/impl/TestServiceImpl.java | 2 +
9 files changed, 228 insertions(+)
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/aop/Log.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/aop/Log.java
new file mode 100644
index 000000000..905dc1875
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/aop/Log.java
@@ -0,0 +1,26 @@
+/*
+ * 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.alibaba.dubbo.service.annotation.aop;
+
+import java.lang.annotation.*;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Log {
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/aop/LogInterceptor.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/aop/LogInterceptor.java
new file mode 100644
index 000000000..52b47a6bb
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/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.alibaba.dubbo.service.annotation.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.alibaba.dubbo.service.annotation.aop.Log)")
+ public void logPointcut() {
+ //just for pointcut
+ }
+
+ @Around("logPointcut()")
+ public Object around(ProceedingJoinPoint point) throws Throwable {
+ try {
+ log.info("before");
+ return point.proceed(point.getArgs());
+ } finally {
+ log.info("after");
+ }
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboTestServiceImpl.java
index 2b5690e40..0beefed85 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboTestServiceImpl.java
@@ -18,6 +18,7 @@ package org.apache.shenyu.examples.alibaba.dubbo.service.annotation.impl;
import com.alibaba.dubbo.config.annotation.Service;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
+import org.apache.shenyu.examples.alibaba.dubbo.service.annotation.aop.Log;
import org.apache.shenyu.examples.dubbo.api.entity.DubboTest;
import org.apache.shenyu.examples.dubbo.api.entity.ListResp;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestService;
@@ -33,6 +34,7 @@ public class DubboTestServiceImpl implements DubboTestService {
@Override
@ShenyuDubboClient("/findById")
+ @Log
public DubboTest findById(final String id) {
return new DubboTest(id, "hello world shenyu Alibaba Dubbo, findById");
}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/aop/Log.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/aop/Log.java
new file mode 100644
index 000000000..99f22a64c
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/aop/Log.java
@@ -0,0 +1,26 @@
+/*
+ * 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.alibaba.dubbo.service.aop;
+
+import java.lang.annotation.*;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Log {
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/aop/LogInterceptor.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/aop/LogInterceptor.java
new file mode 100644
index 000000000..076de2d9b
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/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.alibaba.dubbo.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.alibaba.dubbo.service.aop.Log)")
+ public void logPointcut() {
+ //just for pointcut
+ }
+
+ @Around("logPointcut()")
+ public Object around(ProceedingJoinPoint point) throws Throwable {
+ try {
+ log.info("before");
+ return point.proceed(point.getArgs());
+ } finally {
+ log.info("after");
+ }
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboTestServiceImpl.java
index d92cbb80b..cfa1a468f 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboTestServiceImpl.java
@@ -17,6 +17,7 @@
package org.apache.shenyu.examples.alibaba.dubbo.service.impl;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
+import org.apache.shenyu.examples.alibaba.dubbo.service.aop.Log;
import org.apache.shenyu.examples.dubbo.api.entity.DubboTest;
import org.apache.shenyu.examples.dubbo.api.entity.ListResp;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestService;
@@ -33,6 +34,7 @@ public class DubboTestServiceImpl implements DubboTestService {
@Override
@ShenyuDubboClient("/findById")
+ @Log
public DubboTest findById(final String id) {
return new DubboTest(id, "hello world shenyu Alibaba Dubbo, findById");
}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/aop/Log.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/aop/Log.java
new file mode 100644
index 000000000..79d83ab77
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/aop/Log.java
@@ -0,0 +1,26 @@
+/*
+ * 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.spring.cloud.dubbo.service.annotation.aop;
+
+import java.lang.annotation.*;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Log {
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/aop/LogInterceptor.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/aop/LogInterceptor.java
new file mode 100644
index 000000000..967f8b4eb
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/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.spring.cloud.dubbo.service.annotation.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.spring.cloud.dubbo.service.annotation.aop.Log)")
+ public void logPointcut() {
+ //just for pointcut
+ }
+
+ @Around("logPointcut()")
+ public Object around(ProceedingJoinPoint point) throws Throwable {
+ try {
+ log.info("before");
+ return point.proceed(point.getArgs());
+ } finally {
+ log.info("after");
+ }
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/impl/TestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/impl/TestServiceImpl.java
index 939928b39..4b0da634d 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/impl/TestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-spring-cloud-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/spring/cloud/dubbo/service/annotation/impl/TestServiceImpl.java
@@ -21,6 +21,7 @@ import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.examples.dubbo.api.entity.DubboTest;
import org.apache.shenyu.examples.dubbo.api.entity.ListResp;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestService;
+import org.apache.shenyu.examples.spring.cloud.dubbo.service.annotation.aop.Log;
import java.util.Collections;
import java.util.Random;
@@ -33,6 +34,7 @@ public class TestServiceImpl implements DubboTestService {
@Override
@ShenyuDubboClient("/findById")
+ @Log
public DubboTest findById(final String id) {
return new DubboTest(id, "hello world shenyu Apache, findById");
}