From f6c57b294d93301ae38036cd51252e2f17834227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=81=AA=E6=B4=8B?= <1601081222@qq.com> Date: Tue, 16 Apr 2024 21:37:42 +0800 Subject: [PATCH 1/2] delete_metadata_rest_related --- .artifacts | 1 - dubbo-distribution/dubbo-all-shaded/pom.xml | 18 - dubbo-distribution/dubbo-all/pom.xml | 26 - dubbo-distribution/dubbo-core-spi/pom.xml | 18 - .../dubbo-metadata-processor/pom.xml | 19 - ...ractAnnotatedMethodParameterProcessor.java | 63 --- .../AbstractServiceRestMetadataResolver.java | 317 ------------ .../AnnotatedMethodParameterProcessor.java | 67 --- .../DefaultServiceRestMetadataResolver.java | 206 -------- ...erviceRestMetadataAnnotationProcessor.java | 88 ---- .../rest/ServiceRestMetadataResolver.java | 57 -- .../rest/ServiceRestMetadataStorage.java | 66 --- .../jaxrs/DefaultValueParameterProcessor.java | 82 --- .../jaxrs/FormParamParameterProcessor.java | 34 -- .../jaxrs/HeaderParamParameterProcessor.java | 56 -- .../JAXRSServiceRestMetadataResolver.java | 119 ----- .../jaxrs/MatrixParamParameterProcessor.java | 34 -- .../ParamAnnotationParameterProcessor.java | 44 -- .../jaxrs/QueryParamParameterProcessor.java | 34 -- ...ctRequestAnnotationParameterProcessor.java | 72 --- .../RequestHeaderParameterProcessor.java | 49 -- .../RequestParamParameterProcessor.java | 49 -- .../SpringMvcServiceRestMetadataResolver.java | 176 ------- ...ing.rest.AnnotatedMethodParameterProcessor | 10 - ...rocessing.rest.ServiceRestMetadataResolver | 3 - .../javax.annotation.processing.Processor | 1 - ...AnnotatedMethodParameterProcessorTest.java | 59 --- .../processing/util/AnnotationUtilsTest.java | 12 - .../metadata/rest/DefaultRestService.java | 69 --- .../dubbo/metadata/rest/RestService.java | 41 -- .../metadata/rest/SpringRestService.java | 96 ---- .../metadata/rest/StandardRestService.java | 109 ---- .../org/apache/dubbo/metadata/rest/User.java | 62 --- .../tools/DefaultRestServiceTest.java | 46 -- .../dubbo/metadata/tools/RestServiceTest.java | 40 -- .../metadata/tools/SpringRestServiceTest.java | 39 -- .../tools/StandardRestServiceTest.java | 39 -- dubbo-metadata/dubbo-metadata-rest/pom.xml | 101 ---- ...ractAnnotatedMethodParameterProcessor.java | 84 --- ...AbstractNoAnnotatedParameterProcessor.java | 78 --- .../AbstractServiceRestMetadataResolver.java | 487 ------------------ .../AnnotatedMethodParameterProcessor.java | 80 --- .../apache/dubbo/metadata/rest/ArgInfo.java | 175 ------- .../ClassPathServiceRestMetadataReader.java | 70 --- .../DefaultServiceRestMetadataResolver.java | 61 --- .../metadata/rest/JAXRSClassConstants.java | 62 --- ...AnnotatedParameterRequestTagProcessor.java | 32 -- .../apache/dubbo/metadata/rest/ParamType.java | 93 ---- .../dubbo/metadata/rest/PathMatcher.java | 284 ---------- .../apache/dubbo/metadata/rest/PathUtil.java | 147 ------ .../dubbo/metadata/rest/RequestMetadata.java | 240 --------- .../metadata/rest/RestMetadataConstants.java | 180 ------- .../metadata/rest/RestMethodMetadata.java | 254 --------- .../metadata/rest/ServiceRestMetadata.java | 250 --------- .../rest/ServiceRestMetadataReader.java | 38 -- .../rest/ServiceRestMetadataResolver.java | 51 -- .../rest/SpringMvcClassConstants.java | 47 -- .../rest/jaxrs/BodyParameterProcessor.java | 54 -- .../jaxrs/DefaultValueParameterProcessor.java | 81 --- .../jaxrs/FormBodyParameterProcessor.java | 60 --- .../jaxrs/FormParamParameterProcessor.java | 34 -- .../jaxrs/HeaderParamParameterProcessor.java | 56 -- .../JAXRSServiceRestMetadataResolver.java | 119 ----- .../jaxrs/MatrixParamParameterProcessor.java | 34 -- .../ParamAnnotationParameterProcessor.java | 45 -- .../jaxrs/PathParamParameterProcessor.java | 35 -- .../jaxrs/QueryParamParameterProcessor.java | 34 -- .../dubbo/metadata/rest/media/MediaType.java | 53 -- ...AnnotationServiceRestMetadataResolver.java | 95 ---- ...ctRequestAnnotationParameterProcessor.java | 71 --- .../FormBodyNoAnnotatedProcessor.java | 41 -- .../JsonBodyNoAnnotatedProcessor.java | 36 -- .../springmvc/ParamNoAnnotatedProcessor.java | 43 -- .../PathVariableParameterProcessor.java | 41 -- .../RequestBodyParameterProcessor.java | 46 -- .../RequestHeaderParameterProcessor.java | 49 -- .../RequestParamParameterProcessor.java | 49 -- .../SpringMvcServiceRestMetadataResolver.java | 186 ------- .../dubbo/metadata/rest/tag/BodyTag.java | 22 - .../metadata/rest/tag/NoAnnotationTag.java | 22 - .../dubbo/metadata/rest/tag/ParamTag.java | 22 - ...ata.rest.AnnotatedMethodParameterProcessor | 15 - ...st.NoAnnotatedParameterRequestTagProcessor | 3 - ....metadata.rest.ServiceRestMetadataResolver | 4 - .../dubbo/metadata/PathMatcherTest.java | 97 ---- .../apache/dubbo/metadata/TestMediaType.java | 33 -- .../metadata/rest/DefaultRestService.java | 78 --- .../dubbo/metadata/rest/RestService.java | 47 -- .../metadata/rest/SpringRestService.java | 108 ---- .../metadata/rest/StandardRestService.java | 127 ----- .../org/apache/dubbo/metadata/rest/User.java | 62 --- .../rest/api/AnotherUserRestService.java | 45 -- ...oubleCheckContainsPathVariableService.java | 35 -- .../rest/api/JaxrsRestDoubleCheckService.java | 40 -- .../metadata/rest/api/JaxrsRestService.java | 69 --- .../rest/api/JaxrsRestServiceImpl.java | 54 -- .../metadata/rest/api/JaxrsUsingService.java | 47 -- .../rest/api/SpringControllerService.java | 104 ---- .../metadata/rest/api/SpringRestService.java | 89 ---- .../rest/api/SpringRestServiceImpl.java | 66 --- .../rest/feign/FeignClientController.java | 29 -- .../rest/feign/FeignClientControllerImpl.java | 25 - .../JAXRSServiceRestMetadataResolverTest.java | 147 ------ .../rest/jaxrs/JaxrsRestDoubleCheckTest.java | 73 --- ...tationServiceRestMetadataResolverTest.java | 81 --- .../springmvc/FeignClientAnnotationTest.java | 51 -- ...ingMvcServiceRestMetadataResolverTest.java | 160 ------ .../dubbo/jax-rs-service-rest-metadata.json | 324 ------------ .../spring-mvc-service-rest-metadata.json | 321 ------------ .../src/test/resources/log4j2-test.xml | 29 -- dubbo-metadata/pom.xml | 1 - 111 files changed, 8827 deletions(-) delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractAnnotatedMethodParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/DefaultServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataAnnotationProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataStorage.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/DefaultValueParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/FormParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/HeaderParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/MatrixParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/ParamAnnotationParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/QueryParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestHeaderParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/RestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/User.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/DefaultRestServiceTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/RestServiceTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/SpringRestServiceTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/StandardRestServiceTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/pom.xml delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractAnnotatedMethodParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractNoAnnotatedParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AnnotatedMethodParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ArgInfo.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ClassPathServiceRestMetadataReader.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/DefaultServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/JAXRSClassConstants.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/NoAnnotatedParameterRequestTagProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ParamType.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathUtil.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMetadataConstants.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMethodMetadata.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadata.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataReader.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/SpringMvcClassConstants.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/BodyParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/DefaultValueParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormBodyParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/HeaderParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/MatrixParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/ParamAnnotationParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/PathParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/QueryParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/media/MediaType.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/noannotaion/NoAnnotationServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/FormBodyNoAnnotatedProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/JsonBodyNoAnnotatedProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/ParamNoAnnotatedProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/PathVariableParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestBodyParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestHeaderParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestParamParameterProcessor.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/BodyTag.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/NoAnnotationTag.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/ParamTag.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/PathMatcherTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/TestMediaType.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/RestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/User.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/AnotherUserRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckContainsPathVariableService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestServiceImpl.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsUsingService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringControllerService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestService.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestServiceImpl.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientController.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientControllerImpl.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolverTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JaxrsRestDoubleCheckTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/noannotation/NoAnnotationServiceRestMetadataResolverTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/FeignClientAnnotationTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolverTest.java delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/jax-rs-service-rest-metadata.json delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/spring-mvc-service-rest-metadata.json delete mode 100644 dubbo-metadata/dubbo-metadata-rest/src/test/resources/log4j2-test.xml diff --git a/.artifacts b/.artifacts index cd6334693d0..a8036aba481 100644 --- a/.artifacts +++ b/.artifacts @@ -47,7 +47,6 @@ dubbo-kubernetes dubbo-maven-plugin dubbo-metadata dubbo-metadata-api -dubbo-metadata-rest dubbo-metadata-definition-protobuf dubbo-metadata-processor dubbo-metadata-report-nacos diff --git a/dubbo-distribution/dubbo-all-shaded/pom.xml b/dubbo-distribution/dubbo-all-shaded/pom.xml index b0591156921..ef80aee7ad0 100644 --- a/dubbo-distribution/dubbo-all-shaded/pom.xml +++ b/dubbo-distribution/dubbo-all-shaded/pom.xml @@ -631,24 +631,12 @@ META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.builder.TypeBuilder - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataReader - META-INF/dubbo/internal/org.apache.dubbo.monitor.MonitorFactory @@ -717,9 +705,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.filter.RestResponseFilter - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor - META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.message.HttpMessageCodec @@ -921,9 +906,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.router.mesh.util.TracingContextProvider - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index 19fd7dbbfc3..bf6d99e6b1b 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -128,13 +128,6 @@ compile true - - org.apache.dubbo - dubbo-metadata-rest - ${project.version} - compile - true - org.apache.dubbo dubbo-metadata-report-zookeeper @@ -528,7 +521,6 @@ org.apache.dubbo:dubbo-filter-cache org.apache.dubbo:dubbo-filter-validation org.apache.dubbo:dubbo-metadata-api - org.apache.dubbo:dubbo-metadata-rest org.apache.dubbo:dubbo-metadata-definition-protobuf org.apache.dubbo:dubbo-metadata-report-nacos org.apache.dubbo:dubbo-metadata-report-redis @@ -686,24 +678,12 @@ META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.builder.TypeBuilder - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataReader - META-INF/dubbo/internal/org.apache.dubbo.monitor.MonitorFactory @@ -772,9 +752,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.filter.RestResponseFilter - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor - META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.message.HttpMessageCodec @@ -976,9 +953,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.router.mesh.util.TracingContextProvider - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index 6ef9c5d928e..11488468511 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -247,24 +247,12 @@ META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.builder.TypeBuilder - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor - - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataReader - META-INF/dubbo/internal/org.apache.dubbo.monitor.MonitorFactory @@ -333,9 +321,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.filter.RestResponseFilter - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor - META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.rest.message.HttpMessageCodec @@ -537,9 +522,6 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.router.mesh.util.TracingContextProvider - - META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver - META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory diff --git a/dubbo-metadata/dubbo-metadata-processor/pom.xml b/dubbo-metadata/dubbo-metadata-processor/pom.xml index fe6041612b2..bf8b63c8dbf 100644 --- a/dubbo-metadata/dubbo-metadata-processor/pom.xml +++ b/dubbo-metadata/dubbo-metadata-processor/pom.xml @@ -30,21 +30,6 @@ The metadata processor module of Dubbo project - - org.apache.dubbo - dubbo-metadata-rest - ${project.parent.version} - - - org.apache.dubbo - dubbo-rpc-api - - - org.apache.dubbo - dubbo-cluster - - - org.apache.dubbo @@ -77,10 +62,6 @@ - - org.apache.dubbo - dubbo-metadata-api - org.apache.dubbo dubbo-remoting-api diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractAnnotatedMethodParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractAnnotatedMethodParameterProcessor.java deleted file mode 100644 index 142429e0f3d..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractAnnotatedMethodParameterProcessor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import static org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor.buildDefaultValue; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getValue; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation - * - * @since 2.7.6 - */ -public abstract class AbstractAnnotatedMethodParameterProcessor implements AnnotatedMethodParameterProcessor { - - @Override - public final void process( - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - String annotationValue = getAnnotationValue(annotation, parameter, parameterIndex); - String defaultValue = getDefaultValue(annotation, parameter, parameterIndex); - process(annotationValue, defaultValue, annotation, parameter, parameterIndex, method, restMethodMetadata); - } - - protected abstract void process( - String annotationValue, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata); - - protected String getAnnotationValue(AnnotationMirror annotation, VariableElement parameter, int parameterIndex) { - return getValue(annotation); - } - - protected String getDefaultValue(AnnotationMirror annotation, VariableElement parameter, int parameterIndex) { - return buildDefaultValue(parameterIndex); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractServiceRestMetadataResolver.java deleted file mode 100644 index a2a388d34da..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AbstractServiceRestMetadataResolver.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.metadata.annotation.processing.util.ExecutableElementComparator; -import org.apache.dubbo.metadata.definition.model.MethodDefinition; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.util.Elements; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static java.lang.ThreadLocal.withInitial; -import static java.util.Collections.emptyList; -import static java.util.Collections.sort; -import static java.util.Optional.empty; -import static java.util.Optional.of; -import static org.apache.dubbo.metadata.annotation.processing.builder.MethodDefinitionBuilder.build; -import static org.apache.dubbo.metadata.annotation.processing.util.LoggerUtils.info; -import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getOverrideMethod; -import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getPublicNonStaticMethods; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getGroup; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getVersion; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.resolveServiceInterfaceName; - -/** - * Abstract {@link ServiceRestMetadataResolver} implementation - * - * @since 2.7.6 - */ -public abstract class AbstractServiceRestMetadataResolver implements ServiceRestMetadataResolver { - - private static final ThreadLocal> threadLocalCache = withInitial(HashMap::new); - - private static final Map> parameterProcessorsMap = - loadAnnotatedMethodParameterProcessors(); - - private final String processorName = getClass().getSimpleName(); - - @Override - public final ServiceRestMetadata resolve( - ProcessingEnvironment processingEnv, TypeElement serviceType, Set annotations) { - - info( - "%s is processing the service type[%s] with annotations[%s]", - processorName, - serviceType, - annotations.stream().map(t -> "@" + t.toString()).collect(Collectors.joining(","))); - - ServiceRestMetadata serviceRestMetadata = new ServiceRestMetadata(); - - Elements elements = processingEnv.getElementUtils(); - - try { - AnnotationMirror serviceAnnotation = getAnnotation(serviceType); - String serviceInterfaceName = resolveServiceInterfaceName(serviceType, serviceAnnotation); - serviceRestMetadata.setServiceInterface(serviceInterfaceName); - serviceRestMetadata.setGroup(getGroup(serviceAnnotation)); - serviceRestMetadata.setVersion(getVersion(serviceAnnotation)); - - TypeElement serviceInterfaceType = elements.getTypeElement(serviceInterfaceName); - - List serviceMethods = - new LinkedList<>(getPublicNonStaticMethods(serviceInterfaceType, Object.class)); - - // Sorts - sort(serviceMethods, ExecutableElementComparator.INSTANCE); - - serviceMethods.forEach(serviceMethod -> { - resolveRestMethodMetadata( - processingEnv, serviceType, serviceInterfaceType, serviceMethod, serviceRestMetadata) - .ifPresent(serviceRestMetadata.getMeta()::add); - }); - - } finally { - clearCache(); - } - - info("The %s's process result : %s", processorName, serviceRestMetadata); - - return serviceRestMetadata; - } - - protected Optional resolveRestMethodMetadata( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement serviceMethod, - ServiceRestMetadata serviceRestMetadata) { - - ExecutableElement restCapableMethod = - findRestCapableMethod(processingEnv, serviceType, serviceInterfaceType, serviceMethod); - - if (restCapableMethod == null) { // if can't be found - return empty(); - } - - String requestPath = - resolveRequestPath(processingEnv, serviceType, restCapableMethod); // requestPath is required - - if (requestPath == null) { - return empty(); - } - - String requestMethod = - resolveRequestMethod(processingEnv, serviceType, restCapableMethod); // requestMethod is required - - if (requestMethod == null) { - return empty(); - } - - RestMethodMetadata metadata = new RestMethodMetadata(); - - MethodDefinition methodDefinition = resolveMethodDefinition(processingEnv, serviceType, restCapableMethod); - // Set MethodDefinition - metadata.setMethod(methodDefinition); - - // process the annotated method parameters - processAnnotatedMethodParameters(restCapableMethod, serviceType, metadata); - - // process produces - Set produces = new LinkedHashSet<>(); - processProduces(processingEnv, serviceType, restCapableMethod, produces); - - // process consumes - Set consumes = new LinkedHashSet<>(); - processConsumes(processingEnv, serviceType, restCapableMethod, consumes); - - // Initialize RequestMetadata - RequestMetadata request = metadata.getRequest(); - request.setPath(requestPath); - request.appendContextPathFromUrl(serviceRestMetadata.getContextPathFromUrl()); - - request.setMethod(requestMethod); - request.setProduces(produces); - request.setConsumes(consumes); - - // Post-Process - postProcessRestMethodMetadata(processingEnv, serviceType, serviceMethod, metadata); - - return of(metadata); - } - - /** - * Find the method with the capable for REST from the specified service method and its override method - * - * @param processingEnv {@link ProcessingEnvironment} - * @param serviceType - * @param serviceInterfaceType - * @param serviceMethod - * @return null if can't be found - */ - private ExecutableElement findRestCapableMethod( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement serviceMethod) { - // try to judge the override first - ExecutableElement overrideMethod = getOverrideMethod(processingEnv, serviceType, serviceMethod); - if (supports(processingEnv, serviceType, serviceInterfaceType, overrideMethod)) { - return overrideMethod; - } - // or, try to judge the declared method - return supports(processingEnv, serviceType, serviceInterfaceType, serviceMethod) ? serviceMethod : null; - } - - /** - * Does the specified method support REST or not ? - * - * @param processingEnv {@link ProcessingEnvironment} - * @param method the method may be declared on the interface or class - * @return if supports, return true, or false - */ - protected abstract boolean supports( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement method); - - /** - * Post-Process for {@link RestMethodMetadata}, sub-type could override this method for further works - * - * @param processingEnv {@link ProcessingEnvironment} - * @param serviceType The type that @Service annotated - * @param method The public method of serviceType - * @param metadata {@link RestMethodMetadata} maybe updated - */ - protected void postProcessRestMethodMetadata( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - RestMethodMetadata metadata) {} - - protected abstract String resolveRequestPath( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method); - - protected abstract String resolveRequestMethod( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method); - - protected MethodDefinition resolveMethodDefinition( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - return build(processingEnv, method, new HashMap<>()); - } - - protected void processAnnotatedMethodParameters( - ExecutableElement method, TypeElement type, RestMethodMetadata metadata) { - List methodParameters = method.getParameters(); - int size = methodParameters.size(); - for (int i = 0; i < size; i++) { - VariableElement parameter = methodParameters.get(i); - // Add indexed parameter name - metadata.addIndexToName(i, parameter.getSimpleName().toString()); - processAnnotatedMethodParameter(parameter, i, method, type, metadata); - } - } - - protected void processAnnotatedMethodParameter( - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - TypeElement serviceType, - RestMethodMetadata metadata) { - - parameter.getAnnotationMirrors().forEach(annotation -> { - String annotationType = annotation.getAnnotationType().toString(); - parameterProcessorsMap.getOrDefault(annotationType, emptyList()).forEach(parameterProcessor -> { - parameterProcessor.process(annotation, parameter, parameterIndex, method, metadata); - }); - }); - } - - protected abstract void processProduces( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set produces); - - protected abstract void processConsumes( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set consumes); - - protected static final void put(String name, Object value) { - Map cache = getCache(); - cache.put(name, value); - } - - protected static final T get(String name) throws ClassCastException { - Map cache = getCache(); - return (T) cache.get(name); - } - - protected static final V computeIfAbsent(String name, Function mappingFunction) { - return (V) getCache().computeIfAbsent(name, mappingFunction); - } - - private static Map> loadAnnotatedMethodParameterProcessors() { - Map> parameterProcessorsMap = new LinkedHashMap<>(); - - // load(AnnotatedMethodParameterProcessor.class, - // AnnotatedMethodParameterProcessor.class.getClassLoader()) - - ApplicationModel.defaultModel() - .getExtensionLoader(AnnotatedMethodParameterProcessor.class) - .getSupportedExtensionInstances() - .forEach(processor -> { - List processors = parameterProcessorsMap.computeIfAbsent( - processor.getAnnotationType(), k -> new LinkedList<>()); - processors.add(processor); - }); - - return parameterProcessorsMap; - } - - private static Map getCache() { - return threadLocalCache.get(); - } - - private static void clearCache() { - Map cache = getCache(); - cache.clear(); - threadLocalCache.remove(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessor.java deleted file mode 100644 index dd97c2dbd35..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.common.extension.SPI; -import org.apache.dubbo.common.lang.Prioritized; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -/** - * The interface to process the parameter of method that was annotated - * - * @since 2.7.6 - */ -@SPI -public interface AnnotatedMethodParameterProcessor extends Prioritized { - - /** - * The string presenting the annotation type - * - * @return non-null - */ - String getAnnotationType(); - - /** - * Process the specified method {@link VariableElement parameter} - * - * @param annotation {@link AnnotationMirror the target annotation} whose type is {@link #getAnnotationType()} - * @param parameter {@link VariableElement method parameter} - * @param parameterIndex the index of parameter in the method - * @param method {@link ExecutableElement method that parameter belongs to} - * @param restMethodMetadata {@link RestMethodMetadata the metadata is used to update} - */ - void process( - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata); - - /** - * Build the default value - * - * @param parameterIndex the index of parameter - * @return the placeholder - */ - static String buildDefaultValue(int parameterIndex) { - return "{" + parameterIndex + "}"; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/DefaultServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/DefaultServiceRestMetadataResolver.java deleted file mode 100644 index 24875726827..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/DefaultServiceRestMetadataResolver.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.common.convert.Converter; -import org.apache.dubbo.common.convert.ConverterUtil; -import org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.JAXRSServiceRestMetadataResolver; -import org.apache.dubbo.metadata.annotation.processing.rest.springmvc.SpringMvcServiceRestMetadataResolver; -import org.apache.dubbo.rpc.model.FrameworkModel; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeMirror; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static java.lang.String.valueOf; -import static java.util.Arrays.asList; -import static org.apache.dubbo.common.utils.ClassUtils.forName; -import static org.apache.dubbo.common.utils.StringUtils.SLASH_CHAR; -import static org.apache.dubbo.metadata.annotation.processing.util.LoggerUtils.warn; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.getAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.resolveServiceInterfaceName; -import static org.apache.dubbo.metadata.annotation.processing.util.TypeUtils.findInterface; - -/** - * The default implementation of {@link ServiceRestMetadataResolver} - * - * @since 2.7.6 - */ -public class DefaultServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - - private static final char PACKAGE_SEPARATOR = '.'; - - private static final char PATH_SEPARATOR = SLASH_CHAR; - - private static final String HTTP_REQUEST_METHOD = "POST"; - - private static final List MEDIA_TYPES = asList( - "application/json;", - "application/*+json", - "application/xml;charset=UTF-8", - "text/xml;charset=UTF-8", - "application/*+xml;charset=UTF-8"); - - private final Set hasComplexParameterTypeMethods = new HashSet<>(); - - @Override - public boolean supports(ProcessingEnvironment processingEnvironment, TypeElement serviceType) { - return !JAXRSServiceRestMetadataResolver.supports(serviceType) - && !SpringMvcServiceRestMetadataResolver.supports(serviceType); - } - - @Override - protected boolean supports( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement method) { - // TODO add some criterion - return true; - } - - @Override - protected String resolveRequestPath( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - - AnnotationMirror serviceAnnotation = getAnnotation(serviceType); - - String serviceInterfaceName = resolveServiceInterfaceName(serviceType, serviceAnnotation); - - TypeMirror serviceInterface = findInterface(serviceType.asType(), serviceInterfaceName); - - StringBuilder requestPathBuilder = new StringBuilder(); - // the name of service type as the root path - String rootPath = buildRootPath(serviceInterface); - // the method name as the sub path - String subPath = buildSubPath(method); - - requestPathBuilder.append(rootPath).append(subPath); - // the methods' parameters as the the path variables - List parameters = method.getParameters(); - - for (int i = 0; i < parameters.size(); i++) { - VariableElement parameter = parameters.get(i); - TypeMirror parameterType = parameter.asType(); - if (isComplexType(parameterType)) { - if (addComplexParameterType(method)) { - continue; - } else { - // The count of complex types must be only one, or return immediately - warn( - "The method[%s] contains more than one complex parameter type, " - + "thus it will not be chosen as the REST service", - method.toString()); - } - } - String parameterName = parameter.getSimpleName().toString(); - // If "-parameters" option is enabled, take the parameter name as the path variable name, - // or use the index of parameter - String pathVariableName = isEnabledParametersCompilerOption(parameterName) ? parameterName : valueOf(i); - requestPathBuilder - .append(PATH_SEPARATOR) - .append('{') - .append(pathVariableName) - .append('}'); - } - - return requestPathBuilder.toString(); - } - - private String buildRootPath(TypeMirror serviceInterface) { - return PATH_SEPARATOR + serviceInterface.toString().replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); - } - - private String buildSubPath(ExecutableElement method) { - return PATH_SEPARATOR + method.getSimpleName().toString(); - } - - private boolean isEnabledParametersCompilerOption(String parameterName) { - return !parameterName.startsWith("arg"); - } - - private boolean isComplexType(TypeMirror parameterType) { - return !supportsPathVariableType(parameterType); - } - - /** - * Supports the type of parameter or not, based by {@link Converter}'s conversion feature - * - * @param parameterType the type of parameter - * @return if supports, this method will return true, or false - */ - private boolean supportsPathVariableType(TypeMirror parameterType) { - String className = parameterType.toString(); - ClassLoader classLoader = getClass().getClassLoader(); - boolean supported; - try { - Class targetType = forName(className, classLoader); - supported = FrameworkModel.defaultModel() - .getBeanFactory() - .getBean(ConverterUtil.class) - .getConverter(String.class, targetType) - != null; - } catch (ClassNotFoundException e) { - supported = false; - } - return supported; - } - - @Override - protected String resolveRequestMethod( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - return HTTP_REQUEST_METHOD; - } - - @Override - protected void processProduces( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set produces) { - TypeMirror returnType = method.getReturnType(); - if (isComplexType(returnType)) { - produces.addAll(MEDIA_TYPES); - } - } - - @Override - protected void processConsumes( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set consumes) { - if (hasComplexParameterType(method)) { - consumes.addAll(MEDIA_TYPES); - } - } - - private boolean addComplexParameterType(ExecutableElement method) { - return hasComplexParameterTypeMethods.add(method); - } - - private boolean hasComplexParameterType(ExecutableElement method) { - return hasComplexParameterTypeMethods.remove(method); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataAnnotationProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataAnnotationProcessor.java deleted file mode 100644 index e9f0c8bed51..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataAnnotationProcessor.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.metadata.annotation.processing.AbstractServiceAnnotationProcessor; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.Processor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.element.TypeElement; - -import java.io.IOException; -import java.util.LinkedHashSet; -import java.util.Set; - -import static javax.lang.model.util.ElementFilter.typesIn; -import static org.apache.dubbo.metadata.annotation.processing.util.ServiceAnnotationUtils.isServiceAnnotationPresent; - -/** - * The {@link Processor} class to generate the metadata of REST from the classes that are annotated by Dubbo's - * - * @Service - * @see Processor - * @since 2.7.6 - */ -public class ServiceRestMetadataAnnotationProcessor extends AbstractServiceAnnotationProcessor { - - private Set metadataProcessors; - - private ServiceRestMetadataStorage serviceRestMetadataWriter; - - private Set serviceRestMetadata = new LinkedHashSet<>(); - - @Override - public synchronized void init(ProcessingEnvironment processingEnv) { - super.init(processingEnv); - this.metadataProcessors = ApplicationModel.defaultModel() - .getExtensionLoader(ServiceRestMetadataResolver.class) - .getSupportedExtensionInstances(); - this.serviceRestMetadataWriter = new ServiceRestMetadataStorage(processingEnv); - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - - typesIn(roundEnv.getRootElements()).forEach(serviceType -> process(processingEnv, serviceType, annotations)); - - if (roundEnv.processingOver()) { - try { - serviceRestMetadataWriter.append(serviceRestMetadata); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - return false; - } - - private void process( - ProcessingEnvironment processingEnv, TypeElement serviceType, Set annotations) { - metadataProcessors.stream() - .filter(processor -> supports(processor, processingEnv, serviceType)) - .map(processor -> processor.resolve(processingEnv, serviceType, annotations)) - .forEach(serviceRestMetadata::add); - } - - private boolean supports( - ServiceRestMetadataResolver processor, ProcessingEnvironment processingEnv, TypeElement serviceType) { - // @Service must be present in service type - return isServiceAnnotationPresent(serviceType) && processor.supports(processingEnv, serviceType); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataResolver.java deleted file mode 100644 index ed29a2d909d..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataResolver.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.common.extension.SPI; -import org.apache.dubbo.common.lang.Prioritized; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.TypeElement; - -import java.util.Set; - -/** - * The class to resolve {@link ServiceRestMetadata} based on Annotation Processor Tool - * - * @since 2.7.6 - */ -@SPI("default") -public interface ServiceRestMetadataResolver extends Prioritized { - - /** - * Supports or not to the specified service type - * - * @param processingEnvironment {@link ProcessingEnvironment} - * @param serviceType Dubbo service type or interface - * @return if supports, return true, or false - */ - boolean supports(ProcessingEnvironment processingEnvironment, TypeElement serviceType); - - /** - * Resolve the {@link ServiceRestMetadata} from given service type - * - * @param processingEnvironment {@link ProcessingEnvironment} - * @param serviceType Dubbo service type or interface - * @param annotations - * @return non-null - */ - ServiceRestMetadata resolve( - ProcessingEnvironment processingEnvironment, - TypeElement serviceType, - Set annotations); -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataStorage.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataStorage.java deleted file mode 100644 index 14a14c24eb8..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/ServiceRestMetadataStorage.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.common.utils.JsonUtils; -import org.apache.dubbo.metadata.annotation.processing.ClassPathMetadataStorage; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; - -import javax.annotation.processing.ProcessingEnvironment; - -import java.io.IOException; -import java.util.Set; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SERVICE_REST_METADATA_RESOURCE_PATH; - -/** - * The storage for {@link ServiceRestMetadata} - */ -public class ServiceRestMetadataStorage { - - private final ClassPathMetadataStorage storage; - - public ServiceRestMetadataStorage(ProcessingEnvironment processingEnv) { - this.storage = new ClassPathMetadataStorage(processingEnv); - } - - public void append(Set serviceRestMetadata) throws IOException { - // Add all existed ServiceRestMetadata - storage.read(SERVICE_REST_METADATA_RESOURCE_PATH, reader -> { - try { - StringBuilder stringBuilder = new StringBuilder(); - char[] buf = new char[1024]; - int len; - while ((len = reader.read(buf)) != -1) { - stringBuilder.append(buf, 0, len); - } - return JsonUtils.toJavaList(stringBuilder.toString(), ServiceRestMetadata.class); - } catch (IOException e) { - return null; - } - }) - .ifPresent(serviceRestMetadata::addAll); - write(serviceRestMetadata); - } - - public void write(Set serviceRestMetadata) throws IOException { - if (serviceRestMetadata.isEmpty()) { - return; - } - storage.write(() -> JsonUtils.toJson(serviceRestMetadata), SERVICE_REST_METADATA_RESOURCE_PATH); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/DefaultValueParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/DefaultValueParameterProcessor.java deleted file mode 100644 index 213d2647b40..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/DefaultValueParameterProcessor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import java.util.List; -import java.util.Map; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.DEFAULT_VALUE_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @DefaultValue - * * - * - * @since 2.7.6 - */ -public class DefaultValueParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationType() { - return DEFAULT_VALUE_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String annotationValue, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - - // process the request parameters - setDefaultValue(requestMetadata.getParams(), defaultValue, annotationValue); - // process the request headers - setDefaultValue(requestMetadata.getHeaders(), defaultValue, annotationValue); - } - - private void setDefaultValue(Map> source, String placeholderValue, String defaultValue) { - OUTTER: - for (Map.Entry> entry : source.entrySet()) { - List values = entry.getValue(); - int size = values.size(); - for (int i = 0; i < size; i++) { - String value = values.get(i); - if (placeholderValue.equals(value)) { - values.set(i, defaultValue); - break OUTTER; - } - } - } - } - - @Override - public int getPriority() { - return MIN_PRIORITY; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/FormParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/FormParamParameterProcessor.java deleted file mode 100644 index 01e57db7a06..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/FormParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.FORM_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @FormParam - * - * @since 2.7.6 - */ -public class FormParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationType() { - return FORM_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/HeaderParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/HeaderParamParameterProcessor.java deleted file mode 100644 index 5579904e702..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/HeaderParamParameterProcessor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import static org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor.buildDefaultValue; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.HEADER_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @HeaderParam - * - * @since 2.7.6 - */ -public class HeaderParamParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationType() { - return HEADER_PARAM_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String headerName, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - // Add the placeholder as header value - requestMetadata.addHeader(headerName, buildDefaultValue(parameterIndex)); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java deleted file mode 100644 index fcfc9f341fb..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractServiceRestMetadataResolver; -import org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.AnnotatedConstruct; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; - -import java.util.Set; -import java.util.stream.Stream; - -import static org.apache.dubbo.common.utils.PathUtils.buildPath; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getValue; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.CONSUMES_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.HTTP_METHOD_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PATH_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PRODUCES_ANNOTATION_CLASS_NAME; - -/** - * {@link ServiceRestMetadataResolver} implementation for JAX-RS 2 and 1 - * - * @since 2.7.6 - */ -public class JAXRSServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - - @Override - public boolean supports(ProcessingEnvironment processingEnvironment, TypeElement serviceType) { - return supports(serviceType); - } - - public static boolean supports(TypeElement serviceType) { - return isAnnotationPresent(serviceType, PATH_ANNOTATION_CLASS_NAME); - } - - @Override - protected boolean supports( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement method) { - return isAnnotationPresent(method, PATH_ANNOTATION_CLASS_NAME) - || isAnnotationPresent(method, HTTP_METHOD_ANNOTATION_CLASS_NAME); - } - - @Override - protected String resolveRequestPath( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - String pathFromType = getPathValue(processingEnv, serviceType); - String pathFromMethod = getPathValue(method); - return buildPath(pathFromType, pathFromMethod); - } - - @Override - protected String resolveRequestMethod( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - AnnotationMirror annotation = findMetaAnnotation(method, HTTP_METHOD_ANNOTATION_CLASS_NAME); - return getValue(annotation); - } - - @Override - protected void processProduces( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set produces) { - addAnnotationValues(method, PRODUCES_ANNOTATION_CLASS_NAME, produces); - } - - @Override - protected void processConsumes( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set consumes) { - addAnnotationValues(method, CONSUMES_ANNOTATION_CLASS_NAME, consumes); - } - - private void addAnnotationValues(Element element, String annotationAttributeName, Set result) { - AnnotationMirror annotation = findAnnotation(element, annotationAttributeName); - String[] value = getValue(annotation); - if (value != null) { - Stream.of(value).forEach(result::add); - } - } - - private String getPathValue(ProcessingEnvironment processingEnv, TypeElement serviceType) { - AnnotationMirror annotation = findAnnotation(serviceType, PATH_ANNOTATION_CLASS_NAME); - return getValue(annotation); - } - - private String getPathValue(AnnotatedConstruct annotatedConstruct) { - AnnotationMirror annotation = getAnnotation(annotatedConstruct, PATH_ANNOTATION_CLASS_NAME); - return getValue(annotation); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/MatrixParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/MatrixParamParameterProcessor.java deleted file mode 100644 index cf1d96d9aa7..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/MatrixParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.MATRIX_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @MatrixParam - * - * @since 2.7.6 - */ -public class MatrixParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationType() { - return MATRIX_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/ParamAnnotationParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/ParamAnnotationParameterProcessor.java deleted file mode 100644 index 8052fc91237..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/ParamAnnotationParameterProcessor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @*Param - */ -public abstract class ParamAnnotationParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - protected void process( - String name, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - requestMetadata.addParam(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/QueryParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/QueryParamParameterProcessor.java deleted file mode 100644 index 71ba378f9f8..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/QueryParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.jaxrs; - -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.QUERY_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @QueryParam - * - * @since 2.7.6 - */ -public class QueryParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationType() { - return QUERY_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java deleted file mode 100644 index 2d9cf8dfb51..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.springmvc; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAttribute; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @Request* - */ -public abstract class AbstractRequestAnnotationParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - protected abstract void process( - String name, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata); - - @Override - protected String getAnnotationValue(AnnotationMirror annotation, VariableElement parameter, int parameterIndex) { - // try to get "value" attribute first - String name = super.getAnnotationValue(annotation, parameter, parameterIndex); - - // try to get "name" attribute if required - if (isEmpty(name)) { - name = getAttribute(annotation, "name"); - } - - // finally , try to the name of parameter - if (isEmpty(name)) { - name = parameter.getSimpleName().toString(); - } - - return name; - } - - protected String getDefaultValue(AnnotationMirror annotation, VariableElement parameter, int parameterIndex) { - String defaultValue = getAttribute(annotation, "defaultValue"); - if (isEmpty(defaultValue)) { - defaultValue = super.getDefaultValue(annotation, parameter, parameterIndex); - } - return defaultValue; - } - - protected boolean isEmpty(String str) { - return str == null || str.isEmpty(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestHeaderParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestHeaderParameterProcessor.java deleted file mode 100644 index 49a5f747e8f..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestHeaderParameterProcessor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.springmvc; - -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_HEADER_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @RequestHeader - */ -public class RequestHeaderParameterProcessor extends AbstractRequestAnnotationParameterProcessor { - - @Override - public String getAnnotationType() { - return REQUEST_HEADER_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String name, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - restMethodMetadata.getRequest().addHeader(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestParamParameterProcessor.java deleted file mode 100644 index f881f1ca12b..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/RequestParamParameterProcessor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.springmvc; - -import org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @RequestParam - */ -public class RequestParamParameterProcessor extends AbstractRequestAnnotationParameterProcessor { - - @Override - public String getAnnotationType() { - return REQUEST_PARAM_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String name, - String defaultValue, - AnnotationMirror annotation, - VariableElement parameter, - int parameterIndex, - ExecutableElement method, - RestMethodMetadata restMethodMetadata) { - restMethodMetadata.getRequest().addParam(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java deleted file mode 100644 index bcf1d6edd79..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest.springmvc; - -import org.apache.dubbo.metadata.annotation.processing.rest.AbstractServiceRestMetadataResolver; -import org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; - -import java.lang.reflect.Array; -import java.util.Set; - -import static java.lang.String.valueOf; -import static java.lang.reflect.Array.getLength; -import static java.util.stream.Stream.of; -import static org.apache.dubbo.common.function.Streams.filterFirst; -import static org.apache.dubbo.common.utils.ArrayUtils.isEmpty; -import static org.apache.dubbo.common.utils.ArrayUtils.isNotEmpty; -import static org.apache.dubbo.common.utils.PathUtils.buildPath; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAllAnnotations; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAttribute; -import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.CONTROLLER_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_MAPPING_ANNOTATION_CLASS_NAME; - -/** - * {@link ServiceRestMetadataResolver} - * - * @since 2.7.6 - */ -public class SpringMvcServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - - private static final int FIRST_ELEMENT_INDEX = 0; - - @Override - public boolean supports(ProcessingEnvironment processingEnvironment, TypeElement serviceType) { - return supports(serviceType); - } - - @Override - protected boolean supports( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - TypeElement serviceInterfaceType, - ExecutableElement method) { - return isAnnotationPresent(method, REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - } - - public static boolean supports(TypeElement serviceType) { - // class @Controller or @RequestMapping - return isAnnotationPresent(serviceType, CONTROLLER_ANNOTATION_CLASS_NAME) - || isAnnotationPresent(serviceType, REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - } - - @Override - protected String resolveRequestPath( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - - String requestPathFromType = getRequestPath(serviceType); - - String requestPathFromMethod = getRequestPath(method); - - return buildPath(requestPathFromType, requestPathFromMethod); - } - - @Override - protected String resolveRequestMethod( - ProcessingEnvironment processingEnv, TypeElement serviceType, ExecutableElement method) { - - AnnotationMirror requestMapping = getRequestMapping(method); - - // httpMethod is an array of RequestMethod - Object httpMethod = getAttribute(requestMapping, "method"); - - if (httpMethod == null || getLength(httpMethod) < 1) { - return null; - } - - // TODO Is is required to support more request methods? - return valueOf(Array.get(httpMethod, FIRST_ELEMENT_INDEX)); - } - - private AnnotationMirror getRequestMapping(Element element) { - // try "@RequestMapping" first - AnnotationMirror requestMapping = findAnnotation(element, REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - // try the annotation meta-annotated later - if (requestMapping == null) { - requestMapping = findMetaAnnotation(element, REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - } - return requestMapping; - } - - @Override - protected void processProduces( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set produces) { - addMediaTypes(method, "produces", produces); - } - - @Override - protected void processConsumes( - ProcessingEnvironment processingEnv, - TypeElement serviceType, - ExecutableElement method, - Set consumes) { - addMediaTypes(method, "consumes", consumes); - } - - private void addMediaTypes(ExecutableElement method, String annotationAttributeName, Set mediaTypesSet) { - - AnnotationMirror mappingAnnotation = getMappingAnnotation(method); - - String[] mediaTypes = getAttribute(mappingAnnotation, annotationAttributeName); - - if (isNotEmpty(mediaTypes)) { - of(mediaTypes).forEach(mediaTypesSet::add); - } - } - - private AnnotationMirror getMappingAnnotation(Element element) { - return computeIfAbsent( - valueOf(element), - key -> filterFirst(getAllAnnotations(element), annotation -> { - DeclaredType annotationType = annotation.getAnnotationType(); - // try "@RequestMapping" first - if (REQUEST_MAPPING_ANNOTATION_CLASS_NAME.equals(annotationType.toString())) { - return true; - } - // try meta annotation - return isAnnotationPresent(annotationType.asElement(), REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - })); - } - - private String getRequestPath(Element element) { - AnnotationMirror mappingAnnotation = getMappingAnnotation(element); - return getRequestPath(mappingAnnotation); - } - - private String getRequestPath(AnnotationMirror mappingAnnotation) { - // try "value" first - String[] value = getAttribute(mappingAnnotation, "value"); - - if (isEmpty(value)) { // try "path" later - value = getAttribute(mappingAnnotation, "path"); - } - - if (isEmpty(value)) { - return ""; - } - // TODO Is is required to support more request paths? - return value[FIRST_ELEMENT_INDEX]; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor b/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor deleted file mode 100644 index 985daed606c..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.AnnotatedMethodParameterProcessor +++ /dev/null @@ -1,10 +0,0 @@ -# JAX-RS's implementations -jax-rs.query-param = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.QueryParamParameterProcessor -jax-rs.form-param = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.FormParamParameterProcessor -jax-rs.matrix-param = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.MatrixParamParameterProcessor -jax-rs.header-param = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.HeaderParamParameterProcessor -jax-rs.default-value-param = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.DefaultValueParameterProcessor - -# Spring Web MVC's implementations -spring-webmvc.request-param = org.apache.dubbo.metadata.annotation.processing.rest.springmvc.RequestParamParameterProcessor -spring-webmvc.request-header = org.apache.dubbo.metadata.annotation.processing.rest.springmvc.RequestHeaderParameterProcessor \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver b/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver deleted file mode 100644 index 9737e7d6f2a..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataResolver +++ /dev/null @@ -1,3 +0,0 @@ -default = org.apache.dubbo.metadata.annotation.processing.rest.DefaultServiceRestMetadataResolver -jax-rs = org.apache.dubbo.metadata.annotation.processing.rest.jaxrs.JAXRSServiceRestMetadataResolver -spring-webmvc = org.apache.dubbo.metadata.annotation.processing.rest.springmvc.SpringMvcServiceRestMetadataResolver \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 6c5909c26ff..7d46e9fa68a 100644 --- a/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/dubbo-metadata/dubbo-metadata-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,2 +1 @@ org.apache.dubbo.metadata.annotation.processing.ServiceDefinitionMetadataAnnotationProcessor -org.apache.dubbo.metadata.annotation.processing.rest.ServiceRestMetadataAnnotationProcessor diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java deleted file mode 100644 index 6db0efb5b5a..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -/** - * The abstract class for {@link AnnotatedMethodParameterProcessor}'s test cases - * - * @since 2.7.6 - */ -public abstract class AnnotatedMethodParameterProcessorTest extends AbstractAnnotationProcessingTest { - - protected AnnotatedMethodParameterProcessor processor; - - protected RestMethodMetadata restMethodMetadata; - - protected abstract AnnotatedMethodParameterProcessor createTestInstance(); - - @BeforeEach - public final void prepare() { - this.processor = createTestInstance(); - this.restMethodMetadata = createRestMethodMetadata(); - } - - protected RestMethodMetadata createRestMethodMetadata() { - return new RestMethodMetadata(); - } - - protected abstract String getExpectedAnnotationType(); - - @Test - void testGetAnnotationType() { - String expectedAnnotationType = getExpectedAnnotationType(); - assertNull(processor.getAnnotationType()); - assertEquals(expectedAnnotationType, processor.getAnnotationType()); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/AnnotationUtilsTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/AnnotationUtilsTest.java index 1bb202d91d4..b07df32017e 100644 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/AnnotationUtilsTest.java +++ b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/annotation/processing/util/AnnotationUtilsTest.java @@ -18,14 +18,12 @@ import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; -import org.apache.dubbo.metadata.rest.SpringRestService; import org.apache.dubbo.metadata.tools.TestService; import org.apache.dubbo.metadata.tools.TestServiceImpl; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import javax.ws.rs.Path; @@ -35,7 +33,6 @@ import java.util.Set; import org.junit.jupiter.api.Test; -import org.springframework.web.bind.annotation.GetMapping; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation; @@ -45,9 +42,7 @@ import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAttribute; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getValue; import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.findMethod; import static org.apache.dubbo.metadata.annotation.processing.util.MethodUtils.getAllDeclaredMethods; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -237,13 +232,6 @@ void testGetAttribute() { assertNull(getAttribute(findAnnotation(testType, Path.class), null)); assertNull(getAttribute(findAnnotation(testType, (Class) null), null)); - - ExecutableElement method = findMethod(getType(SpringRestService.class), "param", String.class); - - AnnotationMirror annotation = findAnnotation(method, GetMapping.class); - - assertArrayEquals(new String[] {"/param"}, (String[]) getAttribute(annotation, "value")); - assertNull(getAttribute(annotation, "path")); } @Test diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java deleted file mode 100644 index 844fe840f37..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.DubboService; - -import java.util.Map; - -/** - * The default implementation of {@link RestService} - * - * @since 2.7.6 - */ -@DubboService(version = "1.0.0", group = "default") -public class DefaultRestService implements RestService { - - @Override - public String param(String param) { - return null; - } - - @Override - public String params(int a, String b) { - return null; - } - - @Override - public String headers(String header, String header2, Integer param) { - return null; - } - - @Override - public String pathVariables(String path1, String path2, String param) { - return null; - } - - @Override - public String form(String form) { - return null; - } - - @Override - public User requestBodyMap(Map data, String param) { - return null; - } - - @Override - public Map requestBodyUser(User user) { - return null; - } - - public User user(User user) { - return user; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/RestService.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/RestService.java deleted file mode 100644 index 7b6883780da..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/RestService.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.util.Map; - -/** - * An interface for REST service - * - * @since 2.7.6 - */ -public interface RestService { - - String param(String param); - - String params(int a, String b); - - String headers(String header, String header2, Integer param); - - String pathVariables(String path1, String path2, String param); - - String form(String form); - - User requestBodyMap(Map data, String param); - - Map requestBodyUser(User user); -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java deleted file mode 100644 index b475bd53da8..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.DubboService; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * Spring MVC {@link RestService} - * - * @since 2.7.6 - */ -@DubboService(version = "2.0.0", group = "spring") -@RestController -public class SpringRestService implements RestService { - - @Override - @GetMapping(value = "/param") - public String param(@RequestParam(defaultValue = "value-param") String param) { - return null; - } - - @Override - @PostMapping("/params") - public String params( - @RequestParam(defaultValue = "value-a") int a, @RequestParam(defaultValue = "value-b") String b) { - return null; - } - - @Override - @GetMapping("/headers") - public String headers( - @RequestHeader(name = "h", defaultValue = "value-h") String header, - @RequestHeader(name = "h2", defaultValue = "value-h2") String header2, - @RequestParam(value = "v", defaultValue = "1") Integer param) { - return null; - } - - @Override - @GetMapping("/path-variables/{p1}/{p2}") - public String pathVariables( - @PathVariable("p1") String path1, @PathVariable("p2") String path2, @RequestParam("v") String param) { - return null; - } - - @Override - @PostMapping("/form") - public String form(@RequestParam("f") String form) { - return String.valueOf(form); - } - - @Override - @PostMapping(value = "/request/body/map", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public User requestBodyMap(@RequestBody Map data, @RequestParam("param") String param) { - User user = new User(); - user.setId(((Integer) data.get("id")).longValue()); - user.setName((String) data.get("name")); - user.setAge((Integer) data.get("age")); - return user; - } - - @PostMapping(value = "/request/body/user", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) - @Override - public Map requestBodyUser(@RequestBody User user) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("name", user.getName()); - map.put("age", user.getAge()); - return map; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java deleted file mode 100644 index 2f7d57e557b..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.DubboService; - -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import java.util.HashMap; -import java.util.Map; - -/** - * JAX-RS {@link RestService} - */ -@DubboService( - version = "3.0.0", - protocol = {"dubbo", "rest"}, - group = "standard") -@Path("/") -public class StandardRestService implements RestService { - - @Override - @Path("param") - @GET - public String param(@QueryParam("param") String param) { - return param; - } - - @Override - @Path("params") - @POST - public String params(@QueryParam("a") int a, @QueryParam("b") String b) { - return a + b; - } - - @Override - @Path("headers") - @GET - public String headers( - @HeaderParam("h") String header, @HeaderParam("h2") String header2, @QueryParam("v") Integer param) { - String result = header + " , " + header2 + " , " + param; - return result; - } - - @Override - @Path("path-variables/{p1}/{p2}") - @GET - public String pathVariables( - @PathParam("p1") String path1, @PathParam("p2") String path2, @QueryParam("v") String param) { - String result = path1 + " , " + path2 + " , " + param; - return result; - } - - // @CookieParam does not support : https://github.com/OpenFeign/feign/issues/913 - // @CookieValue also does not support - - @Override - @Path("form") - @POST - public String form(@FormParam("f") String form) { - return String.valueOf(form); - } - - @Override - @Path("request/body/map") - @POST - @Produces("application/json;charset=UTF-8") - public User requestBodyMap(Map data, @QueryParam("param") String param) { - User user = new User(); - user.setId(((Integer) data.get("id")).longValue()); - user.setName((String) data.get("name")); - user.setAge((Integer) data.get("age")); - return user; - } - - @Path("request/body/user") - @POST - @Override - @Consumes("application/json;charset=UTF-8") - public Map requestBodyUser(User user) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("name", user.getName()); - map.put("age", user.getAge()); - return map; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/User.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/User.java deleted file mode 100644 index 2b6c4a21baa..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/rest/User.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.io.Serializable; - -/** - * User Entity - * - * @since 2.7.6 - */ -public class User implements Serializable { - - private Long id; - - private String name; - - private Integer age; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - @Override - public String toString() { - return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/DefaultRestServiceTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/DefaultRestServiceTest.java deleted file mode 100644 index 9b020d2ca4d..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/DefaultRestServiceTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.dubbo.metadata.tools; - -import org.apache.dubbo.metadata.rest.DefaultRestService; -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.SpringRestService; -import org.apache.dubbo.metadata.rest.StandardRestService; -import org.apache.dubbo.metadata.rest.User; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -/** - * The test case for {@link DefaultRestService} - * - * @since 2.7.6 - */ -class DefaultRestServiceTest { - - @Test - void test() throws IOException { - Compiler compiler = new Compiler(); - compiler.compile( - User.class, - RestService.class, - DefaultRestService.class, - SpringRestService.class, - StandardRestService.class); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/RestServiceTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/RestServiceTest.java deleted file mode 100644 index b8ea68c957f..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/RestServiceTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.dubbo.metadata.tools; - -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.SpringRestService; -import org.apache.dubbo.metadata.rest.StandardRestService; -import org.apache.dubbo.metadata.rest.User; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -/** - * {@link RestService} Test - * - * @since 2.7.6 - */ -class RestServiceTest { - - @Test - void test() throws IOException { - Compiler compiler = new Compiler(); - compiler.compile(User.class, RestService.class, StandardRestService.class, SpringRestService.class); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/SpringRestServiceTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/SpringRestServiceTest.java deleted file mode 100644 index 5871c21fefe..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/SpringRestServiceTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.dubbo.metadata.tools; - -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.SpringRestService; -import org.apache.dubbo.metadata.rest.User; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -/** - * {@link SpringRestService} Test - * - * @since 2.7.6 - */ -class SpringRestServiceTest { - - @Test - void test() throws IOException { - Compiler compiler = new Compiler(); - compiler.compile(User.class, RestService.class, SpringRestService.class); - } -} diff --git a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/StandardRestServiceTest.java b/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/StandardRestServiceTest.java deleted file mode 100644 index 84c8199dc7d..00000000000 --- a/dubbo-metadata/dubbo-metadata-processor/src/test/java/org/apache/dubbo/metadata/tools/StandardRestServiceTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.dubbo.metadata.tools; - -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.StandardRestService; -import org.apache.dubbo.metadata.rest.User; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -/** - * The test case for {@link StandardRestService} - * - * @since 2.7.6 - */ -class StandardRestServiceTest { - - @Test - void test() throws IOException { - Compiler compiler = new Compiler(); - compiler.compile(User.class, RestService.class, StandardRestService.class); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/pom.xml b/dubbo-metadata/dubbo-metadata-rest/pom.xml deleted file mode 100644 index 8df334033a4..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - 4.0.0 - - org.apache.dubbo - dubbo-metadata - ${revision} - ../pom.xml - - - dubbo-metadata-rest - jar - - dubbo-metadata-rest - The rest metadata module of Dubbo project - - - 2.7.17 - - - - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot.version} - pom - import - - - org.springframework.boot - spring-boot-starter - ${spring-boot.version} - - - org.springframework.boot - spring-boot-starter-logging - - - - - - - - - org.apache.dubbo - dubbo-metadata-api - ${project.parent.version} - - - - - javax.ws.rs - javax.ws.rs-api - test - - - - - org.springframework - spring-web - test - - - - - org.springframework - spring-context - test - - - - org.springframework.cloud - spring-cloud-openfeign-core - test - - - - org.springframework.boot - spring-boot-starter-log4j2 - test - - - - diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractAnnotatedMethodParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractAnnotatedMethodParameterProcessor.java deleted file mode 100644 index d7f9a32bc39..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractAnnotatedMethodParameterProcessor.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.common.utils.AnnotationUtils.getValue; -import static org.apache.dubbo.common.utils.ClassUtils.getClassLoader; -import static org.apache.dubbo.common.utils.ClassUtils.resolveClass; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation - * - * @since 2.7.6 - */ -public abstract class AbstractAnnotatedMethodParameterProcessor implements AnnotatedMethodParameterProcessor { - - @Override - public void process( - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata restMethodMetadata) { - - String annotationValue = getAnnotationValue(annotation, parameter, parameterIndex); - String defaultValue = getDefaultValue(annotation, parameter, parameterIndex); - addArgInfo(parameter, parameterIndex, restMethodMetadata, annotationValue, defaultValue); - process(annotationValue, defaultValue, annotation, parameter, parameterIndex, method, restMethodMetadata); - } - - protected void process( - String annotationValue, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) {} - - @Override - public Class getAnnotationClass() { - return resolveClass(getAnnotationName(), getClassLoader()); - } - - protected void addArgInfo( - Parameter parameter, - int parameterIndex, - RestMethodMetadata restMethodMetadata, - String annotationValue, - Object defaultValue) { - ArgInfo argInfo = ArgInfo.build(parameterIndex, parameter) - .setParamAnnotationType(getAnnotationClass()) - .setAnnotationNameAttribute(annotationValue) - .setDefaultValue(defaultValue); - restMethodMetadata.addArgInfo(argInfo); - } - - protected String getAnnotationValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return getValue(annotation); - } - - protected String getDefaultValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return AnnotatedMethodParameterProcessor.buildDefaultValue(parameterIndex); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractNoAnnotatedParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractNoAnnotatedParameterProcessor.java deleted file mode 100644 index 23cdd4cbf3f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractNoAnnotatedParameterProcessor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.media.MediaType; - -import java.lang.reflect.Parameter; -import java.util.Set; - -import static org.apache.dubbo.common.utils.ClassUtils.getClassLoader; -import static org.apache.dubbo.common.utils.ClassUtils.resolveClass; - -public abstract class AbstractNoAnnotatedParameterProcessor implements NoAnnotatedParameterRequestTagProcessor { - - public boolean process(Parameter parameter, int parameterIndex, RestMethodMetadata restMethodMetadata) { - MediaType mediaType = consumerContentType(); - if (!contentTypeSupport(restMethodMetadata, mediaType, parameter.getType())) { - return false; - } - boolean isFormBody = isFormContentType(restMethodMetadata); - addArgInfo(parameter, parameterIndex, restMethodMetadata, isFormBody); - return true; - } - - private boolean contentTypeSupport(RestMethodMetadata restMethodMetadata, MediaType mediaType, Class paramType) { - - // @RequestParam String,number param - if (mediaType.equals(MediaType.ALL_VALUE)) { - // jaxrs no annotation param is from http body - if (JAXRSServiceRestMetadataResolver.class.equals(restMethodMetadata.getCodeStyle())) { - return true; - } - - // spring mvc no annotation param only is used by text data(string,number) - if (String.class == paramType || paramType.isPrimitive() || Number.class.isAssignableFrom(paramType)) { - return true; - } - } - - Set consumes = restMethodMetadata.getRequest().getConsumes(); - for (String consume : consumes) { - if (consume.contains(mediaType.value)) { - return true; - } - } - - return false; - } - - protected boolean isFormContentType(RestMethodMetadata restMethodMetadata) { - - return false; - } - - protected void addArgInfo( - Parameter parameter, int parameterIndex, RestMethodMetadata restMethodMetadata, boolean isFormBody) { - ArgInfo argInfo = ArgInfo.build(parameterIndex, parameter) - .setParamAnnotationType(resolveClass(defaultAnnotationClassName(restMethodMetadata), getClassLoader())) - .setAnnotationNameAttribute(parameter.getName()) - .setFormContentType(isFormBody); - restMethodMetadata.addArgInfo(argInfo); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractServiceRestMetadataResolver.java deleted file mode 100644 index d3e1d537000..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AbstractServiceRestMetadataResolver.java +++ /dev/null @@ -1,487 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.compact.Dubbo2CompactUtils; -import org.apache.dubbo.common.utils.MethodComparator; -import org.apache.dubbo.common.utils.ServiceAnnotationResolver; -import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.config.annotation.Service; -import org.apache.dubbo.metadata.definition.MethodDefinitionBuilder; -import org.apache.dubbo.metadata.definition.model.MethodDefinition; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -import static java.util.Collections.emptyList; -import static java.util.Collections.sort; -import static java.util.Collections.unmodifiableMap; -import static org.apache.dubbo.common.function.ThrowableFunction.execute; -import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.common.utils.AnnotationUtils.isAnyAnnotationPresent; -import static org.apache.dubbo.common.utils.ClassUtils.forName; -import static org.apache.dubbo.common.utils.ClassUtils.getAllInterfaces; -import static org.apache.dubbo.common.utils.MemberUtils.isPrivate; -import static org.apache.dubbo.common.utils.MemberUtils.isStatic; -import static org.apache.dubbo.common.utils.MethodUtils.excludedDeclaredClass; -import static org.apache.dubbo.common.utils.MethodUtils.getAllMethods; -import static org.apache.dubbo.common.utils.MethodUtils.overrides; - -/** - * The abstract {@link ServiceRestMetadataResolver} class to provider some template methods assemble the instance of - * {@link ServiceRestMetadata} will extended by the sub-classes. - * - * @since 2.7.6 - */ -public abstract class AbstractServiceRestMetadataResolver implements ServiceRestMetadataResolver { - - private final Map> parameterProcessorsMap; - private final Set noAnnotatedParameterRequestTagProcessors; - - public AbstractServiceRestMetadataResolver(ApplicationModel applicationModel) { - this.parameterProcessorsMap = loadAnnotatedMethodParameterProcessors(applicationModel); - this.noAnnotatedParameterRequestTagProcessors = loadNoAnnotatedMethodParameterProcessors(applicationModel); - } - - @Override - public final boolean supports(Class serviceType) { - return supports(serviceType, false); - } - - @Override - public final boolean supports(Class serviceType, boolean consumer) { - - if (serviceType == null) { - return false; - } - - // for consumer - // it is possible serviceType is impl - // for provider - // for xml config bean && isServiceAnnotationPresent(serviceType) - // isImplementedInterface(serviceType) SpringController - return supports0(serviceType); - } - - protected final boolean isImplementedInterface(Class serviceType) { - return !getAllInterfaces(serviceType).isEmpty(); - } - - protected final boolean isServiceAnnotationPresent(Class serviceType) { - if (Dubbo2CompactUtils.isEnabled() && Dubbo2CompactUtils.isServiceClassLoaded()) { - return isAnyAnnotationPresent( - serviceType, DubboService.class, Service.class, Dubbo2CompactUtils.getServiceClass()); - } else { - return isAnyAnnotationPresent(serviceType, DubboService.class, Service.class); - } - } - - /** - * internal support method - * - * @param serviceType Dubbo Service interface or type - * @return If supports, return true, or false - */ - protected abstract boolean supports0(Class serviceType); - - @Override - public final ServiceRestMetadata resolve(Class serviceType) { - ServiceRestMetadata serviceRestMetadata = new ServiceRestMetadata(); - - // Process ServiceRestMetadata - processServiceRestMetadata(serviceRestMetadata, serviceType); - - return resolve(serviceType, serviceRestMetadata); - } - - @Override - public final ServiceRestMetadata resolve(Class serviceType, ServiceRestMetadata serviceRestMetadata) { - serviceRestMetadata.setCodeStyle(this.getClass()); - // Process RestMethodMetadata - processAllRestMethodMetadata(serviceRestMetadata, serviceType); - - return serviceRestMetadata; - } - - /** - * Process the service type including the sub-routines: - *
    - *
  • {@link ServiceRestMetadata#setServiceInterface(String)}
  • - *
  • {@link ServiceRestMetadata#setVersion(String)}
  • - *
  • {@link ServiceRestMetadata#setGroup(String)}
  • - *
- * - * @param serviceRestMetadata {@link ServiceRestMetadata} - * @param serviceType Dubbo Service interface or type - */ - protected void processServiceRestMetadata(ServiceRestMetadata serviceRestMetadata, Class serviceType) { - ServiceAnnotationResolver resolver = new ServiceAnnotationResolver(serviceType); - serviceRestMetadata.setServiceInterface(resolver.resolveInterfaceClassName()); - serviceRestMetadata.setVersion(resolver.resolveVersion()); - serviceRestMetadata.setGroup(resolver.resolveGroup()); - } - - /** - * Process all {@link RestMethodMetadata} - * - * @param serviceRestMetadata {@link ServiceRestMetadata} - * @param serviceType Dubbo Service interface or type - */ - protected void processAllRestMethodMetadata(ServiceRestMetadata serviceRestMetadata, Class serviceType) { - Class serviceInterfaceClass = resolveServiceInterfaceClass(serviceRestMetadata, serviceType); - Map serviceMethodsMap = resolveServiceMethodsMap(serviceType, serviceInterfaceClass); - for (Map.Entry entry : serviceMethodsMap.entrySet()) { - // try the overrider method first - Method serviceMethod = entry.getKey(); - // If failed, it indicates the overrider method does not contain metadata , then try the declared method - if (!processRestMethodMetadata( - serviceMethod, - serviceType, - serviceInterfaceClass, - serviceRestMetadata::addRestMethodMetadata, - serviceRestMetadata)) { - Method declaredServiceMethod = entry.getValue(); - processRestMethodMetadata( - declaredServiceMethod, - serviceType, - serviceInterfaceClass, - serviceRestMetadata::addRestMethodMetadata, - serviceRestMetadata); - } - } - } - - /** - * Resolve a map of all public services methods from the specified service type and its interface class, whose key is the - * declared method, and the value is the overrider method - * - * @param serviceType the service interface implementation class - * @param serviceInterfaceClass the service interface class - * @return non-null read-only {@link Map} - */ - protected Map resolveServiceMethodsMap(Class serviceType, Class serviceInterfaceClass) { - Map serviceMethodsMap = new LinkedHashMap<>(); - // exclude the public methods declared in java.lang.Object.class - List declaredServiceMethods = - new ArrayList<>(getAllMethods(serviceInterfaceClass, excludedDeclaredClass(Object.class))); - - // controller class - if (serviceType.equals(serviceInterfaceClass)) { - putServiceMethodToMap(serviceMethodsMap, declaredServiceMethods); - return unmodifiableMap(serviceMethodsMap); - } - - // for interface , such as consumer interface - if (serviceType.isInterface()) { - putServiceMethodToMap(serviceMethodsMap, declaredServiceMethods); - return unmodifiableMap(serviceMethodsMap); - } - - List serviceMethods = new ArrayList<>(getAllMethods(serviceType, excludedDeclaredClass(Object.class))); - - // sort methods - sort(declaredServiceMethods, MethodComparator.INSTANCE); - sort(serviceMethods, MethodComparator.INSTANCE); - - // prevent from repeat method (impl proxy) & leaving out method(interface proxy) - HashSet methodComparators = new HashSet<>(); - - // TODO Map key: method desc & value: Set for accelerate loop speed - for (Method declaredServiceMethod : declaredServiceMethods) { - for (Method serviceMethod : serviceMethods) { - - if (!overrides(serviceMethod, declaredServiceMethod)) { - continue; - } - - String methodDesc = getMethodDesc(serviceMethod); - - if (!methodComparators.add(methodDesc)) { - continue; - } - - serviceMethodsMap.put(serviceMethod, declaredServiceMethod); - } - } - - // make them to be read-only - return unmodifiableMap(serviceMethodsMap); - } - - /** - * For simple method desc - * - * @param serviceMethod - * @return - */ - private String getMethodDesc(Method serviceMethod) { - return serviceMethod.getName() + Arrays.toString(serviceMethod.getParameterTypes()); - } - - private void putServiceMethodToMap(Map serviceMethodsMap, List declaredServiceMethods) { - declaredServiceMethods.stream().forEach(method -> { - - // filter static private default - if (isStatic(method) || isPrivate(method) || method.isDefault()) { - return; - } - serviceMethodsMap.put(method, method); - }); - } - - /** - * Resolve the class of Dubbo Service interface - * - * @param serviceRestMetadata {@link ServiceRestMetadata} - * @param serviceType Dubbo Service interface or type - * @return non-null - * @throws RuntimeException If the class is not found, the {@link RuntimeException} wraps the cause will be thrown - */ - protected Class resolveServiceInterfaceClass(ServiceRestMetadata serviceRestMetadata, Class serviceType) { - return execute(serviceType.getClassLoader(), classLoader -> { - String serviceInterface = serviceRestMetadata.getServiceInterface(); - return forName(serviceInterface, classLoader); - }); - } - - /** - * Process the single {@link RestMethodMetadata} by the specified {@link Consumer} if present - * - * @param serviceMethod Dubbo Service method - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @param metadataToProcess {@link RestMethodMetadata} to process if present - * @return if processed successfully, return true, or false - */ - protected boolean processRestMethodMetadata( - Method serviceMethod, - Class serviceType, - Class serviceInterfaceClass, - Consumer metadataToProcess, - ServiceRestMetadata serviceRestMetadata) { - - if (!isRestCapableMethod(serviceMethod, serviceType, serviceInterfaceClass)) { - return false; - } - - String requestPath = - resolveRequestPath(serviceMethod, serviceType, serviceInterfaceClass); // requestPath is required - - if (requestPath == null) { - return false; - } - - String requestMethod = - resolveRequestMethod(serviceMethod, serviceType, serviceInterfaceClass); // requestMethod is required - - if (requestMethod == null) { - return false; - } - - RestMethodMetadata metadata = new RestMethodMetadata(); - - metadata.setCodeStyle(this.getClass()); - - // to consumer service map - metadata.setReflectMethod(serviceMethod); - - MethodDefinition methodDefinition = resolveMethodDefinition(serviceMethod, serviceType, serviceInterfaceClass); - // Set MethodDefinition - metadata.setMethod(methodDefinition); - - // process produces - Set produces = new LinkedHashSet<>(); - processProduces(serviceMethod, serviceType, serviceInterfaceClass, produces); - - // process consumes - Set consumes = new LinkedHashSet<>(); - processConsumes(serviceMethod, serviceType, serviceInterfaceClass, consumes); - - // Initialize RequestMetadata - RequestMetadata request = metadata.getRequest(); - request.setPath(requestPath); - request.appendContextPathFromUrl(serviceRestMetadata.getContextPathFromUrl()); - request.setMethod(requestMethod); - request.setProduces(produces); - request.setConsumes(consumes); - - // process the annotated method parameters - processAnnotatedMethodParameters(serviceMethod, serviceType, serviceInterfaceClass, metadata); - - // Post-Process - postResolveRestMethodMetadata(serviceMethod, serviceType, serviceInterfaceClass, metadata); - - // Accept RestMethodMetadata - metadataToProcess.accept(metadata); - - return true; - } - - /** - * Test the service method is capable of REST or not? - * - * @param serviceMethod Dubbo Service method - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @return If capable, return true - */ - protected abstract boolean isRestCapableMethod( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass); - - /** - * Resolve the request method - * - * @param serviceMethod Dubbo Service method - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @return if can't be resolve, return null - */ - protected abstract String resolveRequestMethod( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass); - - /** - * Resolve the request path - * - * @param serviceMethod Dubbo Service method - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @return if can't be resolve, return null - */ - protected abstract String resolveRequestPath( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass); - - /** - * Resolve the {@link MethodDefinition} - * - * @param serviceMethod Dubbo Service method - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @return if can't be resolve, return null - * @see MethodDefinitionBuilder - */ - protected MethodDefinition resolveMethodDefinition( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - MethodDefinitionBuilder builder = new MethodDefinitionBuilder(); - return builder.build(serviceMethod); - } - - private void processAnnotatedMethodParameters( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, RestMethodMetadata metadata) { - int paramCount = serviceMethod.getParameterCount(); - Parameter[] parameters = serviceMethod.getParameters(); - for (int i = 0; i < paramCount; i++) { - Parameter parameter = parameters[i]; - // Add indexed parameter name - metadata.addIndexToName(i, parameter.getName()); - processAnnotatedMethodParameter(parameter, i, serviceMethod, serviceType, serviceInterfaceClass, metadata); - } - } - - protected void processAnnotatedMethodParameter( - Parameter parameter, - int parameterIndex, - Method serviceMethod, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata metadata) { - Annotation[] annotations = parameter.getAnnotations(); - - if (annotations == null || annotations.length == 0) { - - for (NoAnnotatedParameterRequestTagProcessor processor : noAnnotatedParameterRequestTagProcessors) { - // no annotation only one default annotationType - if (processor.process(parameter, parameterIndex, metadata)) { - return; - } - } - } - - for (Annotation annotation : annotations) { - String annotationType = annotation.annotationType().getName(); - parameterProcessorsMap.getOrDefault(annotationType, emptyList()).forEach(processor -> { - processor.process( - annotation, - parameter, - parameterIndex, - serviceMethod, - serviceType, - serviceInterfaceClass, - metadata); - }); - } - } - - protected abstract void processProduces( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set produces); - - protected abstract void processConsumes( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set consumes); - - protected void postResolveRestMethodMetadata( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, RestMethodMetadata metadata) { - - // parse pathVariable index from url by annotation info - PathUtil.setArgInfoSplitIndex(metadata.getRequest().getPath(), metadata.getArgInfos()); - } - - private static Map> loadAnnotatedMethodParameterProcessors( - ApplicationModel applicationModel) { - Map> parameterProcessorsMap = new LinkedHashMap<>(); - applicationModel - .getExtensionLoader(AnnotatedMethodParameterProcessor.class) - .getSupportedExtensionInstances() - .forEach(processor -> { - List processors = parameterProcessorsMap.computeIfAbsent( - processor.getAnnotationName(), k -> new LinkedList<>()); - processors.add(processor); - }); - return parameterProcessorsMap; - } - - private static Set loadNoAnnotatedMethodParameterProcessors( - ApplicationModel applicationModel) { - Set supportedExtensionInstances = applicationModel - .getExtensionLoader(NoAnnotatedParameterRequestTagProcessor.class) - .getSupportedExtensionInstances(); - - return supportedExtensionInstances; - } - - public static boolean isServiceMethodAnnotationPresent(Class serviceImpl, String annotationClass) { - List allMethods = getAllMethods(serviceImpl, excludedDeclaredClass(Object.class)); - - for (Method method : allMethods) { - if (isAnnotationPresent(method, annotationClass)) { - return true; - } - } - - return false; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AnnotatedMethodParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AnnotatedMethodParameterProcessor.java deleted file mode 100644 index b05bd4b48e2..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/AnnotatedMethodParameterProcessor.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.extension.ExtensionScope; -import org.apache.dubbo.common.extension.SPI; -import org.apache.dubbo.common.lang.Prioritized; - -import javax.lang.model.element.VariableElement; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -/** - * The interface to process the annotated method parameter - * - * @since 2.7.6 - */ -@SPI(scope = ExtensionScope.FRAMEWORK) -public interface AnnotatedMethodParameterProcessor extends Prioritized { - - /** - * The string presenting the annotation name - * - * @return non-null - */ - String getAnnotationName(); - - /** - * The string presenting the annotation type - * - * @return non-null - */ - Class getAnnotationClass(); - - /** - * Process the specified method {@link VariableElement parameter} - * - * @param annotation {@link Annotation the target annotation} whose type is {@link #getAnnotationName()} - * @param parameter the method parameter - * @param parameterIndex the index of method parameter - * @param method {@link Method method that parameter belongs to} - * @param serviceType Dubbo Service interface or type - * @param serviceInterfaceClass The type of Dubbo Service interface - * @param restMethodMetadata {@link RestMethodMetadata the metadata is used to update} - */ - void process( - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata restMethodMetadata); - - /** - * Build the default value - * - * @param parameterIndex the index of parameter - * @return the placeholder - */ - static String buildDefaultValue(int parameterIndex) { - return "{" + parameterIndex + "}"; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ArgInfo.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ArgInfo.java deleted file mode 100644 index dc2f7001f8a..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ArgInfo.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.lang.reflect.Parameter; -import java.lang.reflect.Type; - -/** - * description of service method args info - */ -public class ArgInfo { - /** - * method arg index 0,1,2,3 - */ - private int index; - /** - * method annotation name or name - */ - private String annotationNameAttribute; - - /** - * param annotation type - */ - private Class paramAnnotationType; - - /** - * param Type - */ - private Class paramType; - - /** - * param actual Type(collection,map,array) - */ - private Type actualType; - - /** - * param name - */ - private String paramName; - - /** - * url split("/") String[n] index - */ - private int urlSplitIndex; - - private Object defaultValue; - - private boolean formContentType; - - public ArgInfo(int index, String name, Class paramType) { - this.index = index; - this.paramName = name; - this.paramType = paramType; - } - - public ArgInfo(int index, Parameter parameter) { - this(index, parameter.getName(), parameter.getType()); - this.actualType = parameter.getParameterizedType(); - } - - public ArgInfo() {} - - public int getIndex() { - return index; - } - - public ArgInfo setIndex(int index) { - this.index = index; - return this; - } - - public String getAnnotationNameAttribute() { - if (annotationNameAttribute == null) { - // such as String param no annotation - return paramName; - } - return annotationNameAttribute; - } - - public ArgInfo setAnnotationNameAttribute(String annotationNameAttribute) { - this.annotationNameAttribute = annotationNameAttribute; - return this; - } - - public Class getParamAnnotationType() { - return paramAnnotationType; - } - - public ArgInfo setParamAnnotationType(Class paramAnnotationType) { - this.paramAnnotationType = paramAnnotationType; - return this; - } - - public Class getParamType() { - return paramType; - } - - public void setParamType(Class paramType) { - this.paramType = paramType; - } - - public int getUrlSplitIndex() { - return urlSplitIndex; - } - - public void setUrlSplitIndex(int urlSplitIndex) { - this.urlSplitIndex = urlSplitIndex; - } - - public static ArgInfo build() { - return new ArgInfo(); - } - - public static ArgInfo build(int index, Parameter parameter) { - return new ArgInfo(index, parameter); - } - - public String getParamName() { - return paramName; - } - - public ArgInfo setParamName(String paramName) { - this.paramName = paramName; - return this; - } - - public Object getDefaultValue() { - return defaultValue; - } - - public ArgInfo setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - return this; - } - - public boolean isFormContentType() { - return formContentType; - } - - public ArgInfo setFormContentType(boolean isFormContentType) { - this.formContentType = isFormContentType; - return this; - } - - public Type actualReflectType() { - return actualType; - } - - @Override - public String toString() { - return "ArgInfo{" + "index=" - + index + ", annotationNameAttribute='" - + annotationNameAttribute + '\'' + ", paramAnnotationType=" - + paramAnnotationType + ", paramType=" - + paramType + ", paramName='" - + paramName + '\'' + ", urlSplitIndex=" - + urlSplitIndex + ", defaultValue=" - + defaultValue + ", formContentType=" - + formContentType + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ClassPathServiceRestMetadataReader.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ClassPathServiceRestMetadataReader.java deleted file mode 100644 index 102f37ad03e..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ClassPathServiceRestMetadataReader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.utils.IOUtils; -import org.apache.dubbo.common.utils.JsonUtils; - -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.List; - -import static java.util.Collections.unmodifiableList; -import static org.apache.dubbo.common.function.ThrowableAction.execute; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.METADATA_ENCODING; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SERVICE_REST_METADATA_RESOURCE_PATH; - -/** - * Class-Path based {@link ServiceRestMetadataReader} implementation - * - * @see ServiceRestMetadataReader - * @since 2.7.6 - */ -public class ClassPathServiceRestMetadataReader implements ServiceRestMetadataReader { - - private final String serviceRestMetadataJsonResourcePath; - - public ClassPathServiceRestMetadataReader() { - this(SERVICE_REST_METADATA_RESOURCE_PATH); - } - - public ClassPathServiceRestMetadataReader(String serviceRestMetadataJsonResourcePath) { - this.serviceRestMetadataJsonResourcePath = serviceRestMetadataJsonResourcePath; - } - - @Override - public List read() { - - List serviceRestMetadataList = new LinkedList<>(); - - ClassLoader classLoader = getClass().getClassLoader(); - - execute(() -> { - Enumeration resources = classLoader.getResources(serviceRestMetadataJsonResourcePath); - while (resources.hasMoreElements()) { - URL resource = resources.nextElement(); - InputStream inputStream = resource.openStream(); - String json = IOUtils.read(inputStream, METADATA_ENCODING); - serviceRestMetadataList.addAll(JsonUtils.toJavaList(json, ServiceRestMetadata.class)); - } - }); - - return unmodifiableList(serviceRestMetadataList); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/DefaultServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/DefaultServiceRestMetadataResolver.java deleted file mode 100644 index 41a4e1bec99..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/DefaultServiceRestMetadataResolver.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.lang.reflect.Method; -import java.util.Set; - -/** - * The default implementation {@link ServiceRestMetadataResolver} - * - * @since 2.7.6 - */ -public class DefaultServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - public DefaultServiceRestMetadataResolver(ApplicationModel applicationModel) { - super(applicationModel); - } - - @Override - protected boolean supports0(Class serviceType) { - return false; - } - - @Override - protected boolean isRestCapableMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - return false; - } - - @Override - protected String resolveRequestMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - return null; - } - - @Override - protected String resolveRequestPath(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - return null; - } - - @Override - protected void processProduces( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set produces) {} - - @Override - protected void processConsumes( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set consumes) {} -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/JAXRSClassConstants.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/JAXRSClassConstants.java deleted file mode 100644 index 47c9149ff40..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/JAXRSClassConstants.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import static org.apache.dubbo.common.utils.ClassUtils.getClassLoader; -import static org.apache.dubbo.common.utils.ClassUtils.resolveClass; - -public interface JAXRSClassConstants extends RestMetadataConstants.JAX_RS { - /** - * The annotation class of @Path - */ - Class PATH_ANNOTATION_CLASS = resolveClass(PATH_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @FormParam - */ - Class FORM_PARAM_ANNOTATION_CLASS = resolveClass(FORM_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @Form - */ - Class FORM_BODY_ANNOTATION_CLASS = resolveClass(REST_EASY_FORM_BODY_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @HeaderParam - */ - Class HEADER_PARAM_ANNOTATION_CLASS = resolveClass(HEADER_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @MatrixParam - */ - Class MATRIX_PARAM_ANNOTATION_CLASS = resolveClass(MATRIX_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @QueryParam - */ - Class QUERY_PARAM_ANNOTATION_CLASS = resolveClass(QUERY_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @Body - */ - Class REST_EASY_BODY_ANNOTATION_CLASS = resolveClass(REST_EASY_BODY_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @PathParam - */ - Class PATH_PARAM_ANNOTATION_CLASS = resolveClass(PATH_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/NoAnnotatedParameterRequestTagProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/NoAnnotatedParameterRequestTagProcessor.java deleted file mode 100644 index 376e2245240..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/NoAnnotatedParameterRequestTagProcessor.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.extension.ExtensionScope; -import org.apache.dubbo.common.extension.SPI; -import org.apache.dubbo.metadata.rest.media.MediaType; - -import java.lang.reflect.Parameter; - -@SPI(scope = ExtensionScope.FRAMEWORK) -public interface NoAnnotatedParameterRequestTagProcessor { - MediaType consumerContentType(); - - String defaultAnnotationClassName(RestMethodMetadata restMethodMetadata); - - boolean process(Parameter parameter, int parameterIndex, RestMethodMetadata restMethodMetadata); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ParamType.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ParamType.java deleted file mode 100644 index 23ac6a840e9..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ParamType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.metadata.rest.tag.BodyTag; -import org.apache.dubbo.metadata.rest.tag.NoAnnotationTag; -import org.apache.dubbo.metadata.rest.tag.ParamTag; - -import java.util.ArrayList; -import java.util.List; - -public enum ParamType { - HEADER(addSupportTypes( - JAXRSClassConstants.HEADER_PARAM_ANNOTATION_CLASS, - SpringMvcClassConstants.REQUEST_HEADER_ANNOTATION_CLASS)), - - PARAM(addSupportTypes( - JAXRSClassConstants.QUERY_PARAM_ANNOTATION_CLASS, - SpringMvcClassConstants.REQUEST_PARAM_ANNOTATION_CLASS, - ParamTag.class)), - - BODY(addSupportTypes( - JAXRSClassConstants.REST_EASY_BODY_ANNOTATION_CLASS, - SpringMvcClassConstants.REQUEST_BODY_ANNOTATION_CLASS, - BodyTag.class)), - - PATH(addSupportTypes( - JAXRSClassConstants.PATH_PARAM_ANNOTATION_CLASS, SpringMvcClassConstants.PATH_VARIABLE_ANNOTATION_CLASS)), - - FORM(addSupportTypes( - JAXRSClassConstants.FORM_PARAM_ANNOTATION_CLASS, - JAXRSClassConstants.FORM_BODY_ANNOTATION_CLASS, - SpringMvcClassConstants.REQUEST_BODY_ANNOTATION_CLASS)), - - PROVIDER_BODY(addSupportTypes( - JAXRSClassConstants.REST_EASY_BODY_ANNOTATION_CLASS, - JAXRSClassConstants.FORM_PARAM_ANNOTATION_CLASS, - SpringMvcClassConstants.REQUEST_BODY_ANNOTATION_CLASS, - BodyTag.class, - JAXRSClassConstants.FORM_BODY_ANNOTATION_CLASS)), - - PROVIDER_NO_ANNOTATION(addSupportTypes(NoAnnotationTag.class)), - - EMPTY(addSupportTypes()); - private List annotationClasses; - - ParamType(List annotationClasses) { - this.annotationClasses = annotationClasses; - } - - public boolean supportAnno(Class anno) { - if (anno == null) { - return false; - } - return this.annotationClasses.contains(anno); - } - - /** - * exclude null types - * - * @param classes - * @return - */ - private static List addSupportTypes(Class... classes) { - - ArrayList types = new ArrayList<>(); - - for (Class clazz : classes) { - - if (clazz == null) { - continue; - } - - types.add(clazz); - } - - return types; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java deleted file mode 100644 index 2e526d19a64..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Objects; - -/** - * for http request path match - */ -public class PathMatcher { - private static final String SEPARATOR = "/"; - private String path; - private String version; // service version - private String group; // service group - private Integer port; // service port - private String[] pathSplits; - private boolean hasPathVariable; - private String contextPath; - private String httpMethod; - // for provider http method compare,http 405 - private boolean needCompareHttpMethod = true; - // compare method directly (for get Invoker by method) - private boolean needCompareServiceMethod = false; - - // service method - private Method method; - - public PathMatcher(String path) { - this(path, null, null, null); - } - - public PathMatcher(String path, String version, String group, Integer port) { - this.path = path; - dealPathVariable(path); - this.version = version; - this.group = group; - this.port = (port == null || port == -1 || port == 0) ? null : port; - } - - public PathMatcher(String path, String version, String group, Integer port, String httpMethod) { - this(path, version, group, port); - setHttpMethod(httpMethod); - } - - public PathMatcher(Method method) { - this.method = method; - } - - private void dealPathVariable(String path) { - if (path == null) { - return; - } - this.pathSplits = path.split(SEPARATOR); - - for (String pathSplit : pathSplits) { - - if (isPlaceHold(pathSplit)) { - hasPathVariable = true; - break; - } - } - } - - private void setPath(String path) { - this.path = path; - } - - public void setVersion(String version) { - this.version = version; - } - - public void setGroup(String group) { - this.group = group; - } - - public void setPort(Integer port) { - this.port = port; - } - - public void setContextPath(String contextPath) { - - contextPath = contextPathFormat(contextPath); - - this.contextPath = contextPath; - - setPath(contextPath + path); - - dealPathVariable(path); - } - - public static PathMatcher getInvokeCreatePathMatcher( - String path, String version, String group, Integer port, String method) { - return new PathMatcher(path, version, group, port, method).compareHttpMethod(false); - } - - public static PathMatcher getInvokeCreatePathMatcher(Method serviceMethod) { - return new PathMatcher(serviceMethod).setNeedCompareServiceMethod(true); - } - - public static PathMatcher convertPathMatcher(PathMatcher pathMatcher) { - return getInvokeCreatePathMatcher( - pathMatcher.path, pathMatcher.version, pathMatcher.group, pathMatcher.port, pathMatcher.httpMethod); - } - - public boolean hasPathVariable() { - return hasPathVariable; - } - - public Integer getPort() { - return port; - } - - public String getHttpMethod() { - return httpMethod; - } - - public PathMatcher setHttpMethod(String httpMethod) { - this.httpMethod = httpMethod; - return this; - } - - public PathMatcher compareHttpMethod(boolean needCompareHttpMethod) { - this.needCompareHttpMethod = needCompareHttpMethod; - return this; - } - - public Method getMethod() { - return method; - } - - public void setMethod(Method method) { - this.method = method; - } - - private PathMatcher setNeedCompareServiceMethod(boolean needCompareServiceMethod) { - this.needCompareServiceMethod = needCompareServiceMethod; - return this; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PathMatcher that = (PathMatcher) o; - return serviceMethodEqual(that, this) || pathMatch(that); - } - - private boolean pathMatch(PathMatcher that) { - return (!that.needCompareServiceMethod && !needCompareServiceMethod) // no need service method compare - && pathEqual(that) // path compare - && Objects.equals(version, that.version) // service version compare - && httpMethodMatch(that) // http method compare - && Objects.equals(group, that.group) - && Objects.equals(port, that.port); - } - - /** - * it is needed to compare http method when one of needCompareHttpMethod is true,and don`t compare when both needCompareHttpMethod are false - * - * @param that - * @return - */ - private boolean httpMethodMatch(PathMatcher that) { - return !that.needCompareHttpMethod || !this.needCompareHttpMethod - ? true - : Objects.equals(this.httpMethod, that.httpMethod); - } - - private boolean serviceMethodEqual(PathMatcher thatPathMatcher, PathMatcher thisPathMatcher) { - Method thatMethod = thatPathMatcher.method; - Method thisMethod = thisPathMatcher.method; - return thatMethod != null - && thisMethod != null - && (thatPathMatcher.needCompareServiceMethod || thisPathMatcher.needCompareServiceMethod) - && thisMethod.getName().equals(thatMethod.getName()) - && Arrays.equals(thisMethod.getParameterTypes(), thatMethod.getParameterTypes()); - } - - @Override - public int hashCode() { - return Objects.hash(version, group, port); - } - - private boolean pathEqual(PathMatcher pathMatcher) { - // path is null return false directly - if (this.path == null || pathMatcher.path == null) { - return false; - } - - // no place hold - if (!pathMatcher.hasPathVariable) { - return this.path.equals(pathMatcher.path); - } - - String[] pathSplits = pathMatcher.pathSplits; - String[] thisPathSplits = this.pathSplits; - - if (thisPathSplits.length != pathSplits.length) { - return false; - } - - for (int i = 0; i < pathSplits.length; i++) { - boolean equals = thisPathSplits[i].equals(pathSplits[i]); - if (equals) { - continue; - } else { - if (placeHoldCompare(pathSplits[i], thisPathSplits[i])) { - continue; - } else { - return false; - } - } - } - - return true; - } - - private boolean placeHoldCompare(String pathSplit, String pathToCompare) { - boolean startAndEndEqual = isPlaceHold(pathSplit) || isPlaceHold(pathToCompare); - - // start { end } - if (!startAndEndEqual) { - return false; - } - - // exclude {} - boolean lengthCondition = pathSplit.length() >= 3 || pathToCompare.length() >= 3; - - if (!lengthCondition) { - return false; - } - - return true; - } - - private boolean isPlaceHold(String pathSplit) { - return pathSplit.startsWith("{") && pathSplit.endsWith("}"); - } - - private String contextPathFormat(String contextPath) { - - if (contextPath == null || contextPath.equals(SEPARATOR) || contextPath.length() == 0) { - return ""; - } - - return pathFormat(contextPath); - } - - private String pathFormat(String path) { - if (path.startsWith(SEPARATOR)) { - return path; - } else { - return SEPARATOR + path; - } - } - - @Override - public String toString() { - return "PathMatcher{" + "path='" - + path + '\'' + ", version='" - + version + '\'' + ", group='" - + group + '\'' + ", port=" - + port + ", hasPathVariable=" - + hasPathVariable + ", contextPath='" - + contextPath + '\'' + ", httpMethod='" - + httpMethod + '\'' + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathUtil.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathUtil.java deleted file mode 100644 index 90cc7cd8fad..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/PathUtil.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.metadata.MetadataConstants; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * is used to parse url pathVariable - *

- * String[] splits= url.split("/") - * List strings = Arrays.asList(split); - * strings.set(UrlSplitIndex, (String) args.get(argIndex)); - */ -public class PathUtil { - private static final String SEPARATOR = MetadataConstants.PATH_SEPARATOR; - - /** - * generate real path from rawPath according to argInfo and method args - * - * @param rawPath - * @param argInfos - * @param args - * @return - */ - public static String resolvePathVariable(String rawPath, List argInfos, List args) { - - String[] split = rawPath.split(SEPARATOR); - - List strings = Arrays.asList(split); - - List pathArgInfos = new ArrayList<>(); - - for (ArgInfo argInfo : argInfos) { - if (ParamType.PATH.supportAnno(argInfo.getParamAnnotationType())) { - pathArgInfos.add(argInfo); - } - } - - for (ArgInfo pathArgInfo : pathArgInfos) { - strings.set(pathArgInfo.getUrlSplitIndex(), String.valueOf(args.get(pathArgInfo.getIndex()))); - } - - String pat = SEPARATOR; - - for (String string : strings) { - - if (string.length() == 0) { - continue; - } - - pat = pat + string + SEPARATOR; - } - - if (pat.endsWith(SEPARATOR)) { - pat = pat.substring(0, pat.lastIndexOf(SEPARATOR)); - } - - return pat; - } - - /** - * parse pathVariable index from url by annotation info - * - * @param rawPath - * @param argInfos - */ - public static void setArgInfoSplitIndex(String rawPath, List argInfos) { - String[] split = rawPath.split(SEPARATOR); - - List pathPairs = new ArrayList<>(); - - for (ArgInfo argInfo : argInfos) { - if (ParamType.PATH.supportAnno(argInfo.getParamAnnotationType())) { - pathPairs.add(new PathPair(argInfo)); - } - } - - for (int i = 0; i < split.length; i++) { - String s = split[i]; - for (PathPair pathPair : pathPairs) { - boolean match = pathPair.match(s); - if (match) { - pathPair.setArgInfoSplitIndex(i); - } - } - } - } - - public static class PathPair { - - String value; - - ArgInfo argInfo; - - public PathPair(ArgInfo argInfo) { - this.argInfo = argInfo; - this.value = argInfo.getAnnotationNameAttribute(); - } - - public String getPatten() { - return "{" + value + "}"; - } - - public String getLeftPatten() { - return "{" + value; - } - - public String getRightPatten() { - return "}"; - } - - public boolean match(String value) { - return getPatten().equals(value) // for : {id} - || (value.startsWith(getLeftPatten()) && value.endsWith(getRightPatten())); // for : {id: \d+} - } - - public String getValue() { - return value; - } - - public void setArgInfo(ArgInfo argInfo) { - this.argInfo = argInfo; - } - - public void setArgInfoSplitIndex(int urlSplitIndex) { - this.argInfo.setUrlSplitIndex(urlSplitIndex); - } - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java deleted file mode 100644 index bdac2575e4f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.utils.CollectionUtils; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import static java.util.Collections.unmodifiableMap; -import static org.apache.dubbo.common.utils.PathUtils.normalize; -import static org.apache.dubbo.common.utils.StringUtils.SLASH; -import static org.apache.dubbo.common.utils.StringUtils.isBlank; - -/** - * The metadata class for REST request - * - * @since 2.7.6 - */ -public class RequestMetadata implements Serializable { - - private static final long serialVersionUID = -240099840085329958L; - - private String method; - - private String path; - - private Map> params = new LinkedHashMap<>(); - - private Map> headers = new LinkedHashMap<>(); - - private Set consumes = new LinkedHashSet<>(); - - private Set produces = new LinkedHashSet<>(); - - /** - * Default Constructor - */ - public RequestMetadata() {} - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method == null ? null : method.toUpperCase(); - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = normalize(path); - - if (!path.startsWith(SLASH)) { - this.path = SLASH + path; - } - } - - public Map> getParams() { - return unmodifiableMap(params); - } - - public void setParams(Map> params) { - params(params); - } - - private static void add(Map> multiValueMap, String key, String value) { - if (isBlank(key)) { - return; - } - List values = get(multiValueMap, key, true); - values.add(value); - } - - private static > void addAll( - Map> multiValueMap, Map source) { - for (Map.Entry entry : source.entrySet()) { - String key = entry.getKey(); - for (String value : entry.getValue()) { - add(multiValueMap, key, value); - } - } - } - - private static String getFirst(Map> multiValueMap, String key) { - List values = get(multiValueMap, key); - return CollectionUtils.isNotEmpty(values) ? values.get(0) : null; - } - - private static List get(Map> multiValueMap, String key) { - return get(multiValueMap, key, false); - } - - private static List get(Map> multiValueMap, String key, boolean createIfAbsent) { - return createIfAbsent ? multiValueMap.computeIfAbsent(key, k -> new LinkedList<>()) : multiValueMap.get(key); - } - - public Map> getHeaders() { - return unmodifiableMap(headers); - } - - public void setHeaders(Map> headers) { - headers(headers); - } - - public Set getConsumes() { - return consumes; - } - - public void setConsumes(Set consumes) { - this.consumes = consumes; - } - - public Set getProduces() { - return produces; - } - - public void setProduces(Set produces) { - this.produces = produces; - } - - public Set getParamNames() { - return new HashSet<>(params.keySet()); - } - - public Set getHeaderNames() { - return new HashSet<>(headers.keySet()); - } - - // public List getConsumeMediaTypes() { - // return toMediaTypes(consumes); - // } - // - // public List getProduceMediaTypes() { - // return toMediaTypes(produces); - // } - - public String getParameter(String name) { - return getFirst(params, name); - } - - public String getHeader(String name) { - return getFirst(headers, name); - } - - public RequestMetadata addParam(String name, String value) { - add(params, name, value); - return this; - } - - public RequestMetadata addHeader(String name, String value) { - add(headers, name, value); - return this; - } - - private > RequestMetadata params(Map params) { - addAll(this.params, params); - return this; - } - - private > RequestMetadata headers(Map> headers) { - if (headers != null && !headers.isEmpty()) { - Map> httpHeaders = new LinkedHashMap<>(); - // Add all headers - addAll(httpHeaders, headers); - // Handles "Content-Type" and "Accept" headers if present - // mediaTypes(httpHeaders, HttpHeaders.CONTENT_TYPE, this.consumes); - // mediaTypes(httpHeaders, HttpHeaders.ACCEPT, this.produces); - this.headers.putAll(httpHeaders); - } - return this; - } - - public void appendContextPathFromUrl(String contextPathFromUrl) { - if (contextPathFromUrl == null) { - return; - } - setPath(contextPathFromUrl + path); - } - - public boolean methodAllowed(String method) { - return method != null && method.equals(this.method); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof RequestMetadata)) { - return false; - } - RequestMetadata that = (RequestMetadata) o; - return Objects.equals(method, that.method) - && Objects.equals(path, that.path) - && Objects.equals(consumes, that.consumes) - && Objects.equals(produces, that.produces) - && - // Metadata should not compare the values - Objects.equals(getParamNames(), that.getParamNames()) - && Objects.equals(getHeaderNames(), that.getHeaderNames()); - } - - @Override - public int hashCode() { - // The values of metadata should not use for the hashCode() method - return Objects.hash(method, path, consumes, produces, getParamNames(), getHeaderNames()); - } - - @Override - public String toString() { - return "RequestMetadata{" + "method='" + method + '\'' + ", path='" + path + '\'' - + ", params=" + params + ", headers=" + headers + ", consumes=" + consumes - + ", produces=" + produces + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMetadataConstants.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMetadataConstants.java deleted file mode 100644 index 97bca97595f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMetadataConstants.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.lang.annotation.Annotation; - -import static org.apache.dubbo.common.utils.ClassUtils.getClassLoader; -import static org.apache.dubbo.common.utils.ClassUtils.resolveClass; - -/** - * The REST Metadata Constants definition interface - * - * @since 2.7.6 - */ -public interface RestMetadataConstants { - - /** - * The encoding of metadata - */ - String METADATA_ENCODING = "UTF-8"; - - /** - * {@link ServiceRestMetadata} Resource PATH - */ - String SERVICE_REST_METADATA_RESOURCE_PATH = "META-INF/dubbo/service-rest-metadata.json"; - - /** - * JAX-RS - */ - interface JAX_RS { - - /** - * The annotation class name of @Path - */ - String PATH_ANNOTATION_CLASS_NAME = "javax.ws.rs.Path"; - - /** - * The annotation class name of @HttpMethod - */ - String HTTP_METHOD_ANNOTATION_CLASS_NAME = "javax.ws.rs.HttpMethod"; - - /** - * The annotation class name of @Produces - */ - String PRODUCES_ANNOTATION_CLASS_NAME = "javax.ws.rs.Produces"; - - /** - * The annotation class name of @Consumes - */ - String CONSUMES_ANNOTATION_CLASS_NAME = "javax.ws.rs.Consumes"; - - /** - * The annotation class name of @DefaultValue - */ - String DEFAULT_VALUE_ANNOTATION_CLASS_NAME = "javax.ws.rs.DefaultValue"; - - /** - * The annotation class name of @FormParam - */ - String FORM_PARAM_ANNOTATION_CLASS_NAME = "javax.ws.rs.FormParam"; - - /** - * The annotation class name of @HeaderParam - */ - String HEADER_PARAM_ANNOTATION_CLASS_NAME = "javax.ws.rs.HeaderParam"; - - /** - * The annotation class name of @MatrixParam - */ - String MATRIX_PARAM_ANNOTATION_CLASS_NAME = "javax.ws.rs.MatrixParam"; - - /** - * The annotation class name of @QueryParam - */ - String QUERY_PARAM_ANNOTATION_CLASS_NAME = "javax.ws.rs.QueryParam"; - - /** - * The annotation class name of @Body - */ - String REST_EASY_BODY_ANNOTATION_CLASS_NAME = "org.jboss.resteasy.annotations.Body"; - - /** - * The annotation class name of @Form - */ - String REST_EASY_FORM_BODY_ANNOTATION_CLASS_NAME = "org.jboss.resteasy.annotations.Form"; - - /** - * The annotation class name of @PathParam - */ - String PATH_PARAM_ANNOTATION_CLASS_NAME = "javax.ws.rs.PathParam"; - } - - /** - * Spring MVC - */ - interface SPRING_MVC { - - /** - * The annotation class name of @Controller - */ - String CONTROLLER_ANNOTATION_CLASS_NAME = "org.springframework.stereotype.Controller"; - - /** - * The annotation class name of @FeignClient - */ - String FEIGN_CLIENT_CLASS_NAME = "org.springframework.cloud.openfeign.FeignClient"; - - /** - * The annotation class name of @RequestMapping - */ - String REQUEST_MAPPING_ANNOTATION_CLASS_NAME = "org.springframework.web.bind.annotation.RequestMapping"; - - /** - * The annotation class name of @RequestHeader - */ - String REQUEST_HEADER_ANNOTATION_CLASS_NAME = "org.springframework.web.bind.annotation.RequestHeader"; - - /** - * The annotation class name of @RequestParam - */ - String REQUEST_PARAM_ANNOTATION_CLASS_NAME = "org.springframework.web.bind.annotation.RequestParam"; - - /** - * The annotation class name of @RequestBody - */ - String REQUEST_BODY_ANNOTATION_CLASS_NAME = "org.springframework.web.bind.annotation.RequestBody"; - - /** - * The annotation class name of @PathVariable - */ - String PATH_VARIABLE_ANNOTATION_CLASS_NAME = "org.springframework.web.bind.annotation.PathVariable"; - - /** - * The class of @Controller - * - * @since 2.7.9 - */ - Class CONTROLLER_ANNOTATION_CLASS = - (Class) resolveClass(CONTROLLER_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The class of @RequestMapping - * - * @since 2.7.9 - */ - Class REQUEST_MAPPING_ANNOTATION_CLASS = - (Class) resolveClass(REQUEST_MAPPING_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class name of AnnotatedElementUtils - * - * @since 2.7.9 - */ - String ANNOTATED_ELEMENT_UTILS_CLASS_NAME = "org.springframework.core.annotation.AnnotatedElementUtils"; - - /** - * The class of AnnotatedElementUtils - * - * @since 2.7.9 - */ - Class ANNOTATED_ELEMENT_UTILS_CLASS = resolveClass(ANNOTATED_ELEMENT_UTILS_CLASS_NAME, getClassLoader()); - - Class FEIGN_CLIENT_CLASS = - (Class) resolveClass(FEIGN_CLIENT_CLASS_NAME, getClassLoader()); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMethodMetadata.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMethodMetadata.java deleted file mode 100644 index e820b5fa75a..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/RestMethodMetadata.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.metadata.definition.model.MethodDefinition; -import org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.tag.NoAnnotationTag; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static java.util.Collections.emptyList; - -/** - * The metadata class for {@link RequestMetadata HTTP(REST) request} and - * its binding {@link MethodDefinition method definition} - * - * @since 2.7.6 - */ -public class RestMethodMetadata implements Serializable { - - private static final long serialVersionUID = 2935252016200830694L; - - private MethodDefinition method; - - private RequestMetadata request; - - private Integer urlIndex; - - private Integer bodyIndex; - - private Integer headerMapIndex; - - private String bodyType; - - private Map> indexToName; - - private List formParams; - - private Map indexToEncoded; - - private List argInfos; - - private Method reflectMethod; - - /** - * make a distinction between mvc & resteasy - */ - private Class codeStyle; - - public MethodDefinition getMethod() { - if (method == null) { - method = new MethodDefinition(); - } - return method; - } - - public void setMethod(MethodDefinition method) { - this.method = method; - } - - public RequestMetadata getRequest() { - if (request == null) { - request = new RequestMetadata(); - } - return request; - } - - public void setRequest(RequestMetadata request) { - this.request = request; - } - - public Integer getUrlIndex() { - return urlIndex; - } - - public void setUrlIndex(Integer urlIndex) { - this.urlIndex = urlIndex; - } - - public Integer getBodyIndex() { - return bodyIndex; - } - - public void setBodyIndex(Integer bodyIndex) { - this.bodyIndex = bodyIndex; - } - - public Integer getHeaderMapIndex() { - return headerMapIndex; - } - - public void setHeaderMapIndex(Integer headerMapIndex) { - this.headerMapIndex = headerMapIndex; - } - - public String getBodyType() { - return bodyType; - } - - public void setBodyType(String bodyType) { - this.bodyType = bodyType; - } - - public Map> getIndexToName() { - if (indexToName == null) { - indexToName = new LinkedHashMap<>(); - } - return indexToName; - } - - public void setIndexToName(Map> indexToName) { - this.indexToName = indexToName; - } - - public void addIndexToName(Integer index, String name) { - if (index == null) { - return; - } - - if (name.startsWith("arg") && name.endsWith(index.toString())) { - // Ignore this value because of the Java byte-code without the metadata of method parameters - return; - } - - Map> indexToName = getIndexToName(); - Collection parameterNames = indexToName.computeIfAbsent(index, i -> new ArrayList<>(1)); - parameterNames.add(name); - } - - public boolean hasIndexedName(Integer index, String name) { - Map> indexToName = getIndexToName(); - return indexToName.getOrDefault(index, emptyList()).contains(name); - } - - public List getFormParams() { - return formParams; - } - - public void setFormParams(List formParams) { - this.formParams = formParams; - } - - public Map getIndexToEncoded() { - return indexToEncoded; - } - - public void setIndexToEncoded(Map indexToEncoded) { - this.indexToEncoded = indexToEncoded; - } - - public List getArgInfos() { - if (argInfos == null) { - argInfos = new ArrayList<>(); - } - return argInfos; - } - - public void addArgInfo(ArgInfo argInfo) { - if (currentCodeStyleIsNoAnnotationMode()) { - argInfo.setParamAnnotationType(NoAnnotationTag.class); - } - getArgInfos().add(argInfo); - } - - public Method getReflectMethod() { - return reflectMethod; - } - - public void setReflectMethod(Method reflectMethod) { - this.reflectMethod = reflectMethod; - } - - public Class getCodeStyle() { - return codeStyle; - } - - public void setCodeStyle(Class codeStyle) { - this.codeStyle = codeStyle; - } - - public boolean currentCodeStyleIsNoAnnotationMode() { - return NoAnnotationServiceRestMetadataResolver.class.equals(getCodeStyle()); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof RestMethodMetadata)) { - return false; - } - RestMethodMetadata that = (RestMethodMetadata) o; - return Objects.equals(getMethod(), that.getMethod()) - && Objects.equals(getRequest(), that.getRequest()) - && Objects.equals(getUrlIndex(), that.getUrlIndex()) - && Objects.equals(getBodyIndex(), that.getBodyIndex()) - && Objects.equals(getHeaderMapIndex(), that.getHeaderMapIndex()) - && Objects.equals(getBodyType(), that.getBodyType()) - && Objects.equals(getFormParams(), that.getFormParams()) - && Objects.equals(getIndexToEncoded(), that.getIndexToEncoded()); - } - - @Override - public int hashCode() { - return Objects.hash( - getMethod(), - getRequest(), - getUrlIndex(), - getBodyIndex(), - getHeaderMapIndex(), - getBodyType(), - getFormParams(), - getIndexToEncoded()); - } - - @Override - public String toString() { - return "RestMethodMetadata{" + "method=" - + method + ", request=" - + request + ", urlIndex=" - + urlIndex + ", bodyIndex=" - + bodyIndex + ", headerMapIndex=" - + headerMapIndex + ", bodyType='" - + bodyType + '\'' + ", indexToName=" - + indexToName + ", formParams=" - + formParams + ", indexToEncoded=" - + indexToEncoded + ", argInfos=" - + argInfos + ", reflectMethod=" - + reflectMethod + ", codeStyle=" - + codeStyle + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadata.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadata.java deleted file mode 100644 index f18da310978..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadata.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.utils.PathUtils; -import org.apache.dubbo.metadata.ParameterTypesComparator; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -/** - * The metadata class for {@link RequestMetadata HTTP(REST) request} and - * its binding Dubbo service metadata - * - * @since 2.7.6 - */ -public class ServiceRestMetadata implements Serializable { - - private static final long serialVersionUID = -4549723140727443569L; - - private String serviceInterface; - - private String version; - - private String group; - - private Set meta; - - private Integer port; - - private boolean consumer; - - private String contextPathFromUrl; - - /** - * make a distinction between mvc & resteasy - */ - private Class codeStyle; - - private Map pathToServiceMapContainPathVariable = new HashMap<>(); - private Map pathToServiceMapUnContainPathVariable = new HashMap<>(); - private Map> methodToServiceMap = new HashMap<>(); - - public ServiceRestMetadata(String serviceInterface, String version, String group, boolean consumer) { - this.serviceInterface = serviceInterface; - this.version = version; - this.group = group; - this.consumer = consumer; - } - - public ServiceRestMetadata() {} - - public ServiceRestMetadata(String serviceInterface, String version, String group) { - this(serviceInterface, version, group, false); - } - - public String getServiceInterface() { - return serviceInterface; - } - - public void setServiceInterface(String serviceInterface) { - this.serviceInterface = serviceInterface; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } - - public Set getMeta() { - if (meta == null) { - meta = new LinkedHashSet<>(); - } - return meta; - } - - public void setMeta(Set meta) { - this.meta = meta; - } - - public void addRestMethodMetadata(RestMethodMetadata restMethodMetadata) { - PathMatcher pathMather = new PathMatcher( - restMethodMetadata.getRequest().getPath(), - this.getVersion(), - this.getGroup(), - this.getPort(), - restMethodMetadata.getRequest().getMethod()); - pathMather.setMethod(restMethodMetadata.getReflectMethod()); - addPathToServiceMap(pathMather, restMethodMetadata); - addMethodToServiceMap(restMethodMetadata); - getMeta().add(restMethodMetadata); - } - - public Map getPathContainPathVariableToServiceMap() { - return pathToServiceMapContainPathVariable; - } - - public Map getPathUnContainPathVariableToServiceMap() { - return pathToServiceMapUnContainPathVariable; - } - - public void addPathToServiceMap(PathMatcher pathMather, RestMethodMetadata restMethodMetadata) { - - if (pathMather.hasPathVariable()) { - doublePathCheck(pathToServiceMapContainPathVariable, pathMather, restMethodMetadata, true); - } else { - doublePathCheck(pathToServiceMapUnContainPathVariable, pathMather, restMethodMetadata, false); - } - } - - private void doublePathCheck( - Map pathMatcherRestMethodMetadataMap, - PathMatcher pathMather, - RestMethodMetadata restMethodMetadata, - boolean containPathVariable) { - if (pathMatcherRestMethodMetadataMap.containsKey(pathMather)) { - if (containPathVariable) { - throw new IllegalArgumentException( - "dubbo rest metadata resolve double path error,and contain path variable is: " + pathMather - + ", rest method metadata is: " + restMethodMetadata); - - } else { - throw new IllegalArgumentException( - "dubbo rest metadata resolve double path error,and do not contain path variable is: " - + pathMather + ", rest method metadata is: " + restMethodMetadata); - } - } - - pathMatcherRestMethodMetadataMap.put(pathMather, restMethodMetadata); - } - - public Integer getPort() { - return port; - } - - public void setPort(Integer port) { - this.port = port; - setPort(port, getPathContainPathVariableToServiceMap()); - setPort(port, getPathUnContainPathVariableToServiceMap()); - } - - private void setPort(Integer port, Map pathToServiceMapContainPathVariable) { - for (PathMatcher pathMather : pathToServiceMapContainPathVariable.keySet()) { - pathMather.setPort(port); - } - } - - public boolean isConsumer() { - return consumer; - } - - public void setConsumer(boolean consumer) { - this.consumer = consumer; - } - - public Map> getMethodToServiceMap() { - return methodToServiceMap; - } - - public void addMethodToServiceMap(RestMethodMetadata restMethodMetadata) { - if (this.methodToServiceMap == null) { - this.methodToServiceMap = new HashMap<>(); - } - - this.methodToServiceMap - .computeIfAbsent(restMethodMetadata.getReflectMethod().getName(), k -> new HashMap<>()) - .put( - ParameterTypesComparator.getInstance( - restMethodMetadata.getReflectMethod().getParameterTypes()), - restMethodMetadata); - } - - public Class getCodeStyle() { - return codeStyle; - } - - public void setCodeStyle(Class codeStyle) { - this.codeStyle = codeStyle; - } - - public String getContextPathFromUrl() { - return contextPathFromUrl == null ? "" : contextPathFromUrl; - } - - public void setContextPathFromUrl(String contextPathFromUrl) { - this.contextPathFromUrl = PathUtils.normalize(contextPathFromUrl); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ServiceRestMetadata)) { - return false; - } - ServiceRestMetadata that = (ServiceRestMetadata) o; - return Objects.equals(getServiceInterface(), that.getServiceInterface()) - && Objects.equals(getVersion(), that.getVersion()) - && Objects.equals(getGroup(), that.getGroup()) - && Objects.equals(getMeta(), that.getMeta()) - && Objects.equals(getPort(), that.getPort()); - } - - @Override - public int hashCode() { - return Objects.hash(getServiceInterface(), getVersion(), getGroup(), getMeta(), getPort()); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("ServiceRestMetadata{"); - sb.append("serviceInterface='").append(serviceInterface).append('\''); - sb.append(", version='").append(version).append('\''); - sb.append(", group='").append(group).append('\''); - sb.append(", meta=").append(meta); - sb.append(", port=").append(port); - sb.append('}'); - return sb.toString(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataReader.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataReader.java deleted file mode 100644 index 6a590260c32..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataReader.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.extension.SPI; - -import java.util.List; - -/** - * An interface to read {@link ServiceRestMetadata} - * - * @see ServiceRestMetadata - * @since 2.7.6 - */ -@SPI -public interface ServiceRestMetadataReader { - - /** - * Read the instances of {@link ServiceRestMetadata} - * - * @return non-null - */ - List read(); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataResolver.java deleted file mode 100644 index b36ba51decd..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/ServiceRestMetadataResolver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.common.extension.ExtensionScope; -import org.apache.dubbo.common.extension.SPI; - -/** - * The interface to resolve the {@link ServiceRestMetadata REST metadata} from the specified - * Dubbo Service interface or type. - * - * @since 2.7.6 - */ -@SPI(scope = ExtensionScope.APPLICATION) -public interface ServiceRestMetadataResolver { - - /** - * Support to resolve {@link ServiceRestMetadata REST metadata} or not - * - * @param serviceType Dubbo Service interface or type - * @return If supports, return true, or false - */ - boolean supports(Class serviceType); - - boolean supports(Class serviceType, boolean consumer); - - /** - * Resolve the {@link ServiceRestMetadata REST metadata} from the specified - * Dubbo Service interface or type - * - * @param serviceType Dubbo Service interface or type - * @return - */ - ServiceRestMetadata resolve(Class serviceType); - - ServiceRestMetadata resolve(Class serviceType, ServiceRestMetadata serviceRestMetadata); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/SpringMvcClassConstants.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/SpringMvcClassConstants.java deleted file mode 100644 index d16ba215234..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/SpringMvcClassConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import static org.apache.dubbo.common.utils.ClassUtils.getClassLoader; -import static org.apache.dubbo.common.utils.ClassUtils.resolveClass; - -public interface SpringMvcClassConstants extends RestMetadataConstants.SPRING_MVC { - /** - * The annotation class of @RequestMapping - */ - Class REQUEST_MAPPING_ANNOTATION_CLASS = resolveClass(REQUEST_MAPPING_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @RequestHeader - */ - Class REQUEST_HEADER_ANNOTATION_CLASS = resolveClass(REQUEST_HEADER_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @RequestParam - */ - Class REQUEST_PARAM_ANNOTATION_CLASS = resolveClass(REQUEST_PARAM_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @RequestBody - */ - Class REQUEST_BODY_ANNOTATION_CLASS = resolveClass(REQUEST_BODY_ANNOTATION_CLASS_NAME, getClassLoader()); - - /** - * The annotation class of @RequestBody - */ - Class PATH_VARIABLE_ANNOTATION_CLASS = resolveClass(PATH_VARIABLE_ANNOTATION_CLASS_NAME, getClassLoader()); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/BodyParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/BodyParameterProcessor.java deleted file mode 100644 index 2ee067091b6..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/BodyParameterProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.ArgInfo; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.REST_EASY_BODY_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @FormParam - * - * @since 2.7.6 - */ -public class BodyParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return REST_EASY_BODY_ANNOTATION_CLASS_NAME; - } - - @Override - public void process( - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata restMethodMetadata) { - ArgInfo argInfo = ArgInfo.build(parameterIndex, parameter).setParamAnnotationType(getAnnotationClass()); - restMethodMetadata.addArgInfo(argInfo); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/DefaultValueParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/DefaultValueParameterProcessor.java deleted file mode 100644 index 5b3a4ee2a26..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/DefaultValueParameterProcessor.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.List; -import java.util.Map; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.DEFAULT_VALUE_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @DefaultValue - * * - * - * @since 2.7.6 - */ -public class DefaultValueParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return DEFAULT_VALUE_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String annotationValue, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - - // process the request parameters - setDefaultValue(requestMetadata.getParams(), defaultValue, annotationValue); - // process the request headers - setDefaultValue(requestMetadata.getHeaders(), defaultValue, annotationValue); - } - - private void setDefaultValue(Map> source, String placeholderValue, String defaultValue) { - OUTTER: - for (Map.Entry> entry : source.entrySet()) { - List values = entry.getValue(); - int size = values.size(); - for (int i = 0; i < size; i++) { - String value = values.get(i); - if (placeholderValue.equals(value)) { - values.set(i, defaultValue); - break OUTTER; - } - } - } - } - - @Override - public int getPriority() { - return MIN_PRIORITY; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormBodyParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormBodyParameterProcessor.java deleted file mode 100644 index 26483885bf1..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormBodyParameterProcessor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.REST_EASY_FORM_BODY_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.media.MediaType.APPLICATION_FORM_URLENCODED_VALUE; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @FormParam - * - * @since 2.7.6 - */ -public class FormBodyParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return REST_EASY_FORM_BODY_ANNOTATION_CLASS_NAME; - } - - @Override - public void process( - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata restMethodMetadata) { - super.process( - annotation, parameter, parameterIndex, method, serviceType, serviceInterfaceClass, restMethodMetadata); - restMethodMetadata.getRequest().getConsumes().add(APPLICATION_FORM_URLENCODED_VALUE.value); - } - - @Override - protected String getAnnotationValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return null; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormParamParameterProcessor.java deleted file mode 100644 index 6dae712118f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/FormParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.FORM_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @FormParam - * - * @since 2.7.6 - */ -public class FormParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationName() { - return FORM_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/HeaderParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/HeaderParamParameterProcessor.java deleted file mode 100644 index 9fc5299e831..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/HeaderParamParameterProcessor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor.buildDefaultValue; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.HEADER_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @HeaderParam - * - * @since 2.7.6 - */ -public class HeaderParamParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return HEADER_PARAM_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String headerName, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - // Add the placeholder as header value - requestMetadata.addHeader(headerName, buildDefaultValue(parameterIndex)); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java deleted file mode 100644 index d344c279fce..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.metadata.rest.AbstractServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.Set; -import java.util.stream.Stream; - -import static org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation; -import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation; -import static org.apache.dubbo.common.utils.AnnotationUtils.getValue; -import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.common.utils.PathUtils.buildPath; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.CONSUMES_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.HTTP_METHOD_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PATH_ANNOTATION_CLASS_NAME; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PRODUCES_ANNOTATION_CLASS_NAME; - -/** - * JAX-RS {@link ServiceRestMetadataResolver} implementation - * - * @since 2.7.6 - */ -@Activate(order = 100) -public class JAXRSServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - public JAXRSServiceRestMetadataResolver(ApplicationModel applicationModel) { - super(applicationModel); - } - - @Override - protected boolean supports0(Class serviceType) { - return isAnnotationPresent(serviceType, PATH_ANNOTATION_CLASS_NAME) - // method @Path - || isServiceMethodAnnotationPresent(serviceType, PATH_ANNOTATION_CLASS_NAME); - } - - @Override - protected boolean isRestCapableMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - return isAnnotationPresent(serviceMethod, HTTP_METHOD_ANNOTATION_CLASS_NAME); - } - - @Override - protected String resolveRequestMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - Annotation httpMethod = findMetaAnnotation(serviceMethod, HTTP_METHOD_ANNOTATION_CLASS_NAME); - return getValue(httpMethod); - } - - @Override - protected String resolveRequestPath(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - String requestBasePath = resolveRequestPathFromType(serviceType, serviceInterfaceClass); - String requestRelativePath = resolveRequestPathFromMethod(serviceMethod); - return buildPath(requestBasePath, requestRelativePath); - } - - private String resolveRequestPathFromType(Class serviceType, Class serviceInterfaceClass) { - Annotation path = findAnnotation(serviceType, PATH_ANNOTATION_CLASS_NAME); - if (path == null) { - path = findAnnotation(serviceInterfaceClass, PATH_ANNOTATION_CLASS_NAME); - } - return getValue(path); - } - - private String resolveRequestPathFromMethod(Method serviceMethod) { - Annotation path = findAnnotation(serviceMethod, PATH_ANNOTATION_CLASS_NAME); - return getValue(path); - } - - @Override - protected void processProduces( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set produces) { - addAnnotationValues(serviceMethod, PRODUCES_ANNOTATION_CLASS_NAME, produces); - addAnnotationValues(serviceType, PRODUCES_ANNOTATION_CLASS_NAME, produces); - addAnnotationValues(serviceInterfaceClass, PRODUCES_ANNOTATION_CLASS_NAME, produces); - } - - @Override - protected void processConsumes( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set consumes) { - addAnnotationValues(serviceMethod, CONSUMES_ANNOTATION_CLASS_NAME, consumes); - addAnnotationValues(serviceType, CONSUMES_ANNOTATION_CLASS_NAME, consumes); - addAnnotationValues(serviceInterfaceClass, CONSUMES_ANNOTATION_CLASS_NAME, consumes); - } - - private void addAnnotationValues(Method serviceMethod, String annotationAttributeName, Set result) { - Annotation annotation = findAnnotation(serviceMethod, annotationAttributeName); - String[] value = getValue(annotation); - if (value != null) { - Stream.of(value).forEach(result::add); - } - } - - private void addAnnotationValues(Class serviceType, String annotationAttributeName, Set result) { - Annotation annotation = findAnnotation(serviceType, annotationAttributeName); - String[] value = getValue(annotation); - if (value != null) { - Stream.of(value).forEach(result::add); - } - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/MatrixParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/MatrixParamParameterProcessor.java deleted file mode 100644 index a75284a6898..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/MatrixParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.MATRIX_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @MatrixParam - * - * @since 2.7.6 - */ -public class MatrixParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationName() { - return MATRIX_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/ParamAnnotationParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/ParamAnnotationParameterProcessor.java deleted file mode 100644 index e2feefb9cb1..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/ParamAnnotationParameterProcessor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RequestMetadata; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @*Param - */ -public abstract class ParamAnnotationParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - protected void process( - String name, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) { - RequestMetadata requestMetadata = restMethodMetadata.getRequest(); - requestMetadata.addParam(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/PathParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/PathParamParameterProcessor.java deleted file mode 100644 index 478182312ee..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/PathParamParameterProcessor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PATH_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @PathParam - * - * @since 2.7.6 - */ -public class PathParamParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return PATH_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/QueryParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/QueryParamParameterProcessor.java deleted file mode 100644 index ed6972f17ac..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/QueryParamParameterProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.QUERY_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for JAX-RS's @QueryParam - * - * @since 2.7.6 - */ -public class QueryParamParameterProcessor extends ParamAnnotationParameterProcessor { - - @Override - public String getAnnotationName() { - return QUERY_PARAM_ANNOTATION_CLASS_NAME; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/media/MediaType.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/media/MediaType.java deleted file mode 100644 index df59aa4961b..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/media/MediaType.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.dubbo.metadata.rest.media; - -import java.util.Arrays; -import java.util.List; - -public enum MediaType { - ALL_VALUE("*/*"), - APPLICATION_JSON_VALUE("application/json"), - APPLICATION_FORM_URLENCODED_VALUE("application/x-www-form-urlencoded"), - TEXT_PLAIN("text/plain"), - TEXT_XML("text/xml"), - OCTET_STREAM("application/octet-stream"), - ; - - MediaType(String value) { - this.value = value; - } - - public String value; - - public static String getAllContentType() { - - MediaType[] values = MediaType.values(); - - StringBuilder stringBuilder = new StringBuilder(); - - for (MediaType mediaType : values) { - stringBuilder.append(mediaType.value + " "); - } - return stringBuilder.toString(); - } - - public static List getSupportMediaTypes() { - return Arrays.asList( - APPLICATION_JSON_VALUE, APPLICATION_FORM_URLENCODED_VALUE, TEXT_PLAIN, TEXT_XML, OCTET_STREAM); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/noannotaion/NoAnnotationServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/noannotaion/NoAnnotationServiceRestMetadataResolver.java deleted file mode 100644 index 61cb1abb625..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/noannotaion/NoAnnotationServiceRestMetadataResolver.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.dubbo.metadata.rest.noannotaion; - -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.metadata.rest.AbstractServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.ArgInfo; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.media.MediaType; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.Set; - -import static org.apache.dubbo.common.utils.PathUtils.buildPath; - -/** - * NoAnnotationServiceRestMetadataResolver - * - * @since 3.3 - */ -@Activate(order = Integer.MAX_VALUE) -public class NoAnnotationServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - - private static final String CONTENT_TYPE = MediaType.APPLICATION_JSON_VALUE.value; - private static final String REQUEST_METHOD = "POST"; - - public NoAnnotationServiceRestMetadataResolver(ApplicationModel applicationModel) { - super(applicationModel); - } - - @Override - protected boolean supports0(Class serviceType) { - // class @Controller or @RequestMapping - return true; - } - - @Override - protected boolean isRestCapableMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - // method only match @RequestMapping - return true; - } - - @Override - protected String resolveRequestMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - - return REQUEST_METHOD; - } - - @Override - protected String resolveRequestPath(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - - // use serviceInterfaceClass class name - return buildPath(serviceInterfaceClass.getName(), serviceMethod.getName()); - } - - @Override - protected void processProduces( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set produces) { - produces.add(CONTENT_TYPE); - } - - @Override - protected void processConsumes( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set consumes) { - consumes.add(CONTENT_TYPE); - } - - @Override - protected void processAnnotatedMethodParameter( - Parameter parameter, - int parameterIndex, - Method serviceMethod, - Class serviceType, - Class serviceInterfaceClass, - RestMethodMetadata metadata) { - ArgInfo argInfo = ArgInfo.build(parameterIndex, parameter); - metadata.addArgInfo(argInfo); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java deleted file mode 100644 index 2eac157d671..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/AbstractRequestAnnotationParameterProcessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.common.utils.AnnotationUtils; -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Parameter; -import java.util.Objects; - -import static org.apache.dubbo.common.utils.AnnotationUtils.getAttribute; - -/** - * The abstract {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @Request* - */ -public abstract class AbstractRequestAnnotationParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - protected String getAnnotationValue(Annotation annotation, Parameter parameter, int parameterIndex) { - // try to get "value" attribute first - String name = super.getAnnotationValue(annotation, parameter, parameterIndex); - - // try to get "name" attribute if required - if (isEmpty(name)) { - name = getAttribute(annotation, "name"); - } - - // finally , try to the name of parameter - if (isEmpty(name)) { - name = parameter.getName(); - } - - return name; - } - - @Override - protected String getDefaultValue(Annotation annotation, Parameter parameter, int parameterIndex) { - String attributeName = "defaultValue"; - String attributeValue = getAttribute(annotation, attributeName); - - if (isEmpty(attributeValue) || isDefaultValue(annotation, attributeName, attributeValue)) { - attributeValue = super.getDefaultValue(annotation, parameter, parameterIndex); - } - return attributeValue; - } - - private boolean isDefaultValue(Annotation annotation, String attributeName, Object attributeValue) { - String defaultValue = AnnotationUtils.getDefaultValue(annotation, attributeName); - return Objects.deepEquals(attributeValue, defaultValue); - } - - protected boolean isEmpty(String str) { - return str == null || str.isEmpty(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/FormBodyNoAnnotatedProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/FormBodyNoAnnotatedProcessor.java deleted file mode 100644 index 38dc88663ff..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/FormBodyNoAnnotatedProcessor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AbstractNoAnnotatedParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.media.MediaType; -import org.apache.dubbo.metadata.rest.tag.BodyTag; - -import static org.apache.dubbo.metadata.rest.media.MediaType.APPLICATION_FORM_URLENCODED_VALUE; - -public class FormBodyNoAnnotatedProcessor extends AbstractNoAnnotatedParameterProcessor { - @Override - public MediaType consumerContentType() { - return APPLICATION_FORM_URLENCODED_VALUE; - } - - @Override - public String defaultAnnotationClassName(RestMethodMetadata restMethodMetadata) { - return BodyTag.class.getName(); - } - - @Override - protected boolean isFormContentType(RestMethodMetadata restMethodMetadata) { - return true; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/JsonBodyNoAnnotatedProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/JsonBodyNoAnnotatedProcessor.java deleted file mode 100644 index 64df7adf51e..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/JsonBodyNoAnnotatedProcessor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AbstractNoAnnotatedParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.media.MediaType; -import org.apache.dubbo.metadata.rest.tag.BodyTag; - -import static org.apache.dubbo.metadata.rest.media.MediaType.APPLICATION_JSON_VALUE; - -public class JsonBodyNoAnnotatedProcessor extends AbstractNoAnnotatedParameterProcessor { - @Override - public MediaType consumerContentType() { - return APPLICATION_JSON_VALUE; - } - - @Override - public String defaultAnnotationClassName(RestMethodMetadata restMethodMetadata) { - return BodyTag.class.getName(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/ParamNoAnnotatedProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/ParamNoAnnotatedProcessor.java deleted file mode 100644 index a591c289614..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/ParamNoAnnotatedProcessor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AbstractNoAnnotatedParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.media.MediaType; -import org.apache.dubbo.metadata.rest.tag.BodyTag; -import org.apache.dubbo.metadata.rest.tag.ParamTag; - -import static org.apache.dubbo.metadata.rest.media.MediaType.ALL_VALUE; - -public class ParamNoAnnotatedProcessor extends AbstractNoAnnotatedParameterProcessor { - @Override - public MediaType consumerContentType() { - return ALL_VALUE; - } - - @Override - public String defaultAnnotationClassName(RestMethodMetadata restMethodMetadata) { - - if (JAXRSServiceRestMetadataResolver.class.equals(restMethodMetadata.getCodeStyle())) { - return BodyTag.class.getName(); - } - - return ParamTag.class.getName(); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/PathVariableParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/PathVariableParameterProcessor.java deleted file mode 100644 index fe239f62215..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/PathVariableParameterProcessor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.PATH_VARIABLE_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @PathVariable - */ -public class PathVariableParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return PATH_VARIABLE_ANNOTATION_CLASS_NAME; - } - - @Override - protected String getDefaultValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return null; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestBodyParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestBodyParameterProcessor.java deleted file mode 100644 index 0c93615e68b..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestBodyParameterProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AbstractAnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_BODY_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @RequestBody - */ -public class RequestBodyParameterProcessor extends AbstractAnnotatedMethodParameterProcessor { - - @Override - public String getAnnotationName() { - return REQUEST_BODY_ANNOTATION_CLASS_NAME; - } - - @Override - protected String getAnnotationValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return null; - } - - @Override - protected String getDefaultValue(Annotation annotation, Parameter parameter, int parameterIndex) { - return null; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestHeaderParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestHeaderParameterProcessor.java deleted file mode 100644 index 1edb86fc050..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestHeaderParameterProcessor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_HEADER_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @RequestHeader - */ -public class RequestHeaderParameterProcessor extends AbstractRequestAnnotationParameterProcessor { - - @Override - public String getAnnotationName() { - return REQUEST_HEADER_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String name, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) { - restMethodMetadata.getRequest().addHeader(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestParamParameterProcessor.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestParamParameterProcessor.java deleted file mode 100644 index ad457d3c94c..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/RequestParamParameterProcessor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_PARAM_ANNOTATION_CLASS_NAME; - -/** - * The {@link AnnotatedMethodParameterProcessor} implementation for Spring Web MVC's @RequestParam - */ -public class RequestParamParameterProcessor extends AbstractRequestAnnotationParameterProcessor { - - @Override - public String getAnnotationName() { - return REQUEST_PARAM_ANNOTATION_CLASS_NAME; - } - - @Override - protected void process( - String name, - String defaultValue, - Annotation annotation, - Parameter parameter, - int parameterIndex, - Method method, - RestMethodMetadata restMethodMetadata) { - restMethodMetadata.getRequest().addParam(name, defaultValue); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java deleted file mode 100644 index fe8c9c2f70c..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.metadata.rest.AbstractServiceRestMetadataResolver; -import org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Array; -import java.lang.reflect.Method; -import java.util.Set; - -import static java.lang.String.valueOf; -import static java.lang.reflect.Array.getLength; -import static java.util.stream.Stream.of; -import static org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation; -import static org.apache.dubbo.common.utils.AnnotationUtils.getAttribute; -import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent; -import static org.apache.dubbo.common.utils.ArrayUtils.isEmpty; -import static org.apache.dubbo.common.utils.ArrayUtils.isNotEmpty; -import static org.apache.dubbo.common.utils.MethodUtils.findMethod; -import static org.apache.dubbo.common.utils.PathUtils.buildPath; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.ANNOTATED_ELEMENT_UTILS_CLASS; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.CONTROLLER_ANNOTATION_CLASS; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.FEIGN_CLIENT_CLASS; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_MAPPING_ANNOTATION_CLASS; -import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_MAPPING_ANNOTATION_CLASS_NAME; - -/** - * {@link ServiceRestMetadataResolver} - * - * @since 2.7.6 - */ -@Activate(order = 100) -public class SpringMvcServiceRestMetadataResolver extends AbstractServiceRestMetadataResolver { - - private static final int FIRST_ELEMENT_INDEX = 0; - - public SpringMvcServiceRestMetadataResolver(ApplicationModel applicationModel) { - super(applicationModel); - } - - @Override - protected boolean supports0(Class serviceType) { - // class @Controller or @RequestMapping - return isAnnotationPresent(serviceType, CONTROLLER_ANNOTATION_CLASS) - || isAnnotationPresent(serviceType, FEIGN_CLIENT_CLASS) - || isAnnotationPresent(serviceType, REQUEST_MAPPING_ANNOTATION_CLASS) // method @RequestMapping - || isServiceMethodAnnotationPresent(serviceType, REQUEST_MAPPING_ANNOTATION_CLASS_NAME); - } - - @Override - protected boolean isRestCapableMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - // method only match @RequestMapping - return isAnnotationPresent(serviceMethod, REQUEST_MAPPING_ANNOTATION_CLASS); - } - - @Override - protected String resolveRequestMethod(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - Annotation requestMapping = getRequestMapping(serviceMethod); - - // httpMethod is an array of RequestMethod - Object httpMethod = getAttribute(requestMapping, "method"); - - if (httpMethod == null || getLength(httpMethod) < 1) { - return null; - } - - // TODO Is is required to support more request methods? - return valueOf(Array.get(httpMethod, FIRST_ELEMENT_INDEX)); - } - - @Override - protected String resolveRequestPath(Method serviceMethod, Class serviceType, Class serviceInterfaceClass) { - String feignClientBasePath = resolveFeignClientBaseRequestPath(serviceType); - String requestMappingBasePath = resolveRequestPath(serviceType); - String requestRelativePath = resolveRequestPath(serviceMethod); - return buildPath(feignClientBasePath, buildPath(requestMappingBasePath, requestRelativePath)); - } - - @Override - protected void processProduces( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set produces) { - addMediaTypes(serviceMethod, "produces", produces); - addMediaTypes(serviceType, "produces", produces); - addMediaTypes(serviceInterfaceClass, "produces", produces); - } - - @Override - protected void processConsumes( - Method serviceMethod, Class serviceType, Class serviceInterfaceClass, Set consumes) { - addMediaTypes(serviceMethod, "consumes", consumes); - addMediaTypes(serviceType, "consumes", consumes); - addMediaTypes(serviceInterfaceClass, "consumes", consumes); - } - - private String resolveFeignClientBaseRequestPath(AnnotatedElement annotatedElement) { - Annotation feignClient = findAnnotation(annotatedElement, FEIGN_CLIENT_CLASS); - - String path = getAttribute(feignClient, "path"); - - if (path == null) { - return ""; - } - - return path; - } - - private String resolveRequestPath(AnnotatedElement annotatedElement) { - Annotation mappingAnnotation = getRequestMapping(annotatedElement); - - // try "value" first - String[] value = getAttribute(mappingAnnotation, "value"); - - if (isEmpty(value)) { // try "path" later - value = getAttribute(mappingAnnotation, "path"); - } - - if (isEmpty(value)) { - return ""; - } - // TODO Is is required to support more request paths? - return value[FIRST_ELEMENT_INDEX]; - } - - private void addMediaTypes(Method serviceMethod, String annotationAttributeName, Set mediaTypesSet) { - - Annotation mappingAnnotation = getRequestMapping(serviceMethod); - - String[] mediaTypes = getAttribute(mappingAnnotation, annotationAttributeName); - - if (isNotEmpty(mediaTypes)) { - of(mediaTypes).forEach(mediaTypesSet::add); - } - } - - private void addMediaTypes(Class serviceType, String annotationAttributeName, Set mediaTypesSet) { - - Annotation mappingAnnotation = getRequestMapping(serviceType); - - String[] mediaTypes = getAttribute(mappingAnnotation, annotationAttributeName); - - if (isNotEmpty(mediaTypes)) { - of(mediaTypes).forEach(mediaTypesSet::add); - } - } - - private Annotation getRequestMapping(AnnotatedElement annotatedElement) { - // try "@RequestMapping" first - Annotation requestMapping = findAnnotation(annotatedElement, REQUEST_MAPPING_ANNOTATION_CLASS); - if (requestMapping == null) { - // To try the meta-annotated annotation if can't be found. - // For example, if the annotation "@GetMapping" is used in the Spring Framework is 4.2 or above, - // because of "@GetMapping" alias for ("@AliasFor") "@RequestMapping" , both of them belongs to - // the artifact "spring-web" which depends on "spring-core", thus Spring core's - // AnnotatedElementUtils.findMergedAnnotation(AnnotatedElement, Class) must be involved. - Method method = findMethod( - ANNOTATED_ELEMENT_UTILS_CLASS, "findMergedAnnotation", AnnotatedElement.class, Class.class); - if (method != null) { - try { - requestMapping = - (Annotation) method.invoke(null, annotatedElement, REQUEST_MAPPING_ANNOTATION_CLASS); - } catch (Exception ignored) { - } - } - } - return requestMapping; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/BodyTag.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/BodyTag.java deleted file mode 100644 index c308bcee0ba..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/BodyTag.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.dubbo.metadata.rest.tag; - -/** - * for @RequestBody class no found - */ -public interface BodyTag {} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/NoAnnotationTag.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/NoAnnotationTag.java deleted file mode 100644 index 949157b0beb..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/NoAnnotationTag.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.dubbo.metadata.rest.tag; - -/** - * for no annotation mode param - */ -public interface NoAnnotationTag {} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/ParamTag.java b/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/ParamTag.java deleted file mode 100644 index cfc16e36642..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/java/org/apache/dubbo/metadata/rest/tag/ParamTag.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.dubbo.metadata.rest.tag; - -/** - * for @RequestParam or @QueryParam class no found - */ -public interface ParamTag {} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor b/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor deleted file mode 100644 index 141ce6f8e0f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.AnnotatedMethodParameterProcessor +++ /dev/null @@ -1,15 +0,0 @@ -# JAX-RS's implementations -jax-rs.query-param = org.apache.dubbo.metadata.rest.jaxrs.QueryParamParameterProcessor -jax-rs.form-param = org.apache.dubbo.metadata.rest.jaxrs.FormParamParameterProcessor -jax-rs.matrix-param = org.apache.dubbo.metadata.rest.jaxrs.MatrixParamParameterProcessor -jax-rs.header-param = org.apache.dubbo.metadata.rest.jaxrs.HeaderParamParameterProcessor -jax-rs.default-value-param = org.apache.dubbo.metadata.rest.jaxrs.DefaultValueParameterProcessor -jax-rs.body = org.apache.dubbo.metadata.rest.jaxrs.BodyParameterProcessor -jax-rs.form-body = org.apache.dubbo.metadata.rest.jaxrs.FormBodyParameterProcessor -jax-rs.path-param = org.apache.dubbo.metadata.rest.jaxrs.PathParamParameterProcessor - -# Spring Web MVC's implementations -spring-webmvc.request-param = org.apache.dubbo.metadata.rest.springmvc.RequestParamParameterProcessor -spring-webmvc.request-header = org.apache.dubbo.metadata.rest.springmvc.RequestHeaderParameterProcessor -spring-webmvc.request-body = org.apache.dubbo.metadata.rest.springmvc.RequestBodyParameterProcessor -spring-webmvc.request-path = org.apache.dubbo.metadata.rest.springmvc.PathVariableParameterProcessor diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor b/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor deleted file mode 100644 index 5324f222215..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.NoAnnotatedParameterRequestTagProcessor +++ /dev/null @@ -1,3 +0,0 @@ -body-form=org.apache.dubbo.metadata.rest.springmvc.FormBodyNoAnnotatedProcessor -body-json=org.apache.dubbo.metadata.rest.springmvc.JsonBodyNoAnnotatedProcessor -param=org.apache.dubbo.metadata.rest.springmvc.ParamNoAnnotatedProcessor diff --git a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver b/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver deleted file mode 100644 index ac37a96c5ea..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.rest.ServiceRestMetadataResolver +++ /dev/null @@ -1,4 +0,0 @@ -default = -jax-rs = org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver -spring-webmvc = org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver -no-annotation = org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/PathMatcherTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/PathMatcherTest.java deleted file mode 100644 index 875b589b2bf..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/PathMatcherTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.dubbo.metadata; - -import org.apache.dubbo.metadata.rest.PathMatcher; - -import java.lang.reflect.Method; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class PathMatcherTest { - - @Test - void testPathMatcher() { - PathMatcher pathMatherMeta = new PathMatcher("/a/b/c/{path1}/d/{path2}/e"); - - PathMatcher requestPathMather = new PathMatcher("/a/b/c/1/d/2/e"); - Assertions.assertEquals(requestPathMather, pathMatherMeta); - - PathMatcher requestPathMather1 = new PathMatcher("/{c}/b/c/1/d/2/e"); - Assertions.assertEquals(requestPathMather, requestPathMather1); - - PathMatcher pathMatcher = new PathMatcher("/{d}/b/c/1/d/2/e"); - - pathMatcher.setGroup(null); - pathMatcher.setPort(null); - pathMatcher.setVersion(null); - pathMatcher.setContextPath(""); - - Assertions.assertEquals(pathMatherMeta, pathMatcher); - } - - @Test - void testEqual() { - PathMatcher pathMatherMeta = new PathMatcher("/a/b/c"); - pathMatherMeta.setContextPath("/context"); - PathMatcher pathMatherMeta1 = new PathMatcher("/a/b/d"); - - pathMatherMeta1.setContextPath("/context"); - Assertions.assertNotEquals(pathMatherMeta, pathMatherMeta1); - - pathMatherMeta1 = new PathMatcher("/a/b/c"); - pathMatherMeta1.setContextPath("/context"); - - Assertions.assertEquals(pathMatherMeta, pathMatherMeta1); - - pathMatherMeta.setContextPath("context"); - - pathMatherMeta1.setContextPath("context"); - - Assertions.assertEquals(pathMatherMeta, pathMatherMeta1); - Assertions.assertEquals(pathMatherMeta.toString(), pathMatherMeta1.toString()); - } - - @Test - void testMethodCompare() { - Method hashCode = null; - Method equals = null; - try { - hashCode = Object.class.getDeclaredMethod("hashCode"); - equals = Object.class.getDeclaredMethod("equals", Object.class); - } catch (NoSuchMethodException e) { - - } - - // no need to compare service method - PathMatcher pathMatcher = new PathMatcher(hashCode); - PathMatcher pathMatchers = new PathMatcher(hashCode); - Assertions.assertNotEquals(pathMatcher, pathMatchers); - - // equal - PathMatcher pathMatherMetaHashCode = PathMatcher.getInvokeCreatePathMatcher(hashCode); - PathMatcher pathMatherMetaHashCodes = new PathMatcher(hashCode); - Assertions.assertEquals(pathMatherMetaHashCode, pathMatherMetaHashCodes); - - PathMatcher pathMatherMetaEquals = PathMatcher.getInvokeCreatePathMatcher(equals); - PathMatcher pathMatherMetaEqual = PathMatcher.getInvokeCreatePathMatcher(equals); - Assertions.assertEquals(pathMatherMetaEqual, pathMatherMetaEquals); - - Assertions.assertNotEquals(pathMatherMetaHashCode, pathMatherMetaEquals); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/TestMediaType.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/TestMediaType.java deleted file mode 100644 index 1a6fbad425e..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/TestMediaType.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.dubbo.metadata; - -import org.apache.dubbo.metadata.rest.media.MediaType; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class TestMediaType { - - @Test - void testGetAll() { - Assertions.assertDoesNotThrow(() -> { - MediaType.getAllContentType(); - MediaType.getSupportMediaTypes(); - }); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java deleted file mode 100644 index 56075447d5d..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/DefaultRestService.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.Service; - -import java.util.Map; - -/** - * The default implementation of {@link RestService} - * - * @since 2.7.6 - */ -@Service(version = "1.0.0") -public class DefaultRestService implements RestService { - - @Override - public String param(String param) { - return null; - } - - @Override - public String params(int a, String b) { - return null; - } - - @Override - public String headers(String header, String header2, Integer param) { - return null; - } - - @Override - public String pathVariables(String path1, String path2, String param) { - return null; - } - - @Override - public String form(String form) { - return null; - } - - @Override - public User requestBodyMap(Map data, String param) { - return null; - } - - @Override - public Map requestBodyUser(User user) { - return null; - } - - @Override - public void noAnnotationJsonBody(User user) {} - - @Override - public void noAnnotationFormBody(User user) {} - - @Override - public void noAnnotationParam(String text) {} - - public User user(User user) { - return user; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/RestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/RestService.java deleted file mode 100644 index 049335e0f54..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/RestService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.util.Map; - -/** - * An interface for REST service - * - * @since 2.7.6 - */ -public interface RestService { - - String param(String param); - - String params(int a, String b); - - String headers(String header, String header2, Integer param); - - String pathVariables(String path1, String path2, String param); - - String form(String form); - - User requestBodyMap(Map data, String param); - - Map requestBodyUser(User user); - - void noAnnotationJsonBody(User user); - - void noAnnotationFormBody(User user); - - void noAnnotationParam(String text); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java deleted file mode 100644 index 05c3fea7ef6..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/SpringRestService.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.DubboService; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * Spring MVC {@link RestService} - * - * @since 2.7.6 - */ -@DubboService(version = "2.0.0", group = "spring") -@RestController -public class SpringRestService implements RestService { - - @Override - @GetMapping(value = "/param") - public String param(@RequestParam(defaultValue = "value-param") String param) { - return null; - } - - @Override - @PostMapping("/params") - public String params( - @RequestParam(defaultValue = "value-a") int a, @RequestParam(defaultValue = "value-b") String b) { - return null; - } - - @Override - @GetMapping("/headers") - public String headers( - @RequestHeader(name = "h", defaultValue = "value-h") String header, - @RequestHeader(name = "h2", defaultValue = "value-h2") String header2, - @RequestParam(value = "v", defaultValue = "1") Integer param) { - return null; - } - - @Override - @GetMapping("/path-variables/{p1}/{p2}") - public String pathVariables( - @PathVariable("p1") String path1, @PathVariable("p2") String path2, @RequestParam("v") String param) { - return null; - } - - @Override - @PostMapping("/form") - public String form(@RequestParam("f") String form) { - return String.valueOf(form); - } - - @Override - @PostMapping(value = "/request/body/map", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public User requestBodyMap(@RequestBody Map data, @RequestParam("param") String param) { - User user = new User(); - user.setId(((Integer) data.get("id")).longValue()); - user.setName((String) data.get("name")); - user.setAge((Integer) data.get("age")); - return user; - } - - @PostMapping(value = "/request/body/user", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) - @Override - public Map requestBodyUser(@RequestBody User user) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("name", user.getName()); - map.put("age", user.getAge()); - return map; - } - - @PostMapping(value = "/request/body/user/json", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) - @Override - public void noAnnotationJsonBody(User user) {} - - @PostMapping(value = "/request/body/user/form", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - @Override - public void noAnnotationFormBody(User user) {} - - @PostMapping(value = "/request/body/user/param") - @Override - public void noAnnotationParam(String text) {} -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java deleted file mode 100644 index 45b84b9ce34..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/StandardRestService.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import org.apache.dubbo.config.annotation.DubboService; - -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -import java.util.HashMap; -import java.util.Map; - -/** - * JAX-RS {@link RestService} - */ -@DubboService( - version = "3.0.0", - protocol = {"dubbo", "rest"}, - group = "standard") -@Path("/") -public class StandardRestService implements RestService { - - @Override - @Path("param") - @GET - public String param(@QueryParam("param") String param) { - return param; - } - - @Override - @Path("params") - @POST - public String params(@QueryParam("a") int a, @QueryParam("b") String b) { - return a + b; - } - - @Override - @Path("headers") - @GET - public String headers( - @HeaderParam("h") String header, @HeaderParam("h2") String header2, @QueryParam("v") Integer param) { - String result = header + " , " + header2 + " , " + param; - return result; - } - - @Override - @Path("path-variables/{p1}/{p2}") - @GET - public String pathVariables( - @PathParam("p1") String path1, @PathParam("p2") String path2, @QueryParam("v") String param) { - String result = path1 + " , " + path2 + " , " + param; - return result; - } - - // @CookieParam does not support : https://github.com/OpenFeign/feign/issues/913 - // @CookieValue also does not support - - @Override - @Path("form") - @POST - public String form(@FormParam("f") String form) { - return String.valueOf(form); - } - - @Override - @Path("request/body/map") - @POST - @Produces("application/json;charset=UTF-8") - public User requestBodyMap(Map data, @QueryParam("param") String param) { - User user = new User(); - user.setId(((Integer) data.get("id")).longValue()); - user.setName((String) data.get("name")); - user.setAge((Integer) data.get("age")); - return user; - } - - @Path("request/body/user") - @POST - @Override - @Consumes("application/json;charset=UTF-8") - public Map requestBodyUser(User user) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("name", user.getName()); - map.put("age", user.getAge()); - return map; - } - - @Path("noAnnotationJsonBody/json") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Override - public void noAnnotationJsonBody(User user) {} - - @Path("noAnnotationFormBody/form") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @POST - @Override - public void noAnnotationFormBody(User user) {} - - @Path("noAnnotationParam/text") - @POST - @Override - public void noAnnotationParam(String text) {} -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/User.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/User.java deleted file mode 100644 index 2b6c4a21baa..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/User.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.dubbo.metadata.rest; - -import java.io.Serializable; - -/** - * User Entity - * - * @since 2.7.6 - */ -public class User implements Serializable { - - private Long id; - - private String name; - - private Integer age; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - @Override - public String toString() { - return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + '}'; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/AnotherUserRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/AnotherUserRestService.java deleted file mode 100644 index 7afb0fc37a8..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/AnotherUserRestService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -@Path("u") -@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML}) -@Produces({MediaType.APPLICATION_JSON}) -public interface AnotherUserRestService { - - @GET - @Path("{id : \\d+}") - User getUser(@PathParam("id") Long id); - - @POST - @Path("register") - String registerUser(User user); - - @GET - @Path("context") - String getContext(); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckContainsPathVariableService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckContainsPathVariableService.java deleted file mode 100644 index 324ba19adeb..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckContainsPathVariableService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; - -@Path("/test") -public interface JaxrsRestDoubleCheckContainsPathVariableService { - @Path("/a/{b}") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String param(@QueryParam("param") String param); - - @Path("/{b}/b") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String header(@HeaderParam("header") String header); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckService.java deleted file mode 100644 index 389af5e78c9..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestDoubleCheckService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -@Path("/test") -public interface JaxrsRestDoubleCheckService { - @Path("/param") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String param(@QueryParam("param") String param); - - @Path("/param") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String header(@HeaderParam("header") String header); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestService.java deleted file mode 100644 index 3cc8416fbdc..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestService.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; - -public interface JaxrsRestService { - - @Path("/param") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String param(@QueryParam("param") String param); - - @Path("/header") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @GET - String header(@HeaderParam("header") String header); - - @Path("/body") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @POST - User body(User user); - - @Path("/multiValue") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Produces(MediaType.APPLICATION_FORM_URLENCODED) - @POST - MultivaluedMap multiValue(MultivaluedMap map); - - @Path("/pathVariable/{a}") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Produces(MediaType.APPLICATION_FORM_URLENCODED) - @POST - String pathVariable(@PathParam("a") String a); - - @Path("/noAnno") - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - @POST - String noAnno(String a); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestServiceImpl.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestServiceImpl.java deleted file mode 100644 index 2f309e28c05..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsRestServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import javax.ws.rs.core.MultivaluedMap; - -public class JaxrsRestServiceImpl implements JaxrsRestService { - - @Override - public String param(String param) { - return param; - } - - @Override - public String header(String header) { - return header; - } - - @Override - public User body(User user) { - return user; - } - - @Override - public MultivaluedMap multiValue(MultivaluedMap map) { - return map; - } - - @Override - public String pathVariable(String a) { - return a; - } - - @Override - public String noAnno(String a) { - return a; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsUsingService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsUsingService.java deleted file mode 100644 index 4bcc761f1d9..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/JaxrsUsingService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -@Path("usingService") -@Consumes({MediaType.APPLICATION_JSON}) -@Produces({MediaType.APPLICATION_JSON}) -public interface JaxrsUsingService { - - @GET - Response getUsers(); - - @POST - Response createUser(Object user); - - @GET - @Path("{uid}") - Response getUserByUid(@PathParam("uid") String uid); - - @DELETE - @Path("{uid}") - Response deleteUserByUid(@PathParam("uid") String uid); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringControllerService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringControllerService.java deleted file mode 100644 index 479714a4d46..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringControllerService.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import org.springframework.http.MediaType; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SpringControllerService { - @RequestMapping( - value = "/param", - method = RequestMethod.GET, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - public String param(@RequestParam String param) { - return param; - } - - @RequestMapping( - value = "/header", - method = RequestMethod.GET, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - public String header(@RequestHeader String header) { - return header; - } - - @RequestMapping( - value = "/body", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - public User body(@RequestBody User user) { - return user; - } - - @RequestMapping( - value = "/multiValue", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, - produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - public MultiValueMap multiValue(@RequestBody MultiValueMap map) { - return map; - } - - @RequestMapping( - value = "/pathVariable/{a}", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, - produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - public String pathVariable(@PathVariable String a) { - return a; - } - - @RequestMapping( - value = "/noAnnoParam", - method = RequestMethod.POST, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - public String noAnnoParam(String a) { - return a; - } - - @RequestMapping( - value = "/noAnnoNumber", - method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - public int noAnnoNumber(Integer b) { - return b; - } - - @RequestMapping( - value = "/noAnnoPrimitive", - method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - public int noAnnoPrimitive(int c) { - return c; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestService.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestService.java deleted file mode 100644 index 8a8c727553f..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestService.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import org.springframework.http.MediaType; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public interface SpringRestService { - - @RequestMapping( - value = "/param", - method = RequestMethod.GET, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - String param(@RequestParam("param") String param); - - @RequestMapping( - value = "/header", - method = RequestMethod.GET, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - String header(@RequestHeader("header") String header); - - @RequestMapping( - value = "/body", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - User body(@RequestBody User user); - - @RequestMapping( - value = "/multiValue", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, - produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - MultiValueMap multiValue(@RequestBody MultiValueMap map); - - @RequestMapping( - value = "/pathVariable/{a}", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, - produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - String pathVariable(@PathVariable String a); - - @RequestMapping( - value = "/noAnnoParam", - method = RequestMethod.POST, - consumes = MediaType.TEXT_PLAIN_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - String noAnnoParam(String a); - - @RequestMapping( - value = "/noAnnoNumber", - method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - int noAnnoNumber(Integer b); - - @RequestMapping( - value = "/noAnnoPrimitive", - method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - int noAnnoPrimitive(int c); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestServiceImpl.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestServiceImpl.java deleted file mode 100644 index a9cfb9c3080..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/api/SpringRestServiceImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.dubbo.metadata.rest.api; - -import org.apache.dubbo.metadata.rest.User; - -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SpringRestServiceImpl implements SpringRestService { - - @Override - public String param(String param) { - return param; - } - - @Override - public String header(String header) { - return header; - } - - @Override - public User body(User user) { - return user; - } - - @Override - public MultiValueMap multiValue(MultiValueMap map) { - return map; - } - - @Override - public String pathVariable(String a) { - return a; - } - - @Override - public String noAnnoParam(String a) { - return a; - } - - @Override - public int noAnnoNumber(Integer b) { - return b; - } - - @Override - public int noAnnoPrimitive(int c) { - return c; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientController.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientController.java deleted file mode 100644 index e3b0ecbf7b7..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientController.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.dubbo.metadata.rest.feign; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -@FeignClient(path = "/feign") -@RequestMapping("/context") -public interface FeignClientController { - - @RequestMapping(value = "/hello", method = RequestMethod.GET) - String hello(); -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientControllerImpl.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientControllerImpl.java deleted file mode 100644 index 8f0cc225be4..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/feign/FeignClientControllerImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dubbo.metadata.rest.feign; - -public class FeignClientControllerImpl implements FeignClientController { - - @Override - public String hello() { - return "hello, feign"; - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolverTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolverTest.java deleted file mode 100644 index e68b995e84e..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolverTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.common.utils.CollectionUtils; -import org.apache.dubbo.common.utils.JsonUtils; -import org.apache.dubbo.metadata.rest.ClassPathServiceRestMetadataReader; -import org.apache.dubbo.metadata.rest.DefaultRestService; -import org.apache.dubbo.metadata.rest.PathUtil; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.metadata.rest.StandardRestService; -import org.apache.dubbo.metadata.rest.api.AnotherUserRestService; -import org.apache.dubbo.metadata.rest.api.JaxrsRestService; -import org.apache.dubbo.metadata.rest.api.JaxrsRestServiceImpl; -import org.apache.dubbo.metadata.rest.api.SpringRestService; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * {@link JAXRSServiceRestMetadataResolver} Test - * - * @since 2.7.6 - */ -class JAXRSServiceRestMetadataResolverTest { - - private JAXRSServiceRestMetadataResolver instance = - new JAXRSServiceRestMetadataResolver(ApplicationModel.defaultModel()); - - @Test - void testSupports() { - // JAX-RS RestService class - assertTrue(instance.supports(StandardRestService.class)); - // Spring MVC RestService class - assertFalse(instance.supports(SpringRestService.class)); - // Default RestService class - assertFalse(instance.supports(DefaultRestService.class)); - // No annotated RestService class - assertFalse(instance.supports(RestService.class)); - // null - assertFalse(instance.supports(null)); - } - - @Test - @Disabled - void testResolve() { - // Generated by "dubbo-metadata-processor" - ClassPathServiceRestMetadataReader reader = - new ClassPathServiceRestMetadataReader("META-INF/dubbo/jax-rs-service-rest-metadata.json"); - List serviceRestMetadataList = reader.read(); - - ServiceRestMetadata expectedServiceRestMetadata = serviceRestMetadataList.get(0); - ServiceRestMetadata serviceRestMetadata = instance.resolve(StandardRestService.class); - - assertTrue(CollectionUtils.equals(expectedServiceRestMetadata.getMeta(), serviceRestMetadata.getMeta())); - - assertEquals(expectedServiceRestMetadata, serviceRestMetadata); - } - - @Test - void testResolves() { - testResolve(JaxrsRestService.class); - testResolve(JaxrsRestServiceImpl.class); - } - - void testResolve(Class service) { - // Generated by "dubbo-metadata-processor" - - List jsons = Arrays.asList( - "{\"argInfos\":[{\"annotationNameAttribute\":\"a\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.BodyTag\",\"paramName\":\"a\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"a\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/noAnno\",\"produces\":[\"text/plain\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"a\",\"defaultValue\":\"{0}\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"javax.ws.rs.PathParam\",\"paramName\":\"a\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":2}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"a\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/x-www-form-urlencoded\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/pathVariable/{a}\",\"produces\":[\"application/x-www-form-urlencoded\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"map\",\"formContentType\":true,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.BodyTag\",\"paramName\":\"map\",\"paramType\":\"javax.ws.rs.core.MultivaluedMap\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"map\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/x-www-form-urlencoded\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/multiValue\",\"produces\":[\"application/x-www-form-urlencoded\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"user\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.BodyTag\",\"paramName\":\"user\",\"paramType\":\"org.apache.dubbo.metadata.rest.User\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"user\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/body\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"param\",\"defaultValue\":\"{0}\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"javax.ws.rs.QueryParam\",\"paramName\":\"param\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[],\"headers\":{},\"method\":\"GET\",\"paramNames\":[\"param\"],\"params\":{\"param\":[\"{0}\"]},\"path\":\"/param\",\"produces\":[\"text/plain\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"header\",\"defaultValue\":\"{0}\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"javax.ws.rs.HeaderParam\",\"paramName\":\"header\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.jaxrs.JAXRSServiceRestMetadataResolver\",\"indexToName\":{0:[\"header\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[\"header\"],\"headers\":{\"header\":[\"{0}\"]},\"method\":\"GET\",\"paramNames\":[],\"params\":{},\"path\":\"/header\",\"produces\":[\"text/plain\"]}}"); - - ServiceRestMetadata jaxrsRestMetadata = new ServiceRestMetadata(); - jaxrsRestMetadata.setServiceInterface(service.getName()); - ServiceRestMetadata jaxrsMetadata = instance.resolve(service, jaxrsRestMetadata); - - List jsonsTmp = new ArrayList<>(); - for (RestMethodMetadata restMethodMetadata : jaxrsMetadata.getMeta()) { - restMethodMetadata.setReflectMethod(null); - restMethodMetadata.setMethod(null); - jsonsTmp.add(JsonUtils.toJson(restMethodMetadata)); - } - - Comparator comparator = new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.length() - o2.length(); - } - }; - jsons.sort(comparator); - jsonsTmp.sort(comparator); - - for (int i = 0; i < jsons.size(); i++) { - assertEquals(jsons.get(i), jsonsTmp.get(i)); - } - } - - @Test - void testJaxrsPathPattern() { - Class service = AnotherUserRestService.class; - ServiceRestMetadata jaxrsRestMetadata = new ServiceRestMetadata(); - jaxrsRestMetadata.setServiceInterface(service.getName()); - ServiceRestMetadata jaxrsMetadata = instance.resolve(service, jaxrsRestMetadata); - - RestMethodMetadata[] objects = jaxrsMetadata.getMeta().toArray(new RestMethodMetadata[0]); - RestMethodMetadata object = null; - for (RestMethodMetadata obj : objects) { - if ("getUser".equals(obj.getReflectMethod().getName())) { - object = obj; - } - } - - Assertions.assertEquals( - "/u/1", PathUtil.resolvePathVariable("/u/{id : \\d+}", object.getArgInfos(), Arrays.asList(1))); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JaxrsRestDoubleCheckTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JaxrsRestDoubleCheckTest.java deleted file mode 100644 index 362e7f3acbd..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/jaxrs/JaxrsRestDoubleCheckTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.dubbo.metadata.rest.jaxrs; - -import org.apache.dubbo.metadata.rest.PathMatcher; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.metadata.rest.api.JaxrsRestDoubleCheckContainsPathVariableService; -import org.apache.dubbo.metadata.rest.api.JaxrsRestDoubleCheckService; -import org.apache.dubbo.metadata.rest.api.JaxrsUsingService; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.Map; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class JaxrsRestDoubleCheckTest { - private JAXRSServiceRestMetadataResolver instance = - new JAXRSServiceRestMetadataResolver(ApplicationModel.defaultModel()); - - @Test - void testDoubleCheckException() { - - Assertions.assertThrows(IllegalArgumentException.class, () -> { - ServiceRestMetadata resolve = new ServiceRestMetadata(); - resolve.setServiceInterface(JaxrsRestDoubleCheckService.class.getName()); - instance.resolve(JaxrsRestDoubleCheckService.class, resolve); - }); - - Assertions.assertThrows(IllegalArgumentException.class, () -> { - ServiceRestMetadata resolve = new ServiceRestMetadata(); - resolve.setServiceInterface(JaxrsRestDoubleCheckContainsPathVariableService.class.getName()); - instance.resolve(JaxrsRestDoubleCheckContainsPathVariableService.class, resolve); - }); - } - - @Test - void testSameHttpMethodException() { - - Assertions.assertDoesNotThrow(() -> { - ServiceRestMetadata resolve = new ServiceRestMetadata(); - resolve.setServiceInterface(JaxrsUsingService.class.getName()); - instance.resolve(JaxrsUsingService.class, resolve); - }); - - ServiceRestMetadata resolve = new ServiceRestMetadata(); - resolve.setServiceInterface(JaxrsUsingService.class.getName()); - instance.resolve(JaxrsUsingService.class, resolve); - - Map pathContainPathVariableToServiceMap = - resolve.getPathContainPathVariableToServiceMap(); - - RestMethodMetadata restMethodMetadata = pathContainPathVariableToServiceMap.get( - PathMatcher.getInvokeCreatePathMatcher("/usingService/aaa", null, null, null, "TEST")); - - Assertions.assertNotNull(restMethodMetadata); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/noannotation/NoAnnotationServiceRestMetadataResolverTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/noannotation/NoAnnotationServiceRestMetadataResolverTest.java deleted file mode 100644 index 1db4aae9821..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/noannotation/NoAnnotationServiceRestMetadataResolverTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.dubbo.metadata.rest.noannotation; - -import org.apache.dubbo.common.utils.JsonUtils; -import org.apache.dubbo.metadata.rest.DefaultRestService; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class NoAnnotationServiceRestMetadataResolverTest { - private NoAnnotationServiceRestMetadataResolver instance = - new NoAnnotationServiceRestMetadataResolver(ApplicationModel.defaultModel()); - - @Test - void testResolve() { - - List jsons = Arrays.asList( - "{\"argInfos\":[{\"annotationNameAttribute\":\"form\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"form\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"form\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/form\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"header\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"header\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"header2\",\"formContentType\":false,\"index\":1,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"header2\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"param\",\"formContentType\":false,\"index\":2,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"param\",\"paramType\":\"java.lang.Integer\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"header\"],1:[\"header2\"],2:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/headers\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"user\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"user\",\"paramType\":\"org.apache.dubbo.metadata.rest.User\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"user\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/noAnnotationFormBody\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"user\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"user\",\"paramType\":\"org.apache.dubbo.metadata.rest.User\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"user\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/noAnnotationJsonBody\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"text\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"text\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"text\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/noAnnotationParam\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"param\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"param\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/param\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"a\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"a\",\"paramType\":\"int\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"b\",\"formContentType\":false,\"index\":1,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"b\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"a\"],1:[\"b\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/params\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"path1\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"path1\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"path2\",\"formContentType\":false,\"index\":1,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"path2\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"param\",\"formContentType\":false,\"index\":2,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"param\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"path1\"],1:[\"path2\"],2:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/pathVariables\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"data\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"data\",\"paramType\":\"java.util.Map\",\"urlSplitIndex\":0},{\"annotationNameAttribute\":\"param\",\"formContentType\":false,\"index\":1,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"param\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"data\"],1:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/requestBodyMap\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"user\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.NoAnnotationTag\",\"paramName\":\"user\",\"paramType\":\"org.apache.dubbo.metadata.rest.User\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.noannotaion.NoAnnotationServiceRestMetadataResolver\",\"indexToName\":{0:[\"user\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/org.apache.dubbo.metadata.rest.RestService/requestBodyUser\",\"produces\":[\"application/json\"]}}"); - - boolean supports = instance.supports(DefaultRestService.class); - - Assertions.assertEquals(true, supports); - - ServiceRestMetadata serviceRestMetadata = instance.resolve(DefaultRestService.class); - - List jsonsTmp = new ArrayList<>(); - for (RestMethodMetadata restMethodMetadata : serviceRestMetadata.getMeta()) { - restMethodMetadata.setReflectMethod(null); - restMethodMetadata.setMethod(null); - jsonsTmp.add(JsonUtils.toJson(restMethodMetadata)); - } - - Comparator comparator = new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.length() - o2.length(); - } - }; - jsons.sort(comparator); - jsonsTmp.sort(comparator); - - for (int i = 0; i < jsons.size(); i++) { - assertEquals(jsons.get(i), jsonsTmp.get(i)); - } - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/FeignClientAnnotationTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/FeignClientAnnotationTest.java deleted file mode 100644 index f2aa5b88ff0..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/FeignClientAnnotationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.metadata.rest.PathMatcher; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.metadata.rest.feign.FeignClientController; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.Map; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class FeignClientAnnotationTest { - - private SpringMvcServiceRestMetadataResolver instance = - new SpringMvcServiceRestMetadataResolver(ApplicationModel.defaultModel()); - - @Test - void testFeignClientAnnotationResolve() { - - Assertions.assertEquals(true, instance.supports(FeignClientController.class)); - Class service = FeignClientController.class; - ServiceRestMetadata serviceRestMetadata = new ServiceRestMetadata(); - serviceRestMetadata.setServiceInterface(service.getName()); - - ServiceRestMetadata resolve = instance.resolve(service, serviceRestMetadata); - - Map unContainPathVariableToServiceMap = - resolve.getPathUnContainPathVariableToServiceMap(); - RestMethodMetadata restMethodMetadata = unContainPathVariableToServiceMap.get( - PathMatcher.getInvokeCreatePathMatcher("/feign/context/hello", null, null, null, "GET")); - Assertions.assertNotNull(restMethodMetadata); - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolverTest.java b/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolverTest.java deleted file mode 100644 index 4c96e383345..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolverTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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.dubbo.metadata.rest.springmvc; - -import org.apache.dubbo.common.utils.CollectionUtils; -import org.apache.dubbo.common.utils.JsonUtils; -import org.apache.dubbo.metadata.rest.ClassPathServiceRestMetadataReader; -import org.apache.dubbo.metadata.rest.DefaultRestService; -import org.apache.dubbo.metadata.rest.PathMatcher; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; -import org.apache.dubbo.metadata.rest.RestService; -import org.apache.dubbo.metadata.rest.ServiceRestMetadata; -import org.apache.dubbo.metadata.rest.StandardRestService; -import org.apache.dubbo.metadata.rest.api.SpringControllerService; -import org.apache.dubbo.metadata.rest.api.SpringRestService; -import org.apache.dubbo.metadata.rest.api.SpringRestServiceImpl; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * {@link SpringMvcServiceRestMetadataResolver} Test - * - * @since 2.7.9 - */ -class SpringMvcServiceRestMetadataResolverTest { - - private SpringMvcServiceRestMetadataResolver instance = - new SpringMvcServiceRestMetadataResolver(ApplicationModel.defaultModel()); - - @Test - void testSupports() { - // Spring MVC RestService class - assertTrue(instance.supports(SpringRestService.class, true)); - // JAX-RS RestService class - assertFalse(instance.supports(StandardRestService.class, true)); - // Default RestService class - assertFalse(instance.supports(DefaultRestService.class, true)); - // No annotated RestService class - assertFalse(instance.supports(RestService.class, true)); - // null - assertFalse(instance.supports(null, true)); - } - - @Test - @Disabled - void testResolve() { - // Generated by "dubbo-metadata-processor" - ClassPathServiceRestMetadataReader reader = - new ClassPathServiceRestMetadataReader("META-INF/dubbo/spring-mvc-service-rest-metadata.json"); - List serviceRestMetadataList = reader.read(); - - ServiceRestMetadata expectedServiceRestMetadata = serviceRestMetadataList.get(0); - ServiceRestMetadata serviceRestMetadata = instance.resolve(SpringRestService.class); - - assertTrue(CollectionUtils.equals(expectedServiceRestMetadata.getMeta(), serviceRestMetadata.getMeta())); - - assertEquals(expectedServiceRestMetadata, serviceRestMetadata); - } - - @Test - void testResolves() { - testResolve(SpringRestService.class); - testResolve(SpringRestServiceImpl.class); - testResolve(SpringControllerService.class); - } - - void testResolve(Class service) { - List jsons = Arrays.asList( - "{\"argInfos\":[{\"annotationNameAttribute\":\"b\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.ParamTag\",\"paramName\":\"b\",\"paramType\":\"java.lang.Integer\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"b\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"*/*\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/noAnnoNumber\",\"produces\":[\"*/*\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"c\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.ParamTag\",\"paramName\":\"c\",\"paramType\":\"int\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"c\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"*/*\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/noAnnoPrimitive\",\"produces\":[\"*/*\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"a\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.apache.dubbo.metadata.rest.tag.ParamTag\",\"paramName\":\"a\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"a\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/noAnnoParam\",\"produces\":[\"text/plain\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.springframework.web.bind.annotation.PathVariable\",\"paramName\":\"a\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":2}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"a\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/x-www-form-urlencoded\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/pathVariable/{a}\",\"produces\":[\"application/x-www-form-urlencoded\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"user\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.springframework.web.bind.annotation.RequestBody\",\"paramName\":\"user\",\"paramType\":\"org.apache.dubbo.metadata.rest.User\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"user\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/json\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/body\",\"produces\":[\"application/json\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"param\",\"defaultValue\":\"{0}\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.springframework.web.bind.annotation.RequestParam\",\"paramName\":\"param\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"param\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[],\"headers\":{},\"method\":\"GET\",\"paramNames\":[\"param\"],\"params\":{\"param\":[\"{0}\"]},\"path\":\"/param\",\"produces\":[\"text/plain\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"map\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.springframework.web.bind.annotation.RequestBody\",\"paramName\":\"map\",\"paramType\":\"org.springframework.util.MultiValueMap\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"map\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"application/x-www-form-urlencoded\"],\"headerNames\":[],\"headers\":{},\"method\":\"POST\",\"paramNames\":[],\"params\":{},\"path\":\"/multiValue\",\"produces\":[\"application/x-www-form-urlencoded\"]}}", - "{\"argInfos\":[{\"annotationNameAttribute\":\"header\",\"defaultValue\":\"{0}\",\"formContentType\":false,\"index\":0,\"paramAnnotationType\":\"org.springframework.web.bind.annotation.RequestHeader\",\"paramName\":\"header\",\"paramType\":\"java.lang.String\",\"urlSplitIndex\":0}],\"codeStyle\":\"org.apache.dubbo.metadata.rest.springmvc.SpringMvcServiceRestMetadataResolver\",\"indexToName\":{0:[\"header\"]},\"method\":{\"annotations\":[],\"parameters\":[]},\"request\":{\"consumes\":[\"text/plain\"],\"headerNames\":[\"header\"],\"headers\":{\"header\":[\"{0}\"]},\"method\":\"GET\",\"paramNames\":[],\"params\":{},\"path\":\"/header\",\"produces\":[\"text/plain\"]}}"); - - ServiceRestMetadata springRestMetadata = new ServiceRestMetadata(); - springRestMetadata.setServiceInterface(service.getName()); - ServiceRestMetadata springMetadata = instance.resolve(service, springRestMetadata); - - List jsonsTmp = new ArrayList<>(); - for (RestMethodMetadata restMethodMetadata : springMetadata.getMeta()) { - restMethodMetadata.setReflectMethod(null); - restMethodMetadata.setMethod(null); - jsonsTmp.add(JsonUtils.toJson(restMethodMetadata)); - } - - Comparator comparator = new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.length() - o2.length(); - } - }; - jsons.sort(comparator); - jsonsTmp.sort(comparator); - - for (int i = 0; i < jsons.size(); i++) { - assertEquals(jsons.get(i), jsonsTmp.get(i)); - } - } - - @Test - void testDoubleCheck() { - - ServiceRestMetadata springRestMetadata = new ServiceRestMetadata(); - springRestMetadata.setServiceInterface(SpringRestServiceImpl.class.getName()); - ServiceRestMetadata springMetadata = instance.resolve(SpringRestServiceImpl.class, springRestMetadata); - - springMetadata.setContextPathFromUrl("context"); - - Assertions.assertEquals("context", springMetadata.getContextPathFromUrl()); - - springMetadata.setContextPathFromUrl("//context"); - Assertions.assertEquals("/context", springMetadata.getContextPathFromUrl()); - springMetadata.setPort(404); - Map pathContainPathVariableToServiceMap = - springMetadata.getPathContainPathVariableToServiceMap(); - - for (PathMatcher pathMatcher : pathContainPathVariableToServiceMap.keySet()) { - Assertions.assertTrue(pathMatcher.hasPathVariable()); - Assertions.assertEquals(404, pathMatcher.getPort()); - } - - Map pathUnContainPathVariableToServiceMap = - springMetadata.getPathUnContainPathVariableToServiceMap(); - - for (PathMatcher pathMatcher : pathUnContainPathVariableToServiceMap.keySet()) { - Assertions.assertFalse(pathMatcher.hasPathVariable()); - Assertions.assertEquals(404, pathMatcher.getPort()); - } - } -} diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/jax-rs-service-rest-metadata.json b/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/jax-rs-service-rest-metadata.json deleted file mode 100644 index d5779f6ffdb..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/jax-rs-service-rest-metadata.json +++ /dev/null @@ -1,324 +0,0 @@ -[ - { - "serviceInterface": "org.apache.dubbo.metadata.rest.RestService", - "version": "3.0.0", - "group": "standard", - "meta": [ - { - "method": { - "name": "form", - "parameterTypes": [ - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/form", - "params": { - "f": [ - "{0}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "form" - ] - } - }, - { - "method": { - "name": "headers", - "parameterTypes": [ - "java.lang.String", - "java.lang.String", - "java.lang.Integer" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.Integer", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/headers", - "params": { - "v": [ - "{2}" - ] - }, - "headers": { - "h": [ - "{0}" - ], - "h2": [ - "{1}" - ] - }, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "header" - ], - "1": [ - "header2" - ], - "2": [ - "param" - ] - } - }, - { - "method": { - "name": "param", - "parameterTypes": [ - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/param", - "params": { - "param": [ - "{0}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "param" - ] - } - }, - { - "method": { - "name": "params", - "parameterTypes": [ - "int", - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "int", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/params", - "params": { - "a": [ - "{0}" - ], - "b": [ - "{1}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "a" - ], - "1": [ - "b" - ] - } - }, - { - "method": { - "name": "pathVariables", - "parameterTypes": [ - "java.lang.String", - "java.lang.String", - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/path-variables/{p1}/{p2}", - "params": { - "v": [ - "{2}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "path1" - ], - "1": [ - "path2" - ], - "2": [ - "param" - ] - } - }, - { - "method": { - "name": "requestBodyMap", - "parameterTypes": [ - "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "java.lang.String" - ], - "returnType": "org.apache.dubbo.metadata.rest.User", - "parameters": [ - { - "type": "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "items": [ - "java.lang.String", - "java.lang.Object" - ], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/request/body/map", - "params": { - "param": [ - "{1}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [ - "application/json;charset\u003dUTF-8" - ] - }, - "indexToName": { - "0": [ - "data" - ], - "1": [ - "param" - ] - } - }, - { - "method": { - "name": "requestBodyUser", - "parameterTypes": [ - "org.apache.dubbo.metadata.rest.User" - ], - "returnType": "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "parameters": [ - { - "type": "org.apache.dubbo.metadata.rest.User", - "items": [], - "enum": [], - "properties": { - "name": "java.lang.String", - "id": "java.lang.Long", - "age": "java.lang.Integer" - } - } - ] - }, - "request": { - "method": "POST", - "path": "/request/body/user", - "params": {}, - "headers": {}, - "consumes": [ - "application/json;charset\u003dUTF-8" - ], - "produces": [] - }, - "indexToName": { - "0": [ - "user" - ] - } - } - ] - } -] \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/spring-mvc-service-rest-metadata.json b/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/spring-mvc-service-rest-metadata.json deleted file mode 100644 index c0f25f59a55..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/META-INF/dubbo/spring-mvc-service-rest-metadata.json +++ /dev/null @@ -1,321 +0,0 @@ -[ - { - "serviceInterface": "org.apache.dubbo.metadata.rest.RestService", - "version": "2.0.0", - "group": "spring", - "meta": [ - { - "method": { - "name": "form", - "parameterTypes": [ - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/form", - "params": { - "f": [ - "{0}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "form" - ] - } - }, - { - "method": { - "name": "headers", - "parameterTypes": [ - "java.lang.String", - "java.lang.String", - "java.lang.Integer" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.Integer", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/headers", - "params": { - "v": [ - "1" - ] - }, - "headers": { - "h": [ - "value-h" - ], - "h2": [ - "value-h2" - ] - }, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "header" - ], - "1": [ - "header2" - ], - "2": [ - "param" - ] - } - }, - { - "method": { - "name": "param", - "parameterTypes": [ - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/param", - "params": { - "param": [ - "value-param" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "param" - ] - } - }, - { - "method": { - "name": "params", - "parameterTypes": [ - "int", - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "int", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/params", - "params": { - "a": [ - "value-a" - ], - "b": [ - "value-b" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "a" - ], - "1": [ - "b" - ] - } - }, - { - "method": { - "name": "pathVariables", - "parameterTypes": [ - "java.lang.String", - "java.lang.String", - "java.lang.String" - ], - "returnType": "java.lang.String", - "parameters": [ - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "GET", - "path": "/path-variables/{p1}/{p2}", - "params": { - "v": [ - "{2}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [] - }, - "indexToName": { - "0": [ - "path1" - ], - "1": [ - "path2" - ], - "2": [ - "param" - ] - } - }, - { - "method": { - "name": "requestBodyMap", - "parameterTypes": [ - "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "java.lang.String" - ], - "returnType": "org.apache.dubbo.metadata.rest.User", - "parameters": [ - { - "type": "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "items": ["java.lang.String", "java.lang.Object"], - "enum": [], - "properties": {} - }, - { - "type": "java.lang.String", - "items": [], - "enum": [], - "properties": {} - } - ] - }, - "request": { - "method": "POST", - "path": "/request/body/map", - "params": { - "param": [ - "{1}" - ] - }, - "headers": {}, - "consumes": [], - "produces": [ - "application/json;charset\u003dUTF-8" - ] - }, - "indexToName": { - "0": [ - "data" - ], - "1": [ - "param" - ] - } - }, - { - "method": { - "name": "requestBodyUser", - "parameterTypes": [ - "org.apache.dubbo.metadata.rest.User" - ], - "returnType": "java.util.Map\u003cjava.lang.String,java.lang.Object\u003e", - "parameters": [ - { - "type": "org.apache.dubbo.metadata.rest.User", - "items": [], - "enum": [], - "properties": { - "name": "java.lang.String", - "id": "java.lang.Long", - "age": "java.lang.Integer" - } - } - ] - }, - "request": { - "method": "POST", - "path": "/request/body/user", - "params": {}, - "headers": {}, - "consumes": [ - "application/json;charset\u003dUTF-8" - ], - "produces": [] - }, - "indexToName": { - "0": [ - "user" - ] - } - } - ] - } -] \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/log4j2-test.xml b/dubbo-metadata/dubbo-metadata-rest/src/test/resources/log4j2-test.xml deleted file mode 100644 index ba99f52cc2d..00000000000 --- a/dubbo-metadata/dubbo-metadata-rest/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - diff --git a/dubbo-metadata/pom.xml b/dubbo-metadata/pom.xml index 4ef046aa6aa..81af6197aa6 100644 --- a/dubbo-metadata/pom.xml +++ b/dubbo-metadata/pom.xml @@ -28,7 +28,6 @@ pom dubbo-metadata-api - dubbo-metadata-rest dubbo-metadata-definition-protobuf dubbo-metadata-processor dubbo-metadata-report-zookeeper From dc89065938fb7710afc9ea916b0f425f5c7b4698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=81=AA=E6=B4=8B?= <1601081222@qq.com> Date: Tue, 16 Apr 2024 22:02:58 +0800 Subject: [PATCH 2/2] AnnotatedMethodParameterProcessorTest --- ...AnnotatedMethodParameterProcessorTest.java | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java deleted file mode 100644 index 6db0efb5b5a..00000000000 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/metadata/annotation/processing/rest/AnnotatedMethodParameterProcessorTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.dubbo.metadata.annotation.processing.rest; - -import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest; -import org.apache.dubbo.metadata.rest.RestMethodMetadata; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -/** - * The abstract class for {@link AnnotatedMethodParameterProcessor}'s test cases - * - * @since 2.7.6 - */ -public abstract class AnnotatedMethodParameterProcessorTest extends AbstractAnnotationProcessingTest { - - protected AnnotatedMethodParameterProcessor processor; - - protected RestMethodMetadata restMethodMetadata; - - protected abstract AnnotatedMethodParameterProcessor createTestInstance(); - - @BeforeEach - public final void prepare() { - this.processor = createTestInstance(); - this.restMethodMetadata = createRestMethodMetadata(); - } - - protected RestMethodMetadata createRestMethodMetadata() { - return new RestMethodMetadata(); - } - - protected abstract String getExpectedAnnotationType(); - - @Test - void testGetAnnotationType() { - String expectedAnnotationType = getExpectedAnnotationType(); - assertNull(processor.getAnnotationType()); - assertEquals(expectedAnnotationType, processor.getAnnotationType()); - } -}