Skip to content

Commit 7e5394f

Browse files
committed
Rest override support
1 parent e5f93f2 commit 7e5394f

File tree

28 files changed

+466
-465
lines changed

28 files changed

+466
-465
lines changed

.github/workflows/build-and-test-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ jobs:
326326
cd test && bash ./build-test-image.sh
327327
- name: "Run tests"
328328
run: cd test && bash ./run-tests.sh
329-
- name: "merge jacoco resule"
329+
- name: "merge jacoco result"
330330
run: |
331331
cd test/dubbo-test-jacoco-merger && mvn clean compile exec:java -Dexec.mainClass="org.apache.dubbo.test.JacocoMerge" -Dexec.args="${{github.workspace}}"
332332
- name: "Upload jacoco"

dubbo-demo/dubbo-demo-spring-boot/dubbo-demo-spring-boot-provider/src/main/resources/application.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dubbo:
2424
qos-enable: false
2525
protocol:
2626
name: tri
27-
port: ${server.port}
27+
port: -1
28+
#port: ${server.port}
2829
triple:
2930
servlet:
3031
enable: true

dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java

Lines changed: 0 additions & 128 deletions
This file was deleted.

dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/Annotations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public enum Annotations implements AnnotationEnum {
3434
ResponseStatus,
3535
CrossOrigin,
3636
ExceptionHandler,
37+
HttpExchange("org.springframework.web.service.annotation.HttpExchange"),
3738
Nonnull("javax.annotation.Nonnull");
3839

3940
private final String className;

dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,49 @@ public RestToolKit getRestToolKit() {
6262
@Override
6363
public RequestMapping resolve(ServiceMeta serviceMeta) {
6464
AnnotationMeta<?> requestMapping = serviceMeta.findMergedAnnotation(Annotations.RequestMapping);
65-
if (requestMapping == null) {
65+
AnnotationMeta<?> httpExchange = serviceMeta.findMergedAnnotation(Annotations.HttpExchange);
66+
if (requestMapping == null && httpExchange == null) {
6667
return null;
6768
}
68-
AnnotationMeta<?> responseStatus = serviceMeta.findMergedAnnotation(Annotations.ResponseStatus);
69-
AnnotationMeta<?> crossOrigin = serviceMeta.findMergedAnnotation(Annotations.CrossOrigin);
70-
String[] methods = requestMapping.getStringArray("method");
71-
return builder(requestMapping, responseStatus)
69+
70+
String[] methods = requestMapping == null
71+
? httpExchange.getStringArray("method")
72+
: requestMapping.getStringArray("method");
73+
return builder(requestMapping, httpExchange, serviceMeta.findMergedAnnotation(Annotations.ResponseStatus))
7274
.method(methods)
7375
.name(serviceMeta.getType().getSimpleName())
7476
.contextPath(serviceMeta.getContextPath())
75-
.cors(buildCorsMeta(crossOrigin, methods))
77+
.cors(buildCorsMeta(serviceMeta.findMergedAnnotation(Annotations.CrossOrigin), methods))
7678
.build();
7779
}
7880

7981
@Override
8082
public RequestMapping resolve(MethodMeta methodMeta) {
8183
AnnotationMeta<?> requestMapping = methodMeta.findMergedAnnotation(Annotations.RequestMapping);
82-
if (requestMapping == null) {
84+
AnnotationMeta<?> httpExchange = methodMeta.findMergedAnnotation(Annotations.HttpExchange);
85+
if (requestMapping == null && httpExchange == null) {
8386
AnnotationMeta<?> exceptionHandler = methodMeta.getAnnotation(Annotations.ExceptionHandler);
8487
if (exceptionHandler != null) {
8588
methodMeta.getServiceMeta().addExceptionHandler(methodMeta);
8689
}
8790
return null;
8891
}
92+
8993
ServiceMeta serviceMeta = methodMeta.getServiceMeta();
90-
AnnotationMeta<?> responseStatus = methodMeta.findMergedAnnotation(Annotations.ResponseStatus);
91-
AnnotationMeta<?> crossOrigin = methodMeta.findMergedAnnotation(Annotations.CrossOrigin);
92-
String[] methods = requestMapping.getStringArray("method");
93-
return builder(requestMapping, responseStatus)
94+
String[] methods = requestMapping == null
95+
? httpExchange.getStringArray("method")
96+
: requestMapping.getStringArray("method");
97+
return builder(requestMapping, httpExchange, methodMeta.findMergedAnnotation(Annotations.ResponseStatus))
9498
.method(methods)
9599
.name(methodMeta.getMethod().getName())
96100
.contextPath(serviceMeta.getContextPath())
97101
.custom(new ServiceVersionCondition(serviceMeta.getServiceGroup(), serviceMeta.getServiceVersion()))
98-
.cors(buildCorsMeta(crossOrigin, methods))
102+
.cors(buildCorsMeta(methodMeta.findMergedAnnotation(Annotations.CrossOrigin), methods))
99103
.build();
100104
}
101105

102-
private Builder builder(AnnotationMeta<?> requestMapping, AnnotationMeta<?> responseStatus) {
106+
private Builder builder(
107+
AnnotationMeta<?> requestMapping, AnnotationMeta<?> httpExchange, AnnotationMeta<?> responseStatus) {
103108
Builder builder = RequestMapping.builder();
104109
if (responseStatus != null) {
105110
HttpStatus value = responseStatus.getEnum("value");
@@ -109,6 +114,11 @@ private Builder builder(AnnotationMeta<?> requestMapping, AnnotationMeta<?> resp
109114
builder.responseReason(reason);
110115
}
111116
}
117+
if (requestMapping == null) {
118+
return builder.path(httpExchange.getValueArray())
119+
.consume(httpExchange.getStringArray("contentType"))
120+
.produce(httpExchange.getStringArray("accept"));
121+
}
112122
return builder.path(requestMapping.getValueArray())
113123
.param(requestMapping.getStringArray("params"))
114124
.header(requestMapping.getStringArray("headers"))

0 commit comments

Comments
 (0)