Skip to content

Commit

Permalink
Refine
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Nov 30, 2024
1 parent 69fe8bb commit a289a60
Show file tree
Hide file tree
Showing 107 changed files with 4,106 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ dubbo-xds
dubbo-plugin-loom
dubbo-rest-jaxrs
dubbo-rest-spring
dubbo-rest-swagger
dubbo-rest-openapi
dubbo-triple-servlet
dubbo-triple-websocket
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,11 @@ This product contains a modified portion of 'Istio', an open platform to connect
under a "Apache License 2.0" license, see https://github.com/istio/api/blob/master/LICENSE:

* security/v1alpha1/ca.proto

For the file dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/swagger-ui/index.html:

Under a "Apache License 2.0" license, see https://github.com/swagger-api/swagger-ui/blob/master/LICENSE

For the file dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/redoc/index.html:

Under a "MIT License" license, see https://github.com/Redocly/redoc/blob/main/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ default <T> T getDefaultExtension(Class<T> type) {
return extensionLoader != null ? extensionLoader.getDefaultExtension() : null;
}

default <T> T getDefaultExtensionOrNull(Class<T> type) {
ExtensionLoader<T> extensionLoader = getExtensionLoader(type);
if (extensionLoader == null) {
return null;
}
return extensionLoader.getExtension(extensionLoader.getDefaultExtensionName(), true);
}

