This is an automated email from the ASF dual-hosted git repository.
tianpengfei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 701a11d43 [type: refactor] add ExtractorProcessor (#4858)
701a11d43 is described below
commit 701a11d43a801755604c796665afa41e3fd120da
Author: likeguo <[email protected]>
AuthorDate: Mon Jul 17 09:19:13 2023 +0800
[type: refactor] add ExtractorProcessor (#4858)
* feature/register
* feature/register
* feature/extractor-processor
* feature/extractor-processor
* feature/extractor-processor
* feature/extractor-processor
---------
Co-authored-by: tiandy tian <[email protected]>
---
.../extractor/BaseAnnotationApiBeansExtractor.java | 60 +++++++++++++-
...iProcessor.java => ApiAnnotationProcessor.java} | 64 +++++++++------
.../core/register/matcher/ApiDocProcessorImpl.java | 6 +-
.../matcher/BaseAnnotationApiProcessor.java | 25 +-----
...cProcessorImpl.java => ExtractorProcessor.java} | 36 ++++-----
.../apache/dubbo/ApacheDubboApiBeansExtractor.java | 48 +++++++++++
.../processor/extractor/DubboServiceProcessor.java | 91 +++++++++++++++++++++
.../processor/extractor/ServiceProcessor.java} | 28 +++----
.../processor/register/ShenyuDubboProcessor.java} | 31 ++++---
.../extractor/RequestMappingProcessor.java | 71 ++++++++++++++++
.../register/SpringCloudApiBeansExtractor.java | 94 ++--------------------
.../extractor/RequestMappingProcessor.java | 72 +++++++++++++++++
.../ShenyuSpringMvcClientProcessorImpl.java | 8 +-
.../register/SpringMvcApiBeansExtractor.java | 84 ++-----------------
14 files changed, 440 insertions(+), 278 deletions(-)
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/extractor/BaseAnnotationApiBeansExtractor.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/extractor/BaseAnnotationApiBeansExtractor.java
index d89d41b5b..9004713e2 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/extractor/BaseAnnotationApiBeansExtractor.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/extractor/BaseAnnotationApiBeansExtractor.java
@@ -17,12 +17,15 @@
package org.apache.shenyu.client.core.register.extractor;
+import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ExtractorProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.NonNull;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -34,6 +37,12 @@ import java.util.stream.Collectors;
*/
public abstract class BaseAnnotationApiBeansExtractor extends
BaseApiBeansExtractor implements RpcApiBeansExtractor {
+ private final List<Class<? extends Annotation>> supportedApiAnnotations =
new ArrayList<>(1);
+
+ private final List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations = new ArrayList<>(1);
+
+ private final List<ExtractorProcessor> extractorProcessors = new
ArrayList<>(1);
+
@Override
protected Map<String, Object> extractSupportBeans(final ApplicationContext
applicationContext) {
return supportedApiAnnotations().stream()
@@ -53,13 +62,31 @@ public abstract class BaseAnnotationApiBeansExtractor
extends BaseApiBeansExtrac
.collect(Collectors.toList());
}
+ @Override
+ protected void apiPostProcess(final ApiBean api) {
+ for (ExtractorProcessor apiAnnotationProcessor : extractorProcessors) {
+ apiAnnotationProcessor.process(api);
+ }
+ super.apiPostProcess(api);
+ }
+
+ @Override
+ protected void definitionPostProcess(final ApiBean.ApiDefinition
apiDefinition) {
+ for (ExtractorProcessor apiAnnotationProcessor : extractorProcessors) {
+ apiAnnotationProcessor.process(apiDefinition);
+ }
+ super.definitionPostProcess(apiDefinition);
+ }
+
/**
* Supported annotations.
*
* @return class
*/
@NonNull
- protected abstract List<Class<? extends Annotation>>
supportedApiAnnotations();
+ protected List<Class<? extends Annotation>> supportedApiAnnotations() {
+ return supportedApiAnnotations;
+ }
/**
* Supported annotations.
@@ -67,6 +94,35 @@ public abstract class BaseAnnotationApiBeansExtractor
extends BaseApiBeansExtrac
* @return class
*/
@NonNull
- protected abstract List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations();
+ protected List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations() {
+ return supportedApiDefinitionAnnotations;
+ }
+
+ /**
+ * addExtractorProcessor.
+ *
+ * @param processor processor.
+ */
+ public void addExtractorProcessor(final ExtractorProcessor processor) {
+ extractorProcessors.add(processor);
+ }
+
+ /**
+ * addSupportedApiDefinitionAnnotations.
+ *
+ * @param annotation annotation
+ */
+ public void addSupportedApiDefinitionAnnotations(final Class<? extends
Annotation> annotation) {
+ supportedApiDefinitionAnnotations.add(annotation);
+ }
+
+ /**
+ * addSupportedApiAnnotations.
+ *
+ * @param annotation annotation
+ */
+ public void addSupportedApiAnnotations(final Class<? extends Annotation>
annotation) {
+ supportedApiAnnotations.add(annotation);
+ }
}
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiAnnotationProcessor.java
similarity index 57%
copy from
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
copy to
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiAnnotationProcessor.java
index c8be36037..fc93b1872 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiAnnotationProcessor.java
@@ -23,23 +23,21 @@ import java.lang.annotation.Annotation;
import java.util.Objects;
/**
- * BaseAnnotationApiProcessor.<br>
- * API processor that supports annotations.
+ * ApiAnnotationProcessor.
*/
-public abstract class BaseAnnotationApiProcessor<T extends Annotation>
implements ApiProcessor {
+public interface ApiAnnotationProcessor<T extends Annotation> extends
ExtractorProcessor {
+ /**
+ * process.
+ *
+ * @param apiBean apiBean
+ */
@Override
- public void process(final ApiBean apiBean) {
- final T annotation = apiBean.getAnnotation(matchAnnotation());
- if (match(apiBean) && Objects.nonNull(annotation)) {
+ default void process(ApiBean apiBean) {
+ T annotation = getAnnotation(apiBean);
+ if (Objects.nonNull(annotation)) {
process(apiBean, annotation);
}
- for (ApiBean.ApiDefinition definition : apiBean.getApiDefinitions()) {
- final T definitionAnnotation =
definition.getAnnotation(matchAnnotation());
- if (match(definition) && Objects.nonNull(definitionAnnotation)) {
- process(definition, definitionAnnotation);
- }
- }
}
/**
@@ -48,7 +46,7 @@ public abstract class BaseAnnotationApiProcessor<T extends
Annotation> implement
* @param apiBean apiBean
* @param annotation annotation
*/
- protected abstract void process(ApiBean apiBean, T annotation);
+ void process(ApiBean apiBean, T annotation);
/**
* process API.
@@ -56,27 +54,45 @@ public abstract class BaseAnnotationApiProcessor<T extends
Annotation> implement
* @param definition definition
* @param annotation annotation
*/
- protected abstract void process(ApiBean.ApiDefinition definition, T
annotation);
+ void process(ApiBean.ApiDefinition definition, T annotation);
/**
- * support annotation.
+ * process.
*
- * @return annotation
+ * @param definition definition
*/
- protected abstract Class<T> matchAnnotation();
-
@Override
- public boolean match(final ApiBean element) {
- return false;
+ default void process(ApiBean.ApiDefinition definition) {
+ T annotation = getAnnotation(definition);
+ if (Objects.nonNull(annotation)) {
+ process(definition, annotation);
+ }
+ }
+
+ /**
+ * getAnnotation.
+ *
+ * @param apiBean apiBean
+ * @return t
+ */
+ default T getAnnotation(ApiBean apiBean) {
+ return apiBean.getAnnotation(matchAnnotation());
}
/**
- * match.
+ * getAnnotation.
*
* @param definition definition
- * @return true
+ * @return Annotation
*/
- public boolean match(final ApiBean.ApiDefinition definition) {
- return false;
+ default T getAnnotation(ApiBean.ApiDefinition definition) {
+ return definition.getAnnotation(matchAnnotation());
}
+
+ /**
+ * support annotation.
+ *
+ * @return annotation
+ */
+ Class<T> matchAnnotation();
}
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
index ef03fff92..08e5912fb 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
@@ -29,21 +29,21 @@ import org.apache.shenyu.client.core.register.ApiBean;
public class ApiDocProcessorImpl extends BaseAnnotationApiProcessor<ApiDoc> {
@Override
- protected void process(final ApiBean apiBean, final ApiDoc annotation) {
+ public void process(final ApiBean apiBean, final ApiDoc annotation) {
apiBean.addProperties("desc", annotation.desc());
apiBean.addProperties("tags", String.join(",", annotation.tags()));
apiBean.setStatus(ApiBean.Status.REGISTRABLE_API);
}
@Override
- protected void process(final ApiBean.ApiDefinition definition, final
ApiDoc annotation) {
+ public void process(final ApiBean.ApiDefinition definition, final ApiDoc
annotation) {
definition.addProperties("desc", annotation.desc());
definition.addProperties("tags", String.join(",", annotation.tags()));
definition.setStatus(ApiBean.Status.REGISTRABLE);
}
@Override
- protected Class<ApiDoc> matchAnnotation() {
+ public Class<ApiDoc> matchAnnotation() {
return ApiDoc.class;
}
}
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
index c8be36037..adf380853 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/BaseAnnotationApiProcessor.java
@@ -26,7 +26,7 @@ import java.util.Objects;
* BaseAnnotationApiProcessor.<br>
* API processor that supports annotations.
*/
-public abstract class BaseAnnotationApiProcessor<T extends Annotation>
implements ApiProcessor {
+public abstract class BaseAnnotationApiProcessor<T extends Annotation>
implements ApiAnnotationProcessor<T>, ApiProcessor {
@Override
public void process(final ApiBean apiBean) {
@@ -42,29 +42,6 @@ public abstract class BaseAnnotationApiProcessor<T extends
Annotation> implement
}
}
- /**
- * process API Bean.
- *
- * @param apiBean apiBean
- * @param annotation annotation
- */
- protected abstract void process(ApiBean apiBean, T annotation);
-
- /**
- * process API.
- *
- * @param definition definition
- * @param annotation annotation
- */
- protected abstract void process(ApiBean.ApiDefinition definition, T
annotation);
-
- /**
- * support annotation.
- *
- * @return annotation
- */
- protected abstract Class<T> matchAnnotation();
-
@Override
public boolean match(final ApiBean element) {
return false;
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ExtractorProcessor.java
similarity index 50%
copy from
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
copy to
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ExtractorProcessor.java
index ef03fff92..b091af314 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ExtractorProcessor.java
@@ -17,33 +17,25 @@
package org.apache.shenyu.client.core.register.matcher;
-import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
import org.apache.shenyu.client.core.register.ApiBean;
/**
- * ApiDocProcessorImpl.<br>
- * About support for {@link ApiDoc} annotations
- *
- * @see ApiDoc
+ * ApiAnnotationProcessor.
*/
-public class ApiDocProcessorImpl extends BaseAnnotationApiProcessor<ApiDoc> {
+public interface ExtractorProcessor {
- @Override
- protected void process(final ApiBean apiBean, final ApiDoc annotation) {
- apiBean.addProperties("desc", annotation.desc());
- apiBean.addProperties("tags", String.join(",", annotation.tags()));
- apiBean.setStatus(ApiBean.Status.REGISTRABLE_API);
- }
+ /**
+ * process.
+ *
+ * @param apiBean apiBean
+ */
+ void process(ApiBean apiBean);
- @Override
- protected void process(final ApiBean.ApiDefinition definition, final
ApiDoc annotation) {
- definition.addProperties("desc", annotation.desc());
- definition.addProperties("tags", String.join(",", annotation.tags()));
- definition.setStatus(ApiBean.Status.REGISTRABLE);
- }
+ /**
+ * process.
+ *
+ * @param definition definition
+ */
+ void process(ApiBean.ApiDefinition definition);
- @Override
- protected Class<ApiDoc> matchAnnotation() {
- return ApiDoc.class;
- }
}
diff --git
a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboApiBeansExtractor.java
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboApiBeansExtractor.java
new file mode 100644
index 000000000..d67c65a8d
--- /dev/null
+++
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboApiBeansExtractor.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.client.apache.dubbo;
+
+import org.apache.dubbo.config.annotation.DubboService;
+import org.apache.dubbo.config.annotation.Service;
+import
org.apache.shenyu.client.apache.dubbo.processor.extractor.DubboServiceProcessor;
+import
org.apache.shenyu.client.apache.dubbo.processor.extractor.ServiceProcessor;
+import
org.apache.shenyu.client.apache.dubbo.processor.register.ShenyuDubboProcessor;
+import
org.apache.shenyu.client.core.register.extractor.BaseAnnotationApiBeansExtractor;
+import org.apache.shenyu.client.core.register.extractor.RpcApiBeansExtractor;
+import org.apache.shenyu.common.enums.RpcTypeEnum;
+
+public class ApacheDubboApiBeansExtractor extends
BaseAnnotationApiBeansExtractor implements RpcApiBeansExtractor {
+
+ public ApacheDubboApiBeansExtractor() {
+ // Annotations supported by class
+ addSupportedApiAnnotations(DubboService.class);
+ addSupportedApiAnnotations(Service.class);
+
+ // Annotations supported by the method
+
+ addExtractorProcessor(new DubboServiceProcessor());
+ addExtractorProcessor(new ServiceProcessor());
+ addExtractorProcessor(new ShenyuDubboProcessor());
+ }
+
+ @Override
+ public String clientName() {
+ return RpcTypeEnum.DUBBO.getName();
+ }
+
+}
diff --git
a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/DubboServiceProcessor.java
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/DubboServiceProcessor.java
new file mode 100644
index 000000000..8fa6773d7
--- /dev/null
+++
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/DubboServiceProcessor.java
@@ -0,0 +1,91 @@
+/*
+ * 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.client.apache.dubbo.processor.extractor;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.apache.dubbo.config.spring.ServiceBean;
+import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ApiAnnotationProcessor;
+import org.apache.shenyu.client.dubbo.common.dto.DubboRpcExt;
+import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.utils.GsonUtils;
+
+import java.util.Optional;
+
+import static org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT;
+
+/**
+ * DubboServiceProcessor.
+ */
+public class DubboServiceProcessor implements
ApiAnnotationProcessor<DubboService> {
+
+ @Override
+ public void process(final ApiBean apiBean, final DubboService annotation) {
+ apiBean.setBeanPath(annotation.path());
+
+ apiBean.addProperties("rpcExt", getRpcExt(apiBean));
+ }
+
+ @Override
+ public void process(final ApiBean.ApiDefinition definition) {
+ definition.addProperties("rpcExt", getRpcExt(definition));
+ }
+
+ @Override
+ public void process(final ApiBean.ApiDefinition definition, final
DubboService annotation) {
+ // nothing
+ }
+
+ @Override
+ public Class<DubboService> matchAnnotation() {
+ return DubboService.class;
+ }
+
+ private String getRpcExt(final ApiBean apiBean) {
+ final Object beanInstance = apiBean.getBeanInstance();
+ if (beanInstance instanceof ServiceBean) {
+ return getRpcExt((ServiceBean<?>) beanInstance);
+ }
+ return "{}";
+ }
+
+ private String getRpcExt(final ApiBean.ApiDefinition definition) {
+ final Object beanInstance = definition.getApiBean().getBeanInstance();
+ if (beanInstance instanceof ServiceBean) {
+ return getRpcExt((ServiceBean<?>) beanInstance);
+ }
+ return "{}";
+ }
+
+ private static String getRpcExt(final ServiceBean<?> serviceBean) {
+ DubboRpcExt build = DubboRpcExt.builder()
+
.protocol(StringUtils.isNotEmpty(serviceBean.getProtocol().getName()) ?
serviceBean.getProtocol().getName() : "")
+ .group(StringUtils.isNotEmpty(serviceBean.getGroup()) ?
serviceBean.getGroup() : "")
+ .version(StringUtils.isNotEmpty(serviceBean.getVersion()) ?
serviceBean.getVersion() : "")
+
.loadbalance(StringUtils.isNotEmpty(serviceBean.getLoadbalance()) ?
serviceBean.getLoadbalance() : CommonConstants.DEFAULT_LOADBALANCE)
+
.retries(Optional.ofNullable(serviceBean.getRetries()).orElse(CommonConstants.DEFAULT_RETRIES))
+
.timeout(Optional.ofNullable(serviceBean.getTimeout()).orElse(DEFAULT_CONNECT_TIMEOUT))
+
.sent(Optional.ofNullable(serviceBean.getSent()).orElse(Boolean.FALSE))
+ .cluster(StringUtils.isNotEmpty(serviceBean.getCluster()) ?
serviceBean.getCluster() : Constants.DEFAULT_CLUSTER)
+ .url("")
+ .build();
+ return GsonUtils.getInstance().toJson(build);
+ }
+}
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/ServiceProcessor.java
similarity index 50%
copy from
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
copy to
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/ServiceProcessor.java
index ef03fff92..42881598c 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
+++
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/extractor/ServiceProcessor.java
@@ -15,35 +15,29 @@
* limitations under the License.
*/
-package org.apache.shenyu.client.core.register.matcher;
+package org.apache.shenyu.client.apache.dubbo.processor.extractor;
-import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ApiAnnotationProcessor;
+import org.springframework.stereotype.Service;
/**
- * ApiDocProcessorImpl.<br>
- * About support for {@link ApiDoc} annotations
- *
- * @see ApiDoc
+ * ServiceProcessor.
*/
-public class ApiDocProcessorImpl extends BaseAnnotationApiProcessor<ApiDoc> {
+public class ServiceProcessor implements ApiAnnotationProcessor<Service> {
@Override
- protected void process(final ApiBean apiBean, final ApiDoc annotation) {
- apiBean.addProperties("desc", annotation.desc());
- apiBean.addProperties("tags", String.join(",", annotation.tags()));
- apiBean.setStatus(ApiBean.Status.REGISTRABLE_API);
+ public void process(final ApiBean apiBean, final Service annotation) {
+ apiBean.setBeanPath(annotation.value());
}
@Override
- protected void process(final ApiBean.ApiDefinition definition, final
ApiDoc annotation) {
- definition.addProperties("desc", annotation.desc());
- definition.addProperties("tags", String.join(",", annotation.tags()));
- definition.setStatus(ApiBean.Status.REGISTRABLE);
+ public void process(final ApiBean.ApiDefinition definition, final Service
annotation) {
+ // nothing
}
@Override
- protected Class<ApiDoc> matchAnnotation() {
- return ApiDoc.class;
+ public Class<Service> matchAnnotation() {
+ return Service.class;
}
}
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/register/ShenyuDubboProcessor.java
similarity index 50%
copy from
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
copy to
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/register/ShenyuDubboProcessor.java
index ef03fff92..7bdc4749f 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/matcher/ApiDocProcessorImpl.java
+++
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/processor/register/ShenyuDubboProcessor.java
@@ -15,35 +15,32 @@
* limitations under the License.
*/
-package org.apache.shenyu.client.core.register.matcher;
+package org.apache.shenyu.client.apache.dubbo.processor.register;
-import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ApiProcessor;
+import
org.apache.shenyu.client.core.register.matcher.BaseAnnotationApiProcessor;
+import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
/**
- * ApiDocProcessorImpl.<br>
- * About support for {@link ApiDoc} annotations
- *
- * @see ApiDoc
+ * ShenyuDubboProcessor.
*/
-public class ApiDocProcessorImpl extends BaseAnnotationApiProcessor<ApiDoc> {
+public class ShenyuDubboProcessor extends
BaseAnnotationApiProcessor<ShenyuDubboClient> implements ApiProcessor {
@Override
- protected void process(final ApiBean apiBean, final ApiDoc annotation) {
- apiBean.addProperties("desc", annotation.desc());
- apiBean.addProperties("tags", String.join(",", annotation.tags()));
- apiBean.setStatus(ApiBean.Status.REGISTRABLE_API);
+ public void process(final ApiBean apiBean, final ShenyuDubboClient
annotation) {
+ apiBean.setBeanPath(annotation.path().replace("*", ""));
+
}
@Override
- protected void process(final ApiBean.ApiDefinition definition, final
ApiDoc annotation) {
- definition.addProperties("desc", annotation.desc());
- definition.addProperties("tags", String.join(",", annotation.tags()));
- definition.setStatus(ApiBean.Status.REGISTRABLE);
+ public void process(final ApiBean.ApiDefinition definition, final
ShenyuDubboClient annotation) {
+ definition.setMethodPath(annotation.path());
+
}
@Override
- protected Class<ApiDoc> matchAnnotation() {
- return ApiDoc.class;
+ public Class<ShenyuDubboClient> matchAnnotation() {
+ return ShenyuDubboClient.class;
}
}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/proceeor/extractor/RequestMappingProcessor.java
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/proceeor/extractor/RequestMappingProcessor.java
new file mode 100644
index 000000000..87bcd252c
--- /dev/null
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/proceeor/extractor/RequestMappingProcessor.java
@@ -0,0 +1,71 @@
+/*
+ * 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.client.springcloud.proceeor.extractor;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ApiAnnotationProcessor;
+import org.springframework.lang.NonNull;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.Objects;
+
+/**
+ * RequestMappingProcessor.
+ */
+public class RequestMappingProcessor implements
ApiAnnotationProcessor<RequestMapping> {
+ @Override
+ public void process(final ApiBean api, final RequestMapping annotation) {
+
+ String beanPath = Objects.isNull(annotation) ? "" :
getPath(annotation);
+ // rewrite api path
+ api.setBeanPath(beanPath);
+
+ if (Objects.nonNull(annotation)) {
+ api.addProperties("consumes", String.join(",",
annotation.consumes()));
+ api.addProperties("produces", String.join(",",
annotation.produces()));
+ }
+
+ // Get additional values from the annotation.
+ // TO_DO : Provides support annotation extensions
+ }
+
+ @Override
+ public void process(final ApiBean.ApiDefinition definition, final
RequestMapping annotation) {
+ // rewrite api path
+ definition.setMethodPath(getPath(annotation));
+
+ definition.addProperties("consumes", String.join(",",
annotation.consumes()));
+ definition.addProperties("produces", String.join(",",
annotation.produces()));
+
+ // Get additional values from the annotation.
+ // TO_DO : Provides support annotation extensions
+ }
+
+ @Override
+ public Class<RequestMapping> matchAnnotation() {
+ return RequestMapping.class;
+ }
+
+ private String getPath(@NonNull final RequestMapping requestMapping) {
+ if (ArrayUtils.isEmpty(requestMapping.path())) {
+ return "";
+ }
+ return requestMapping.path()[0];
+ }
+}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/register/SpringCloudApiBeansExtractor.java
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/register/SpringCloudApiBeansExtractor.java
index ce55cec1e..58e86294a 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/register/SpringCloudApiBeansExtractor.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/register/SpringCloudApiBeansExtractor.java
@@ -17,113 +17,33 @@
package org.apache.shenyu.client.springcloud.register;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.shenyu.client.core.register.ApiBean;
import
org.apache.shenyu.client.core.register.extractor.BaseAnnotationApiBeansExtractor;
import org.apache.shenyu.client.core.register.extractor.RpcApiBeansExtractor;
+import
org.apache.shenyu.client.springcloud.proceeor.extractor.RequestMappingProcessor;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.jetbrains.annotations.NotNull;
-import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
/**
* Support for Spring Cloud. <br>
* Should inherit from SpringMvcApiBeansExtractor.
*/
public class SpringCloudApiBeansExtractor extends
BaseAnnotationApiBeansExtractor implements RpcApiBeansExtractor {
- private final List<Class<? extends Annotation>> supportedApiAnnotations =
new ArrayList<>(1);
-
- private final List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations = new ArrayList<>(1);
-
public SpringCloudApiBeansExtractor() {
// Annotations supported by class
- supportedApiAnnotations.add(Controller.class);
- supportedApiAnnotations.add(RequestMapping.class);
+ addSupportedApiAnnotations(Controller.class);
+ addSupportedApiAnnotations(RequestMapping.class);
// Annotations supported by the method
- supportedApiDefinitionAnnotations.add(RequestMapping.class);
+ addSupportedApiDefinitionAnnotations(RequestMapping.class);
+
+ addExtractorProcessor(new RequestMappingProcessor());
}
@Override
public String clientName() {
return RpcTypeEnum.SPRING_CLOUD.getName();
}
-
- @Override
- protected void apiPostProcess(final ApiBean api) {
- // Get from annotations
- // Currently only RequestMapping is supported
- final RequestMapping requestMapping =
api.getAnnotation(RequestMapping.class);
-
- String beanPath = Objects.isNull(requestMapping) ? "" :
getPath(requestMapping);
- // rewrite api path
- api.setBeanPath(beanPath);
-
- if (Objects.nonNull(requestMapping)) {
- api.addProperties("consumes", String.join(",",
requestMapping.consumes()));
- api.addProperties("produces", String.join(",",
requestMapping.produces()));
- }
-
- // Get additional values from the annotation.
- super.apiPostProcess(api);
- }
-
- @Override
- protected void definitionPostProcess(final ApiBean.ApiDefinition
apiDefinition) {
- // Get from annotations
- // Currently only RequestMapping is supported
- final RequestMapping requestMapping =
apiDefinition.getAnnotation(RequestMapping.class);
- // rewrite api path
- apiDefinition.setMethodPath(getPath(requestMapping));
-
- apiDefinition.addProperties("consumes", String.join(",",
requestMapping.consumes()));
- apiDefinition.addProperties("produces", String.join(",",
requestMapping.produces()));
-
- // Get additional values from the annotation.
- super.definitionPostProcess(apiDefinition);
- }
-
- /**
- * Add supported class annotations.
- *
- * @param annotation annotation
- */
- public void addSupportedApiAnnotations(final Class<? extends Annotation>
annotation) {
- supportedApiAnnotations.add(annotation);
- }
-
- /**
- * Add supported method annotations.
- *
- * @param annotation annotation
- */
- public void addSupportedApiDefinitionAnnotations(final Class<? extends
Annotation> annotation) {
- supportedApiDefinitionAnnotations.add(annotation);
- }
-
- private String getPath(@NonNull final RequestMapping requestMapping) {
- if (ArrayUtils.isEmpty(requestMapping.path())) {
- return "";
- }
- return requestMapping.path()[0];
- }
-
- @NotNull
- @Override
- protected List<Class<? extends Annotation>> supportedApiAnnotations() {
- return supportedApiAnnotations;
- }
-
- @NotNull
- @Override
- protected List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations() {
- return supportedApiDefinitionAnnotations;
- }
+
}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/extractor/RequestMappingProcessor.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/extractor/RequestMappingProcessor.java
new file mode 100644
index 000000000..e8e1417d2
--- /dev/null
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/extractor/RequestMappingProcessor.java
@@ -0,0 +1,72 @@
+/*
+ * 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.client.springmvc.proceeor.extractor;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.shenyu.client.core.register.ApiBean;
+import org.apache.shenyu.client.core.register.matcher.ApiAnnotationProcessor;
+import org.springframework.lang.NonNull;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.Objects;
+
+/**
+ * RequestMappingProcessor.
+ */
+public class RequestMappingProcessor implements
ApiAnnotationProcessor<RequestMapping> {
+
+ @Override
+ public void process(final ApiBean api, final RequestMapping annotation) {
+
+ String beanPath = Objects.isNull(annotation) ? "" :
getPath(annotation);
+ // rewrite api path
+ api.setBeanPath(beanPath);
+
+ if (Objects.nonNull(annotation)) {
+ api.addProperties("consumes", String.join(",",
annotation.consumes()));
+ api.addProperties("produces", String.join(",",
annotation.produces()));
+ }
+
+ // Get additional values from the annotation.
+ // TO_DO : Provides support annotation extensions
+ }
+
+ @Override
+ public void process(final ApiBean.ApiDefinition definition, final
RequestMapping annotation) {
+ // rewrite api path
+ definition.setMethodPath(getPath(annotation));
+
+ definition.addProperties("consumes", String.join(",",
annotation.consumes()));
+ definition.addProperties("produces", String.join(",",
annotation.produces()));
+
+ // Get additional values from the annotation.
+ // TO_DO : Provides support annotation extensions
+ }
+
+ @Override
+ public Class<RequestMapping> matchAnnotation() {
+ return RequestMapping.class;
+ }
+
+ private String getPath(@NonNull final RequestMapping requestMapping) {
+ if (ArrayUtils.isEmpty(requestMapping.path())) {
+ return "";
+ }
+ return requestMapping.path()[0];
+ }
+}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/ShenyuSpringMvcClientProcessorImpl.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/register/ShenyuSpringMvcClientProcessorImpl.java
similarity index 89%
rename from
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/ShenyuSpringMvcClientProcessorImpl.java
rename to
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/register/ShenyuSpringMvcClientProcessorImpl.java
index d03c16df7..5a40dfc2a 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/ShenyuSpringMvcClientProcessorImpl.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/proceeor/register/ShenyuSpringMvcClientProcessorImpl.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shenyu.client.springmvc.register;
+package org.apache.shenyu.client.springmvc.proceeor.register;
import org.apache.shenyu.client.core.register.ApiBean;
import
org.apache.shenyu.client.core.register.matcher.BaseAnnotationApiProcessor;
@@ -32,7 +32,7 @@ import java.util.Objects;
public class ShenyuSpringMvcClientProcessorImpl extends
BaseAnnotationApiProcessor<ShenyuSpringMvcClient> {
@Override
- protected void process(final ApiBean apiBean, final ShenyuSpringMvcClient
annotation) {
+ public void process(final ApiBean apiBean, final ShenyuSpringMvcClient
annotation) {
apiBean.setBeanPath(annotation.path());
apiBean.addProperties("desc", annotation.desc());
apiBean.addProperties("rule", annotation.ruleName());
@@ -47,7 +47,7 @@ public class ShenyuSpringMvcClientProcessorImpl extends
BaseAnnotationApiProcess
}
@Override
- protected void process(final ApiBean.ApiDefinition definition, final
ShenyuSpringMvcClient annotation) {
+ public void process(final ApiBean.ApiDefinition definition, final
ShenyuSpringMvcClient annotation) {
definition.setMethodPath(annotation.path());
definition.addProperties("desc", annotation.desc());
definition.addProperties("rule", annotation.ruleName());
@@ -62,7 +62,7 @@ public class ShenyuSpringMvcClientProcessorImpl extends
BaseAnnotationApiProcess
}
@Override
- protected Class<ShenyuSpringMvcClient> matchAnnotation() {
+ public Class<ShenyuSpringMvcClient> matchAnnotation() {
return ShenyuSpringMvcClient.class;
}
}
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/SpringMvcApiBeansExtractor.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/SpringMvcApiBeansExtractor.java
index e2b2005a7..02ad4c9ec 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/SpringMvcApiBeansExtractor.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/register/SpringMvcApiBeansExtractor.java
@@ -17,34 +17,24 @@
package org.apache.shenyu.client.springmvc.register;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.shenyu.client.core.register.ApiBean;
import
org.apache.shenyu.client.core.register.extractor.BaseAnnotationApiBeansExtractor;
import org.apache.shenyu.client.core.register.extractor.RpcApiBeansExtractor;
+import
org.apache.shenyu.client.springmvc.proceeor.extractor.RequestMappingProcessor;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.jetbrains.annotations.NotNull;
-import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
public class SpringMvcApiBeansExtractor extends
BaseAnnotationApiBeansExtractor implements RpcApiBeansExtractor {
- private final List<Class<? extends Annotation>> supportedApiAnnotations =
new ArrayList<>(1);
-
- private final List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations = new ArrayList<>(1);
-
public SpringMvcApiBeansExtractor() {
// Annotations supported by class
- supportedApiAnnotations.add(Controller.class);
- supportedApiAnnotations.add(RequestMapping.class);
+ addSupportedApiAnnotations(Controller.class);
+ addSupportedApiAnnotations(RequestMapping.class);
// Annotations supported by the method
- supportedApiDefinitionAnnotations.add(RequestMapping.class);
+ addSupportedApiDefinitionAnnotations(RequestMapping.class);
+
+ addExtractorProcessor(new RequestMappingProcessor());
}
@Override
@@ -52,66 +42,4 @@ public class SpringMvcApiBeansExtractor extends
BaseAnnotationApiBeansExtractor
return RpcTypeEnum.HTTP.getName();
}
- @Override
- protected void apiPostProcess(final ApiBean api) {
- // Get from annotations
- // Currently only RequestMapping is supported
- final RequestMapping requestMapping =
api.getAnnotation(RequestMapping.class);
-
- String beanPath = Objects.isNull(requestMapping) ? "" :
getPath(requestMapping);
- // rewrite api path
- api.setBeanPath(beanPath);
-
- // Get additional values from the annotation.
- // TO_DO : Provides support annotation extensions
- }
-
- @Override
- protected void definitionPostProcess(final ApiBean.ApiDefinition
apiDefinition) {
- // Get from annotations
- // Currently only RequestMapping is supported
- final RequestMapping requestMapping =
apiDefinition.getAnnotation(RequestMapping.class);
- // rewrite api path
- apiDefinition.setMethodPath(getPath(requestMapping));
-
- // Get additional values from the annotation.
- // TO_DO : Provides support annotation extensions
- }
-
- /**
- * Add supported class annotations.
- *
- * @param annotation annotation
- */
- public void addSupportedApiAnnotations(final Class<? extends Annotation>
annotation) {
- supportedApiAnnotations.add(annotation);
- }
-
- /**
- * Add supported method annotations.
- *
- * @param annotation annotation
- */
- public void addSupportedApiDefinitionAnnotations(final Class<? extends
Annotation> annotation) {
- supportedApiDefinitionAnnotations.add(annotation);
- }
-
- private String getPath(@NonNull final RequestMapping requestMapping) {
- if (ArrayUtils.isEmpty(requestMapping.path())) {
- return "";
- }
- return requestMapping.path()[0];
- }
-
- @NotNull
- @Override
- protected List<Class<? extends Annotation>> supportedApiAnnotations() {
- return supportedApiAnnotations;
- }
-
- @NotNull
- @Override
- protected List<Class<? extends Annotation>>
supportedApiDefinitionAnnotations() {
- return supportedApiDefinitionAnnotations;
- }
}