You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/01/30 11:28:17 UTC
[dubbo-spi-extensions] 05/39: move some modules back to core repo
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
commit 3992077ca135d618f3a3e7ef4801b5341656103f
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu May 21 11:58:14 2020 +0800
move some modules back to core repo
---
compiler/pom.xml | 237 -------------
.../org/apache/dubbo/gen/AbstractGenerator.java | 293 ----------------
.../org/apache/dubbo/gen/dubbo/DubboGenerator.java | 42 ---
.../apache/dubbo/gen/grpc/DubboGrpcGenerator.java | 41 ---
.../grpc/reactive/ReactorDubboGrpcGenerator.java | 42 ---
.../gen/grpc/reactive/RxDubboGrpcGenerator.java | 41 ---
compiler/src/main/resources/DubboGrpcStub.mustache | 312 -----------------
compiler/src/main/resources/DubboStub.mustache | 53 ---
.../main/resources/ReactorDubboGrpcStub.mustache | 212 ------------
.../src/main/resources/RxDubboGrpcStub.mustache | 246 --------------
dubbo-spi-filter/dubbo-filter-cache/pom.xml | 48 ---
.../main/java/org/apache/dubbo/cache/Cache.java | 43 ---
.../java/org/apache/dubbo/cache/CacheFactory.java | 43 ---
.../org/apache/dubbo/cache/filter/CacheFilter.java | 133 --------
.../dubbo/cache/support/AbstractCacheFactory.java | 72 ----
.../cache/support/expiring/ExpiringCache.java | 77 -----
.../support/expiring/ExpiringCacheFactory.java | 44 ---
.../dubbo/cache/support/expiring/ExpiringMap.java | 374 ---------------------
.../apache/dubbo/cache/support/jcache/JCache.java | 87 -----
.../dubbo/cache/support/jcache/JCacheFactory.java | 48 ---
.../apache/dubbo/cache/support/lfu/LfuCache.java | 80 -----
.../dubbo/cache/support/lfu/LfuCacheFactory.java | 43 ---
.../apache/dubbo/cache/support/lru/LruCache.java | 80 -----
.../dubbo/cache/support/lru/LruCacheFactory.java | 43 ---
.../support/threadlocal/ThreadLocalCache.java | 77 -----
.../threadlocal/ThreadLocalCacheFactory.java | 43 ---
.../internal/org.apache.dubbo.cache.CacheFactory | 4 -
.../dubbo/internal/org.apache.dubbo.rpc.Filter | 1 -
.../apache/dubbo/cache/filter/CacheFilterTest.java | 137 --------
.../cache/support/AbstractCacheFactoryTest.java | 33 --
.../support/expiring/ExpiringCacheFactoryTest.java | 38 ---
.../cache/support/jcache/JCacheFactoryTest.java | 55 ---
.../cache/support/lru/LruCacheFactoryTest.java | 38 ---
.../threadlocal/ThreadLocalCacheFactoryTest.java | 38 ---
dubbo-spi-filter/dubbo-filter-validation/pom.xml | 72 ----
.../apache/dubbo/validation/MethodValidated.java | 40 ---
.../org/apache/dubbo/validation/Validation.java | 39 ---
.../org/apache/dubbo/validation/Validator.java | 27 --
.../dubbo/validation/filter/ValidationFilter.java | 104 ------
.../validation/support/AbstractValidation.java | 51 ---
.../support/jvalidation/JValidation.java | 40 ---
.../validation/support/jvalidation/JValidator.java | 330 ------------------
.../dubbo/internal/org.apache.dubbo.rpc.Filter | 1 -
.../org.apache.dubbo.validation.Validation | 1 -
.../validation/filter/ValidationFilterTest.java | 137 --------
.../support/jvalidation/JValidationTest.java | 50 ---
.../support/jvalidation/JValidatorTest.java | 86 -----
.../jvalidation/mock/JValidatorTestTarget.java | 41 ---
.../jvalidation/mock/ValidationParameter.java | 31 --
dubbo-spi-filter/pom.xml | 35 --
.../dubbo-metadata-report-nacos/pom.xml | 41 ---
.../metadata/store/nacos/NacosMetadataReport.java | 234 -------------
.../store/nacos/NacosMetadataReportFactory.java | 32 --
...che.dubbo.metadata.report.MetadataReportFactory | 1 -
.../store/nacos/NacosMetadata4TstService.java | 28 --
.../store/nacos/NacosMetadataReportTest.java | 247 --------------
dubbo-spi-metadata/pom.xml | 1 -
dubbo-spi-rpc/dubbo-rpc-grpc/pom.xml | 68 ----
.../rpc/protocol/grpc/DubboHandlerRegistry.java | 70 ----
.../apache/dubbo/rpc/protocol/grpc/GrpcConfig.java | 21 --
.../dubbo/rpc/protocol/grpc/GrpcConstants.java | 41 ---
.../dubbo/rpc/protocol/grpc/GrpcInvoker.java | 118 -------
.../dubbo/rpc/protocol/grpc/GrpcOptionsUtils.java | 225 -------------
.../dubbo/rpc/protocol/grpc/GrpcProtocol.java | 239 -------------
.../grpc/ReferenceCountManagedChannel.java | 85 -----
.../grpc/interceptors/ClientInterceptor.java | 26 --
.../grpc/interceptors/GrpcConfigurator.java | 41 ---
.../grpc/interceptors/RpcContextInterceptor.java | 100 ------
.../grpc/interceptors/ServerInterceptor.java | 26 --
.../grpc/interceptors/ServerTransportFilter.java | 27 --
.../dubbo/internal/org.apache.dubbo.rpc.Protocol | 1 -
...pc.protocol.grpc.interceptors.ClientInterceptor | 1 -
...pc.protocol.grpc.interceptors.ServerInterceptor | 1 -
dubbo-spi-rpc/dubbo-rpc-injvm/pom.xml | 38 ---
.../dubbo/rpc/protocol/injvm/InjvmExporter.java | 47 ---
.../dubbo/rpc/protocol/injvm/InjvmInvoker.java | 65 ----
.../dubbo/rpc/protocol/injvm/InjvmProtocol.java | 120 -------
.../dubbo/internal/org.apache.dubbo.rpc.Protocol | 1 -
.../dubbo/rpc/protocol/injvm/DemoRequest.java | 58 ----
.../dubbo/rpc/protocol/injvm/DemoService.java | 44 ---
.../dubbo/rpc/protocol/injvm/DemoServiceImpl.java | 78 -----
.../org/apache/dubbo/rpc/protocol/injvm/IEcho.java | 21 --
.../rpc/protocol/injvm/InjvmProtocolTest.java | 126 -------
.../dubbo/rpc/protocol/injvm/ProtocolTest.java | 72 ----
.../org/apache/dubbo/rpc/protocol/injvm/Type.java | 21 --
dubbo-spi-rpc/dubbo-rpc-rest/pom.xml | 115 -------
.../rpc/protocol/rest/BaseRestProtocolServer.java | 80 -----
.../apache/dubbo/rpc/protocol/rest/Constants.java | 29 --
.../rpc/protocol/rest/DubboHttpProtocolServer.java | 131 --------
.../rpc/protocol/rest/DubboResourceFactory.java | 76 -----
.../rpc/protocol/rest/NettyRestProtocolServer.java | 73 ----
.../rpc/protocol/rest/RestConstraintViolation.java | 66 ----
.../dubbo/rpc/protocol/rest/RestProtocol.java | 295 ----------------
.../rpc/protocol/rest/RestProtocolServer.java | 33 --
.../dubbo/rpc/protocol/rest/RestServerFactory.java | 44 ---
.../dubbo/rpc/protocol/rest/RpcContextFilter.java | 106 ------
.../rpc/protocol/rest/RpcExceptionMapper.java | 51 ---
.../dubbo/rpc/protocol/rest/ViolationReport.java | 48 ---
.../swagger/DubboSwaggerApiListingResource.java | 48 ---
.../integration/swagger/DubboSwaggerService.java | 43 ---
.../rpc/protocol/rest/support/ContentType.java | 26 --
.../rpc/protocol/rest/support/LoggingFilter.java | 148 --------
.../dubbo/internal/org.apache.dubbo.rpc.Protocol | 1 -
.../dubbo/rpc/protocol/rest/DemoService.java | 45 ---
.../dubbo/rpc/protocol/rest/DemoServiceImpl.java | 57 ----
.../dubbo/rpc/protocol/rest/RestProtocolTest.java | 282 ----------------
.../rpc/protocol/rest/RpcExceptionMapperTest.java | 67 ----
.../DubboSwaggerApiListingResourceTest.java | 62 ----
.../rest/integration/swagger/SwaggerService.java | 34 --
dubbo-spi-rpc/pom.xml | 3 -
110 files changed, 8611 deletions(-)
diff --git a/compiler/pom.xml b/compiler/pom.xml
deleted file mode 100644
index c3d4201..0000000
--- a/compiler/pom.xml
+++ /dev/null
@@ -1,237 +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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache</groupId>
- <artifactId>apache</artifactId>
- <version>21</version>
- </parent>
-
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-compiler</artifactId>
- <version>0.0.1</version>
-
- <packaging>jar</packaging>
-
- <properties>
- <maven_compiler_version>3.6.0</maven_compiler_version>
- <maven_jar_version>3.0.2</maven_jar_version>
- <maven_source_version>3.0.1</maven_source_version>
- <maven_javadoc_version>3.0.1</maven_javadoc_version>
- <java_source_version>1.8</java_source_version>
- <java_target_version>1.8</java_target_version>
- <file_encoding>UTF-8</file_encoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>com.salesforce.servicelibs</groupId>
- <artifactId>grpc-contrib</artifactId>
- <version>0.8.1</version>
- </dependency>
- <dependency>
- <groupId>com.salesforce.servicelibs</groupId>
- <artifactId>jprotoc</artifactId>
- <version>0.9.1</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>${maven_compiler_version}</version>
- <configuration>
- <compilerArgument>-proc:none</compilerArgument>
- <fork>true</fork>
- <source>${java_source_version}</source>
- <target>${java_target_version}</target>
- <encoding>${file_encoding}</encoding>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>${maven_jar_version}</version>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <mainClass>org.apache.dubbo.gen.grpc.DubboGrpcGenerator</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
-
- <!-- Optional, used to build directly executable packages (without using 'java -jar'),
- for example 'artifactId-1.0.0-osx-x86_64.exe', 'artifactId-1.0.0-osx-x86_64.exe' -->
- <plugin>
- <groupId>com.salesforce.servicelibs</groupId>
- <artifactId>canteen-maven-plugin</artifactId>
- <version>1.0.0</version>
- <executions>
- <execution>
- <goals>
- <goal>bootstrap</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <profiles>
- <profile>
- <id>release</id>
- <properties>
- <log4j2_version>2.11.1</log4j2_version>
- </properties>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- <version>${maven_source_version}</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${maven_javadoc_version}</version>
- <executions>
- <execution>
- <id>attach-javadoc</id>
- <goals>
- <goal>jar</goal>
- <goal>aggregate</goal>
- </goals>
- <configuration>
- <additionalDependencies>
- <additionalDependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <version>${log4j2_version}</version>
- </additionalDependency>
- <additionalDependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>${log4j2_version}</version>
- </additionalDependency>
- </additionalDependencies>
- </configuration>
- </execution>
- </executions>
- <configuration>
- <show>public</show>
- <charset>UTF-8</charset>
- <encoding>UTF-8</encoding>
- <docencoding>UTF-8</docencoding>
- <links>
- <link>http://docs.oracle.com/javase/8/docs/api</link>
- </links>
- <doclint>none</doclint>
- <excludePackageNames>
- org.apache.dubbo.demo,org.apache.dubbo.demo.*
- </excludePackageNames>
- <doctitle>Apache Dubbo ${project.version} API</doctitle>
- <windowtitle>Apache Dubbo ${project.version} API</windowtitle>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <executions>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <name>dubbo-compiler</name>
- <description>Dubbo customized RPC stub compiler.</description>
- <url>https://github.com/apache/dubbo</url>
- <inceptionYear>2011</inceptionYear>
- <licenses>
- <license>
- <name>Apache License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
-
- <scm>
- <url>https://github.com/apache/dubbo</url>
- <connection>scm:git:https://github.com/apache/dubbo.git</connection>
- <developerConnection>scm:git:https://github.com/apache/dubbo.git</developerConnection>
- <tag>HEAD</tag>
- </scm>
- <mailingLists>
- <mailingList>
- <name>Development List</name>
- <subscribe>dev-subscribe@dubbo.apache.org</subscribe>
- <unsubscribe>dev-unsubscribe@dubbo.apache.org</unsubscribe>
- <post>dev@dubbo.apache.org</post>
- </mailingList>
- <mailingList>
- <name>Commits List</name>
- <subscribe>commits-subscribe@dubbo.apache.org</subscribe>
- <unsubscribe>commits-unsubscribe@dubbo.apache.org</unsubscribe>
- <post>commits@dubbo.apache.org</post>
- </mailingList>
- <mailingList>
- <name>Issues List</name>
- <subscribe>issues-subscribe@dubbo.apache.org</subscribe>
- <unsubscribe>issues-unsubscribe@dubbo.apache.org</unsubscribe>
- <post>issues@dubbo.apache.org</post>
- </mailingList>
- </mailingLists>
- <developers>
- <developer>
- <id>dubbo.io</id>
- <name>The Dubbo Project Contributors</name>
- <email>dev-subscribe@dubbo.apache.org</email>
- <url>http://dubbo.apache.org/</url>
- </developer>
- </developers>
-
- <organization>
- <name>The Apache Software Foundation</name>
- <url>http://www.apache.org/</url>
- </organization>
-
- <issueManagement>
- <system>Github Issues</system>
- <url>https://github.com/apache/dubbo/issues</url>
- </issueManagement>
-</project>
\ No newline at end of file
diff --git a/compiler/src/main/java/org/apache/dubbo/gen/AbstractGenerator.java b/compiler/src/main/java/org/apache/dubbo/gen/AbstractGenerator.java
deleted file mode 100644
index 3e8dee1..0000000
--- a/compiler/src/main/java/org/apache/dubbo/gen/AbstractGenerator.java
+++ /dev/null
@@ -1,293 +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.gen;
-
-import com.google.common.base.Strings;
-import com.google.common.html.HtmlEscapers;
-import com.google.protobuf.DescriptorProtos.FileDescriptorProto;
-import com.google.protobuf.DescriptorProtos.FileOptions;
-import com.google.protobuf.DescriptorProtos.MethodDescriptorProto;
-import com.google.protobuf.DescriptorProtos.ServiceDescriptorProto;
-import com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location;
-import com.google.protobuf.compiler.PluginProtos;
-import com.salesforce.jprotoc.Generator;
-import com.salesforce.jprotoc.GeneratorException;
-import com.salesforce.jprotoc.ProtoTypeMap;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public abstract class AbstractGenerator extends Generator {
-
- private static final int SERVICE_NUMBER_OF_PATHS = 2;
- private static final int METHOD_NUMBER_OF_PATHS = 4;
-
- protected abstract String getClassPrefix();
-
- protected abstract String getClassSuffix();
-
- private String getServiceJavaDocPrefix() {
- return " ";
- }
-
- private String getMethodJavaDocPrefix() {
- return " ";
- }
-
- @Override
- public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException {
- final ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList());
-
- List<FileDescriptorProto> protosToGenerate = request.getProtoFileList().stream()
- .filter(protoFile -> request.getFileToGenerateList().contains(protoFile.getName()))
- .collect(Collectors.toList());
-
- List<ServiceContext> services = findServices(protosToGenerate, typeMap);
- return generateFiles(services);
- }
-
- private List<ServiceContext> findServices(List<FileDescriptorProto> protos, ProtoTypeMap typeMap) {
- List<ServiceContext> contexts = new ArrayList<>();
-
- protos.forEach(fileProto -> {
- for (int serviceNumber = 0; serviceNumber < fileProto.getServiceCount(); serviceNumber++) {
- ServiceContext serviceContext = buildServiceContext(
- fileProto.getService(serviceNumber),
- typeMap,
- fileProto.getSourceCodeInfo().getLocationList(),
- serviceNumber
- );
- serviceContext.protoName = fileProto.getName();
- serviceContext.packageName = extractPackageName(fileProto);
- contexts.add(serviceContext);
- }
- });
-
- return contexts;
- }
-
- private String extractPackageName(FileDescriptorProto proto) {
- FileOptions options = proto.getOptions();
- if (options != null) {
- String javaPackage = options.getJavaPackage();
- if (!Strings.isNullOrEmpty(javaPackage)) {
- return javaPackage;
- }
- }
-
- return Strings.nullToEmpty(proto.getPackage());
- }
-
- private ServiceContext buildServiceContext(ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<Location> locations, int serviceNumber) {
- ServiceContext serviceContext = new ServiceContext();
- serviceContext.fileName = getClassPrefix() + serviceProto.getName() + getClassSuffix() + ".java";
- serviceContext.className = getClassPrefix() + serviceProto.getName() + getClassSuffix();
- serviceContext.serviceName = serviceProto.getName();
- serviceContext.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated();
-
- List<Location> allLocationsForService = locations.stream()
- .filter(location ->
- location.getPathCount() >= 2 &&
- location.getPath(0) == FileDescriptorProto.SERVICE_FIELD_NUMBER &&
- location.getPath(1) == serviceNumber
- )
- .collect(Collectors.toList());
-
- Location serviceLocation = allLocationsForService.stream()
- .filter(location -> location.getPathCount() == SERVICE_NUMBER_OF_PATHS)
- .findFirst()
- .orElseGet(Location::getDefaultInstance);
- serviceContext.javaDoc = getJavaDoc(getComments(serviceLocation), getServiceJavaDocPrefix());
-
- for (int methodNumber = 0; methodNumber < serviceProto.getMethodCount(); methodNumber++) {
- MethodContext methodContext = buildMethodContext(
- serviceProto.getMethod(methodNumber),
- typeMap,
- locations,
- methodNumber
- );
-
- serviceContext.methods.add(methodContext);
- serviceContext.methodTypes.add(methodContext.inputType);
- serviceContext.methodTypes.add(methodContext.outputType);
- }
- return serviceContext;
- }
-
- private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations, int methodNumber) {
- MethodContext methodContext = new MethodContext();
- methodContext.methodName = lowerCaseFirst(methodProto.getName());
- methodContext.inputType = typeMap.toJavaTypeName(methodProto.getInputType());
- methodContext.outputType = typeMap.toJavaTypeName(methodProto.getOutputType());
- methodContext.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated();
- methodContext.isManyInput = methodProto.getClientStreaming();
- methodContext.isManyOutput = methodProto.getServerStreaming();
- methodContext.methodNumber = methodNumber;
-
- Location methodLocation = locations.stream()
- .filter(location ->
- location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
- location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber
- )
- .findFirst()
- .orElseGet(Location::getDefaultInstance);
- methodContext.javaDoc = getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix());
-
- if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
- methodContext.reactiveCallsMethodName = "oneToOne";
- methodContext.grpcCallsMethodName = "asyncUnaryCall";
- }
- if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
- methodContext.reactiveCallsMethodName = "oneToMany";
- methodContext.grpcCallsMethodName = "asyncServerStreamingCall";
- }
- if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
- methodContext.reactiveCallsMethodName = "manyToOne";
- methodContext.grpcCallsMethodName = "asyncClientStreamingCall";
- }
- if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
- methodContext.reactiveCallsMethodName = "manyToMany";
- methodContext.grpcCallsMethodName = "asyncBidiStreamingCall";
- }
- return methodContext;
- }
-
- private String lowerCaseFirst(String s) {
- return Character.toLowerCase(s.charAt(0)) + s.substring(1);
- }
-
- private List<PluginProtos.CodeGeneratorResponse.File> generateFiles(List<ServiceContext> services) {
- return services.stream()
- .map(this::buildFile)
- .collect(Collectors.toList());
- }
-
- private PluginProtos.CodeGeneratorResponse.File buildFile(ServiceContext context) {
- String content = applyTemplate(getClassPrefix() + getClassSuffix() + "Stub.mustache", context);
- return PluginProtos.CodeGeneratorResponse.File
- .newBuilder()
- .setName(absoluteFileName(context))
- .setContent(content)
- .build();
- }
-
- private String absoluteFileName(ServiceContext ctx) {
- String dir = ctx.packageName.replace('.', '/');
- if (Strings.isNullOrEmpty(dir)) {
- return ctx.fileName;
- } else {
- return dir + "/" + ctx.fileName;
- }
- }
-
- private String getComments(Location location) {
- return location.getLeadingComments().isEmpty() ? location.getTrailingComments() : location.getLeadingComments();
- }
-
- private String getJavaDoc(String comments, String prefix) {
- if (!comments.isEmpty()) {
- StringBuilder builder = new StringBuilder("/**\n")
- .append(prefix).append(" * <pre>\n");
- Arrays.stream(HtmlEscapers.htmlEscaper().escape(comments).split("\n"))
- .map(line -> line.replace("*/", "*/").replace("*", "*"))
- .forEach(line -> builder.append(prefix).append(" * ").append(line).append("\n"));
- builder
- .append(prefix).append(" * </pre>\n")
- .append(prefix).append(" */");
- return builder.toString();
- }
- return null;
- }
-
- /**
- * Template class for proto Service objects.
- */
- private class ServiceContext {
- // CHECKSTYLE DISABLE VisibilityModifier FOR 8 LINES
- public String fileName;
- public String protoName;
- public String packageName;
- public String className;
- public String serviceName;
- public boolean deprecated;
- public String javaDoc;
- public List<MethodContext> methods = new ArrayList<>();
-
- public Set<String> methodTypes = new HashSet<>();
-
- public List<MethodContext> unaryRequestMethods() {
- return methods.stream().filter(m -> !m.isManyInput).collect(Collectors.toList());
- }
-
- public List<MethodContext> unaryMethods() {
- return methods.stream().filter(m -> (!m.isManyInput && !m.isManyOutput)).collect(Collectors.toList());
- }
-
- public List<MethodContext> serverStreamingMethods() {
- return methods.stream().filter(m -> !m.isManyInput && m.isManyOutput).collect(Collectors.toList());
- }
-
- public List<MethodContext> biStreamingMethods() {
- return methods.stream().filter(m -> m.isManyInput).collect(Collectors.toList());
- }
- }
-
- /**
- * Template class for proto RPC objects.
- */
- private class MethodContext {
- // CHECKSTYLE DISABLE VisibilityModifier FOR 10 LINES
- public String methodName;
- public String inputType;
- public String outputType;
- public boolean deprecated;
- public boolean isManyInput;
- public boolean isManyOutput;
- public String reactiveCallsMethodName;
- public String grpcCallsMethodName;
- public int methodNumber;
- public String javaDoc;
-
- // This method mimics the upper-casing method ogf gRPC to ensure compatibility
- // See https://github.com/grpc/grpc-java/blob/v1.8.0/compiler/src/java_plugin/cpp/java_generator.cpp#L58
- public String methodNameUpperUnderscore() {
- StringBuilder s = new StringBuilder();
- for (int i = 0; i < methodName.length(); i++) {
- char c = methodName.charAt(i);
- s.append(Character.toUpperCase(c));
- if ((i < methodName.length() - 1) && Character.isLowerCase(c) && Character.isUpperCase(methodName.charAt(i + 1))) {
- s.append('_');
- }
- }
- return s.toString();
- }
-
- public String methodNamePascalCase() {
- String mn = methodName.replace("_", "");
- return String.valueOf(Character.toUpperCase(mn.charAt(0))) + mn.substring(1);
- }
-
- public String methodNameCamelCase() {
- String mn = methodName.replace("_", "");
- return String.valueOf(Character.toLowerCase(mn.charAt(0))) + mn.substring(1);
- }
- }
-}
diff --git a/compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java b/compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java
deleted file mode 100644
index 1c35f0a..0000000
--- a/compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java
+++ /dev/null
@@ -1,42 +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.gen.dubbo;
-
-import org.apache.dubbo.gen.AbstractGenerator;
-
-import com.salesforce.jprotoc.ProtocPlugin;
-
-public class DubboGenerator extends AbstractGenerator {
-
- public static void main(String[] args) {
- if (args.length == 0) {
- ProtocPlugin.generate(new DubboGenerator());
- } else {
- ProtocPlugin.debug(new DubboGenerator(), args[0]);
- }
- }
-
- @Override
- protected String getClassPrefix() {
- return "";
- }
-
- @Override
- protected String getClassSuffix() {
- return "Dubbo";
- }
-}
\ No newline at end of file
diff --git a/compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.java b/compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.java
deleted file mode 100644
index dafdd5a..0000000
--- a/compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.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.gen.grpc;
-
-import org.apache.dubbo.gen.AbstractGenerator;
-
-import com.salesforce.jprotoc.ProtocPlugin;
-
-public class DubboGrpcGenerator extends AbstractGenerator {
-
- public static void main(String[] args) {
- if (args.length == 0) {
- ProtocPlugin.generate(new DubboGrpcGenerator());
- } else {
- ProtocPlugin.debug(new DubboGrpcGenerator(), args[0]);
- }
- }
-
- @Override
- protected String getClassPrefix() {
- return "Dubbo";
- }
-
- protected String getClassSuffix() {
- return "Grpc";
- }
-}
diff --git a/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java b/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java
deleted file mode 100644
index dd9520b..0000000
--- a/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java
+++ /dev/null
@@ -1,42 +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.gen.grpc.reactive;
-
-import org.apache.dubbo.gen.AbstractGenerator;
-
-import com.salesforce.jprotoc.ProtocPlugin;
-
-public class ReactorDubboGrpcGenerator extends AbstractGenerator {
-
- @Override
- protected String getClassPrefix() {
- return "ReactorDubbo";
- }
-
- @Override
- protected String getClassSuffix() {
- return "Grpc";
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- ProtocPlugin.generate(new ReactorDubboGrpcGenerator());
- } else {
- ProtocPlugin.debug(new ReactorDubboGrpcGenerator(), args[0]);
- }
- }
-}
diff --git a/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.java b/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.java
deleted file mode 100644
index 028332a..0000000
--- a/compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.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.gen.grpc.reactive;
-
-import org.apache.dubbo.gen.AbstractGenerator;
-
-import com.salesforce.jprotoc.ProtocPlugin;
-
-public class RxDubboGrpcGenerator extends AbstractGenerator {
- @Override
- protected String getClassPrefix() {
- return "RxDubbo";
- }
-
- @Override
- protected String getClassSuffix() {
- return "Grpc";
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- ProtocPlugin.generate(new RxDubboGrpcGenerator());
- } else {
- ProtocPlugin.debug(new RxDubboGrpcGenerator(), args[0]);
- }
- }
-}
diff --git a/compiler/src/main/resources/DubboGrpcStub.mustache b/compiler/src/main/resources/DubboGrpcStub.mustache
deleted file mode 100644
index a02d0c4..0000000
--- a/compiler/src/main/resources/DubboGrpcStub.mustache
+++ /dev/null
@@ -1,312 +0,0 @@
-{{#packageName}}
- package {{packageName}};
-{{/packageName}}
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.config.ReferenceConfigBase;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
-import static io.grpc.stub.ServerCalls.asyncUnaryCall;
-import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
-
-{{#deprecated}}
- @java.lang.Deprecated
-{{/deprecated}}
-@javax.annotation.Generated(
-value = "by DubboGrpc generator",
-comments = "Source: {{protoName}}")
-public final class {{className}} {
-private {{className}}() {}
-
-public static class Dubbo{{serviceName}}Stub implements I{{serviceName}} {
-
-protected URL url;
-protected ReferenceConfigBase<?> referenceConfig;
-
-protected {{serviceName}}Grpc.{{serviceName}}BlockingStub blockingStub;
-protected {{serviceName}}Grpc.{{serviceName}}FutureStub futureStub;
-protected {{serviceName}}Grpc.{{serviceName}}Stub stub;
-
-public Dubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-this.url = url;
-this.referenceConfig = referenceConfig;
-
-blockingStub = {{serviceName}}Grpc.newBlockingStub(channel).build(channel, callOptions);
-futureStub = {{serviceName}}Grpc.newFutureStub(channel).build(channel, callOptions);
-stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
-}
-
-{{#unaryMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{outputType}} {{methodName}}({{inputType}} request) {
- return blockingStub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(request);
- }
-
- public com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) {
- return futureStub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(request);
- }
-
- public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver){
- stub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(request, responseObserver);
- }
-
-{{/unaryMethods}}
-{{#serverStreamingMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) {
- return blockingStub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(request);
- }
-
- public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) {
- stub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(request, responseObserver);
- }
-
-{{/serverStreamingMethods}}
-{{#biStreamingMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}(io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) {
- return stub
- .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS)
- .{{methodName}}(responseObserver);
- }
-{{/biStreamingMethods}}
-}
-
-public static Dubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-return new Dubbo{{serviceName}}Stub(channel, callOptions, url, referenceConfig);
-}
-
-public interface I{{serviceName}} {
-{{#unaryMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- default public {{outputType}} {{methodName}}({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- default public com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver);
-
-{{/unaryMethods}}
-{{#serverStreamingMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- default public java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver);
-
-{{/serverStreamingMethods}}
-{{#biStreamingMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}(io.grpc.stub.StreamObserver<{{outputType}}> responseObserver);
-
-{{/biStreamingMethods}}
-}
-
-{{#javaDoc}}
- {{{javaDoc}}}
-{{/javaDoc}}
-public static abstract class {{serviceName}}ImplBase implements io.grpc.BindableService, I{{serviceName}} {
-
-private I{{serviceName}} proxiedImpl;
-
-public final void setProxiedImpl(I{{serviceName}} proxiedImpl) {
-this.proxiedImpl = proxiedImpl;
-}
-
-{{#unaryMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- @java.lang.Override
- public final {{outputType}} {{methodName}}({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- @java.lang.Override
- public final com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
-{{/unaryMethods}}
-{{#serverStreamingMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- @java.lang.Override
- public final java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
-{{/serverStreamingMethods}}
-{{#methods}}
- {{#isManyInput}}
- public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}(
- io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) {
- return asyncUnimplementedStreamingCall({{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), responseObserver);
- }
- {{/isManyInput}}{{^isManyInput}}
- public void {{methodName}}({{inputType}} request,
- io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) {
- asyncUnimplementedUnaryCall({{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), responseObserver);
- }
- {{/isManyInput}}
-{{/methods}}
-
-@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
-return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
-{{#methods}}
- .addMethod(
- {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(),
- {{grpcCallsMethodName}}(
- new MethodHandlers<
- {{inputType}},
- {{outputType}}>(
- proxiedImpl, METHODID_{{methodNameUpperUnderscore}})))
-{{/methods}}
-.build();
-}
-}
-{{#methods}}
- private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}};
-{{/methods}}
-
-private static final class MethodHandlers
-<Req, Resp> implements
-io.grpc.stub.ServerCalls.UnaryMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ServerStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ClientStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.BidiStreamingMethod
-<Req, Resp> {
-private final I{{serviceName}} serviceImpl;
-private final int methodId;
-
-MethodHandlers(I{{serviceName}} serviceImpl, int methodId) {
-this.serviceImpl = serviceImpl;
-this.methodId = methodId;
-}
-
-@java.lang.Override
-@java.lang.SuppressWarnings("unchecked")
-public void invoke(Req request, io.grpc.stub.StreamObserver
-<Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{^isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- serviceImpl.{{methodName}}(({{inputType}}) request,
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver);
- break;
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
-
- @java.lang.Override
- @java.lang.SuppressWarnings("unchecked")
- public io.grpc.stub.StreamObserver
- <Req> invoke(io.grpc.stub.StreamObserver
- <Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{#isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- return (io.grpc.stub.StreamObserver
- <Req>) serviceImpl.{{methodName}}(
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver);
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
- }
-
- }
diff --git a/compiler/src/main/resources/DubboStub.mustache b/compiler/src/main/resources/DubboStub.mustache
deleted file mode 100644
index 06bd7b4..0000000
--- a/compiler/src/main/resources/DubboStub.mustache
+++ /dev/null
@@ -1,53 +0,0 @@
-{{#packageName}}
- package {{packageName}};
-{{/packageName}}
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-{{#deprecated}}
- @java.lang.Deprecated
-{{/deprecated}}
-@javax.annotation.Generated(
-value = "by Dubbo generator",
-comments = "Source: {{protoName}}")
-public final class {{className}} {
-private static final AtomicBoolean registered = new AtomicBoolean();
-
-private static Class<?> init() {
-Class<?> clazz = null;
-try {
-clazz = Class.forName({{serviceName}}Dubbo.class.getName());
-if (registered.compareAndSet(false, true)) {
-{{#methodTypes}}
- org.apache.dubbo.common.serialize.protobuf.support.ProtobufUtils.marshaller(
- {{.}}.getDefaultInstance());
-{{/methodTypes}}
-}
-} catch (ClassNotFoundException e) {
-// ignore
-}
-return clazz;
-}
-
-private {{serviceName}}Dubbo() {}
-
-public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}";
-
-/**
-* Code generated for Dubbo
-*/
-public interface I{{serviceName}} {
-
-static Class<?> clazz = init();
-
-{{#methods}}
- {{outputType}} {{methodName}}({{inputType}} request);
-
- CompletableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request);
-
-{{/methods}}
-
-}
-
-}
diff --git a/compiler/src/main/resources/ReactorDubboGrpcStub.mustache b/compiler/src/main/resources/ReactorDubboGrpcStub.mustache
deleted file mode 100644
index 2cf1471..0000000
--- a/compiler/src/main/resources/ReactorDubboGrpcStub.mustache
+++ /dev/null
@@ -1,212 +0,0 @@
-{{#packageName}}
- package {{packageName}};
-{{/packageName}}
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.config.ReferenceConfigBase;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
-import static io.grpc.stub.ServerCalls.asyncUnaryCall;
-import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
-
-
-{{#deprecated}}
- @java.lang.Deprecated
-{{/deprecated}}
-@javax.annotation.Generated(
-value = "by ReactorDubboGrpc generator",
-comments = "Source: {{protoName}}")
-public final class {{className}} {
-private {{className}}() {}
-
-public static ReactorDubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-return new ReactorDubbo{{serviceName}}Stub(channel, callOptions, url, referenceConfig);
-}
-
-{{#javaDoc}}
- {{{javaDoc}}}
-{{/javaDoc}}
-public static final class ReactorDubbo{{serviceName}}Stub implements IReactor{{serviceName}} {
-
-protected URL url;
-protected ReferenceConfigBase<?> referenceConfig;
-
-protected {{serviceName}}Grpc.{{serviceName}}Stub stub;
-
-public ReactorDubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-this.url = url;
-this.referenceConfig = referenceConfig;
-stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
-}
-
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> reactorRequest) {
- {{serviceName}}Grpc.{{serviceName}}Stub localStub = stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS);
- return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactorRequest, localStub::{{methodName}});
- }
-
-{{/methods}}
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest) {
- {{serviceName}}Grpc.{{serviceName}}Stub localStub = stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS);
- return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactor.core.publisher.Mono.just(reactorRequest), localStub::{{methodName}});
- }
-
-{{/unaryRequestMethods}}
-}
-
-public interface IReactor{{serviceName}} {
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> reactorRequest);
-
-{{/methods}}
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest);
-
-{{/unaryRequestMethods}}
-}
-
-{{#javaDoc}}
- {{{javaDoc}}}
-{{/javaDoc}}
-public static abstract class {{serviceName}}ImplBase implements IReactor{{serviceName}}, io.grpc.BindableService {
-
-private IReactor{{serviceName}} proxiedImpl;
-
-public final void setProxiedImpl(IReactor{{serviceName}} proxiedImpl) {
-this.proxiedImpl = proxiedImpl;
-}
-
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public final {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
-{{/unaryRequestMethods}}
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> request) {
- throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED);
- }
-
-{{/methods}}
-@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
-return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
-{{#methods}}
- .addMethod(
- {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(),
- {{grpcCallsMethodName}}(
- new MethodHandlers<
- {{inputType}},
- {{outputType}}>(
- proxiedImpl, METHODID_{{methodNameUpperUnderscore}})))
-{{/methods}}
-.build();
-}
-}
-
-{{#methods}}
- private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}};
-{{/methods}}
-
-private static final class MethodHandlers
-<Req, Resp> implements
-io.grpc.stub.ServerCalls.UnaryMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ServerStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ClientStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.BidiStreamingMethod
-<Req, Resp> {
-private final IReactor{{serviceName}} serviceImpl;
-private final int methodId;
-
-MethodHandlers(IReactor{{serviceName}} serviceImpl, int methodId) {
-this.serviceImpl = serviceImpl;
-this.methodId = methodId;
-}
-
-@java.lang.Override
-@java.lang.SuppressWarnings("unchecked")
-public void invoke(Req request, io.grpc.stub.StreamObserver
-<Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{^isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request,
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
- serviceImpl::{{methodName}});
- break;
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
-
- @java.lang.Override
- @java.lang.SuppressWarnings("unchecked")
- public io.grpc.stub.StreamObserver
- <Req> invoke(io.grpc.stub.StreamObserver
- <Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{#isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- return (io.grpc.stub.StreamObserver
- <Req>) com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
- serviceImpl::{{methodName}});
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
- }
-
- }
diff --git a/compiler/src/main/resources/RxDubboGrpcStub.mustache b/compiler/src/main/resources/RxDubboGrpcStub.mustache
deleted file mode 100644
index 22c06b0..0000000
--- a/compiler/src/main/resources/RxDubboGrpcStub.mustache
+++ /dev/null
@@ -1,246 +0,0 @@
-{{#packageName}}
- package {{packageName}};
-{{/packageName}}
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.config.ReferenceConfigBase;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
-import static io.grpc.stub.ServerCalls.asyncUnaryCall;
-import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
-
-
-{{#deprecated}}
- @java.lang.Deprecated
-{{/deprecated}}
-@javax.annotation.Generated(
-value = "by RxDubboGrpc generator",
-comments = "Source: {{protoName}}")
-public final class {{className}} {
-private {{className}}() {}
-
-public static RxDubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-return new RxDubbo{{serviceName}}Stub(channel, callOptions, url, referenceConfig);
-}
-
-{{#javaDoc}}
- {{{javaDoc}}}
-{{/javaDoc}}
-public static final class RxDubbo{{serviceName}}Stub implements IRx{{serviceName}} {
-
-protected URL url;
-protected ReferenceConfigBase<?> referenceConfig;
-
-protected {{serviceName}}Grpc.{{serviceName}}Stub stub;
-
-public RxDubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url, ReferenceConfigBase<?> referenceConfig) {
-this.url = url;
-this.referenceConfig = referenceConfig;
-stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
-}
-
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> rxRequest) {
- return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(rxRequest,
- {{^isManyInput}}
- new com.salesforce.reactivegrpc.common.BiConsumer<{{inputType}}, io.grpc.stub.StreamObserver<{{outputType}}>>() {
- @java.lang.Override
- public void accept({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> observer) {
- stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(request, observer);
- }
- });
- {{/isManyInput}}
- {{#isManyInput}}
- new com.salesforce.reactivegrpc.common.Function
- <io.grpc.stub.StreamObserver<{{outputType}}>, io.grpc.stub.StreamObserver<{{inputType}}>>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<{{inputType}}> apply(io.grpc.stub.StreamObserver<{{outputType}}> observer) {
- return stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(observer);
- }
- });
- {{/isManyInput}}
- }
-
-{{/methods}}
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest) {
- return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(io.reactivex.Single.just(rxRequest),
- new com.salesforce.reactivegrpc.common.BiConsumer<{{inputType}}, io.grpc.stub.StreamObserver<{{outputType}}>>() {
- @java.lang.Override
- public void accept({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> observer) {
- stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(request, observer);
- }
- });
- }
-
-{{/unaryRequestMethods}}
-}
-
-public interface IRx{{serviceName}} {
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> rxRequest);
-
-{{/methods}}
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest);
-
-{{/unaryRequestMethods}}
-}
-
-
-{{#javaDoc}}
- {{{javaDoc}}}
-{{/javaDoc}}
-public static abstract class {{serviceName}}ImplBase implements IRx{{serviceName}}, io.grpc.BindableService {
-
-private IRx{{serviceName}} proxiedImpl;
-
-public final void setProxiedImpl(IRx{{serviceName}} proxiedImpl) {
-this.proxiedImpl = proxiedImpl;
-}
-{{#unaryRequestMethods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public final {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest) {
- throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows.");
- }
-
-{{/unaryRequestMethods}}
-{{#methods}}
- {{#javaDoc}}
- {{{javaDoc}}}
- {{/javaDoc}}
- {{#deprecated}}
- @java.lang.Deprecated
- {{/deprecated}}
- public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodNameCamelCase}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> request) {
- throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED);
- }
-
-{{/methods}}
-@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
-return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
-{{#methods}}
- .addMethod(
- {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(),
- {{grpcCallsMethodName}}(
- new MethodHandlers<
- {{inputType}},
- {{outputType}}>(
- proxiedImpl, METHODID_{{methodNameUpperUnderscore}})))
-{{/methods}}
-.build();
-}
-}
-
-{{#methods}}
- private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}};
-{{/methods}}
-
-private static final class MethodHandlers
-<Req, Resp> implements
-io.grpc.stub.ServerCalls.UnaryMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ServerStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.ClientStreamingMethod
-<Req, Resp>,
-io.grpc.stub.ServerCalls.BidiStreamingMethod
-<Req, Resp> {
-private final IRx{{serviceName}} serviceImpl;
-private final int methodId;
-
-MethodHandlers(IRx{{serviceName}} serviceImpl, int methodId) {
-this.serviceImpl = serviceImpl;
-this.methodId = methodId;
-}
-
-@java.lang.Override
-@java.lang.SuppressWarnings("unchecked")
-public void invoke(Req request, io.grpc.stub.StreamObserver
-<Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{^isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request,
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
- new com.salesforce.reactivegrpc.common.Function
- <{{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}
- <{{inputType}}>, {{#isManyOutput}}
- io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}
- io.reactivex.Single{{/isManyOutput}}<{{outputType}}>>() {
- @java.lang.Override
- public {{#isManyOutput}}
- io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}
- io.reactivex.Single{{/isManyOutput}}<{{outputType}}> apply({{#isManyInput}}
- io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}
- io.reactivex.Single{{/isManyInput}}<{{inputType}}> single) {
- return serviceImpl.{{methodNameCamelCase}}(single);
- }
- });
- break;
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
-
- @java.lang.Override
- @java.lang.SuppressWarnings("unchecked")
- public io.grpc.stub.StreamObserver
- <Req> invoke(io.grpc.stub.StreamObserver
- <Resp> responseObserver) {
- switch (methodId) {
- {{#methods}}
- {{#isManyInput}}
- case METHODID_{{methodNameUpperUnderscore}}:
- return (io.grpc.stub.StreamObserver
- <Req>) com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(
- (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
- serviceImpl::{{methodNameCamelCase}});
- {{/isManyInput}}
- {{/methods}}
- default:
- throw new java.lang.AssertionError();
- }
- }
- }
-
- }
diff --git a/dubbo-spi-filter/dubbo-filter-cache/pom.xml b/dubbo-spi-filter/dubbo-filter-cache/pom.xml
deleted file mode 100644
index 49f99cf..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/pom.xml
+++ /dev/null
@@ -1,48 +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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-filter</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-filter-cache</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The cache module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.cache</groupId>
- <artifactId>cache-api</artifactId>
- </dependency>
- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast</artifactId>
- <scope>test</scope>
- <version>${hazelcast_version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
deleted file mode 100644
index 69ae671..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.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.cache;
-
-/**
- * Cache interface to support storing and retrieval of value against a lookup key. It has two operation <b>get</b> and <b>put</b>.
- * <li><b>put</b>-Storing value against a key.</li>
- * <li><b>get</b>-Retrieval of object.</li>
- * @see org.apache.dubbo.cache.support.lru.LruCache
- * @see org.apache.dubbo.cache.support.jcache.JCache
- * @see org.apache.dubbo.cache.support.expiring.ExpiringCache
- * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache
- */
-public interface Cache {
- /**
- * API to store value against a key
- * @param key Unique identifier for the object being store.
- * @param value Value getting store
- */
- void put(Object key, Object value);
-
- /**
- * API to return stored value using a key.
- * @param key Unique identifier for cache lookup
- * @return Return stored object against key
- */
- Object get(Object key);
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java
deleted file mode 100644
index 66b5b59..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.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.cache;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.rpc.Invocation;
-
-/**
- * Interface needs to be implemented by all the cache store provider.Along with implementing <b>CacheFactory</b> interface
- * entry needs to be added in org.apache.dubbo.cache.CacheFactory file in a classpath META-INF sub directories.
- *
- * @see Cache
- */
-@SPI("lru")
-public interface CacheFactory {
-
- /**
- * CacheFactory implementation class needs to implement this return underlying cache instance for method against
- * url and invocation.
- * @param url
- * @param invocation
- * @return Instance of Cache containing cached value against method url and invocation.
- */
- @Adaptive("cache")
- Cache getCache(URL url, Invocation invocation);
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
deleted file mode 100644
index 02d0e29..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
+++ /dev/null
@@ -1,133 +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.cache.filter;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.CacheFactory;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.common.utils.ConfigUtils;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.rpc.AsyncRpcResult;
-import org.apache.dubbo.rpc.Filter;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-
-import java.io.Serializable;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
-import static org.apache.dubbo.common.constants.FilterConstants.CACHE_KEY;
-
-/**
- * CacheFilter is a core component of dubbo.Enabling <b>cache</b> key of service,method,consumer or provider dubbo will cache method return value.
- * Along with cache key we need to configure cache type. Dubbo default implemented cache types are
- * <li>lur</li>
- * <li>threadlocal</li>
- * <li>jcache</li>
- * <li>expiring</li>
- *
- * <pre>
- * e.g. 1)<dubbo:service cache="lru" />
- * 2)<dubbo:service /> <dubbo:method name="method2" cache="threadlocal" /> <dubbo:service/>
- * 3)<dubbo:provider cache="expiring" />
- * 4)<dubbo:consumer cache="jcache" />
- *
- *If cache type is defined in method level then method level type will get precedence. According to above provided
- *example, if service has two method, method1 and method2, method2 will have cache type as <b>threadlocal</b> where others will
- *be backed by <b>lru</b>
- *</pre>
- *
- * @see org.apache.dubbo.rpc.Filter
- * @see org.apache.dubbo.cache.support.lru.LruCacheFactory
- * @see org.apache.dubbo.cache.support.lru.LruCache
- * @see org.apache.dubbo.cache.support.jcache.JCacheFactory
- * @see org.apache.dubbo.cache.support.jcache.JCache
- * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
- * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache
- * @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
- * @see org.apache.dubbo.cache.support.expiring.ExpiringCache
- *
- */
-@Activate(group = {CONSUMER, PROVIDER}, value = CACHE_KEY)
-public class CacheFilter implements Filter {
-
- private CacheFactory cacheFactory;
-
- /**
- * Dubbo will populate and set the cache factory instance based on service/method/consumer/provider configured
- * cache attribute value. Dubbo will search for the class name implementing configured <b>cache</b> in file org.apache.dubbo.cache.CacheFactory
- * under META-INF sub folders.
- *
- * @param cacheFactory instance of CacheFactory based on <b>cache</b> type
- */
- public void setCacheFactory(CacheFactory cacheFactory) {
- this.cacheFactory = cacheFactory;
- }
-
- /**
- * If cache is configured, dubbo will invoke method on each method call. If cache value is returned by cache store
- * then it will return otherwise call the remote method and return value. If remote method's return value has error
- * then it will not cache the value.
- * @param invoker service
- * @param invocation invocation.
- * @return Cache returned value if found by the underlying cache store. If cache miss it will call target method.
- * @throws RpcException
- */
- @Override
- public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
- if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), CACHE_KEY))) {
- Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation);
- if (cache != null) {
- String key = StringUtils.toArgumentString(invocation.getArguments());
- Object value = cache.get(key);
- if (value != null) {
- if (value instanceof ValueWrapper) {
- return AsyncRpcResult.newDefaultAsyncResult(((ValueWrapper) value).get(), invocation);
- } else {
- return AsyncRpcResult.newDefaultAsyncResult(value, invocation);
- }
- }
- Result result = invoker.invoke(invocation);
- if (!result.hasException()) {
- cache.put(key, new ValueWrapper(result.getValue()));
- }
- return result;
- }
- }
- return invoker.invoke(invocation);
- }
-
- /**
- * Cache value wrapper.
- */
- static class ValueWrapper implements Serializable {
-
- private static final long serialVersionUID = -1777337318019193256L;
-
- private final Object value;
-
- public ValueWrapper (Object value) {
- this.value = value;
- }
-
- public Object get() {
- return this.value;
- }
- }
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java
deleted file mode 100644
index 966d923..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.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.cache.support;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.CacheFactory;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.Invocation;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
-
-/**
- * AbstractCacheFactory is a default implementation of {@link CacheFactory}. It abstract out the key formation from URL along with
- * invocation method. It initially check if the value for key already present in own local in-memory store then it won't check underlying storage cache {@link Cache}.
- * Internally it used {@link ConcurrentHashMap} to store do level-1 caching.
- *
- * @see CacheFactory
- * @see org.apache.dubbo.cache.support.jcache.JCacheFactory
- * @see org.apache.dubbo.cache.support.lru.LruCacheFactory
- * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
- * @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
- */
-public abstract class AbstractCacheFactory implements CacheFactory {
-
- /**
- * This is used to store factory level-1 cached data.
- */
- private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
-
- /**
- * Takes URL and invocation instance and return cache instance for a given url.
- * @param url url of the method
- * @param invocation invocation context.
- * @return Instance of cache store used as storage for caching return values.
- */
- @Override
- public Cache getCache(URL url, Invocation invocation) {
- url = url.addParameter(METHOD_KEY, invocation.getMethodName());
- String key = url.toFullString();
- Cache cache = caches.get(key);
- if (cache == null) {
- caches.put(key, createCache(url));
- cache = caches.get(key);
- }
- return cache;
- }
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by AbstractCacheFactory subclass.
- * @param url url of the method
- * @return Create and return new instance of cache store used as storage for caching return values.
- */
- protected abstract Cache createCache(URL url);
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
deleted file mode 100644
index afaf8c6..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
+++ /dev/null
@@ -1,77 +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.cache.support.expiring;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.common.URL;
-
-import java.util.Map;
-
-/**
- * ExpiringCache - With the characteristic of expiration time.
- */
-
-/**
- * This class store the cache value with the characteristic of expiration time. If a service,method,consumer or provided is configured with key <b>cache</b>
- * with value <b>expiring</b>, dubbo initialize the instance of this class using {@link ExpiringCacheFactory} to store method's returns value
- * to server from store without making method call.
- * <pre>
- * e.g. 1) <dubbo:service cache="expiring" cache.seconds="60" cache.interval="10"/>
- * 2) <dubbo:consumer cache="expiring" />
- * </pre>
- * <li>It used constructor argument url instance <b>cache.seconds</b> value to decide time to live of cached object.Default value of it is 180 second.</li>
- * <li>It used constructor argument url instance <b>cache.interval</b> value for cache value expiration interval.Default value of this is 4 second</li>
- * @see Cache
- * @see ExpiringCacheFactory
- * @see org.apache.dubbo.cache.support.AbstractCacheFactory
- * @see org.apache.dubbo.cache.filter.CacheFilter
- */
-public class ExpiringCache implements Cache {
- private final Map<Object, Object> store;
-
- public ExpiringCache(URL url) {
- // cache time (second)
- final int secondsToLive = url.getParameter("cache.seconds", 180);
- // Cache check interval (second)
- final int intervalSeconds = url.getParameter("cache.interval", 4);
- ExpiringMap<Object, Object> expiringMap = new ExpiringMap<>(secondsToLive, intervalSeconds);
- expiringMap.getExpireThread().startExpiryIfNotStarted();
- this.store = expiringMap;
- }
-
- /**
- * API to store value against a key in the calling thread scope.
- * @param key Unique identifier for the object being store.
- * @param value Value getting store
- */
- @Override
- public void put(Object key, Object value) {
- store.put(key, value);
- }
-
- /**
- * API to return stored value using a key against the calling thread specific store.
- * @param key Unique identifier for cache lookup
- * @return Return stored object against key
- */
-
- @Override
- public Object get(Object key) {
- return store.get(key);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactory.java
deleted file mode 100644
index 5259d74..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactory.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.cache.support.expiring;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.common.URL;
-
-
-/**
- * Implement {@link org.apache.dubbo.cache.CacheFactory} by extending {@link AbstractCacheFactory} and provide
- * instance of new {@link ExpiringCache}.
- *
- * @see AbstractCacheFactory
- * @see ExpiringCache
- * @see Cache
- */
-
-public class ExpiringCacheFactory extends AbstractCacheFactory {
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by JCache.
- * @param url url of the method
- * @return ExpiringCache instance of cache
- */
- @Override
- protected Cache createCache(URL url) {
- return new ExpiringCache(url);
- }
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
deleted file mode 100644
index 895f114..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
+++ /dev/null
@@ -1,374 +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.cache.support.expiring;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * can be expired map
- * Contains a background thread that periodically checks if the data is out of date
- */
-public class ExpiringMap<K, V> implements Map<K, V> {
-
- /**
- * default time to live (second)
- */
- private static final int DEFAULT_TIME_TO_LIVE = 180;
-
- /**
- * default expire check interval (second)
- */
- private static final int DEFAULT_EXPIRATION_INTERVAL = 1;
-
- private static AtomicInteger expireCount = new AtomicInteger(1);
-
- private final ConcurrentHashMap<K, ExpiryObject> delegateMap;
-
- private final ExpireThread expireThread;
-
- public ExpiringMap() {
- this(DEFAULT_TIME_TO_LIVE, DEFAULT_EXPIRATION_INTERVAL);
- }
-
- /**
- * Constructor
- *
- * @param timeToLive time to live (second)
- */
- public ExpiringMap(int timeToLive) {
- this(timeToLive, DEFAULT_EXPIRATION_INTERVAL);
- }
-
- public ExpiringMap(int timeToLive, int expirationInterval) {
- this(new ConcurrentHashMap<>(), timeToLive, expirationInterval);
- }
-
- private ExpiringMap(ConcurrentHashMap<K, ExpiryObject> delegateMap, int timeToLive, int expirationInterval) {
- this.delegateMap = delegateMap;
- this.expireThread = new ExpireThread();
- expireThread.setTimeToLive(timeToLive);
- expireThread.setExpirationInterval(expirationInterval);
- }
-
- @Override
- public V put(K key, V value) {
- ExpiryObject answer = delegateMap.put(key, new ExpiryObject(key, value, System.currentTimeMillis()));
- if (answer == null) {
- return null;
- }
- return answer.getValue();
- }
-
- @Override
- public V get(Object key) {
- ExpiryObject object = delegateMap.get(key);
- if (object != null) {
- object.setLastAccessTime(System.currentTimeMillis());
- return object.getValue();
- }
- return null;
- }
-
- @Override
- public V remove(Object key) {
- ExpiryObject answer = delegateMap.remove(key);
- if (answer == null) {
- return null;
- }
- return answer.getValue();
- }
-
- @Override
- public boolean containsKey(Object key) {
- return delegateMap.containsKey(key);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return delegateMap.containsValue(value);
- }
-
- @Override
- public int size() {
- return delegateMap.size();
- }
-
- @Override
- public boolean isEmpty() {
- return delegateMap.isEmpty();
- }
-
- @Override
- public void clear() {
- delegateMap.clear();
- expireThread.stopExpiring();
- }
-
- @Override
- public int hashCode() {
- return delegateMap.hashCode();
- }
-
- @Override
- public Set<K> keySet() {
- return delegateMap.keySet();
- }
-
- @Override
- public boolean equals(Object obj) {
- return delegateMap.equals(obj);
- }
-
- @Override
- public void putAll(Map<? extends K, ? extends V> inMap) {
- for (Entry<? extends K, ? extends V> e : inMap.entrySet()) {
- this.put(e.getKey(), e.getValue());
- }
- }
-
- @Override
- public Collection<V> values() {
- List<V> list = new ArrayList<V>();
- Set<Entry<K, ExpiryObject>> delegatedSet = delegateMap.entrySet();
- for (Entry<K, ExpiryObject> entry : delegatedSet) {
- ExpiryObject value = entry.getValue();
- list.add(value.getValue());
- }
- return list;
- }
-
- @Override
- public Set<Entry<K, V>> entrySet() {
- throw new UnsupportedOperationException();
- }
-
- public ExpireThread getExpireThread() {
- return expireThread;
- }
-
- public int getExpirationInterval() {
- return expireThread.getExpirationInterval();
- }
-
- public void setExpirationInterval(int expirationInterval) {
- expireThread.setExpirationInterval(expirationInterval);
- }
-
- public int getTimeToLive() {
- return expireThread.getTimeToLive();
- }
-
- public void setTimeToLive(int timeToLive) {
- expireThread.setTimeToLive(timeToLive);
- }
-
- @Override
- public String toString() {
- return "ExpiringMap{" +
- "delegateMap=" + delegateMap.toString() +
- ", expireThread=" + expireThread.toString() +
- '}';
- }
-
- /**
- * can be expired object
- */
- private class ExpiryObject {
- private K key;
- private V value;
- private AtomicLong lastAccessTime;
-
- ExpiryObject(K key, V value, long lastAccessTime) {
- if (value == null) {
- throw new IllegalArgumentException("An expiring object cannot be null.");
- }
- this.key = key;
- this.value = value;
- this.lastAccessTime = new AtomicLong(lastAccessTime);
- }
-
- public long getLastAccessTime() {
- return lastAccessTime.get();
- }
-
- public void setLastAccessTime(long lastAccessTime) {
- this.lastAccessTime.set(lastAccessTime);
- }
-
- public K getKey() {
- return key;
- }
-
- public V getValue() {
- return value;
- }
-
- @Override
- public boolean equals(Object obj) {
- return value.equals(obj);
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-
- @Override
- public String toString() {
- return "ExpiryObject{" +
- "key=" + key +
- ", value=" + value +
- ", lastAccessTime=" + lastAccessTime +
- '}';
- }
- }
-
- /**
- * Background thread, periodically checking if the data is out of date
- */
- public class ExpireThread implements Runnable {
- private long timeToLiveMillis;
- private long expirationIntervalMillis;
- private volatile boolean running = false;
- private final Thread expirerThread;
-
- @Override
- public String toString() {
- return "ExpireThread{" +
- ", timeToLiveMillis=" + timeToLiveMillis +
- ", expirationIntervalMillis=" + expirationIntervalMillis +
- ", running=" + running +
- ", expirerThread=" + expirerThread +
- '}';
- }
-
- public ExpireThread() {
- expirerThread = new Thread(this, "ExpiryMapExpire-" + expireCount.getAndIncrement());
- expirerThread.setDaemon(true);
- }
-
- @Override
- public void run() {
- while (running) {
- processExpires();
- try {
- Thread.sleep(expirationIntervalMillis);
- } catch (InterruptedException e) {
- running = false;
- }
- }
- }
-
- private void processExpires() {
- long timeNow = System.currentTimeMillis();
- for (ExpiryObject o : delegateMap.values()) {
- if (timeToLiveMillis <= 0) {
- continue;
- }
- long timeIdle = timeNow - o.getLastAccessTime();
- if (timeIdle >= timeToLiveMillis) {
- delegateMap.remove(o.getKey());
- }
- }
- }
-
- /**
- * start expiring Thread
- */
- public void startExpiring() {
- if (!running) {
- running = true;
- expirerThread.start();
- }
- }
-
- /**
- * start thread
- */
- public void startExpiryIfNotStarted() {
- if (running) {
- return;
- }
- startExpiring();
- }
-
- /**
- * stop thread
- */
- public void stopExpiring() {
- if (running) {
- running = false;
- expirerThread.interrupt();
- }
- }
-
- /**
- * get thread state
- *
- * @return thread state
- */
- public boolean isRunning() {
- return running;
- }
-
- /**
- * get time to live
- *
- * @return time to live
- */
- public int getTimeToLive() {
- return (int) timeToLiveMillis / 1000;
- }
-
- /**
- * update time to live
- *
- * @param timeToLive time to live
- */
- public void setTimeToLive(long timeToLive) {
- this.timeToLiveMillis = timeToLive * 1000;
- }
-
- /**
- * get expiration interval
- *
- * @return expiration interval (second)
- */
- public int getExpirationInterval() {
- return (int) expirationIntervalMillis / 1000;
- }
-
- /**
- * set expiration interval
- *
- * @param expirationInterval expiration interval (second)
- */
- public void setExpirationInterval(long expirationInterval) {
- this.expirationIntervalMillis = expirationInterval * 1000;
- }
- }
-}
-
-
-
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
deleted file mode 100644
index 7972a9d..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
+++ /dev/null
@@ -1,87 +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.cache.support.jcache;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import javax.cache.Cache;
-import javax.cache.CacheException;
-import javax.cache.CacheManager;
-import javax.cache.Caching;
-import javax.cache.configuration.MutableConfiguration;
-import javax.cache.expiry.CreatedExpiryPolicy;
-import javax.cache.expiry.Duration;
-import javax.cache.spi.CachingProvider;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
-
-/**
- * This class store the cache value per thread. If a service,method,consumer or provided is configured with key <b>cache</b>
- * with value <b>jcache</b>, dubbo initialize the instance of this class using {@link JCacheFactory} to store method's returns value
- * to server from store without making method call.
- *
- * @see Cache
- * @see JCacheFactory
- * @see org.apache.dubbo.cache.support.AbstractCacheFactory
- * @see org.apache.dubbo.cache.filter.CacheFilter
- */
-public class JCache implements org.apache.dubbo.cache.Cache {
-
- private final Cache<Object, Object> store;
-
- public JCache(URL url) {
- String method = url.getParameter(METHOD_KEY, "");
- String key = url.getAddress() + "." + url.getServiceKey() + "." + method;
- // jcache parameter is the full-qualified class name of SPI implementation
- String type = url.getParameter("jcache");
-
- CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type);
- CacheManager cacheManager = provider.getCacheManager();
- Cache<Object, Object> cache = cacheManager.getCache(key);
- if (cache == null) {
- try {
- //configure the cache
- MutableConfiguration config =
- new MutableConfiguration<>()
- .setTypes(Object.class, Object.class)
- .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000))))
- .setStoreByValue(false)
- .setManagementEnabled(true)
- .setStatisticsEnabled(true);
- cache = cacheManager.createCache(key, config);
- } catch (CacheException e) {
- // concurrent cache initialization
- cache = cacheManager.getCache(key);
- }
- }
-
- this.store = cache;
- }
-
- @Override
- public void put(Object key, Object value) {
- store.put(key, value);
- }
-
- @Override
- public Object get(Object key) {
- return store.get(key);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCacheFactory.java
deleted file mode 100644
index aba9a2f..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCacheFactory.java
+++ /dev/null
@@ -1,48 +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.cache.support.jcache;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.common.URL;
-
-import javax.cache.spi.CachingProvider;
-
-/**
- * JCacheFactory is factory class to provide instance of javax spi cache.Implement {@link org.apache.dubbo.cache.CacheFactory} by
- * extending {@link AbstractCacheFactory} and provide
- * @see AbstractCacheFactory
- * @see JCache
- * @see org.apache.dubbo.cache.filter.CacheFilter
- * @see Cache
- * @see CachingProvider
- * @see javax.cache.Cache
- * @see javax.cache.CacheManager
- */
-public class JCacheFactory extends AbstractCacheFactory {
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by JCache.
- * @param url url of the method
- * @return JCache instance of cache
- */
- @Override
- protected Cache createCache(URL url) {
- return new JCache(url);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCache.java
deleted file mode 100644
index 9ccc979..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCache.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.cache.support.lfu;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.LFUCache;
-
-/**
- * This class store the cache value per thread. If a service,method,consumer or provided is configured with key <b>cache</b>
- * with value <b>lfu</b>, dubbo initialize the instance of this class using {@link LfuCacheFactory} to store method's returns value
- * to server from store without making method call.
- * <pre>
- * e.g. 1) <dubbo:service cache="lfu" cache.size="5000" cache.evictionFactor="0.3"/>
- * 2) <dubbo:consumer cache="lfu" />
- * </pre>
- * <pre>
- * LfuCache uses url's <b>cache.size</b> value for its max store size, url's <b>cache.evictionFactor</b> value for its eviction factor,
- * default store size value will be 1000, default eviction factor will be 0.3
- * </pre>
- *
- * @see Cache
- * @see LfuCacheFactory
- * @see org.apache.dubbo.cache.support.AbstractCacheFactory
- * @see org.apache.dubbo.cache.filter.CacheFilter
- */
-public class LfuCache implements Cache {
-
- /**
- * This is used to store cache records
- */
- private final LFUCache store;
-
- /**
- * Initialize LfuCache, it uses constructor argument <b>cache.size</b> value as its storage max size.
- * If nothing is provided then it will use 1000 as default size value. <b>cache.evictionFactor</b> value as its eviction factor.
- * If nothing is provided then it will use 0.3 as default value.
- * @param url A valid URL instance
- */
- public LfuCache (URL url) {
- final int max = url.getParameter("cache.size", 1000);
- final float factor = url.getParameter("cache.evictionFactor", 0.75f);
- this.store = new LFUCache(max, factor);
- }
-
- /**
- * API to store value against a key in the calling thread scope.
- * @param key Unique identifier for the object being store.
- * @param value Value getting store
- */
- @Override
- public void put(Object key, Object value) {
- store.put(key, value);
- }
-
- /**
- * API to return stored value using a key against the calling thread specific store.
- * @param key Unique identifier for cache lookup
- * @return Return stored object against key
- */
- @Override
- public Object get(Object key) {
- return store.get(key);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCacheFactory.java
deleted file mode 100644
index f04edca..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lfu/LfuCacheFactory.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.cache.support.lfu;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.common.URL;
-
-/**
- * Implement {@link org.apache.dubbo.cache.CacheFactory} by extending {@link AbstractCacheFactory} and provide
- * instance of new {@link LfuCache}.
- *
- * @see AbstractCacheFactory
- * @see LfuCache
- * @see Cache
- */
-public class LfuCacheFactory extends AbstractCacheFactory {
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by LfuCache.
- * @param url url of the method
- * @return ThreadLocalCache instance of cache
- */
- @Override
- protected Cache createCache(URL url) {
- return new LfuCache(url);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java
deleted file mode 100644
index 1b8022f..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.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.cache.support.lru;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.LRUCache;
-
-import java.util.Map;
-
-/**
- * This class store the cache value per thread. If a service,method,consumer or provided is configured with key <b>cache</b>
- * with value <b>lru</b>, dubbo initialize the instance of this class using {@link LruCacheFactory} to store method's returns value
- * to server from store without making method call.
- * <pre>
- * e.g. 1) <dubbo:service cache="lru" cache.size="5000"/>
- * 2) <dubbo:consumer cache="lru" />
- * </pre>
- * <pre>
- * LruCache uses url's <b>cache.size</b> value for its max store size, if nothing is provided then
- * default value will be 1000
- * </pre>
- *
- * @see Cache
- * @see LruCacheFactory
- * @see org.apache.dubbo.cache.support.AbstractCacheFactory
- * @see org.apache.dubbo.cache.filter.CacheFilter
- */
-public class LruCache implements Cache {
-
- /**
- * This is used to store cache records
- */
- private final Map<Object, Object> store;
-
- /**
- * Initialize LruCache, it uses constructor argument <b>cache.size</b> value as its storage max size.
- * If nothing is provided then it will use 1000 as default value.
- * @param url A valid URL instance
- */
- public LruCache(URL url) {
- final int max = url.getParameter("cache.size", 1000);
- this.store = new LRUCache<>(max);
- }
-
- /**
- * API to store value against a key in the calling thread scope.
- * @param key Unique identifier for the object being store.
- * @param value Value getting store
- */
- @Override
- public void put(Object key, Object value) {
- store.put(key, value);
- }
-
- /**
- * API to return stored value using a key against the calling thread specific store.
- * @param key Unique identifier for cache lookup
- * @return Return stored object against key
- */
- @Override
- public Object get(Object key) {
- return store.get(key);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCacheFactory.java
deleted file mode 100644
index 9ec9486..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCacheFactory.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.cache.support.lru;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.common.URL;
-
-/**
- * Implement {@link org.apache.dubbo.cache.CacheFactory} by extending {@link AbstractCacheFactory} and provide
- * instance of new {@link LruCache}.
- *
- * @see AbstractCacheFactory
- * @see LruCache
- * @see Cache
- */
-public class LruCacheFactory extends AbstractCacheFactory {
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by LruCache.
- * @param url url of the method
- * @return ThreadLocalCache instance of cache
- */
- @Override
- protected Cache createCache(URL url) {
- return new LruCache(url);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
deleted file mode 100644
index 12b3b5c..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
+++ /dev/null
@@ -1,77 +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.cache.support.threadlocal;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.common.URL;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This class store the cache value per thread. If a service,method,consumer or provided is configured with key <b>cache</b>
- * with value <b>threadlocal</b>, dubbo initialize the instance of this class using {@link ThreadLocalCacheFactory} to store method's returns value
- * to server from store without making method call.
- * <pre>
- * e.g. <dubbo:service cache="threadlocal" />
- * </pre>
- * <pre>
- * As this ThreadLocalCache stores key-value in memory without any expiry or delete support per thread wise, if number threads and number of key-value are high then jvm should be
- * configured with appropriate memory.
- * </pre>
- *
- * @see org.apache.dubbo.cache.support.AbstractCacheFactory
- * @see org.apache.dubbo.cache.filter.CacheFilter
- * @see Cache
- */
-public class ThreadLocalCache implements Cache {
-
- /**
- * Thread local variable to store cached data.
- */
- private final ThreadLocal<Map<Object, Object>> store;
-
- /**
- * Taken URL as an argument to create an instance of ThreadLocalCache. In this version of implementation constructor
- * argument is not getting used in the scope of this class.
- * @param url
- */
- public ThreadLocalCache(URL url) {
- this.store = ThreadLocal.withInitial(HashMap::new);
- }
-
- /**
- * API to store value against a key in the calling thread scope.
- * @param key Unique identifier for the object being store.
- * @param value Value getting store
- */
- @Override
- public void put(Object key, Object value) {
- store.get().put(key, value);
- }
-
- /**
- * API to return stored value using a key against the calling thread specific store.
- * @param key Unique identifier for cache lookup
- * @return Return stored object against key
- */
- @Override
- public Object get(Object key) {
- return store.get().get(key);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactory.java b/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactory.java
deleted file mode 100644
index cdda6cf..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactory.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.cache.support.threadlocal;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.common.URL;
-
-/**
- * Implement {@link org.apache.dubbo.cache.CacheFactory} by extending {@link AbstractCacheFactory} and provide
- * instance of new {@link ThreadLocalCache}. Note about this class is, each thread does not have a local copy of factory.
- *
- * @see AbstractCacheFactory
- * @see ThreadLocalCache
- * @see Cache
- */
-public class ThreadLocalCacheFactory extends AbstractCacheFactory {
-
- /**
- * Takes url as an method argument and return new instance of cache store implemented by ThreadLocalCache.
- * @param url url of the method
- * @return ThreadLocalCache instance of cache
- */
- @Override
- protected Cache createCache(URL url) {
- return new ThreadLocalCache(url);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.cache.CacheFactory b/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.cache.CacheFactory
deleted file mode 100644
index 1ea180a..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.cache.CacheFactory
+++ /dev/null
@@ -1,4 +0,0 @@
-threadlocal=org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
-lru=org.apache.dubbo.cache.support.lru.LruCacheFactory
-jcache=org.apache.dubbo.cache.support.jcache.JCacheFactory
-expiring=org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
deleted file mode 100644
index 8d6259b..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
+++ /dev/null
@@ -1 +0,0 @@
-cache=org.apache.dubbo.cache.filter.CacheFilter
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java
deleted file mode 100644
index 3326833..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java
+++ /dev/null
@@ -1,137 +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.cache.filter;
-
-import org.apache.dubbo.cache.CacheFactory;
-import org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory;
-import org.apache.dubbo.cache.support.jcache.JCacheFactory;
-import org.apache.dubbo.cache.support.lru.LruCacheFactory;
-import org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.AsyncRpcResult;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcInvocation;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-
-import java.util.stream.Stream;
-
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-public class CacheFilterTest {
- private RpcInvocation invocation;
- private CacheFilter cacheFilter = new CacheFilter();
- private Invoker<?> invoker = mock(Invoker.class);
- private Invoker<?> invoker1 = mock(Invoker.class);
- private Invoker<?> invoker2 = mock(Invoker.class);
- private Invoker<?> invoker3 = mock(Invoker.class);
- private Invoker<?> invoker4 = mock(Invoker.class);
-
- static Stream<Arguments> cacheFactories() {
- return Stream.of(
- Arguments.of("lru", new LruCacheFactory()),
- Arguments.of("jcache", new JCacheFactory()),
- Arguments.of("threadlocal", new ThreadLocalCacheFactory()),
- Arguments.of("expiring", new ExpiringCacheFactory())
- );
- }
-
- public void setUp(String cacheType, CacheFactory cacheFactory) {
- invocation = new RpcInvocation();
- cacheFilter.setCacheFactory(cacheFactory);
-
- URL url = URL.valueOf("test://test:11/test?cache=" + cacheType);
-
- given(invoker.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult("value", invocation));
- given(invoker.getUrl()).willReturn(url);
-
- given(invoker1.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult("value1", invocation));
- given(invoker1.getUrl()).willReturn(url);
-
- given(invoker2.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult("value2", invocation));
- given(invoker2.getUrl()).willReturn(url);
-
- given(invoker3.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult(new RuntimeException(), invocation));
- given(invoker3.getUrl()).willReturn(url);
-
- given(invoker4.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult(invocation));
- given(invoker4.getUrl()).willReturn(url);
- }
-
- @ParameterizedTest
- @MethodSource("cacheFactories")
- public void testNonArgsMethod(String cacheType, CacheFactory cacheFactory) {
- setUp(cacheType, cacheFactory);
- invocation.setMethodName("echo");
- invocation.setParameterTypes(new Class<?>[]{});
- invocation.setArguments(new Object[]{});
-
- cacheFilter.invoke(invoker, invocation);
- Result rpcResult1 = cacheFilter.invoke(invoker1, invocation);
- Result rpcResult2 = cacheFilter.invoke(invoker2, invocation);
- Assertions.assertEquals(rpcResult1.getValue(), rpcResult2.getValue());
- Assertions.assertEquals(rpcResult1.getValue(), "value");
- }
-
- @ParameterizedTest
- @MethodSource("cacheFactories")
- public void testMethodWithArgs(String cacheType, CacheFactory cacheFactory) {
- setUp(cacheType, cacheFactory);
- invocation.setMethodName("echo1");
- invocation.setParameterTypes(new Class<?>[]{String.class});
- invocation.setArguments(new Object[]{"arg1"});
-
- cacheFilter.invoke(invoker, invocation);
- Result rpcResult1 = cacheFilter.invoke(invoker1, invocation);
- Result rpcResult2 = cacheFilter.invoke(invoker2, invocation);
- Assertions.assertEquals(rpcResult1.getValue(), rpcResult2.getValue());
- Assertions.assertEquals(rpcResult1.getValue(), "value");
- }
-
- @ParameterizedTest
- @MethodSource("cacheFactories")
- public void testException(String cacheType, CacheFactory cacheFactory) {
- setUp(cacheType, cacheFactory);
- invocation.setMethodName("echo1");
- invocation.setParameterTypes(new Class<?>[]{String.class});
- invocation.setArguments(new Object[]{"arg2"});
-
- cacheFilter.invoke(invoker3, invocation);
- Result rpcResult = cacheFilter.invoke(invoker2, invocation);
- Assertions.assertEquals(rpcResult.getValue(), "value2");
- }
-
- @ParameterizedTest
- @MethodSource("cacheFactories")
- public void testNull(String cacheType, CacheFactory cacheFactory) {
- setUp(cacheType, cacheFactory);
- invocation.setMethodName("echo1");
- invocation.setParameterTypes(new Class<?>[]{String.class});
- invocation.setArguments(new Object[]{"arg3"});
-
- cacheFilter.invoke(invoker4, invocation);
- Result result1 = cacheFilter.invoke(invoker1, invocation);
- Result result2 = cacheFilter.invoke(invoker2, invocation);
- Assertions.assertNull(result1.getValue());
- Assertions.assertNull(result2.getValue());
- }
-}
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/AbstractCacheFactoryTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/AbstractCacheFactoryTest.java
deleted file mode 100644
index f93a453..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/AbstractCacheFactoryTest.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.cache.support;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.RpcInvocation;
-
-public abstract class AbstractCacheFactoryTest {
-
- protected Cache constructCache() {
- URL url = URL.valueOf("test://test:11/test?cache=lru");
- Invocation invocation = new RpcInvocation();
- return getCacheFactory().getCache(url, invocation);
- }
-
- protected abstract AbstractCacheFactory getCacheFactory();
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactoryTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactoryTest.java
deleted file mode 100644
index 23484c6..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/expiring/ExpiringCacheFactoryTest.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.cache.support.expiring;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.cache.support.AbstractCacheFactoryTest;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class ExpiringCacheFactoryTest extends AbstractCacheFactoryTest {
- @Test
- public void testLruCacheFactory() throws Exception {
- Cache cache = super.constructCache();
- assertThat(cache instanceof ExpiringCache, is(true));
- }
-
- @Override
- protected AbstractCacheFactory getCacheFactory() {
- return new ExpiringCacheFactory();
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/jcache/JCacheFactoryTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/jcache/JCacheFactoryTest.java
deleted file mode 100644
index 3260fa6..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/jcache/JCacheFactoryTest.java
+++ /dev/null
@@ -1,55 +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.cache.support.jcache;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.cache.support.AbstractCacheFactoryTest;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.RpcInvocation;
-
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-public class JCacheFactoryTest extends AbstractCacheFactoryTest {
-
- @Test
- public void testJCacheFactory() throws Exception {
- Cache cache = super.constructCache();
- assertThat(cache instanceof JCache, is(true));
- }
-
- @Test
- public void testJCacheGetExpired() throws Exception {
- URL url = URL.valueOf("test://test:12/test?cache=jacache&cache.write.expire=1");
- AbstractCacheFactory cacheFactory = getCacheFactory();
- Invocation invocation = new RpcInvocation();
- Cache cache = cacheFactory.getCache(url, invocation);
- cache.put("testKey", "testValue");
- Thread.sleep(10);
- assertNull(cache.get("testKey"));
- }
-
- @Override
- protected AbstractCacheFactory getCacheFactory() {
- return new JCacheFactory();
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/lru/LruCacheFactoryTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/lru/LruCacheFactoryTest.java
deleted file mode 100644
index 149c122..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/lru/LruCacheFactoryTest.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.cache.support.lru;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.cache.support.AbstractCacheFactoryTest;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class LruCacheFactoryTest extends AbstractCacheFactoryTest{
- @Test
- public void testLruCacheFactory() throws Exception {
- Cache cache = super.constructCache();
- assertThat(cache instanceof LruCache, is(true));
- }
-
- @Override
- protected AbstractCacheFactory getCacheFactory() {
- return new LruCacheFactory();
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactoryTest.java b/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactoryTest.java
deleted file mode 100644
index 800f5ad..0000000
--- a/dubbo-spi-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCacheFactoryTest.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.cache.support.threadlocal;
-
-import org.apache.dubbo.cache.Cache;
-import org.apache.dubbo.cache.support.AbstractCacheFactory;
-import org.apache.dubbo.cache.support.AbstractCacheFactoryTest;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class ThreadLocalCacheFactoryTest extends AbstractCacheFactoryTest {
- @Test
- public void testThreadLocalCacheFactory() throws Exception {
- Cache cache = super.constructCache();
- assertThat(cache instanceof ThreadLocalCache, is(true));
- }
-
- @Override
- protected AbstractCacheFactory getCacheFactory() {
- return new ThreadLocalCacheFactory();
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/pom.xml b/dubbo-spi-filter/dubbo-filter-validation/pom.xml
deleted file mode 100644
index 933f1c9..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/pom.xml
+++ /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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-filter</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-filter-validation</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The validation module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <scope>test</scope>
- <version>${hibernate_validator_version}</version>
- </dependency>
- <dependency>
- <groupId>javax.el</groupId>
- <artifactId>javax.el-api</artifactId>
- <scope>test</scope>
- <version>${el_api_version}</version>
- </dependency>
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <scope>test</scope>
- <version>${jaxb_api_version}</version>
- </dependency>
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- <scope>test</scope>
- <version>${jaxb_api_version}</version>
- </dependency>
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-core</artifactId>
- <scope>test</scope>
- <version>${jaxb_api_version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/MethodValidated.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/MethodValidated.java
deleted file mode 100644
index ca41a52..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/MethodValidated.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.validation;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Method grouping validation.
- * <p>
- * Scenario: this annotation can be used on interface's method when need to check against group before invoke the method
- * For example: <pre> @MethodValidated({Save.class, Update.class})
- * void relatedQuery(ValidationParameter parameter);
- * </pre>
- * It means both Save group and Update group are needed to check when method relatedQuery is invoked.
- * </p>
- */
-@Target({ElementType.METHOD})
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface MethodValidated {
- Class<?>[] value() default {};
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validation.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validation.java
deleted file mode 100644
index 73c4cd8..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validation.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.validation;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.SPI;
-
-import static org.apache.dubbo.common.constants.FilterConstants.VALIDATION_KEY;
-
-/**
- * Instance of Validation interface provide instance of {@link Validator} based on the value of <b>validation</b> attribute.
- */
-@SPI("jvalidation")
-public interface Validation {
-
- /**
- * Return the instance of {@link Validator} for a given url.
- * @param url Invocation url
- * @return Instance of {@link Validator}
- */
- @Adaptive(VALIDATION_KEY)
- Validator getValidator(URL url);
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validator.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validator.java
deleted file mode 100644
index c78c62a..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/Validator.java
+++ /dev/null
@@ -1,27 +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.validation;
-
-/**
- * Instance of validator class is an extension to perform validation on method input parameter before the actual method invocation.
- *
- */
-public interface Validator {
-
- void validate(String methodName, Class<?>[] parameterTypes, Object[] arguments) throws Exception;
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java
deleted file mode 100644
index 0df2752..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.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.validation.filter;
-
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.common.utils.ConfigUtils;
-import org.apache.dubbo.rpc.AsyncRpcResult;
-import org.apache.dubbo.rpc.Filter;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.validation.Validation;
-import org.apache.dubbo.validation.Validator;
-
-import javax.validation.ValidationException;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
-import static org.apache.dubbo.common.constants.FilterConstants.VALIDATION_KEY;
-
-/**
- * ValidationFilter invoke the validation by finding the right {@link Validator} instance based on the
- * configured <b>validation</b> attribute value of invoker url before the actual method invocation.
- *
- * <pre>
- * e.g. <dubbo:method name="save" validation="jvalidation" />
- * In the above configuration a validation has been configured of type jvalidation. On invocation of method <b>save</b>
- * dubbo will invoke {@link org.apache.dubbo.validation.support.jvalidation.JValidator}
- * </pre>
- *
- * To add a new type of validation
- * <pre>
- * e.g. <dubbo:method name="save" validation="special" />
- * where "special" is representing a validator for special character.
- * </pre>
- *
- * developer needs to do
- * <br/>
- * 1)Implement a SpecialValidation.java class (package name xxx.yyy.zzz) either by implementing {@link Validation} or extending {@link org.apache.dubbo.validation.support.AbstractValidation} <br/>
- * 2)Implement a SpecialValidator.java class (package name xxx.yyy.zzz) <br/>
- * 3)Add an entry <b>special</b>=<b>xxx.yyy.zzz.SpecialValidation</b> under <b>META-INF folders org.apache.dubbo.validation.Validation file</b>.
- *
- * @see Validation
- * @see Validator
- * @see Filter
- * @see org.apache.dubbo.validation.support.AbstractValidation
- */
-@Activate(group = {CONSUMER, PROVIDER}, value = VALIDATION_KEY, order = 10000)
-public class ValidationFilter implements Filter {
-
- private Validation validation;
-
- /**
- * Sets the validation instance for ValidationFilter
- * @param validation Validation instance injected by dubbo framework based on "validation" attribute value.
- */
- public void setValidation(Validation validation) {
- this.validation = validation;
- }
-
- /**
- * Perform the validation of before invoking the actual method based on <b>validation</b> attribute value.
- * @param invoker service
- * @param invocation invocation.
- * @return Method invocation result
- * @throws RpcException Throws RpcException if validation failed or any other runtime exception occurred.
- */
- @Override
- public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
- if (validation != null && !invocation.getMethodName().startsWith("$")
- && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), VALIDATION_KEY))) {
- try {
- Validator validator = validation.getValidator(invoker.getUrl());
- if (validator != null) {
- validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
- }
- } catch (RpcException e) {
- throw e;
- } catch (ValidationException e) {
- // only use exception's message to avoid potential serialization issue
- return AsyncRpcResult.newDefaultAsyncResult(new ValidationException(e.getMessage()), invocation);
- } catch (Throwable t) {
- return AsyncRpcResult.newDefaultAsyncResult(t, invocation);
- }
- }
- return invoker.invoke(invocation);
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java
deleted file mode 100644
index a6f9c8e..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.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.validation.support;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.validation.Validation;
-import org.apache.dubbo.validation.Validator;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * AbstractValidation is abstract class for Validation interface. It helps low level Validation implementation classes
- * by performing common task e.g. key formation, storing instance of validation class to avoid creation of unnecessary
- * copy of validation instance and faster execution.
- *
- * @see Validation
- * @see Validator
- */
-public abstract class AbstractValidation implements Validation {
-
- private final ConcurrentMap<String, Validator> validators = new ConcurrentHashMap<>();
-
- @Override
- public Validator getValidator(URL url) {
- String key = url.toFullString();
- Validator validator = validators.get(key);
- if (validator == null) {
- validators.put(key, createValidator(url));
- validator = validators.get(key);
- }
- return validator;
- }
-
- protected abstract Validator createValidator(URL url);
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidation.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidation.java
deleted file mode 100644
index e8b48cf..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidation.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.validation.support.jvalidation;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.validation.Validator;
-import org.apache.dubbo.validation.support.AbstractValidation;
-
-/**
- * Creates a new instance of {@link Validator} using input argument url.
- * @see AbstractValidation
- * @see Validator
- */
-public class JValidation extends AbstractValidation {
-
- /**
- * Return new instance of {@link JValidator}
- * @param url Valid URL instance
- * @return Instance of JValidator
- */
- @Override
- protected Validator createValidator(URL url) {
- return new JValidator(url);
- }
-
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java b/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java
deleted file mode 100644
index ea8c6db..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java
+++ /dev/null
@@ -1,330 +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.validation.support.jvalidation;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.bytecode.ClassGenerator;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.ReflectUtils;
-import org.apache.dubbo.validation.MethodValidated;
-import org.apache.dubbo.validation.Validator;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
-import javassist.CtNewConstructor;
-import javassist.Modifier;
-import javassist.NotFoundException;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
-import javassist.bytecode.ConstPool;
-import javassist.bytecode.annotation.ArrayMemberValue;
-import javassist.bytecode.annotation.BooleanMemberValue;
-import javassist.bytecode.annotation.ByteMemberValue;
-import javassist.bytecode.annotation.CharMemberValue;
-import javassist.bytecode.annotation.ClassMemberValue;
-import javassist.bytecode.annotation.DoubleMemberValue;
-import javassist.bytecode.annotation.EnumMemberValue;
-import javassist.bytecode.annotation.FloatMemberValue;
-import javassist.bytecode.annotation.IntegerMemberValue;
-import javassist.bytecode.annotation.LongMemberValue;
-import javassist.bytecode.annotation.MemberValue;
-import javassist.bytecode.annotation.ShortMemberValue;
-import javassist.bytecode.annotation.StringMemberValue;
-
-import javax.validation.Constraint;
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
-import javax.validation.groups.Default;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Implementation of JValidation. JValidation is invoked if configuration validation attribute value is 'jvalidation'.
- * <pre>
- * e.g. <dubbo:method name="save" validation="jvalidation" />
- * </pre>
- */
-public class JValidator implements Validator {
-
- private static final Logger logger = LoggerFactory.getLogger(JValidator.class);
-
- private final Class<?> clazz;
-
- private final Map<String, Class> methodClassMap;
-
- private final javax.validation.Validator validator;
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- public JValidator(URL url) {
- this.clazz = ReflectUtils.forName(url.getServiceInterface());
- String jvalidation = url.getParameter("jvalidation");
- ValidatorFactory factory;
- if (jvalidation != null && jvalidation.length() > 0) {
- factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
- } else {
- factory = Validation.buildDefaultValidatorFactory();
- }
- this.validator = factory.getValidator();
- this.methodClassMap = new ConcurrentHashMap<>();
- }
-
- private static Object getMethodParameterBean(Class<?> clazz, Method method, Object[] args) {
- if (!hasConstraintParameter(method)) {
- return null;
- }
- try {
- String parameterClassName = generateMethodParameterClassName(clazz, method);
- Class<?> parameterClass;
- try {
- parameterClass = Class.forName(parameterClassName, true, clazz.getClassLoader());
- } catch (ClassNotFoundException e) {
- parameterClass = generateMethodParameterClass(clazz, method, parameterClassName);
- }
- Object parameterBean = parameterClass.newInstance();
- for (int i = 0; i < args.length; i++) {
- Field field = parameterClass.getField(method.getName() + "Argument" + i);
- field.set(parameterBean, args[i]);
- }
- return parameterBean;
- } catch (Throwable e) {
- logger.warn(e.getMessage(), e);
- return null;
- }
- }
-
- /**
- * try to generate methodParameterClass.
- *
- * @param clazz interface class
- * @param method invoke method
- * @param parameterClassName generated parameterClassName
- * @return Class<?> generated methodParameterClass
- * @throws Exception
- */
- private static Class<?> generateMethodParameterClass(Class<?> clazz, Method method, String parameterClassName)
- throws Exception {
- ClassPool pool = ClassGenerator.getClassPool(clazz.getClassLoader());
- synchronized (parameterClassName.intern()) {
- CtClass ctClass = null;
- try {
- ctClass = pool.getCtClass(parameterClassName);
- } catch (NotFoundException ignore) {
- }
-
- if (null == ctClass) {
- ctClass = pool.makeClass(parameterClassName);
- ClassFile classFile = ctClass.getClassFile();
- classFile.setVersionToJava5();
- ctClass.addConstructor(CtNewConstructor.defaultConstructor(pool.getCtClass(parameterClassName)));
- // parameter fields
- Class<?>[] parameterTypes = method.getParameterTypes();
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- for (int i = 0; i < parameterTypes.length; i++) {
- Class<?> type = parameterTypes[i];
- Annotation[] annotations = parameterAnnotations[i];
- AnnotationsAttribute attribute = new AnnotationsAttribute(classFile.getConstPool(), AnnotationsAttribute.visibleTag);
- for (Annotation annotation : annotations) {
- if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
- javassist.bytecode.annotation.Annotation ja = new javassist.bytecode.annotation.Annotation(
- classFile.getConstPool(), pool.getCtClass(annotation.annotationType().getName()));
- Method[] members = annotation.annotationType().getMethods();
- for (Method member : members) {
- if (Modifier.isPublic(member.getModifiers())
- && member.getParameterTypes().length == 0
- && member.getDeclaringClass() == annotation.annotationType()) {
- Object value = member.invoke(annotation);
- if (null != value) {
- MemberValue memberValue = createMemberValue(
- classFile.getConstPool(), pool.get(member.getReturnType().getName()), value);
- ja.addMemberValue(member.getName(), memberValue);
- }
- }
- }
- attribute.addAnnotation(ja);
- }
- }
- String fieldName = method.getName() + "Argument" + i;
- CtField ctField = CtField.make("public " + type.getCanonicalName() + " " + fieldName + ";", pool.getCtClass(parameterClassName));
- ctField.getFieldInfo().addAttribute(attribute);
- ctClass.addField(ctField);
- }
- return ctClass.toClass(clazz.getClassLoader(), null);
- } else {
- return Class.forName(parameterClassName, true, clazz.getClassLoader());
- }
- }
- }
-
- private static String generateMethodParameterClassName(Class<?> clazz, Method method) {
- StringBuilder builder = new StringBuilder().append(clazz.getName())
- .append("_")
- .append(toUpperMethoName(method.getName()))
- .append("Parameter");
-
- Class<?>[] parameterTypes = method.getParameterTypes();
- for (Class<?> parameterType : parameterTypes) {
- builder.append("_").append(parameterType.getName());
- }
-
- return builder.toString();
- }
-
- private static boolean hasConstraintParameter(Method method) {
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- if (parameterAnnotations != null && parameterAnnotations.length > 0) {
- for (Annotation[] annotations : parameterAnnotations) {
- for (Annotation annotation : annotations) {
- if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- private static String toUpperMethoName(String methodName) {
- return methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
- }
-
- // Copy from javassist.bytecode.annotation.Annotation.createMemberValue(ConstPool, CtClass);
- private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
- MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
- if (memberValue instanceof BooleanMemberValue) {
- ((BooleanMemberValue) memberValue).setValue((Boolean) value);
- } else if (memberValue instanceof ByteMemberValue) {
- ((ByteMemberValue) memberValue).setValue((Byte) value);
- } else if (memberValue instanceof CharMemberValue) {
- ((CharMemberValue) memberValue).setValue((Character) value);
- } else if (memberValue instanceof ShortMemberValue) {
- ((ShortMemberValue) memberValue).setValue((Short) value);
- } else if (memberValue instanceof IntegerMemberValue) {
- ((IntegerMemberValue) memberValue).setValue((Integer) value);
- } else if (memberValue instanceof LongMemberValue) {
- ((LongMemberValue) memberValue).setValue((Long) value);
- } else if (memberValue instanceof FloatMemberValue) {
- ((FloatMemberValue) memberValue).setValue((Float) value);
- } else if (memberValue instanceof DoubleMemberValue) {
- ((DoubleMemberValue) memberValue).setValue((Double) value);
- } else if (memberValue instanceof ClassMemberValue) {
- ((ClassMemberValue) memberValue).setValue(((Class<?>) value).getName());
- } else if (memberValue instanceof StringMemberValue) {
- ((StringMemberValue) memberValue).setValue((String) value);
- } else if (memberValue instanceof EnumMemberValue) {
- ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
- }
- /* else if (memberValue instanceof AnnotationMemberValue) */
- else if (memberValue instanceof ArrayMemberValue) {
- CtClass arrayType = type.getComponentType();
- int len = Array.getLength(value);
- MemberValue[] members = new MemberValue[len];
- for (int i = 0; i < len; i++) {
- members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
- }
- ((ArrayMemberValue) memberValue).setValue(members);
- }
- return memberValue;
- }
-
- @Override
- public void validate(String methodName, Class<?>[] parameterTypes, Object[] arguments) throws Exception {
- List<Class<?>> groups = new ArrayList<>();
- Class<?> methodClass = methodClass(methodName);
- if (methodClass != null) {
- groups.add(methodClass);
- }
- Set<ConstraintViolation<?>> violations = new HashSet<>();
- Method method = clazz.getMethod(methodName, parameterTypes);
- Class<?>[] methodClasses;
- if (method.isAnnotationPresent(MethodValidated.class)){
- methodClasses = method.getAnnotation(MethodValidated.class).value();
- groups.addAll(Arrays.asList(methodClasses));
- }
- // add into default group
- groups.add(0, Default.class);
- groups.add(1, clazz);
-
- // convert list to array
- Class<?>[] classgroups = groups.toArray(new Class[groups.size()]);
-
- Object parameterBean = getMethodParameterBean(clazz, method, arguments);
- if (parameterBean != null) {
- violations.addAll(validator.validate(parameterBean, classgroups ));
- }
-
- for (Object arg : arguments) {
- validate(violations, arg, classgroups);
- }
-
- if (!violations.isEmpty()) {
- logger.error("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations);
- throw new ConstraintViolationException("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations, violations);
- }
- }
-
- private Class methodClass(String methodName) {
- Class<?> methodClass = null;
- String methodClassName = clazz.getName() + "$" + toUpperMethoName(methodName);
- Class cached = methodClassMap.get(methodClassName);
- if (cached != null) {
- return cached == clazz ? null : cached;
- }
- try {
- methodClass = Class.forName(methodClassName, false, Thread.currentThread().getContextClassLoader());
- methodClassMap.put(methodClassName, methodClass);
- } catch (ClassNotFoundException e) {
- methodClassMap.put(methodClassName, clazz);
- }
- return methodClass;
- }
-
- private void validate(Set<ConstraintViolation<?>> violations, Object arg, Class<?>... groups) {
- if (arg != null && !ReflectUtils.isPrimitives(arg.getClass())) {
- if (arg instanceof Object[]) {
- for (Object item : (Object[]) arg) {
- validate(violations, item, groups);
- }
- } else if (arg instanceof Collection) {
- for (Object item : (Collection<?>) arg) {
- validate(violations, item, groups);
- }
- } else if (arg instanceof Map) {
- for (Map.Entry<?, ?> entry : ((Map<?, ?>) arg).entrySet()) {
- validate(violations, entry.getKey(), groups);
- validate(violations, entry.getValue(), groups);
- }
- } else {
- violations.addAll(validator.validate(arg, groups));
- }
- }
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
deleted file mode 100644
index 65bf329..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
+++ /dev/null
@@ -1 +0,0 @@
-validation=org.apache.dubbo.validation.filter.ValidationFilter
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.validation.Validation b/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.validation.Validation
deleted file mode 100644
index ae3dc96..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.validation.Validation
+++ /dev/null
@@ -1 +0,0 @@
-jvalidation=org.apache.dubbo.validation.support.jvalidation.JValidation
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/filter/ValidationFilterTest.java b/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/filter/ValidationFilterTest.java
deleted file mode 100644
index f2efdd5..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/filter/ValidationFilterTest.java
+++ /dev/null
@@ -1,137 +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.validation.filter;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.AppResponse;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.RpcInvocation;
-import org.apache.dubbo.validation.Validation;
-import org.apache.dubbo.validation.Validator;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-public class ValidationFilterTest {
- private Invoker<?> invoker = mock(Invoker.class);
- private Validation validation = mock(Validation.class);
- private Validator validator = mock(Validator.class);
- private RpcInvocation invocation = mock(RpcInvocation.class);
-
- private ValidationFilter validationFilter;
-
- @BeforeEach
- public void setUp() throws Exception {
- this.validationFilter = new ValidationFilter();
- }
-
- @Test
- public void testItWithNotExistClass() throws Exception {
- URL url = URL.valueOf("test://test:11/test?validation=true");
-
- given(validation.getValidator(url)).willThrow(new IllegalStateException("Not found class test, cause: test"));
- given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
- given(invoker.getUrl()).willReturn(url);
- given(invocation.getMethodName()).willReturn("echo1");
- given(invocation.getParameterTypes()).willReturn(new Class<?>[]{String.class});
- given(invocation.getArguments()).willReturn(new Object[]{"arg1"});
-
- validationFilter.setValidation(validation);
- Result result = validationFilter.invoke(invoker, invocation);
-
- assertThat(result.getException().getMessage(), is("Not found class test, cause: test"));
-
- }
-
- @Test
- public void testItWithExistClass() throws Exception {
- URL url = URL.valueOf("test://test:11/test?validation=true");
-
- given(validation.getValidator(url)).willReturn(validator);
- given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
- given(invoker.getUrl()).willReturn(url);
- given(invocation.getMethodName()).willReturn("echo1");
- given(invocation.getParameterTypes()).willReturn(new Class<?>[]{String.class});
- given(invocation.getArguments()).willReturn(new Object[]{"arg1"});
-
- validationFilter.setValidation(validation);
- Result result = validationFilter.invoke(invoker, invocation);
-
- assertThat(String.valueOf(result.getValue()), is("success"));
- }
-
- @Test
- public void testItWithoutUrlParameters() throws Exception {
- URL url = URL.valueOf("test://test:11/test");
-
- given(validation.getValidator(url)).willReturn(validator);
- given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
- given(invoker.getUrl()).willReturn(url);
- given(invocation.getMethodName()).willReturn("echo1");
- given(invocation.getParameterTypes()).willReturn(new Class<?>[]{String.class});
- given(invocation.getArguments()).willReturn(new Object[]{"arg1"});
-
- validationFilter.setValidation(validation);
- Result result = validationFilter.invoke(invoker, invocation);
-
- assertThat(String.valueOf(result.getValue()), is("success"));
- }
-
- @Test
- public void testItWhileMethodNameStartWithDollar() throws Exception {
- URL url = URL.valueOf("test://test:11/test");
-
- given(validation.getValidator(url)).willReturn(validator);
- given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
- given(invoker.getUrl()).willReturn(url);
- given(invocation.getMethodName()).willReturn("$echo1");
- given(invocation.getParameterTypes()).willReturn(new Class<?>[]{String.class});
- given(invocation.getArguments()).willReturn(new Object[]{"arg1"});
-
- validationFilter.setValidation(validation);
- Result result = validationFilter.invoke(invoker, invocation);
-
- assertThat(String.valueOf(result.getValue()), is("success"));
-
- }
-
-
- @Test
- public void testItWhileThrowoutRpcException() throws Exception {
- Assertions.assertThrows(RpcException.class, () -> {
- URL url = URL.valueOf("test://test:11/test?validation=true");
-
- given(validation.getValidator(url)).willThrow(new RpcException("rpc exception"));
- given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
- given(invoker.getUrl()).willReturn(url);
- given(invocation.getMethodName()).willReturn("echo1");
- given(invocation.getParameterTypes()).willReturn(new Class<?>[]{String.class});
- given(invocation.getArguments()).willReturn(new Object[]{"arg1"});
-
- validationFilter.setValidation(validation);
- validationFilter.invoke(invoker, invocation);
- });
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidationTest.java b/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidationTest.java
deleted file mode 100644
index fbace3f..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidationTest.java
+++ /dev/null
@@ -1,50 +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.validation.support.jvalidation;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.validation.Validation;
-import org.apache.dubbo.validation.Validator;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import javax.validation.ValidationException;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-public class JValidationTest {
- @Test
- public void testReturnTypeWithInvalidValidationProvider() {
- Assertions.assertThrows(ValidationException.class, () -> {
- Validation jValidation = new JValidation();
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.JValidation?" +
- "jvalidation=org.apache.dubbo.validation.Validation");
- jValidation.getValidator(url);
- });
-
- }
-
- @Test
- public void testReturnTypeWithDefaultValidatorProvider() {
- Validation jValidation = new JValidation();
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.JValidation");
- Validator validator = jValidation.getValidator(url);
- assertThat(validator instanceof JValidator, is(true));
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidatorTest.java b/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidatorTest.java
deleted file mode 100644
index 94768d2..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/JValidatorTest.java
+++ /dev/null
@@ -1,86 +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.validation.support.jvalidation;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.validation.support.jvalidation.mock.ValidationParameter;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import javax.validation.ConstraintViolationException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class JValidatorTest {
- @Test
- public void testItWithNonExistMethod() throws Exception {
- Assertions.assertThrows(NoSuchMethodException.class, () -> {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("nonExistingMethod", new Class<?>[]{String.class}, new Object[]{"arg1"});
- });
- }
-
- @Test
- public void testItWithExistMethod() throws Exception {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("someMethod1", new Class<?>[]{String.class}, new Object[]{"anything"});
- }
-
- @Test
- public void testItWhenItViolatedConstraint() throws Exception {
- Assertions.assertThrows(ConstraintViolationException.class, () -> {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("someMethod2", new Class<?>[]{ValidationParameter.class}, new Object[]{new ValidationParameter()});
- });
- }
-
- @Test
- public void testItWhenItMeetsConstraint() throws Exception {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("someMethod2", new Class<?>[]{ValidationParameter.class}, new Object[]{new ValidationParameter("NotBeNull")});
- }
-
- @Test
- public void testItWithArrayArg() throws Exception {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("someMethod3", new Class<?>[]{ValidationParameter[].class}, new Object[]{new ValidationParameter[]{new ValidationParameter("parameter")}});
- }
-
- @Test
- public void testItWithCollectionArg() throws Exception {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- jValidator.validate("someMethod4", new Class<?>[]{List.class}, new Object[]{Arrays.asList("parameter")});
- }
-
- @Test
- public void testItWithMapArg() throws Exception {
- URL url = URL.valueOf("test://test:11/org.apache.dubbo.validation.support.jvalidation.mock.JValidatorTestTarget");
- JValidator jValidator = new JValidator(url);
- Map<String, String> map = new HashMap<>();
- map.put("key", "value");
- jValidator.validate("someMethod5", new Class<?>[]{Map.class}, new Object[]{map});
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/JValidatorTestTarget.java b/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/JValidatorTestTarget.java
deleted file mode 100644
index f65eb05..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/JValidatorTestTarget.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.validation.support.jvalidation.mock;
-
-import org.apache.dubbo.validation.MethodValidated;
-
-import javax.validation.constraints.NotNull;
-import java.util.List;
-import java.util.Map;
-
-public interface JValidatorTestTarget {
- @MethodValidated
- void someMethod1(String anything);
-
- @MethodValidated(Test2.class)
- void someMethod2(@NotNull ValidationParameter validationParameter);
-
- void someMethod3(ValidationParameter[] parameters);
-
- void someMethod4(List<String> strings);
-
- void someMethod5(Map<String, String> map);
-
- @interface Test2 {
- }
-
-}
diff --git a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/ValidationParameter.java b/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/ValidationParameter.java
deleted file mode 100644
index 0b54a04..0000000
--- a/dubbo-spi-filter/dubbo-filter-validation/src/test/java/org/apache/dubbo/validation/support/jvalidation/mock/ValidationParameter.java
+++ /dev/null
@@ -1,31 +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.validation.support.jvalidation.mock;
-
-import javax.validation.constraints.NotNull;
-
-public class ValidationParameter {
- @NotNull
- private String parameter;
-
- public ValidationParameter() {
- }
-
- public ValidationParameter(String parameter) {
- this.parameter = parameter;
- }
-}
diff --git a/dubbo-spi-filter/pom.xml b/dubbo-spi-filter/pom.xml
deleted file mode 100644
index 248be53..0000000
--- a/dubbo-spi-filter/pom.xml
+++ /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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo.spi</groupId>
- <artifactId>dubbo-spi-extensions</artifactId>
- <version>${revision}</version>
- </parent>
- <artifactId>dubbo-spi-filter</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
- <description>The filter module of dubbo project</description>
- <properties>
- <skip_maven_deploy>true</skip_maven_deploy>
- </properties>
- <modules>
- <module>dubbo-filter-cache</module>
- <module>dubbo-filter-validation</module>
- </modules>
-</project>
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/pom.xml b/dubbo-spi-metadata/dubbo-metadata-report-nacos/pom.xml
deleted file mode 100644
index 7885a91..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-metadata</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>dubbo-metadata-report-nacos</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-metadata-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- </dependency>
- </dependencies>
-
-</project>
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java b/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
deleted file mode 100644
index 707d2b8..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
+++ /dev/null
@@ -1,234 +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.store.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
-import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
-import org.apache.dubbo.metadata.report.support.AbstractMetadataReport;
-import org.apache.dubbo.rpc.RpcException;
-
-import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.config.ConfigService;
-import com.alibaba.nacos.api.exception.NacosException;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE;
-import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_POLLING_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.RAM_ROLE_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
-import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
-
-/**
- * metadata report impl for nacos
- */
-public class NacosMetadataReport extends AbstractMetadataReport {
-
- private static final Logger logger = LoggerFactory.getLogger(NacosMetadataReport.class);
-
- private ConfigService configService;
-
- /**
- * The group used to store metadata in Nacos
- */
- private String group;
-
-
- public NacosMetadataReport(URL url) {
- super(url);
- this.configService = buildConfigService(url);
- group = url.getParameter(GROUP_KEY, DEFAULT_ROOT);
- }
-
- public ConfigService buildConfigService(URL url) {
- Properties nacosProperties = buildNacosProperties(url);
- try {
- configService = NacosFactory.createConfigService(nacosProperties);
- } catch (NacosException e) {
- if (logger.isErrorEnabled()) {
- logger.error(e.getErrMsg(), e);
- }
- throw new IllegalStateException(e);
- }
- return configService;
- }
-
- private Properties buildNacosProperties(URL url) {
- Properties properties = new Properties();
- setServerAddr(url, properties);
- setProperties(url, properties);
- return properties;
- }
-
- private void setServerAddr(URL url, Properties properties) {
- StringBuilder serverAddrBuilder =
- new StringBuilder(url.getHost()) // Host
- .append(":")
- .append(url.getPort()); // Port
- // Append backup parameter as other servers
- String backup = url.getParameter(BACKUP_KEY);
- if (backup != null) {
- serverAddrBuilder.append(",").append(backup);
- }
- String serverAddr = serverAddrBuilder.toString();
- properties.put(SERVER_ADDR, serverAddr);
- }
-
- private static void setProperties(URL url, Properties properties) {
- putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
- putPropertyIfAbsent(url, properties, IS_USE_CLOUD_NAMESPACE_PARSING);
- putPropertyIfAbsent(url, properties, IS_USE_ENDPOINT_PARSING_RULE);
- putPropertyIfAbsent(url, properties, ENDPOINT);
- putPropertyIfAbsent(url, properties, ENDPOINT_PORT);
- putPropertyIfAbsent(url, properties, NAMESPACE);
- putPropertyIfAbsent(url, properties, ACCESS_KEY);
- putPropertyIfAbsent(url, properties, SECRET_KEY);
- putPropertyIfAbsent(url, properties, RAM_ROLE_NAME);
- putPropertyIfAbsent(url, properties, CONTEXT_PATH);
- putPropertyIfAbsent(url, properties, CLUSTER_NAME);
- putPropertyIfAbsent(url, properties, ENCODE);
- putPropertyIfAbsent(url, properties, CONFIG_LONG_POLL_TIMEOUT);
- putPropertyIfAbsent(url, properties, CONFIG_RETRY_TIME);
- putPropertyIfAbsent(url, properties, MAX_RETRY);
- putPropertyIfAbsent(url, properties, ENABLE_REMOTE_SYNC_CONFIG);
- putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
- putPropertyIfAbsent(url, properties, NAMING_CLIENT_BEAT_THREAD_COUNT);
- putPropertyIfAbsent(url, properties, NAMING_POLLING_THREAD_COUNT);
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- }
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName, String defaultValue) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- } else {
- properties.setProperty(propertyName, defaultValue);
- }
- }
-
- @Override
- protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) {
- this.storeMetadata(providerMetadataIdentifier, serviceDefinitions);
- }
-
- @Override
- protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String value) {
- this.storeMetadata(consumerMetadataIdentifier, value);
- }
-
- @Override
- protected void doSaveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier, URL url) {
- storeMetadata(serviceMetadataIdentifier, URL.encode(url.toFullString()));
- }
-
- @Override
- protected void doRemoveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier) {
- deleteMetadata(serviceMetadataIdentifier);
- }
-
- @Override
- protected List<String> doGetExportedURLs(ServiceMetadataIdentifier metadataIdentifier) {
- String content = getConfig(metadataIdentifier);
- if (StringUtils.isEmpty(content)) {
- return Collections.emptyList();
- }
- return new ArrayList<String>(Arrays.asList(URL.decode(content)));
- }
-
- @Override
- protected void doSaveSubscriberData(SubscriberMetadataIdentifier subscriberMetadataIdentifier, String urlListStr) {
- storeMetadata(subscriberMetadataIdentifier, urlListStr);
- }
-
- @Override
- protected String doGetSubscribedURLs(SubscriberMetadataIdentifier subscriberMetadataIdentifier) {
- return getConfig(subscriberMetadataIdentifier);
- }
-
- @Override
- public String getServiceDefinition(MetadataIdentifier metadataIdentifier) {
- return getConfig(metadataIdentifier);
- }
-
- private void storeMetadata(BaseMetadataIdentifier identifier, String value) {
- try {
- boolean publishResult = configService.publishConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), group, value);
- if (!publishResult) {
- throw new RuntimeException("publish nacos metadata failed");
- }
- } catch (Throwable t) {
- logger.error("Failed to put " + identifier + " to nacos " + value + ", cause: " + t.getMessage(), t);
- throw new RpcException("Failed to put " + identifier + " to nacos " + value + ", cause: " + t.getMessage(), t);
- }
- }
-
- private void deleteMetadata(BaseMetadataIdentifier identifier) {
- try {
- boolean publishResult = configService.removeConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), group);
- if (!publishResult) {
- throw new RuntimeException("remove nacos metadata failed");
- }
- } catch (Throwable t) {
- logger.error("Failed to remove " + identifier + " from nacos , cause: " + t.getMessage(), t);
- throw new RpcException("Failed to remove " + identifier + " from nacos , cause: " + t.getMessage(), t);
- }
- }
-
- private String getConfig(BaseMetadataIdentifier identifier) {
- try {
- return configService.getConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), group, 300);
- } catch (Throwable t) {
- logger.error("Failed to get " + identifier + " from nacos , cause: " + t.getMessage(), t);
- throw new RpcException("Failed to get " + identifier + " from nacos , cause: " + t.getMessage(), t);
- }
- }
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java b/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.java
deleted file mode 100644
index 2cff74c..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportFactory.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.store.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.metadata.report.MetadataReport;
-import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory;
-
-/**
- * metadata report factory impl for nacos
- */
-public class NacosMetadataReportFactory extends AbstractMetadataReportFactory {
- @Override
- protected MetadataReport createMetadataReport(URL url) {
- return new NacosMetadataReport(url);
- }
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory b/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
deleted file mode 100644
index de3b50a..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
+++ /dev/null
@@ -1 +0,0 @@
-nacos=org.apache.dubbo.metadata.store.nacos.NacosMetadataReportFactory
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java b/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java
deleted file mode 100644
index e84efc5..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadata4TstService.java
+++ /dev/null
@@ -1,28 +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.store.nacos;
-
-/**
- * Test interface for Nacos metadata report
- */
-public interface NacosMetadata4TstService {
-
- int getCounter();
-
- void printResult(String var);
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java b/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
deleted file mode 100644
index 88fc75a..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
+++ /dev/null
@@ -1,247 +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.store.nacos;
-
-import com.alibaba.nacos.api.exception.NacosException;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
-import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
-import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
-import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
-
-import com.alibaba.nacos.api.config.ConfigService;
-import com.google.gson.Gson;
-import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
-
-//FIXME: waiting for embedded Nacos suport, then we can open the switch.
-@Disabled("https://github.com/alibaba/nacos/issues/1188")
-public class NacosMetadataReportTest {
-
- private static final String SESSION_TIMEOUT_KEY = "session";
-
- private static final String TEST_SERVICE = "org.apache.dubbo.metadata.store.nacos.NacosMetadata4TstService";
-
- private NacosMetadataReport nacosMetadataReport;
-
- private NacosMetadataReportFactory nacosMetadataReportFactory;
-
- private ConfigService configService;
-
- private static final String NACOS_GROUP = "metadata_test";
-
- /**
- * timeout(ms) for nacos session
- */
- private static final int SESSION_TIMEOUT = 15 * 1000;
-
- /**
- * timeout(ms) for query operation on nacos
- */
- private static final int NACOS_READ_TIMEOUT = 5 * 1000;
-
- /**
- * interval(ms) to make nacos cache refresh
- */
- private static final int INTERVAL_TO_MAKE_NACOS_REFRESH = 1000;
-
- /**
- * version for test
- */
- private static final String VERSION = "1.0.0";
-
- /**
- * group for test
- */
- private static final String METADATA_GROUP = null;
-
- /**
- * application name for test
- */
- private static final String APPLICATION_NAME = "nacos-metdata-report-test";
-
- /**
- * revision for test
- */
- private static final String REVISION = "90980";
-
- /**
- * protocol for test
- */
- private static final String PROTOCOL = "xxx";
-
- @BeforeEach
- public void setUp() {
- URL url = URL.valueOf("nacos://127.0.0.1:8848?group=" + NACOS_GROUP)
- .addParameter(SESSION_TIMEOUT_KEY, SESSION_TIMEOUT);
- nacosMetadataReportFactory = new NacosMetadataReportFactory();
- this.nacosMetadataReport = (NacosMetadataReport) nacosMetadataReportFactory.createMetadataReport(url);
- this.configService = nacosMetadataReport.buildConfigService(url);
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- }
-
-
- @Test
- public void testStoreProvider() throws Exception {
- MetadataIdentifier providerIdentifier =
- storeProvider(nacosMetadataReport, TEST_SERVICE, VERSION, METADATA_GROUP, APPLICATION_NAME);
- String serverContent = configService.getConfig(providerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNotNull(serverContent);
-
- Gson gson = new Gson();
- FullServiceDefinition fullServiceDefinition = gson.fromJson(serverContent, FullServiceDefinition.class);
- Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "nacosTest");
-
- //Clear test data
- configService.removeConfig(providerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP);
- }
-
- @Test
- public void testStoreConsumer() throws Exception {
- MetadataIdentifier consumerIdentifier = storeConsumer(nacosMetadataReport, TEST_SERVICE, VERSION, METADATA_GROUP, APPLICATION_NAME);
-
- String serverContent = configService.getConfig(consumerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNotNull(serverContent);
- Assertions.assertEquals(serverContent, "{\"paramConsumerTest\":\"nacosConsumer\"}");
-
- //clear test data
- configService.removeConfig(consumerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP);
- }
-
- @Test
- public void testDoSaveServiceMetadata() throws Exception {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + TEST_SERVICE +
- "?paramTest=nacosTest&version=" + VERSION + "&application="
- + APPLICATION_NAME + (METADATA_GROUP == null ? "" : "&group=" + METADATA_GROUP));
- ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, VERSION,
- METADATA_GROUP, "provider", REVISION, PROTOCOL);
- nacosMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
- String serviceMetaData = configService.getConfig(serviceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNotNull(serviceMetaData);
- Assertions.assertEquals(serviceMetaData, URL.encode(url.toFullString()));
-
- //clear test data
- configService.removeConfig(serviceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP);
- }
-
- @Test
- public void testDoRemoveServiceMetadata() throws Exception {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + TEST_SERVICE +
- "?paramTest=nacosTest&version=" + VERSION + "&application="
- + APPLICATION_NAME + (METADATA_GROUP == null ? "" : "&group=" + METADATA_GROUP));
- ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, VERSION,
- METADATA_GROUP, "provider", REVISION, PROTOCOL);
- nacosMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
- String serviceMetaData = configService.getConfig(serviceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNotNull(serviceMetaData);
-
- nacosMetadataReport.doRemoveMetadata(serviceMetadataIdentifier);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
- serviceMetaData = configService.getConfig(serviceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNull(serviceMetaData);
- }
-
- @Test
- public void testDoGetExportedURLs() throws InterruptedException, NacosException {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + TEST_SERVICE +
- "?paramTest=nacosTest&version=" + VERSION + "&application="
- + APPLICATION_NAME + (METADATA_GROUP == null ? "" : "&group=" + METADATA_GROUP));
- ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, VERSION,
- METADATA_GROUP, "provider", REVISION, PROTOCOL);
-
- nacosMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
-
- List<String> exportedURLs = nacosMetadataReport.doGetExportedURLs(serviceMetadataIdentifier);
- Assertions.assertTrue(exportedURLs.size() == 1);
-
- String exportedUrl = exportedURLs.get(0);
- Assertions.assertNotNull(exportedUrl);
- Assertions.assertEquals(exportedUrl, url.toFullString());
-
- //clear test data
- configService.removeConfig(serviceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP);
- }
-
- @Test
- public void testDoSaveSubscriberData() throws InterruptedException, NacosException {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + TEST_SERVICE +
- "?paramTest=nacosTest&version=" + VERSION + "&application="
- + APPLICATION_NAME + (METADATA_GROUP == null ? "" : "&group=" + METADATA_GROUP));
- SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(APPLICATION_NAME, REVISION);
- Gson gson = new Gson();
- String urlListJsonString = gson.toJson(Arrays.asList(url));
- nacosMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, urlListJsonString);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
-
- String subscriberMetadata = configService.getConfig(subscriberMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP, NACOS_READ_TIMEOUT);
- Assertions.assertNotNull(subscriberMetadata);
- Assertions.assertEquals(subscriberMetadata, urlListJsonString);
-
- //clear test data
- configService.removeConfig(subscriberMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), NACOS_GROUP);
-
- }
-
- private MetadataIdentifier storeProvider(NacosMetadataReport nacosMetadataReport, String interfaceName, String version,
- String group, String application)
- throws ClassNotFoundException, InterruptedException {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName +
- "?paramTest=nacosTest&version=" + version + "&application="
- + application + (group == null ? "" : "&group=" + group));
-
- MetadataIdentifier providerMetadataIdentifier =
- new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
- Class interfaceClass = Class.forName(interfaceName);
- FullServiceDefinition fullServiceDefinition =
- ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
-
- nacosMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
- return providerMetadataIdentifier;
- }
-
- private MetadataIdentifier storeConsumer(NacosMetadataReport nacosMetadataReport, String interfaceName,
- String version, String group, String application) throws InterruptedException {
- MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
- Map<String, String> tmp = new HashMap<>();
- tmp.put("paramConsumerTest", "nacosConsumer");
- nacosMetadataReport.storeConsumerMetadata(consumerIdentifier, tmp);
- Thread.sleep(INTERVAL_TO_MAKE_NACOS_REFRESH);
- return consumerIdentifier;
- }
-
-}
diff --git a/dubbo-spi-metadata/pom.xml b/dubbo-spi-metadata/pom.xml
index 72fef74..d35ed4b 100644
--- a/dubbo-spi-metadata/pom.xml
+++ b/dubbo-spi-metadata/pom.xml
@@ -34,7 +34,6 @@
<modules>
<module>dubbo-metadata-report-consul</module>
<module>dubbo-metadata-report-etcd</module>
- <module>dubbo-metadata-report-nacos</module>
</modules>
</project>
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/pom.xml b/dubbo-spi-rpc/dubbo-rpc-grpc/pom.xml
deleted file mode 100644
index 8042750..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/pom.xml
+++ /dev/null
@@ -1,68 +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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-rpc-grpc</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The gRPC integration module</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-http</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-netty</artifactId>
- </dependency>
- <!-- <dependency>-->
- <!-- <groupId>io.grpc</groupId>-->
- <!-- <artifactId>grpc-netty-shaded</artifactId>-->
- <!-- </dependency>-->
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-protobuf</artifactId>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-stub</artifactId>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/DubboHandlerRegistry.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/DubboHandlerRegistry.java
deleted file mode 100644
index aa9a17b..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/DubboHandlerRegistry.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.rpc.protocol.grpc;
-
-import io.grpc.BindableService;
-import io.grpc.HandlerRegistry;
-import io.grpc.ServerMethodDefinition;
-import io.grpc.ServerServiceDefinition;
-
-import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- *
- */
-public class DubboHandlerRegistry extends HandlerRegistry {
-
- private final Map<String, ServerServiceDefinition> services = new ConcurrentHashMap<>();
- private final Map<String, ServerMethodDefinition<?, ?>> methods = new ConcurrentHashMap<>();
-
- public DubboHandlerRegistry() {}
-
- /**
- * Returns the service definitions in this registry.
- */
- @Override
- public List<ServerServiceDefinition> getServices() {
- return Collections.unmodifiableList(new ArrayList<>(services.values()));
- }
-
- @Nullable
- @Override
- public ServerMethodDefinition<?, ?> lookupMethod(String methodName, @Nullable String authority) {
- // TODO (carl-mastrangelo): honor authority header.
- return methods.get(methodName);
- }
-
- void addService(BindableService bindableService, String key) {
- ServerServiceDefinition service = bindableService.bindService();
- services.put(key, service);
- for (ServerMethodDefinition<?, ?> method : service.getMethods()) {
- methods.put(method.getMethodDescriptor().getFullMethodName(), method);
- }
- }
-
- void removeService(String serviceKey) {
- ServerServiceDefinition service = services.remove(serviceKey);
- for (ServerMethodDefinition<?, ?> method : service.getMethods()) {
- methods.remove(method.getMethodDescriptor().getFullMethodName(), method);
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConfig.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConfig.java
deleted file mode 100644
index 08b2f6a..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConfig.java
+++ /dev/null
@@ -1,21 +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.rpc.protocol.grpc;
-
-public class GrpcConfig {
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConstants.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConstants.java
deleted file mode 100644
index 9982751..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcConstants.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.rpc.protocol.grpc;
-
-
-public class GrpcConstants {
-
- public static final String DIERCTOR_KEY = "grpc.director";
- public static final String HANDSHAKE_TIMEOUT = "grpc.handshakeTimeout";
- public static final String MAX_INBOUND_MESSAGE_SIZE = "grpc.maxInboundMessageSize";
- public static final String MAX_INBOUND_METADATA_SIZE = "grpc.maxOutboundMessageSize";
- public static final String FLOWCONTROL_WINDOW = "grpc.flowControlWindow";
- public static final String MAX_CONCURRENT_CALLS_PER_CONNECTION = "grpc.maxConcurrentCallsPerConnection";
-
- public static final String WORKER_THREAD_NUM = "grpc.io.num";
- public static final String BOSS_THREAD_NUM = "grpc.boss.num";
- public static final String CHANNEL_TYPE = "grpc.channel.type";
-
- public static final String SERVER_INTERCEPTORS = "grpc.serverInterceptors";
- public static final String CLIENT_INTERCEPTORS = "grpc.clientInterceptors";
- public static final String TRANSPORT_FILTERS = "grpc.transportFilters";
-
- public static final String EXECUTOR = "grpc.executor";
-
- public static final String CONFIGURATOR = "grpc.configurator";
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcInvoker.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcInvoker.java
deleted file mode 100644
index 4ca6fb7..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcInvoker.java
+++ /dev/null
@@ -1,118 +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.rpc.protocol.grpc;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.AbstractInvoker;
-
-import io.grpc.Status;
-import io.grpc.StatusException;
-
-import java.util.concurrent.locks.ReentrantLock;
-
-public class GrpcInvoker<T> extends AbstractInvoker<T> {
- private final ReentrantLock destroyLock = new ReentrantLock();
-
- private final Invoker<T> target;
- private ReferenceCountManagedChannel channel;
-
-// private static List<Exception> grpcExceptions = new ArrayList<>();
-// static {
-// grpcExceptions.add();
-// }
-
- public GrpcInvoker(Class<T> type, URL url, Invoker<T> target, ReferenceCountManagedChannel channel) {
- super(type, url);
- this.target = target;
- this.channel = channel;
- }
-
- @Override
- protected Result doInvoke(Invocation invocation) throws Throwable {
- try {
- Result result = target.invoke(invocation);
- // FIXME result is an AsyncRpcResult instance.
- Throwable e = result.getException();
- if (e != null) {
- throw getRpcException(getInterface(), getUrl(), invocation, e);
- }
- return result;
- } catch (RpcException e) {
- if (e.getCode() == RpcException.UNKNOWN_EXCEPTION) {
- e.setCode(getErrorCode(e.getCause()));
- }
- throw e;
- } catch (Throwable e) {
- throw getRpcException(getInterface(), getUrl(), invocation, e);
- }
- }
-
- @Override
- public boolean isAvailable() {
- return super.isAvailable() && !channel.isShutdown() && !channel.isTerminated();
- }
-
- @Override
- public boolean isDestroyed() {
- return super.isDestroyed() || channel.isShutdown() || channel.isTerminated();
- }
-
- @Override
- public void destroy() {
- if (!super.isDestroyed()) {
- // double check to avoid dup close
- destroyLock.lock();
- try {
- if (super.isDestroyed()) {
- return;
- }
- super.destroy();
- channel.shutdown();
- } finally {
- destroyLock.unlock();
- }
- }
- }
-
- private RpcException getRpcException(Class<?> type, URL url, Invocation invocation, Throwable e) {
- RpcException re = new RpcException("Failed to invoke remote service: " + type + ", method: "
- + invocation.getMethodName() + ", cause: " + e.getMessage(), e);
- re.setCode(getErrorCode(e));
- return re;
- }
-
- /**
- * FIXME, convert gRPC exceptions to equivalent Dubbo exceptions.
- *
- * @param e
- * @return
- */
- private int getErrorCode(Throwable e) {
- if (e instanceof StatusException) {
- StatusException statusException = (StatusException) e;
- Status status = statusException.getStatus();
- if (status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
- return RpcException.TIMEOUT_EXCEPTION;
- }
- }
- return RpcException.UNKNOWN_EXCEPTION;
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcOptionsUtils.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcOptionsUtils.java
deleted file mode 100644
index d1b1cda..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcOptionsUtils.java
+++ /dev/null
@@ -1,225 +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.rpc.protocol.grpc;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.threadpool.ThreadPool;
-import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.config.SslConfig;
-import org.apache.dubbo.config.context.ConfigManager;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor;
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.GrpcConfigurator;
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor;
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerTransportFilter;
-
-import io.grpc.CallOptions;
-import io.grpc.ManagedChannel;
-import io.grpc.ServerBuilder;
-import io.grpc.netty.GrpcSslContexts;
-import io.grpc.netty.NettyChannelBuilder;
-import io.grpc.netty.NettyServerBuilder;
-import io.netty.handler.ssl.ClientAuth;
-import io.netty.handler.ssl.SslContext;
-import io.netty.handler.ssl.SslContextBuilder;
-
-import javax.net.ssl.SSLException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
-import static org.apache.dubbo.common.constants.CommonConstants.SSL_ENABLED_KEY;
-import static org.apache.dubbo.remoting.Constants.DISPATCHER_KEY;
-import static org.apache.dubbo.rpc.Constants.EXECUTES_KEY;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.CLIENT_INTERCEPTORS;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.EXECUTOR;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_CONCURRENT_CALLS_PER_CONNECTION;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_INBOUND_MESSAGE_SIZE;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_INBOUND_METADATA_SIZE;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.SERVER_INTERCEPTORS;
-import static org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.TRANSPORT_FILTERS;
-
-/**
- * Support gRPC configs in a Dubbo specific way.
- */
-public class GrpcOptionsUtils {
-
- static ServerBuilder buildServerBuilder(URL url, NettyServerBuilder builder) {
-
- int maxInboundMessageSize = url.getParameter(MAX_INBOUND_MESSAGE_SIZE, 0);
- if (maxInboundMessageSize > 0) {
- builder.maxInboundMessageSize(maxInboundMessageSize);
- }
-
- int maxInboundMetadataSize = url.getParameter(MAX_INBOUND_METADATA_SIZE, 0);
- if (maxInboundMetadataSize > 0) {
- builder.maxInboundMetadataSize(maxInboundMetadataSize);
- }
-
- if (url.getParameter(SSL_ENABLED_KEY, false)) {
- builder.sslContext(buildServerSslContext(url));
- }
-
- int flowControlWindow = url.getParameter(MAX_INBOUND_MESSAGE_SIZE, 0);
- if (flowControlWindow > 0) {
- builder.flowControlWindow(flowControlWindow);
- }
-
- int maxCalls = url.getParameter(MAX_CONCURRENT_CALLS_PER_CONNECTION, url.getParameter(EXECUTES_KEY, 0));
- if (maxCalls > 0) {
- builder.maxConcurrentCallsPerConnection(maxCalls);
- }
-
- // server interceptors
- List<ServerInterceptor> serverInterceptors = ExtensionLoader.getExtensionLoader(ServerInterceptor.class)
- .getActivateExtension(url, SERVER_INTERCEPTORS, PROVIDER_SIDE);
- for (ServerInterceptor serverInterceptor : serverInterceptors) {
- builder.intercept(serverInterceptor);
- }
-
- // server filters
- List<ServerTransportFilter> transportFilters = ExtensionLoader.getExtensionLoader(ServerTransportFilter.class)
- .getActivateExtension(url, TRANSPORT_FILTERS, PROVIDER_SIDE);
- for (ServerTransportFilter transportFilter : transportFilters) {
- builder.addTransportFilter(transportFilter.grpcTransportFilter());
- }
-
- String thread = url.getParameter(EXECUTOR, url.getParameter(DISPATCHER_KEY));
- if ("direct".equals(thread)) {
- builder.directExecutor();
- } else {
- builder.executor(ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url));
- }
-
- // Give users the chance to customize ServerBuilder
- return getConfigurator()
- .map(configurator -> configurator.configureServerBuilder(builder, url))
- .orElse(builder);
- }
-
- static ManagedChannel buildManagedChannel(URL url) {
-
- NettyChannelBuilder builder = NettyChannelBuilder.forAddress(url.getHost(), url.getPort());
- if (url.getParameter(SSL_ENABLED_KEY, false)) {
- builder.sslContext(buildClientSslContext(url));
- } else {
- builder.usePlaintext();
- }
-
- builder.disableRetry();
-// builder.directExecutor();
-
- // client interceptors
- List<io.grpc.ClientInterceptor> interceptors = new ArrayList<>(
- ExtensionLoader.getExtensionLoader(ClientInterceptor.class)
- .getActivateExtension(url, CLIENT_INTERCEPTORS, CONSUMER_SIDE)
- );
-
- builder.intercept(interceptors);
-
- return getConfigurator()
- .map(configurator -> configurator.configureChannelBuilder(builder, url))
- .orElse(builder)
- .build();
- }
-
- static CallOptions buildCallOptions(URL url) {
- // gRPC Deadline starts counting when it's created, so we need to create and add a new Deadline for each RPC call.
-// CallOptions callOptions = CallOptions.DEFAULT
-// .withDeadline(Deadline.after(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS));
- CallOptions callOptions = CallOptions.DEFAULT;
- return getConfigurator()
- .map(configurator -> configurator.configureCallOptions(callOptions, url))
- .orElse(callOptions);
- }
-
- private static SslContext buildServerSslContext(URL url) {
- ConfigManager globalConfigManager = ApplicationModel.getConfigManager();
- SslConfig sslConfig = globalConfigManager.getSsl().orElseThrow(() -> new IllegalStateException("Ssl enabled, but no ssl cert information provided!"));
-
- SslContextBuilder sslClientContextBuilder = null;
- try {
- String password = sslConfig.getServerKeyPassword();
- if (password != null) {
- sslClientContextBuilder = GrpcSslContexts.forServer(sslConfig.getServerKeyCertChainPathStream(),
- sslConfig.getServerPrivateKeyPathStream(), password);
- } else {
- sslClientContextBuilder = GrpcSslContexts.forServer(sslConfig.getServerKeyCertChainPathStream(),
- sslConfig.getServerPrivateKeyPathStream());
- }
-
- InputStream trustCertCollectionFilePath = sslConfig.getServerTrustCertCollectionPathStream();
- if (trustCertCollectionFilePath != null) {
- sslClientContextBuilder.trustManager(trustCertCollectionFilePath);
- sslClientContextBuilder.clientAuth(ClientAuth.REQUIRE);
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("Could not find certificate file or the certificate is invalid.", e);
- }
- try {
- return sslClientContextBuilder.build();
- } catch (SSLException e) {
- throw new IllegalStateException("Build SslSession failed.", e);
- }
- }
-
- private static SslContext buildClientSslContext(URL url) {
- ConfigManager globalConfigManager = ApplicationModel.getConfigManager();
- SslConfig sslConfig = globalConfigManager.getSsl().orElseThrow(() -> new IllegalStateException("Ssl enabled, but no ssl cert information provided!"));
-
-
- SslContextBuilder builder = GrpcSslContexts.forClient();
- try {
- InputStream trustCertCollectionFilePath = sslConfig.getClientTrustCertCollectionPathStream();
- if (trustCertCollectionFilePath != null) {
- builder.trustManager(trustCertCollectionFilePath);
- }
- InputStream clientCertChainFilePath = sslConfig.getClientKeyCertChainPathStream();
- InputStream clientPrivateKeyFilePath = sslConfig.getClientPrivateKeyPathStream();
- if (clientCertChainFilePath != null && clientPrivateKeyFilePath != null) {
- String password = sslConfig.getClientKeyPassword();
- if (password != null) {
- builder.keyManager(clientCertChainFilePath, clientPrivateKeyFilePath, password);
- } else {
- builder.keyManager(clientCertChainFilePath, clientPrivateKeyFilePath);
- }
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("Could not find certificate file or find invalid certificate.", e);
- }
- try {
- return builder.build();
- } catch (SSLException e) {
- throw new IllegalStateException("Build SslSession failed.", e);
- }
- }
-
- private static Optional<GrpcConfigurator> getConfigurator() {
- // Give users the chance to customize ServerBuilder
- Set<GrpcConfigurator> configurators = ExtensionLoader.getExtensionLoader(GrpcConfigurator.class)
- .getSupportedExtensionInstances();
- if (CollectionUtils.isNotEmpty(configurators)) {
- return Optional.of(configurators.iterator().next());
- }
- return Optional.empty();
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcProtocol.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcProtocol.java
deleted file mode 100644
index 1342a17..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/GrpcProtocol.java
+++ /dev/null
@@ -1,239 +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.rpc.protocol.grpc;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.config.ReferenceConfigBase;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.ProtocolServer;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.model.ProviderModel;
-import org.apache.dubbo.rpc.model.ServiceRepository;
-import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
-
-import io.grpc.BindableService;
-import io.grpc.CallOptions;
-import io.grpc.Channel;
-import io.grpc.ManagedChannel;
-import io.grpc.Server;
-import io.grpc.netty.NettyServerBuilder;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- *
- */
-public class GrpcProtocol extends AbstractProxyProtocol {
-
- private static final Logger logger = LoggerFactory.getLogger(GrpcProtocol.class);
-
- public final static int DEFAULT_PORT = 50051;
-
- /* <address, gRPC channels> */
- private final ConcurrentMap<String, ReferenceCountManagedChannel> channelMap = new ConcurrentHashMap<>();
- private final Object lock = new Object();
-
- @Override
- protected <T> Runnable doExport(T proxiedImpl, Class<T> type, URL url) throws RpcException {
- String key = url.getAddress();
- ProtocolServer protocolServer = serverMap.computeIfAbsent(key, k -> {
- DubboHandlerRegistry registry = new DubboHandlerRegistry();
-
- NettyServerBuilder builder =
- NettyServerBuilder
- .forPort(url.getPort())
- .fallbackHandlerRegistry(registry);
-
- Server originalServer = GrpcOptionsUtils.buildServerBuilder(url, builder).build();
- GrpcRemotingServer remotingServer = new GrpcRemotingServer(originalServer, registry);
- return new ProxyProtocolServer(remotingServer);
- });
-
- GrpcRemotingServer grpcServer = (GrpcRemotingServer) protocolServer.getRemotingServer();
-
- ServiceRepository serviceRepository = ApplicationModel.getServiceRepository();
- ProviderModel providerModel = serviceRepository.lookupExportedService(url.getServiceKey());
- if (providerModel == null) {
- throw new IllegalStateException("Service " + url.getServiceKey() + "should have already been stored in service repository, " +
- "but failed to find it.");
- }
- Object originalImpl = providerModel.getServiceInstance();
-
- Class<?> implClass = originalImpl.getClass();
- try {
- Method method = implClass.getMethod("setProxiedImpl", type);
- method.invoke(originalImpl, proxiedImpl);
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set dubbo proxied service impl to stub, please make sure your stub " +
- "was generated by the dubbo-protoc-compiler.", e);
- }
- grpcServer.getRegistry().addService((BindableService) originalImpl, url.getServiceKey());
-
- if (!grpcServer.isStarted()) {
- grpcServer.start();
- }
-
- return () -> grpcServer.getRegistry().removeService(url.getServiceKey());
- }
-
- @Override
- protected <T> Invoker<T> protocolBindingRefer(final Class<T> type, final URL url) throws RpcException {
- Class<?> enclosingClass = type.getEnclosingClass();
-
- if (enclosingClass == null) {
- throw new IllegalArgumentException(type.getName() + " must be declared inside protobuf generated classes, " +
- "should be something like ServiceNameGrpc.IServiceName.");
- }
-
- final Method dubboStubMethod;
- try {
- dubboStubMethod = enclosingClass.getDeclaredMethod("getDubboStub", Channel.class, CallOptions.class,
- URL.class, ReferenceConfigBase.class);
- } catch (NoSuchMethodException e) {
- throw new IllegalArgumentException("Does not find getDubboStub in " + enclosingClass.getName() + ", please use the customized protoc-gen-dubbo-java to update the generated classes.");
- }
-
- // Channel
- ReferenceCountManagedChannel channel = getSharedChannel(url);
-
- // CallOptions
- try {
- @SuppressWarnings("unchecked") final T stub = (T) dubboStubMethod.invoke(null,
- channel,
- GrpcOptionsUtils.buildCallOptions(url),
- url,
- ApplicationModel.getConsumerModel(url.getServiceKey()).getReferenceConfig()
- );
- final Invoker<T> target = proxyFactory.getInvoker(stub, type, url);
- GrpcInvoker<T> grpcInvoker = new GrpcInvoker<>(type, url, target, channel);
- invokers.add(grpcInvoker);
- return grpcInvoker;
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new IllegalStateException("Could not create stub through reflection.", e);
- }
- }
-
- /**
- * not used
- *
- * @param type
- * @param url
- * @param <T>
- * @return
- * @throws RpcException
- */
- @Override
- protected <T> T doRefer(Class<T> type, URL url) throws RpcException {
- throw new UnsupportedOperationException("not used");
- }
-
- /**
- * Get shared channel connection
- */
- private ReferenceCountManagedChannel getSharedChannel(URL url) {
- String key = url.getAddress();
- ReferenceCountManagedChannel channel = channelMap.get(key);
-
- if (channel != null && !channel.isTerminated()) {
- channel.incrementAndGetCount();
- return channel;
- }
-
- synchronized (lock) {
- channel = channelMap.get(key);
- // dubbo check
- if (channel != null && !channel.isTerminated()) {
- channel.incrementAndGetCount();
- } else {
- channel = new ReferenceCountManagedChannel(initChannel(url));
- channelMap.put(key, channel);
- }
- }
-
- return channel;
- }
-
- /**
- * Create new connection
- *
- * @param url
- */
- private ManagedChannel initChannel(URL url) {
- return GrpcOptionsUtils.buildManagedChannel(url);
- }
-
- @Override
- public int getDefaultPort() {
- return DEFAULT_PORT;
- }
-
- @Override
- public void destroy() {
- serverMap.values().forEach(ProtocolServer::close);
- channelMap.values().forEach(ReferenceCountManagedChannel::shutdown);
- serverMap.clear();
- channelMap.clear();
- super.destroy();
- }
-
- public class GrpcRemotingServer extends RemotingServerAdapter {
-
- private Server originalServer;
- private DubboHandlerRegistry handlerRegistry;
- private volatile boolean started;
-
- public GrpcRemotingServer(Server server, DubboHandlerRegistry handlerRegistry) {
- this.originalServer = server;
- this.handlerRegistry = handlerRegistry;
- }
-
- public void start() throws RpcException {
- try {
- originalServer.start();
- started = true;
- } catch (IOException e) {
- throw new RpcException("Starting gRPC server failed. ", e);
- }
- }
-
- public DubboHandlerRegistry getRegistry() {
- return handlerRegistry;
- }
-
- @Override
- public Object getDelegateServer() {
- return originalServer;
- }
-
- public boolean isStarted() {
- return started;
- }
-
- @Override
- public void close() {
- originalServer.shutdown();
- }
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/ReferenceCountManagedChannel.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/ReferenceCountManagedChannel.java
deleted file mode 100644
index 3b46f1e..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/ReferenceCountManagedChannel.java
+++ /dev/null
@@ -1,85 +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.rpc.protocol.grpc;
-
-import io.grpc.CallOptions;
-import io.grpc.ClientCall;
-import io.grpc.ManagedChannel;
-import io.grpc.MethodDescriptor;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Also see ReferenceCountExchangeClient
- */
-public class ReferenceCountManagedChannel extends ManagedChannel {
-
- private final AtomicInteger referenceCount = new AtomicInteger(0);
-
- private ManagedChannel grpcChannel;
-
- public ReferenceCountManagedChannel(ManagedChannel delegated) {
- this.grpcChannel = delegated;
- }
-
- /**
- * The reference count of current ExchangeClient, connection will be closed if all invokers destroyed.
- */
- public void incrementAndGetCount() {
- referenceCount.incrementAndGet();
- }
-
- @Override
- public ManagedChannel shutdown() {
- if (referenceCount.decrementAndGet() <= 0) {
- return grpcChannel.shutdown();
- }
- return grpcChannel;
- }
-
- @Override
- public boolean isShutdown() {
- return grpcChannel.isShutdown();
- }
-
- @Override
- public boolean isTerminated() {
- return grpcChannel.isTerminated();
- }
-
- @Override
- public ManagedChannel shutdownNow() {
- // TODO
- return shutdown();
- }
-
- @Override
- public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
- return grpcChannel.awaitTermination(timeout, unit);
- }
-
- @Override
- public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(MethodDescriptor<RequestT, ResponseT> methodDescriptor, CallOptions callOptions) {
- return grpcChannel.newCall(methodDescriptor, callOptions);
- }
-
- @Override
- public String authority() {
- return grpcChannel.authority();
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ClientInterceptor.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ClientInterceptor.java
deleted file mode 100644
index c97fec9..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ClientInterceptor.java
+++ /dev/null
@@ -1,26 +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.rpc.protocol.grpc.interceptors;
-
-import org.apache.dubbo.common.extension.SPI;
-
-/**
- * Adapt to the standard Dubbo SPI, so that we can leverage the advantages of Dubbo ExtensionLoader.
- */
-@SPI
-public interface ClientInterceptor extends io.grpc.ClientInterceptor {
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/GrpcConfigurator.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/GrpcConfigurator.java
deleted file mode 100644
index d5330dc..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/GrpcConfigurator.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.rpc.protocol.grpc.interceptors;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.SPI;
-
-import io.grpc.CallOptions;
-import io.grpc.netty.NettyChannelBuilder;
-import io.grpc.netty.NettyServerBuilder;
-
-@SPI
-public interface GrpcConfigurator {
-
- default NettyServerBuilder configureServerBuilder(NettyServerBuilder builder, URL url) {
- return builder;
- }
-
- default NettyChannelBuilder configureChannelBuilder(NettyChannelBuilder builder, URL url) {
- return builder;
- }
-
- default CallOptions configureCallOptions(CallOptions options, URL url) {
- return options;
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java
deleted file mode 100644
index 86915af..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java
+++ /dev/null
@@ -1,100 +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.rpc.protocol.grpc.interceptors;
-
-import io.grpc.CallOptions;
-import io.grpc.Channel;
-import io.grpc.ClientCall;
-import io.grpc.ForwardingClientCall;
-import io.grpc.ForwardingServerCallListener;
-import io.grpc.Metadata;
-import io.grpc.MethodDescriptor;
-import io.grpc.ServerCall;
-import io.grpc.ServerCallHandler;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.rpc.RpcContext;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
-
-/**
- * Hand over context information from Dubbo to gRPC.
- */
-@Activate(group = {PROVIDER, CONSUMER})
-public class RpcContextInterceptor implements ClientInterceptor, ServerInterceptor {
-
- private static final String DUBBO = "D-";
-
- @Override
- public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
- RpcContext rpcContext = RpcContext.getContext();
- Map<String, Object> attachments = new HashMap<>(rpcContext.getObjectAttachments());
-
- return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
- @Override
- public void start(Listener<RespT> responseListener, Metadata headers) {
- if (!attachments.isEmpty()) {
- for (Map.Entry<String, Object> entry : attachments.entrySet()) {
- // only used for string
- if (entry.getValue() instanceof String) {
- headers.put(Metadata.Key.of(DUBBO + entry.getKey(), ASCII_STRING_MARSHALLER), ((String) entry.getValue()));
- }
- }
- }
- super.start(responseListener, headers);
- }
- };
- }
-
- @Override
- public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
- Set<String> keys = headers.keys();
- Map<String, Object> attachments = new HashMap<>();
- // filter out all dubbo attachments and save in map
- if (keys != null) {
- keys.stream().filter(k -> k.toUpperCase().startsWith(DUBBO)).forEach(k ->
- attachments.put(k.substring(DUBBO.length()), headers.get(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER)))
- );
- }
-
- return new ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(next.startCall(call, headers)) {
- @Override
- public void onHalfClose() {
- // the client completed all message sending and server will call the biz method if client is not the streaming
- if (call.getMethodDescriptor().getType().clientSendsOneMessage()) {
- RpcContext.getContext().setObjectAttachments(attachments);
- }
- super.onHalfClose();
- }
-
- @Override
- public void onMessage(ReqT message) {
- //server receive the request from client and call the biz method if client is streaming
- if (!call.getMethodDescriptor().getType().clientSendsOneMessage()) {
- RpcContext.getContext().setObjectAttachments(attachments);
- }
- super.onMessage(message);
- }
- };
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerInterceptor.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerInterceptor.java
deleted file mode 100644
index a4c9a37..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerInterceptor.java
+++ /dev/null
@@ -1,26 +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.rpc.protocol.grpc.interceptors;
-
-import org.apache.dubbo.common.extension.SPI;
-
-/**
- * Adapt to the standard Dubbo SPI, so that we can leverage the advantages of Dubbo ExtensionLoader.
- */
-@SPI
-public interface ServerInterceptor extends io.grpc.ServerInterceptor {
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerTransportFilter.java b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerTransportFilter.java
deleted file mode 100644
index db815dc..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/ServerTransportFilter.java
+++ /dev/null
@@ -1,27 +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.rpc.protocol.grpc.interceptors;
-
-import org.apache.dubbo.common.extension.SPI;
-
-/**
- * Adapt to the standard Dubbo SPI, so that we can leverage the advantages of Dubbo ExtensionLoader.
- */
-@SPI
-public interface ServerTransportFilter {
- io.grpc.ServerTransportFilter grpcTransportFilter();
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
deleted file mode 100644
index f7acbba..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ /dev/null
@@ -1 +0,0 @@
-grpc=org.apache.dubbo.rpc.protocol.grpc.GrpcProtocol
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor
deleted file mode 100644
index b957657..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor
+++ /dev/null
@@ -1 +0,0 @@
-context=org.apache.dubbo.rpc.protocol.grpc.interceptors.RpcContextInterceptor
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor b/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor
deleted file mode 100644
index b957657..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-grpc/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor
+++ /dev/null
@@ -1 +0,0 @@
-context=org.apache.dubbo.rpc.protocol.grpc.interceptors.RpcContextInterceptor
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/pom.xml b/dubbo-spi-rpc/dubbo-rpc-injvm/pom.xml
deleted file mode 100644
index 7d9ce83..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/pom.xml
+++ /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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-rpc-injvm</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The injvm rpc module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmExporter.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmExporter.java
deleted file mode 100644
index b0a648f..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmExporter.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.rpc.protocol.injvm;
-
-import org.apache.dubbo.rpc.Exporter;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.protocol.AbstractExporter;
-
-import java.util.Map;
-
-/**
- * InjvmExporter
- */
-class InjvmExporter<T> extends AbstractExporter<T> {
-
- private final String key;
-
- private final Map<String, Exporter<?>> exporterMap;
-
- InjvmExporter(Invoker<T> invoker, String key, Map<String, Exporter<?>> exporterMap) {
- super(invoker);
- this.key = key;
- this.exporterMap = exporterMap;
- exporterMap.put(key, this);
- }
-
- @Override
- public void unexport() {
- super.unexport();
- exporterMap.remove(key);
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java
deleted file mode 100644
index a8c75fd..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java
+++ /dev/null
@@ -1,65 +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.rpc.protocol.injvm;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.Exporter;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.AbstractInvoker;
-
-import java.util.Map;
-
-import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
-
-/**
- * InjvmInvoker
- */
-class InjvmInvoker<T> extends AbstractInvoker<T> {
-
- private final String key;
-
- private final Map<String, Exporter<?>> exporterMap;
-
- InjvmInvoker(Class<T> type, URL url, String key, Map<String, Exporter<?>> exporterMap) {
- super(type, url);
- this.key = key;
- this.exporterMap = exporterMap;
- }
-
- @Override
- public boolean isAvailable() {
- InjvmExporter<?> exporter = (InjvmExporter<?>) exporterMap.get(key);
- if (exporter == null) {
- return false;
- } else {
- return super.isAvailable();
- }
- }
-
- @Override
- public Result doInvoke(Invocation invocation) throws Throwable {
- Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
- if (exporter == null) {
- throw new RpcException("Service [" + key + "] not found.");
- }
- RpcContext.getContext().setRemoteAddress(LOCALHOST_VALUE, 0);
- return exporter.getInvoker().invoke(invocation);
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java
deleted file mode 100644
index 3e681b2..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java
+++ /dev/null
@@ -1,120 +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.rpc.protocol.injvm;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.rpc.Exporter;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Protocol;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.AbstractProtocol;
-import org.apache.dubbo.rpc.support.ProtocolUtils;
-
-import java.util.Map;
-
-import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
-import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
-import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
-import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
-import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
-
-/**
- * InjvmProtocol
- */
-public class InjvmProtocol extends AbstractProtocol implements Protocol {
-
- public static final String NAME = LOCAL_PROTOCOL;
-
- public static final int DEFAULT_PORT = 0;
- private static InjvmProtocol INSTANCE;
-
- public InjvmProtocol() {
- INSTANCE = this;
- }
-
- public static InjvmProtocol getInjvmProtocol() {
- if (INSTANCE == null) {
- ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(InjvmProtocol.NAME); // load
- }
- return INSTANCE;
- }
-
- static Exporter<?> getExporter(Map<String, Exporter<?>> map, URL key) {
- Exporter<?> result = null;
-
- if (!key.getServiceKey().contains("*")) {
- result = map.get(key.getServiceKey());
- } else {
- if (CollectionUtils.isNotEmptyMap(map)) {
- for (Exporter<?> exporter : map.values()) {
- if (UrlUtils.isServiceKeyMatch(key, exporter.getInvoker().getUrl())) {
- result = exporter;
- break;
- }
- }
- }
- }
-
- if (result == null) {
- return null;
- } else if (ProtocolUtils.isGeneric(
- result.getInvoker().getUrl().getParameter(GENERIC_KEY))) {
- return null;
- } else {
- return result;
- }
- }
-
- @Override
- public int getDefaultPort() {
- return DEFAULT_PORT;
- }
-
- @Override
- public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
- return new InjvmExporter<T>(invoker, invoker.getUrl().getServiceKey(), exporterMap);
- }
-
- @Override
- public <T> Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url) throws RpcException {
- return new InjvmInvoker<T>(serviceType, url, url.getServiceKey(), exporterMap);
- }
-
- public boolean isInjvmRefer(URL url) {
- String scope = url.getParameter(SCOPE_KEY);
- // Since injvm protocol is configured explicitly, we don't need to set any extra flag, use normal refer process.
- if (SCOPE_LOCAL.equals(scope) || (url.getParameter(LOCAL_PROTOCOL, false))) {
- // if it's declared as local reference
- // 'scope=local' is equivalent to 'injvm=true', injvm will be deprecated in the future release
- return true;
- } else if (SCOPE_REMOTE.equals(scope)) {
- // it's declared as remote reference
- return false;
- } else if (url.getParameter(GENERIC_KEY, false)) {
- // generic invocation is not local reference
- return false;
- } else if (getExporter(exporterMap, url) != null) {
- // by default, go through local reference if there's the service exposed locally
- return true;
- } else {
- return false;
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol b/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
deleted file mode 100644
index 92ec2df..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ /dev/null
@@ -1 +0,0 @@
-injvm=org.apache.dubbo.rpc.protocol.injvm.InjvmProtocol
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoRequest.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoRequest.java
deleted file mode 100644
index cbd2e34..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoRequest.java
+++ /dev/null
@@ -1,58 +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.rpc.protocol.injvm;
-
-import java.io.Serializable;
-
-/**
- * TestRequest.
- */
-
-class DemoRequest implements Serializable {
- private static final long serialVersionUID = -2579095288792344869L;
-
- private String mServiceName;
-
- private String mMethodName;
-
- private Class<?>[] mParameterTypes;
-
- private Object[] mArguments;
-
- public DemoRequest(String serviceName, String methodName, Class<?>[] parameterTypes, Object[] args) {
- mServiceName = serviceName;
- mMethodName = methodName;
- mParameterTypes = parameterTypes;
- mArguments = args;
- }
-
- public String getServiceName() {
- return mServiceName;
- }
-
- public String getMethodName() {
- return mMethodName;
- }
-
- public Class<?>[] getParameterTypes() {
- return mParameterTypes;
- }
-
- public Object[] getArguments() {
- return mArguments;
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java
deleted file mode 100644
index 821015f..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.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.rpc.protocol.injvm;
-
-/**
- * <code>TestService</code>
- */
-
-public interface DemoService {
- void sayHello(String name);
-
- String echo(String text);
-
- long timestamp();
-
- String getThreadName();
-
- int getSize(String[] strs);
-
- int getSize(Object[] os);
-
- Object invoke(String service, String method) throws Exception;
-
- int stringLength(String str);
-
- Type enumlength(Type... types);
-
-
- String getRemoteApplicationName();
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java
deleted file mode 100644
index a6e3f2c..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.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.rpc.protocol.injvm;
-
-import org.apache.dubbo.rpc.RpcContext;
-
-/**
- * DemoServiceImpl
- */
-
-public class DemoServiceImpl implements DemoService {
- public DemoServiceImpl() {
- super();
- }
-
- public void sayHello(String name) {
- System.out.println("hello " + name);
- }
-
- public String echo(String text) {
- return text;
- }
-
- public long timestamp() {
- return System.currentTimeMillis();
- }
-
- public String getThreadName() {
- return Thread.currentThread().getName();
- }
-
- public int getSize(String[] strs) {
- if (strs == null)
- return -1;
- return strs.length;
- }
-
- public int getSize(Object[] os) {
- if (os == null)
- return -1;
- return os.length;
- }
-
- public Object invoke(String service, String method) throws Exception {
- System.out.println("RpcContext.getContext().getRemoteHost()=" + RpcContext.getContext().getRemoteHost());
- return service + ":" + method;
- }
-
- public Type enumlength(Type... types) {
- if (types.length == 0)
- return Type.Lower;
- return types[0];
- }
-
- public int stringLength(String str) {
- return str.length();
- }
-
-
- @Override
- public String getRemoteApplicationName() {
- return RpcContext.getContext().getRemoteApplicationName();
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/IEcho.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/IEcho.java
deleted file mode 100644
index 0883946..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/IEcho.java
+++ /dev/null
@@ -1,21 +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.rpc.protocol.injvm;
-
-public interface IEcho {
- String echo(String e);
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java
deleted file mode 100644
index ea6de85..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java
+++ /dev/null
@@ -1,126 +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.rpc.protocol.injvm;
-
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.rpc.Exporter;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Protocol;
-import org.apache.dubbo.rpc.ProxyFactory;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
-import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
-import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
-import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
-import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
-import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * <code>ProxiesTest</code>
- */
-
-public class InjvmProtocolTest {
-
- static {
- InjvmProtocol injvm = InjvmProtocol.getInjvmProtocol();
- }
-
- private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
- private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- private List<Exporter<?>> exporters = new ArrayList<Exporter<?>>();
-
- @AfterEach
- public void after() throws Exception {
- for (Exporter<?> exporter : exporters) {
- exporter.unexport();
- }
- exporters.clear();
- }
-
- @Test
- public void testLocalProtocol() throws Exception {
- DemoService service = new DemoServiceImpl();
- Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName()));
- assertTrue(invoker.isAvailable());
- Exporter<?> exporter = protocol.export(invoker);
- exporters.add(exporter);
- service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName())));
- assertEquals(service.getSize(new String[]{"", "", ""}), 3);
- service.invoke("injvm://127.0.0.1/TestService", "invoke");
-
- InjvmInvoker injvmInvoker = new InjvmInvoker(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService"), null, new HashMap<String, Exporter<?>>());
- assertFalse(injvmInvoker.isAvailable());
-
- }
-
- @Test
- public void testIsInjvmRefer() throws Exception {
- DemoService service = new DemoServiceImpl();
- URL url = URL.valueOf("injvm://127.0.0.1/TestService")
- .addParameter(INTERFACE_KEY, DemoService.class.getName());
- Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
- exporters.add(exporter);
-
- url = url.setProtocol("dubbo");
- assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- url = url.addParameter(GROUP_KEY, "*")
- .addParameter(VERSION_KEY, "*");
- assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(SCOPE_KEY, SCOPE_LOCAL);
- assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(LOCAL_PROTOCOL, true);
- assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(SCOPE_KEY, SCOPE_REMOTE);
- assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(GENERIC_KEY, true);
- assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
-
- }
-
-
- @Test
- public void testRemoteApplicationName() throws Exception {
- DemoService service = new DemoServiceImpl();
- URL url = URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName()).addParameter("application", "consumer");
- Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, url);
- assertTrue(invoker.isAvailable());
- Exporter<?> exporter = protocol.export(invoker);
- exporters.add(exporter);
- service = proxy.getProxy(protocol.refer(DemoService.class, url));
- assertEquals(service.getRemoteApplicationName(), "consumer");
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java
deleted file mode 100644
index 12de553..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.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.rpc.protocol.injvm;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Protocol;
-import org.apache.dubbo.rpc.ProxyFactory;
-
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class ProtocolTest {
-
- IEcho echo = new IEcho() {
- public String echo(String e) {
- return e;
- }
- };
-
- static {
- InjvmProtocol injvm = InjvmProtocol.getInjvmProtocol();
- }
-
- ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("javassist");
-
- URL url = URL.valueOf("injvm://localhost:0/org.apache.dubbo.rpc.support.IEcho?interface=org.apache.dubbo.rpc.support.IEcho");
-
- Invoker<IEcho> invoker = proxyFactory.getInvoker(echo, IEcho.class, url);
-
- @Test
- public void test_destroyWontCloseAllProtocol() throws Exception {
- Protocol autowireProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
-
- Protocol InjvmProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("injvm");
-
- assertEquals(0, InjvmProtocol.getDefaultPort());
-
- InjvmProtocol.export(invoker);
-
- Invoker<IEcho> refer = InjvmProtocol.refer(IEcho.class, url);
- IEcho echoProxy = proxyFactory.getProxy(refer);
-
- assertEquals("ok", echoProxy.echo("ok"));
-
- try {
- autowireProtocol.destroy();
- } catch (UnsupportedOperationException expected) {
- assertThat(expected.getMessage(), containsString("of interface org.apache.dubbo.rpc.Protocol is not adaptive method!"));
- }
-
- assertEquals("ok2", echoProxy.echo("ok2"));
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/Type.java b/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/Type.java
deleted file mode 100644
index 4d39de6..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/Type.java
+++ /dev/null
@@ -1,21 +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.rpc.protocol.injvm;
-
-public enum Type {
- High, Normal, Lower
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/pom.xml b/dubbo-spi-rpc/dubbo-rpc-rest/pom.xml
deleted file mode 100644
index 3f379b4..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/pom.xml
+++ /dev/null
@@ -1,115 +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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-rpc-rest</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The JAX-RS rpc module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-http</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-client</artifactId>
- </dependency>
-
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- </dependency>
-
- <!-- optional dependencies ==================== -->
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-netty4</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jdk-http</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jackson-provider</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- </dependency>
-
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
- </dependency>
-
- <!-- swagger -->
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-annotations</artifactId>
- <exclusions>
- <exclusion>
- <groupId>javax.ws.rs</groupId>
- <artifactId>jsr311-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-jaxrs</artifactId>
- <exclusions>
- <exclusion>
- <groupId>javax.ws.rs</groupId>
- <artifactId>jsr311-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-serialization-jdk</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestProtocolServer.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestProtocolServer.java
deleted file mode 100644
index 3621848..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestProtocolServer.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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import org.jboss.resteasy.spi.ResteasyDeployment;
-
-import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
-import static org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY;
-
-public abstract class BaseRestProtocolServer implements RestProtocolServer {
-
- private String address;
-
- @Override
- public void start(URL url) {
- getDeployment().getMediaTypeMappings().put("json", "application/json");
- getDeployment().getMediaTypeMappings().put("xml", "text/xml");
-// server.getDeployment().getMediaTypeMappings().put("xml", "application/xml");
- getDeployment().getProviderClasses().add(RpcContextFilter.class.getName());
- // TODO users can override this mapper, but we just rely on the current priority strategy of resteasy
- getDeployment().getProviderClasses().add(RpcExceptionMapper.class.getName());
-
- loadProviders(url.getParameter(EXTENSION_KEY, ""));
-
- doStart(url);
- }
-
- @Override
- public void deploy(Class resourceDef, Object resourceInstance, String contextPath) {
- if (StringUtils.isEmpty(contextPath)) {
- getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef));
- } else {
- getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef), contextPath);
- }
- }
-
- @Override
- public void undeploy(Class resourceDef) {
- getDeployment().getRegistry().removeRegistrations(resourceDef);
- }
-
- @Override
- public String getAddress() {
- return address;
- }
-
- @Override
- public void setAddress(String address) {
- this.address = address;
- }
-
- protected void loadProviders(String value) {
- for (String clazz : COMMA_SPLIT_PATTERN.split(value)) {
- if (!StringUtils.isEmpty(clazz)) {
- getDeployment().getProviderClasses().add(clazz.trim());
- }
- }
- }
-
- protected abstract ResteasyDeployment getDeployment();
-
- protected abstract void doStart(URL url);
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java
deleted file mode 100644
index 90747c9..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.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.rpc.protocol.rest;
-
-/**
- *
- */
-public interface Constants {
- String KEEP_ALIVE_KEY = "keepalive";
-
- boolean DEFAULT_KEEP_ALIVE = true;
-
- String EXTENSION_KEY = "extension";
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboHttpProtocolServer.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboHttpProtocolServer.java
deleted file mode 100644
index 1ab039a..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboHttpProtocolServer.java
+++ /dev/null
@@ -1,131 +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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.remoting.http.HttpBinder;
-import org.apache.dubbo.remoting.http.HttpHandler;
-import org.apache.dubbo.remoting.http.HttpServer;
-import org.apache.dubbo.remoting.http.servlet.BootstrapListener;
-import org.apache.dubbo.remoting.http.servlet.ServletManager;
-import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.rpc.RpcException;
-
-import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
-import org.jboss.resteasy.spi.ResteasyDeployment;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Enumeration;
-
-public class DubboHttpProtocolServer extends BaseRestProtocolServer {
-
- private final HttpServletDispatcher dispatcher = new HttpServletDispatcher();
- private final ResteasyDeployment deployment = new ResteasyDeployment();
- private HttpBinder httpBinder;
- private HttpServer httpServer;
-// private boolean isExternalServer;
-
- public DubboHttpProtocolServer(HttpBinder httpBinder) {
- this.httpBinder = httpBinder;
- }
-
- @Override
- protected void doStart(URL url) {
- // TODO jetty will by default enable keepAlive so the xml config has no effect now
- httpServer = httpBinder.bind(url, new RestHandler());
-
- ServletContext servletContext = ServletManager.getInstance().getServletContext(url.getPort());
- if (servletContext == null) {
- servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
- }
- if (servletContext == null) {
- throw new RpcException("No servlet context found. If you are using server='servlet', " +
- "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
- }
-
- servletContext.setAttribute(ResteasyDeployment.class.getName(), deployment);
-
- try {
- dispatcher.init(new SimpleServletConfig(servletContext));
- } catch (ServletException e) {
- throw new RpcException(e);
- }
- }
-
- @Override
- public void close() {
- httpServer.close();
- }
-
- @Override
- protected ResteasyDeployment getDeployment() {
- return deployment;
- }
-
- private class RestHandler implements HttpHandler {
-
- @Override
- public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
- dispatcher.service(request, response);
- }
- }
-
- private static class SimpleServletConfig implements ServletConfig {
-
- private final ServletContext servletContext;
-
- public SimpleServletConfig(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- @Override
- public String getServletName() {
- return "DispatcherServlet";
- }
-
- @Override
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- @Override
- public String getInitParameter(String s) {
- return null;
- }
-
- @Override
- public Enumeration getInitParameterNames() {
- return new Enumeration() {
- @Override
- public boolean hasMoreElements() {
- return false;
- }
-
- @Override
- public Object nextElement() {
- return null;
- }
- };
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboResourceFactory.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboResourceFactory.java
deleted file mode 100644
index 191102e..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/DubboResourceFactory.java
+++ /dev/null
@@ -1,76 +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.rpc.protocol.rest;
-
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.HttpResponse;
-import org.jboss.resteasy.spi.ResourceFactory;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
-/**
- * We don't support propertyInjector here since the resource impl should be singleton in dubbo
- *
- */
-public class DubboResourceFactory implements ResourceFactory {
-
- private Object resourceInstance;
- private Class scannableClass;
-// private PropertyInjector propertyInjector;
-// private String context = null;
-
- public DubboResourceFactory(Object resourceInstance, Class scannableClass) {
- this.resourceInstance = resourceInstance;
- this.scannableClass = scannableClass;
- }
-
-// public PropertyInjector getPropertyInjector() {
-// return propertyInjector;
-// }
-
- @Override
- public Object createResource(HttpRequest request, HttpResponse response,
- ResteasyProviderFactory factory) {
- return resourceInstance;
- }
-
- @Override
- public Class<?> getScannableClass() {
- return scannableClass;
- }
-
- @Override
- public void registered(ResteasyProviderFactory factory) {
-// this.propertyInjector = factory.getInjectorFactory().createPropertyInjector(getScannableClass(), factory);
- }
-
- @Override
- public void requestFinished(HttpRequest request, HttpResponse response,
- Object resource) {
- }
-
- @Override
- public void unregistered() {
- }
-
-// public void setContext(String context) {
-// this.context = context;
-// }
-//
-// public String getContext() {
-// return context;
-// }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyRestProtocolServer.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyRestProtocolServer.java
deleted file mode 100644
index b066c79..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyRestProtocolServer.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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-
-import io.netty.channel.ChannelOption;
-import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
-import org.jboss.resteasy.spi.ResteasyDeployment;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS;
-import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
-import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY;
-import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
-import static org.apache.dubbo.remoting.Constants.DEFAULT_IO_THREADS;
-import static org.apache.dubbo.remoting.Constants.DEFAULT_PAYLOAD;
-import static org.apache.dubbo.remoting.Constants.PAYLOAD_KEY;
-import static org.apache.dubbo.rpc.protocol.rest.Constants.DEFAULT_KEEP_ALIVE;
-import static org.apache.dubbo.rpc.protocol.rest.Constants.KEEP_ALIVE_KEY;
-
-/**
- * Netty server can't support @Context injection of servlet objects since it's not a servlet container
- *
- */
-public class NettyRestProtocolServer extends BaseRestProtocolServer {
-
- private final NettyJaxrsServer server = new NettyJaxrsServer();
-
- @Override
- protected void doStart(URL url) {
- String bindIp = url.getParameter(BIND_IP_KEY, url.getHost());
- if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) {
- server.setHostname(bindIp);
- }
- server.setPort(url.getParameter(BIND_PORT_KEY, url.getPort()));
- Map<ChannelOption, Object> channelOption = new HashMap<ChannelOption, Object>();
- channelOption.put(ChannelOption.SO_KEEPALIVE, url.getParameter(KEEP_ALIVE_KEY, DEFAULT_KEEP_ALIVE));
- server.setChildChannelOptions(channelOption);
- server.setExecutorThreadCount(url.getParameter(THREADS_KEY, DEFAULT_THREADS));
- server.setIoWorkerCount(url.getParameter(IO_THREADS_KEY, DEFAULT_IO_THREADS));
- server.setMaxRequestSize(url.getParameter(PAYLOAD_KEY, DEFAULT_PAYLOAD));
- server.start();
- }
-
- @Override
- public void close() {
- server.stop();
- }
-
- @Override
- protected ResteasyDeployment getDeployment() {
- return server.getDeployment();
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestConstraintViolation.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestConstraintViolation.java
deleted file mode 100644
index f229773..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestConstraintViolation.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.rpc.protocol.rest;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-
-@XmlRootElement(name = "constraintViolation")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class RestConstraintViolation implements Serializable {
-
- private static final long serialVersionUID = -23497234978L;
-
- private String path;
- private String message;
- private String value;
-
- public RestConstraintViolation(String path, String message, String value) {
- this.path = path;
- this.message = message;
- this.value = value;
- }
-
- public RestConstraintViolation() {
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
deleted file mode 100644
index 7e22132..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
+++ /dev/null
@@ -1,295 +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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.remoting.http.HttpBinder;
-import org.apache.dubbo.remoting.http.servlet.BootstrapListener;
-import org.apache.dubbo.remoting.http.servlet.ServletManager;
-import org.apache.dubbo.rpc.ProtocolServer;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
-
-import org.apache.http.HeaderElement;
-import org.apache.http.HeaderElementIterator;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.config.SocketConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.message.BasicHeaderElementIterator;
-import org.apache.http.protocol.HTTP;
-import org.jboss.resteasy.client.jaxrs.ResteasyClient;
-import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
-import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
-import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
-import org.jboss.resteasy.util.GetRestful;
-
-import javax.servlet.ServletContext;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.WebApplicationException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY;
-import static org.apache.dubbo.remoting.Constants.CONNECT_TIMEOUT_KEY;
-import static org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT;
-import static org.apache.dubbo.remoting.Constants.SERVER_KEY;
-import static org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY;
-
-public class RestProtocol extends AbstractProxyProtocol {
-
- private static final int DEFAULT_PORT = 80;
- private static final String DEFAULT_SERVER = "jetty";
-
- private static final int HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE = 20;
- private static final int HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL = 20;
- private static final int HTTPCLIENT_KEEPALIVEDURATION = 30 * 1000;
- private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS = 1000;
- private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S = 30;
-
- private final RestServerFactory serverFactory = new RestServerFactory();
-
- // TODO in the future maybe we can just use a single rest client and connection manager
- private final List<ResteasyClient> clients = Collections.synchronizedList(new LinkedList<>());
-
- private volatile ConnectionMonitor connectionMonitor;
-
- public RestProtocol() {
- super(WebApplicationException.class, ProcessingException.class);
- }
-
- public void setHttpBinder(HttpBinder httpBinder) {
- serverFactory.setHttpBinder(httpBinder);
- }
-
- @Override
- public int getDefaultPort() {
- return DEFAULT_PORT;
- }
-
- @Override
- protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
- String addr = getAddr(url);
- Class implClass = ApplicationModel.getProviderModel(url.getServiceKey()).getServiceInstance().getClass();
- RestProtocolServer server = (RestProtocolServer) serverMap.computeIfAbsent(addr, restServer -> {
- RestProtocolServer s = serverFactory.createServer(url.getParameter(SERVER_KEY, DEFAULT_SERVER));
- s.setAddress(url.getAddress());
- s.start(url);
- return s;
- });
-
- String contextPath = getContextPath(url);
- if ("servlet".equalsIgnoreCase(url.getParameter(SERVER_KEY, DEFAULT_SERVER))) {
- ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
- if (servletContext == null) {
- throw new RpcException("No servlet context found. Since you are using server='servlet', " +
- "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
- }
- String webappPath = servletContext.getContextPath();
- if (StringUtils.isNotEmpty(webappPath)) {
- webappPath = webappPath.substring(1);
- if (!contextPath.startsWith(webappPath)) {
- throw new RpcException("Since you are using server='servlet', " +
- "make sure that the 'contextpath' property starts with the path of external webapp");
- }
- contextPath = contextPath.substring(webappPath.length());
- if (contextPath.startsWith("/")) {
- contextPath = contextPath.substring(1);
- }
- }
- }
-
- final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
-
- server.deploy(resourceDef, impl, contextPath);
-
- final RestProtocolServer s = server;
- return () -> {
- // TODO due to dubbo's current architecture,
- // it will be called from registry protocol in the shutdown process and won't appear in logs
- s.undeploy(resourceDef);
- };
- }
-
- @Override
- protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
-
- // TODO more configs to add
- PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
- // 20 is the default maxTotal of current PoolingClientConnectionManager
- connectionManager.setMaxTotal(url.getParameter(CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL));
- connectionManager.setDefaultMaxPerRoute(url.getParameter(CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE));
-
- if (connectionMonitor == null) {
- connectionMonitor = new ConnectionMonitor();
- connectionMonitor.start();
- }
- connectionMonitor.addConnectionManager(connectionManager);
- RequestConfig requestConfig = RequestConfig.custom()
- .setConnectTimeout(url.getParameter(CONNECT_TIMEOUT_KEY, DEFAULT_CONNECT_TIMEOUT))
- .setSocketTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT))
- .build();
-
- SocketConfig socketConfig = SocketConfig.custom()
- .setSoKeepAlive(true)
- .setTcpNoDelay(true)
- .build();
-
- CloseableHttpClient httpClient = HttpClientBuilder.create()
- .setConnectionManager(connectionManager)
- .setKeepAliveStrategy((response, context) -> {
- HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
- while (it.hasNext()) {
- HeaderElement he = it.nextElement();
- String param = he.getName();
- String value = he.getValue();
- if (value != null && param.equalsIgnoreCase(TIMEOUT_KEY)) {
- return Long.parseLong(value) * 1000;
- }
- }
- return HTTPCLIENT_KEEPALIVEDURATION;
- })
- .setDefaultRequestConfig(requestConfig)
- .setDefaultSocketConfig(socketConfig)
- .build();
-
- ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);
-
- ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
- clients.add(client);
-
- client.register(RpcContextFilter.class);
- for (String clazz : COMMA_SPLIT_PATTERN.split(url.getParameter(EXTENSION_KEY, ""))) {
- if (!StringUtils.isEmpty(clazz)) {
- try {
- client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
- } catch (ClassNotFoundException e) {
- throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
- }
- }
- }
-
- // TODO protocol
- ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
- return target.proxy(serviceType);
- }
-
- @Override
- protected int getErrorCode(Throwable e) {
- // TODO
- return super.getErrorCode(e);
- }
-
- @Override
- public void destroy() {
- super.destroy();
-
- if (connectionMonitor != null) {
- connectionMonitor.shutdown();
- }
-
- for (Map.Entry<String, ProtocolServer> entry : serverMap.entrySet()) {
- try {
- if (logger.isInfoEnabled()) {
- logger.info("Closing the rest server at " + entry.getKey());
- }
- entry.getValue().close();
- } catch (Throwable t) {
- logger.warn("Error closing rest server", t);
- }
- }
- serverMap.clear();
-
- if (logger.isInfoEnabled()) {
- logger.info("Closing rest clients");
- }
- for (ResteasyClient client : clients) {
- try {
- client.close();
- } catch (Throwable t) {
- logger.warn("Error closing rest client", t);
- }
- }
- clients.clear();
- }
-
- /**
- * getPath() will return: [contextpath + "/" +] path
- * 1. contextpath is empty if user does not set through ProtocolConfig or ProviderConfig
- * 2. path will never be empty, it's default value is the interface name.
- *
- * @return return path only if user has explicitly gave then a value.
- */
- protected String getContextPath(URL url) {
- String contextPath = url.getPath();
- if (contextPath != null) {
- if (contextPath.equalsIgnoreCase(url.getParameter(INTERFACE_KEY))) {
- return "";
- }
- if (contextPath.endsWith(url.getParameter(INTERFACE_KEY))) {
- contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(INTERFACE_KEY)));
- }
- return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
- } else {
- return "";
- }
- }
-
- protected class ConnectionMonitor extends Thread {
- private volatile boolean shutdown;
- private final List<PoolingHttpClientConnectionManager> connectionManagers = Collections.synchronizedList(new LinkedList<>());
-
- public void addConnectionManager(PoolingHttpClientConnectionManager connectionManager) {
- connectionManagers.add(connectionManager);
- }
-
- @Override
- public void run() {
- try {
- while (!shutdown) {
- synchronized (this) {
- wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS);
- for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) {
- connectionManager.closeExpiredConnections();
- connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS);
- }
- }
- }
- } catch (InterruptedException ex) {
- shutdown();
- }
- }
-
- public void shutdown() {
- shutdown = true;
- connectionManagers.clear();
- synchronized (this) {
- notifyAll();
- }
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolServer.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolServer.java
deleted file mode 100644
index fe16f46..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolServer.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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.rpc.ProtocolServer;
-
-public interface RestProtocolServer extends ProtocolServer {
-
- void start(URL url);
-
- /**
- * @param resourceDef it could be either resource interface or resource impl
- */
- void deploy(Class resourceDef, Object resourceInstance, String contextPath);
-
- void undeploy(Class resourceDef);
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestServerFactory.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestServerFactory.java
deleted file mode 100644
index 6fcf7f6..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestServerFactory.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.rpc.protocol.rest;
-
-import org.apache.dubbo.remoting.http.HttpBinder;
-
-/**
- * Only the server that implements servlet container
- * could support something like @Context injection of servlet objects.
- *
- */
-public class RestServerFactory {
-
- private HttpBinder httpBinder;
-
- public void setHttpBinder(HttpBinder httpBinder) {
- this.httpBinder = httpBinder;
- }
-
- public RestProtocolServer createServer(String name) {
- // TODO move names to Constants
- if ("servlet".equalsIgnoreCase(name) || "jetty".equalsIgnoreCase(name) || "tomcat".equalsIgnoreCase(name)) {
- return new DubboHttpProtocolServer(httpBinder);
- } else if ("netty".equalsIgnoreCase(name)) {
- return new NettyRestProtocolServer();
- } else {
- throw new IllegalArgumentException("Unrecognized server name: " + name);
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcContextFilter.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcContextFilter.java
deleted file mode 100644
index 1711181..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcContextFilter.java
+++ /dev/null
@@ -1,106 +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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.rpc.RpcContext;
-
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
-import javax.annotation.Priority;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-
-@Priority(Integer.MIN_VALUE + 1)
-public class RpcContextFilter implements ContainerRequestFilter, ClientRequestFilter {
-
- private static final String DUBBO_ATTACHMENT_HEADER = "Dubbo-Attachments";
-
- // currently we use a single header to hold the attachments so that the total attachment size limit is about 8k
- private static final int MAX_HEADER_SIZE = 8 * 1024;
-
- @Override
- public void filter(ContainerRequestContext requestContext) throws IOException {
- HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
- RpcContext.getContext().setRequest(request);
-
- // this only works for servlet containers
- if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
- RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
- }
-
- RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));
-
- String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
- if (headers != null) {
- for (String header : headers.split(",")) {
- int index = header.indexOf("=");
- if (index > 0) {
- String key = header.substring(0, index);
- String value = header.substring(index + 1);
- if (!StringUtils.isEmpty(key)) {
- RpcContext.getContext().setAttachment(key.trim(), value.trim());
- }
- }
- }
- }
- }
-
- @Override
- public void filter(ClientRequestContext requestContext) throws IOException {
- int size = 0;
- for (Map.Entry<String, Object> entry : RpcContext.getContext().getObjectAttachments().entrySet()) {
- String key = entry.getKey();
- String value = (String) entry.getValue();
- if (illegalHttpHeaderKey(key) || illegalHttpHeaderValue(value)) {
- throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
- }
-
- // TODO for now we don't consider the differences of encoding and server limit
- if (value != null) {
- size += value.getBytes(StandardCharsets.UTF_8).length;
- }
- if (size > MAX_HEADER_SIZE) {
- throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " is too big");
- }
-
- String attachments = key + "=" + value;
- requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments);
- }
- }
-
- private boolean illegalHttpHeaderKey(String key) {
- if (StringUtils.isNotEmpty(key)) {
- return key.contains(",") || key.contains("=");
- }
- return false;
- }
-
- private boolean illegalHttpHeaderValue(String value) {
- if (StringUtils.isNotEmpty(value)) {
- return value.contains(",");
- }
- return false;
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapper.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapper.java
deleted file mode 100644
index e0fb782..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapper.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.rpc.protocol.rest;
-
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.rest.support.ContentType;
-
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-
-public class RpcExceptionMapper implements ExceptionMapper<RpcException> {
-
- @Override
- public Response toResponse(RpcException e) {
- // TODO do more sophisticated exception handling and output
- if (e.getCause() instanceof ConstraintViolationException) {
- return handleConstraintViolationException((ConstraintViolationException) e.getCause());
- }
- // we may want to avoid exposing the dubbo exception details to certain clients
- // TODO for now just do plain text output
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Internal server error: " + e.getMessage()).type(ContentType.TEXT_PLAIN_UTF_8).build();
- }
-
- protected Response handleConstraintViolationException(ConstraintViolationException cve) {
- ViolationReport report = new ViolationReport();
- for (ConstraintViolation cv : cve.getConstraintViolations()) {
- report.addConstraintViolation(new RestConstraintViolation(
- cv.getPropertyPath().toString(),
- cv.getMessage(),
- cv.getInvalidValue() == null ? "null" : cv.getInvalidValue().toString()));
- }
- // TODO for now just do xml output
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(report).type(ContentType.TEXT_XML_UTF_8).build();
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/ViolationReport.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/ViolationReport.java
deleted file mode 100644
index 1d53460..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/ViolationReport.java
+++ /dev/null
@@ -1,48 +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.rpc.protocol.rest;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-import java.util.LinkedList;
-import java.util.List;
-
-@XmlRootElement(name="violationReport")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class ViolationReport implements Serializable {
-
- private static final long serialVersionUID = -130498234L;
-
- private List<RestConstraintViolation> constraintViolations;
-
- public List<RestConstraintViolation> getConstraintViolations() {
- return constraintViolations;
- }
-
- public void setConstraintViolations(List<RestConstraintViolation> constraintViolations) {
- this.constraintViolations = constraintViolations;
- }
-
- public void addConstraintViolation(RestConstraintViolation constraintViolation) {
- if (constraintViolations == null) {
- constraintViolations = new LinkedList<RestConstraintViolation>();
- }
- constraintViolations.add(constraintViolation);
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResource.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResource.java
deleted file mode 100644
index 41b8ff5..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResource.java
+++ /dev/null
@@ -1,48 +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.rpc.protocol.rest.integration.swagger;
-
-import org.apache.dubbo.config.annotation.Service;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import io.swagger.jaxrs.listing.BaseApiListingResource;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-@Service
-public class DubboSwaggerApiListingResource extends BaseApiListingResource implements DubboSwaggerService {
-
- @Context
- ServletContext context;
-
- @Override
- public Response getListingJson(Application app, ServletConfig sc,
- HttpHeaders headers, UriInfo uriInfo) throws JsonProcessingException {
- Response response = getListingJsonResponse(app, context, sc, headers, uriInfo);
- response.getHeaders().add("Access-Control-Allow-Origin", "*");
- response.getHeaders().add("Access-Control-Allow-Headers", "x-requested-with, ssi-token");
- response.getHeaders().add("Access-Control-Max-Age", "3600");
- response.getHeaders().add("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS");
- return response;
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerService.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerService.java
deleted file mode 100644
index bc3eae8..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerService.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.rpc.protocol.rest.integration.swagger;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-import javax.servlet.ServletConfig;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-
-@Path("dubbo")
-@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
-@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8", MediaType.TEXT_XML + "; " + "charset=UTF-8"})
-public interface DubboSwaggerService {
-
- @GET
- @Path("swagger")
- Response getListingJson(@Context Application app, @Context ServletConfig sc,
- @Context HttpHeaders headers, @Context UriInfo uriInfo) throws JsonProcessingException;
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/ContentType.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/ContentType.java
deleted file mode 100644
index 1457966..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/ContentType.java
+++ /dev/null
@@ -1,26 +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.rpc.protocol.rest.support;
-
-import javax.ws.rs.core.MediaType;
-
-public class ContentType {
-
- public static final String APPLICATION_JSON_UTF_8 = MediaType.APPLICATION_JSON + "; " + MediaType.CHARSET_PARAMETER + "=UTF-8";
- public static final String TEXT_XML_UTF_8 = MediaType.TEXT_XML + "; " + MediaType.CHARSET_PARAMETER + "=UTF-8";
- public static final String TEXT_PLAIN_UTF_8 = MediaType.TEXT_PLAIN + "; " + MediaType.CHARSET_PARAMETER + "=UTF-8";
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/LoggingFilter.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/LoggingFilter.java
deleted file mode 100644
index 62c168e..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/support/LoggingFilter.java
+++ /dev/null
@@ -1,148 +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.rpc.protocol.rest.support;
-
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-
-import org.apache.commons.io.IOUtils;
-
-import javax.annotation.Priority;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
-import javax.ws.rs.client.ClientResponseContext;
-import javax.ws.rs.client.ClientResponseFilter;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.ReaderInterceptor;
-import javax.ws.rs.ext.ReaderInterceptorContext;
-import javax.ws.rs.ext.WriterInterceptor;
-import javax.ws.rs.ext.WriterInterceptorContext;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This logging filter is not highly optimized for now
- *
- */
-@Priority(Integer.MIN_VALUE)
-public class LoggingFilter implements ContainerRequestFilter, ClientRequestFilter, ContainerResponseFilter, ClientResponseFilter, WriterInterceptor, ReaderInterceptor {
-
- private static final Logger logger = LoggerFactory.getLogger(LoggingFilter.class);
-
- @Override
- public void filter(ClientRequestContext context) throws IOException {
- logHttpHeaders(context.getStringHeaders());
- }
-
- @Override
- public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
- logHttpHeaders(responseContext.getHeaders());
- }
-
- @Override
- public void filter(ContainerRequestContext context) throws IOException {
- logHttpHeaders(context.getHeaders());
- }
-
- @Override
- public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
- logHttpHeaders(responseContext.getStringHeaders());
- }
-
- @Override
- public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
- byte[] buffer = IOUtils.toByteArray(context.getInputStream());
- logger.info("The contents of request body is: \n" + new String(buffer, StandardCharsets.UTF_8) + "\n");
- context.setInputStream(new ByteArrayInputStream(buffer));
- return context.proceed();
- }
-
- @Override
- public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
- OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
- context.setOutputStream(wrapper);
- context.proceed();
- logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), StandardCharsets.UTF_8) + "\n");
- }
-
- protected void logHttpHeaders(MultivaluedMap<String, String> headers) {
- StringBuilder msg = new StringBuilder("The HTTP headers are: \n");
- for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
- msg.append(entry.getKey()).append(": ");
- for (int i = 0; i < entry.getValue().size(); i++) {
- msg.append(entry.getValue().get(i));
- if (i < entry.getValue().size() - 1) {
- msg.append(", ");
- }
- }
- msg.append("\n");
- }
- logger.info(msg.toString());
- }
-
- protected static class OutputStreamWrapper extends OutputStream {
-
- private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- private final OutputStream output;
-
- private OutputStreamWrapper(OutputStream output) {
- this.output = output;
- }
-
- @Override
- public void write(int i) throws IOException {
- buffer.write(i);
- output.write(i);
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- buffer.write(b);
- output.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- buffer.write(b, off, len);
- output.write(b, off, len);
- }
-
- @Override
- public void flush() throws IOException {
- output.flush();
- }
-
- @Override
- public void close() throws IOException {
- output.close();
- }
-
- public byte[] getBytes() {
- return buffer.toByteArray();
- }
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol b/dubbo-spi-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
deleted file mode 100644
index d492da9..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ /dev/null
@@ -1 +0,0 @@
-rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoService.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoService.java
deleted file mode 100644
index 78a132a..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoService.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.rpc.protocol.rest;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-
-@Path("/demoService")
-public interface DemoService {
- @GET
- @Path("/hello")
- Integer hello(@QueryParam("a") Integer a, @QueryParam("b") Integer b);
-
- @GET
- @Path("/error")
- String error();
-
- @POST
- @Path("/say")
- @Consumes({MediaType.TEXT_PLAIN})
- String sayHello(String name);
-
- @GET
- @Path("/getRemoteApplicationName")
- String getRemoteApplicationName();
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoServiceImpl.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoServiceImpl.java
deleted file mode 100644
index f7d3921..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/DemoServiceImpl.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.rpc.protocol.rest;
-
-
-import org.apache.dubbo.rpc.RpcContext;
-
-import java.util.Map;
-
-public class DemoServiceImpl implements DemoService {
- private static Map<String, Object> context;
- private boolean called;
-
- public String sayHello(String name) {
- called = true;
- return "Hello, " + name;
- }
-
-
- public boolean isCalled() {
- return called;
- }
-
- @Override
- public Integer hello(Integer a, Integer b) {
- context = RpcContext.getContext().getObjectAttachments();
- return a + b;
- }
-
- @Override
- public String error() {
- throw new RuntimeException();
- }
-
- public static Map<String, Object> getAttachments() {
- return context;
- }
-
- @Override
- public String getRemoteApplicationName() {
- return RpcContext.getContext().getRemoteApplicationName();
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java
deleted file mode 100644
index b07997f..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java
+++ /dev/null
@@ -1,282 +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.rpc.protocol.rest;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.rpc.Exporter;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Protocol;
-import org.apache.dubbo.rpc.ProxyFactory;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.RpcInvocation;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.model.ServiceDescriptor;
-import org.apache.dubbo.rpc.model.ServiceRepository;
-
-import org.hamcrest.CoreMatchers;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.util.Map;
-
-import static org.apache.dubbo.remoting.Constants.SERVER_KEY;
-import static org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class RestProtocolTest {
- private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("rest");
- private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- private final int availablePort = NetUtils.getAvailablePort();
- private final URL exportUrl = URL.valueOf("rest://127.0.0.1:" + availablePort + "/rest?interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
- private final ServiceRepository repository = ApplicationModel.getServiceRepository();
-
- @AfterEach
- public void tearDown() {
- protocol.destroy();
- }
-
- @Test
- public void testRestProtocol() {
- URL url = URL.valueOf("rest://127.0.0.1:" + NetUtils.getAvailablePort() + "/rest/say?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
- DemoServiceImpl server = new DemoServiceImpl();
-
- this.registerProvider(url, server, DemoService.class);
-
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url));
- Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
- Assertions.assertFalse(server.isCalled());
-
- DemoService client = proxy.getProxy(invoker);
- String result = client.sayHello("haha");
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testRestProtocolWithContextPath() {
- DemoServiceImpl server = new DemoServiceImpl();
- Assertions.assertFalse(server.isCalled());
- int port = NetUtils.getAvailablePort();
- URL url = URL.valueOf("rest://127.0.0.1:" + port + "/a/b/c?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
-
- this.registerProvider(url, server, DemoService.class);
-
- ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class);
- repository.registerProvider(
- url.getPathKey(),
- server,
- serviceDescriptor,
- null,
- null
- );
-
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url));
-
- url = URL.valueOf("rest://127.0.0.1:" + port + "/a/b/c/?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
- Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
- DemoService client = proxy.getProxy(invoker);
- String result = client.sayHello("haha");
- Assertions.assertTrue(server.isCalled());
- Assertions.assertEquals("Hello, haha", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- @Test
- public void testExport() {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- RpcContext.getContext().setAttachment("timeout", "200");
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, exportUrl));
-
- DemoService demoService = this.proxy.getProxy(protocol.refer(DemoService.class, exportUrl));
-
- Integer echoString = demoService.hello(1, 2);
- assertThat(echoString, is(3));
-
- exporter.unexport();
- }
-
- @Test
- public void testNettyServer() {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- URL nettyUrl = exportUrl.addParameter(SERVER_KEY, "netty");
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(new DemoServiceImpl(), DemoService.class, nettyUrl));
-
- DemoService demoService = this.proxy.getProxy(protocol.refer(DemoService.class, nettyUrl));
-
- Integer echoString = demoService.hello(10, 10);
- assertThat(echoString, is(20));
-
- exporter.unexport();
- }
-
- @Test
- public void testServletWithoutWebConfig() {
- Assertions.assertThrows(RpcException.class, () -> {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- URL servletUrl = exportUrl.addParameter(SERVER_KEY, "servlet");
-
- protocol.export(proxy.getInvoker(server, DemoService.class, servletUrl));
- });
- }
-
- @Test
- public void testErrorHandler() {
- Assertions.assertThrows(RpcException.class, () -> {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- URL nettyUrl = exportUrl.addParameter(SERVER_KEY, "netty");
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, nettyUrl));
-
- DemoService demoService = this.proxy.getProxy(protocol.refer(DemoService.class, nettyUrl));
-
- demoService.error();
- });
- }
-
- @Test
- public void testInvoke() {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, exportUrl));
-
- RpcInvocation rpcInvocation = new RpcInvocation("hello", DemoService.class.getName(), new Class[]{Integer.class, Integer.class}, new Integer[]{2, 3});
-
- Result result = exporter.getInvoker().invoke(rpcInvocation);
- assertThat(result.getValue(), CoreMatchers.<Object>is(5));
- }
-
- @Test
- public void testFilter() {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- URL nettyUrl = exportUrl.addParameter(SERVER_KEY, "netty")
- .addParameter(EXTENSION_KEY, "org.apache.dubbo.rpc.protocol.rest.support.LoggingFilter");
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, nettyUrl));
-
- DemoService demoService = this.proxy.getProxy(protocol.refer(DemoService.class, nettyUrl));
-
- Integer result = demoService.hello(1, 2);
-
- assertThat(result, is(3));
-
- exporter.unexport();
- }
-
- @Test
- public void testRpcContextFilter() {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- // use RpcContextFilter
- URL nettyUrl = exportUrl.addParameter(SERVER_KEY, "netty")
- .addParameter(EXTENSION_KEY, "org.apache.dubbo.rpc.protocol.rest.RpcContextFilter");
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, nettyUrl));
-
- DemoService demoService = this.proxy.getProxy(protocol.refer(DemoService.class, nettyUrl));
-
- // make sure null and base64 encoded string can work
- RpcContext.getContext().setAttachment("key1", null);
- RpcContext.getContext().setAttachment("key2", "value");
- RpcContext.getContext().setAttachment("key3", "=value");
- RpcContext.getContext().setAttachment("key4", "YWJjZGVmCg==");
- RpcContext.getContext().setAttachment("key5", "val=ue");
- Integer result = demoService.hello(1, 2);
-
- assertThat(result, is(3));
-
- Map<String, Object> attachment = DemoServiceImpl.getAttachments();
- assertThat(attachment.get("key1"), nullValue());
- assertThat(attachment.get("key2"), equalTo("value"));
- assertThat(attachment.get("key3"), equalTo("=value"));
- assertThat(attachment.get("key4"), equalTo("YWJjZGVmCg=="));
- assertThat(attachment.get("key5"), equalTo("val=ue"));
-
- exporter.unexport();
- }
-
- @Test
- public void testRegFail() {
- Assertions.assertThrows(RuntimeException.class, () -> {
- DemoService server = new DemoServiceImpl();
-
- this.registerProvider(exportUrl, server, DemoService.class);
-
- URL nettyUrl = exportUrl.addParameter(EXTENSION_KEY, "com.not.existing.Filter");
- protocol.export(proxy.getInvoker(server, DemoService.class, nettyUrl));
- });
- }
-
- @Test
- public void testDefaultPort() {
- assertThat(protocol.getDefaultPort(), is(80));
- }
-
- @Test
- public void testRemoteApplicationName() {
- URL url = URL.valueOf("rest://127.0.0.1:" + NetUtils.getAvailablePort() + "/rest/say?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService").addParameter("application", "consumer");
- DemoServiceImpl server = new DemoServiceImpl();
-
- this.registerProvider(url, server, DemoService.class);
-
- Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url));
- Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
-
- DemoService client = proxy.getProxy(invoker);
- String result = client.getRemoteApplicationName();
- Assertions.assertEquals("consumer", result);
- invoker.destroy();
- exporter.unexport();
- }
-
- private void registerProvider(URL url, Object impl, Class<?> interfaceClass) {
- ServiceDescriptor serviceDescriptor = repository.registerService(interfaceClass);
- repository.registerProvider(
- url.getServiceKey(),
- impl,
- serviceDescriptor,
- null,
- null
- );
- }
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapperTest.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapperTest.java
deleted file mode 100644
index 74a133a..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RpcExceptionMapperTest.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.rpc.protocol.rest;
-
-import org.apache.dubbo.rpc.RpcException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Answers;
-import org.mockito.internal.util.collections.Sets;
-
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.ws.rs.core.Response;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-public class RpcExceptionMapperTest {
-
- private RpcExceptionMapper exceptionMapper;
-
- @BeforeEach
- public void setUp() {
- this.exceptionMapper = new RpcExceptionMapper();
- }
-
- @Test
- public void testConstraintViolationException() {
- ConstraintViolationException violationException = mock(ConstraintViolationException.class);
- ConstraintViolation violation = mock(ConstraintViolation.class, Answers.RETURNS_DEEP_STUBS);
- given(violationException.getConstraintViolations()).willReturn(Sets.<ConstraintViolation<?>>newSet(violation));
- RpcException rpcException = new RpcException("violation", violationException);
-
- Response response = exceptionMapper.toResponse(rpcException);
-
- assertThat(response, not(nullValue()));
- assertThat(response.getEntity(), instanceOf(ViolationReport.class));
- }
-
- @Test
- public void testNormalException() {
- RpcException rpcException = new RpcException();
- Response response = exceptionMapper.toResponse(rpcException);
-
-
- assertThat(response, not(nullValue()));
- assertThat(response.getEntity(), instanceOf(String.class));
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java
deleted file mode 100644
index 565ddf7..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.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.rpc.protocol.rest.integration.swagger;
-
-import io.swagger.models.Swagger;
-import org.jboss.resteasy.spi.ResteasyUriInfo;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
-import java.net.URI;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DubboSwaggerApiListingResourceTest {
-
- private Application app;
- private ServletConfig sc;
-
- @Test
- public void test() throws Exception {
-
- DubboSwaggerApiListingResource resource = new DubboSwaggerApiListingResource();
-
- app = mock(Application.class);
- sc = mock(ServletConfig.class);
- Set<Class<?>> sets = new HashSet<Class<?>>();
- sets.add(SwaggerService.class);
-
- when(sc.getServletContext()).thenReturn(mock(ServletContext.class));
- when(app.getClasses()).thenReturn(sets);
-
- Response response = resource.getListingJson(app, sc,
- null, new ResteasyUriInfo(new URI("http://rest.test")));
-
- Assertions.assertNotNull(response);
- Swagger swagger = (Swagger)response.getEntity();
- Assertions.assertEquals("SwaggerService",swagger.getTags().get(0).getName());
- Assertions.assertEquals("/demoService/hello",swagger.getPaths().keySet().toArray()[0].toString());
- }
-
-}
diff --git a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/SwaggerService.java b/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/SwaggerService.java
deleted file mode 100644
index 8c00af4..0000000
--- a/dubbo-spi-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/SwaggerService.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.rpc.protocol.rest.integration.swagger;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
-
-@Path("/demoService")
-@Api(value = "SwaggerService")
-public interface SwaggerService {
- @GET
- @Path("/hello")
- @ApiOperation(value = "hello")
- Integer hello(@QueryParam("a") Integer a, @QueryParam("b") Integer b);
-
-}
diff --git a/dubbo-spi-rpc/pom.xml b/dubbo-spi-rpc/pom.xml
index 076bf30..0641187 100644
--- a/dubbo-spi-rpc/pom.xml
+++ b/dubbo-spi-rpc/pom.xml
@@ -29,7 +29,6 @@
<skip_maven_deploy>true</skip_maven_deploy>
</properties>
<modules>
- <module>dubbo-rpc-injvm</module>
<module>dubbo-rpc-http</module>
<module>dubbo-rpc-rmi</module>
<module>dubbo-rpc-hessian</module>
@@ -38,8 +37,6 @@
<module>dubbo-rpc-thrift</module>
<module>dubbo-rpc-memcached</module>
<module>dubbo-rpc-redis</module>
- <module>dubbo-rpc-rest</module>
<module>dubbo-rpc-xml</module>
- <module>dubbo-rpc-grpc</module>
</modules>
</project>