default <T> List<T> getActivateExtensions(Class<T> type) {
ExtensionLoader<T> extensionLoader = getExtensionLoader(type);
return extensionLoader != null ? extensionLoader.getActivateExtensions() : Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ public class RestConfig implements Serializable {
public static final boolean DEFAULT_CASE_SENSITIVE_MATCH = true;
public static final String DEFAULT_FORMAT_PARAMETER_NAME = "format";

/**
* Whether to enable rest support
* <p>The default value is 'true'.
*/
private Boolean enabled;

/**
* Whether to enable the default mapping '/{interfaceName}/{methodName}'.
* <p>The default value is 'true'.
*/
private Boolean enableDefaultMapping;

/**
* Whether path matching should be match paths with a trailing slash.
* If enabled, a method mapped to "/users" also matches to "/users/".
Expand Down Expand Up @@ -90,6 +102,22 @@ public class RestConfig implements Serializable {
*/
private Map<String, OpenAPIConfig> openapis;

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public Boolean getEnableDefaultMapping() {
return enableDefaultMapping;
}

public void setEnableDefaultMapping(Boolean enableDefaultMapping) {
this.enableDefaultMapping = enableDefaultMapping;
}

public Boolean getTrailingSlashMatch() {
return trailingSlashMatch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<artifactId>dubbo-registry-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-qos</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-triple</artifactId>
Expand All @@ -54,7 +59,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-swagger</artifactId>
<artifactId>dubbo-rest-openapi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
7 changes: 5 additions & 2 deletions dubbo-distribution/dubbo-all-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-swagger</artifactId>
<artifactId>dubbo-rest-openapi</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
Expand Down Expand Up @@ -531,7 +531,7 @@
<include>org.apache.dubbo:dubbo-rpc-triple</include>
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-rest-swagger</include>
<include>org.apache.dubbo:dubbo-rest-openapi</include>
<include>org.apache.dubbo:dubbo-triple-servlet</include>
<include>org.apache.dubbo:dubbo-triple-websocket</include>
<include>org.apache.dubbo:dubbo-serialization-api</include>
Expand Down Expand Up @@ -889,6 +889,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension</resource>
</transformer>
Expand Down
7 changes: 5 additions & 2 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-swagger</artifactId>
<artifactId>dubbo-rest-openapi</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
Expand Down Expand Up @@ -530,7 +530,7 @@
<include>org.apache.dubbo:dubbo-rpc-triple</include>
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-rest-swagger</include>
<include>org.apache.dubbo:dubbo-rest-openapi</include>
<include>org.apache.dubbo:dubbo-triple-servlet</include>
<include>org.apache.dubbo:dubbo-triple-websocket</include>
<include>org.apache.dubbo:dubbo-serialization-api</include>
Expand Down Expand Up @@ -887,6 +887,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension</resource>
</transformer>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-distribution/dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rest-swagger</artifactId>
<artifactId>dubbo-rest-openapi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
3 changes: 3 additions & 0 deletions dubbo-distribution/dubbo-core-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension</resource>
</transformer>
Expand Down
13 changes: 13 additions & 0 deletions dubbo-metadata/dubbo-metadata-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
Expand All @@ -81,4 +85,13 @@
<version>${project.parent.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- <plugin>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-maven-plugin</artifactId>
</plugin>-->
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static MetadataServiceV2 newStub(Invoker<?> invoker) {
return new MetadataServiceV2Stub((Invoker<MetadataServiceV2>) invoker);
}

/**
* <pre>
* Retrieves metadata information.
* </pre>
*/
private static final StubMethodDescriptor getMetadataInfoMethod = new StubMethodDescriptor(
"GetMetadataInfo",
MetadataRequest.class,
Expand Down Expand Up @@ -91,10 +96,46 @@ public static MetadataServiceV2 newStub(Invoker<?> invoker) {
obj -> ((Message) obj).toByteArray(),
MetadataRequest::parseFrom,
MetadataInfoV2::parseFrom);
/**
* <pre>
* Retrieves OpenAPI.
* </pre>
*/
private static final StubMethodDescriptor getOpenAPIMethod = new StubMethodDescriptor(
"GetOpenAPI",
OpenAPIRequest.class,
OpenAPI.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
OpenAPIRequest::parseFrom,
OpenAPI::parseFrom);

private static final StubMethodDescriptor getOpenAPIAsyncMethod = new StubMethodDescriptor(
"GetOpenAPI",
OpenAPIRequest.class,
CompletableFuture.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
OpenAPIRequest::parseFrom,
OpenAPI::parseFrom);

private static final StubMethodDescriptor getOpenAPIProxyAsyncMethod = new StubMethodDescriptor(
"GetOpenAPIAsync",
OpenAPIRequest.class,
OpenAPI.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
OpenAPIRequest::parseFrom,
OpenAPI::parseFrom);

static {
serviceDescriptor.addMethod(getMetadataInfoMethod);
serviceDescriptor.addMethod(getMetadataInfoProxyAsyncMethod);
serviceDescriptor.addMethod(getOpenAPIMethod);
serviceDescriptor.addMethod(getOpenAPIProxyAsyncMethod);
}

public static class MetadataServiceV2Stub implements MetadataServiceV2, Destroyable {
Expand All @@ -109,6 +150,11 @@ public MetadataServiceV2Stub(Invoker<MetadataServiceV2> invoker) {
invoker.destroy();
}

/**
* <pre>
* Retrieves metadata information.
* </pre>
*/
@Override
public MetadataInfoV2 getMetadataInfo(MetadataRequest request) {
return StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request);
Expand All @@ -118,9 +164,37 @@ public CompletableFuture<MetadataInfoV2> getMetadataInfoAsync(MetadataRequest re
return StubInvocationUtil.unaryCall(invoker, getMetadataInfoAsyncMethod, request);
}

/**
* <pre>
* Retrieves metadata information.
* </pre>
*/
public void getMetadataInfo(MetadataRequest request, StreamObserver<MetadataInfoV2> responseObserver) {
StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request, responseObserver);
}

/**
* <pre>
* Retrieves OpenAPI.
* </pre>
*/
@Override
public OpenAPI getOpenAPI(OpenAPIRequest request) {
return StubInvocationUtil.unaryCall(invoker, getOpenAPIMethod, request);
}

public CompletableFuture<OpenAPI> getOpenAPIAsync(OpenAPIRequest request) {
return StubInvocationUtil.unaryCall(invoker, getOpenAPIAsyncMethod, request);
}

/**
* <pre>
* Retrieves OpenAPI.
* </pre>
*/
public void getOpenAPI(OpenAPIRequest request, StreamObserver<OpenAPI> responseObserver) {
StubInvocationUtil.unaryCall(invoker, getOpenAPIMethod, request, responseObserver);
}
}

public abstract static class MetadataServiceV2ImplBase
Expand All @@ -146,6 +220,11 @@ public CompletableFuture<MetadataInfoV2> getMetadataInfoAsync(MetadataRequest re
return CompletableFuture.completedFuture(getMetadataInfo(request));
}

@Override
public CompletableFuture<OpenAPI> getOpenAPIAsync(OpenAPIRequest request) {
return CompletableFuture.completedFuture(getOpenAPI(request));
}

/**
* This server stream type unary method is <b>only</b> used for generated stub to support async unary method.
* It will not be called if you are NOT using Dubbo3 generated triple stub and <b>DO NOT</b> implement this method.
Expand All @@ -161,6 +240,17 @@ public void getMetadataInfo(MetadataRequest request, StreamObserver<MetadataInfo
});
}

public void getOpenAPI(OpenAPIRequest request, StreamObserver<OpenAPI> responseObserver) {
getOpenAPIAsync(request).whenComplete((r, t) -> {
if (t != null) {
responseObserver.onError(t);
} else {
responseObserver.onNext(r);
responseObserver.onCompleted();
}
});
}

@Override
public final Invoker<MetadataServiceV2> getInvoker(URL url) {
PathResolver pathResolver = url.getOrDefaultFrameworkModel()
Expand All @@ -174,13 +264,23 @@ public final Invoker<MetadataServiceV2> getInvoker(URL url) {
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfo");
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfoAsync");

pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetOpenAPI");
pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetOpenAPIAsync");
// for compatibility
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetOpenAPI");
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetOpenAPIAsync");

BiConsumer<MetadataRequest, StreamObserver<MetadataInfoV2>> getMetadataInfoFunc = this::getMetadataInfo;
handlers.put(getMetadataInfoMethod.getMethodName(), new UnaryStubMethodHandler<>(getMetadataInfoFunc));
BiConsumer<MetadataRequest, StreamObserver<MetadataInfoV2>> getMetadataInfoAsyncFunc =
syncToAsync(this::getMetadataInfo);
handlers.put(
getMetadataInfoProxyAsyncMethod.getMethodName(),
new UnaryStubMethodHandler<>(getMetadataInfoAsyncFunc));
BiConsumer<OpenAPIRequest, StreamObserver<OpenAPI>> getOpenAPIFunc = this::getOpenAPI;
handlers.put(getOpenAPIMethod.getMethodName(), new UnaryStubMethodHandler<>(getOpenAPIFunc));
BiConsumer<OpenAPIRequest, StreamObserver<OpenAPI>> getOpenAPIAsyncFunc = syncToAsync(this::getOpenAPI);
handlers.put(getOpenAPIProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getOpenAPIAsyncFunc));

return new StubInvoker<>(this, url, MetadataServiceV2.class, handlers);
}
Expand All @@ -190,6 +290,11 @@ public MetadataInfoV2 getMetadataInfo(MetadataRequest request) {
throw unimplementedMethodException(getMetadataInfoMethod);
}

@Override
public OpenAPI getOpenAPI(OpenAPIRequest request) {
throw unimplementedMethodException(getOpenAPIMethod);
}

@Override
public final ServiceDescriptor getServiceDescriptor() {
return serviceDescriptor;
Expand Down
Loading

0 comments on commit a289a60

Please sign in to comment.