Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][3.3] Triple rest useTrailingSlashMatch useSuffixPatternMatch support #14036 #14105

Closed
wants to merge 11 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.config.utils;

import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
Expand All @@ -31,10 +30,7 @@
import org.mockito.Mockito;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

class ConfigValidationUtilsTest {

Expand Down Expand Up @@ -102,22 +98,6 @@ void testValidateApplicationConfig() throws Exception {
}
}

@Test
void testCheckQosInApplicationConfig() throws Exception {
ConfigValidationUtils mock = Mockito.mock(ConfigValidationUtils.class);
ErrorTypeAwareLogger loggerMock = Mockito.mock(ErrorTypeAwareLogger.class);
injectField(mock.getClass().getDeclaredField("logger"), loggerMock);
ApplicationConfig config = new ApplicationConfig();
config.setName("testName");
config.setQosEnable(false);
mock.validateApplicationConfig(config);
verify(loggerMock, never()).warn(any(), any(Throwable.class));

config.setQosEnable(true);
mock.validateApplicationConfig(config);
verify(loggerMock).info(anyString());
}

private void injectField(Field field, Object newValue) throws Exception {
field.setAccessible(true);
field.set(null, newValue);
Expand Down
12 changes: 12 additions & 0 deletions dubbo-rpc/dubbo-rpc-triple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.3.0-beta.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.7.18</version>
<scope>compile</scope>
</dependency>
Comment on lines +110 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add these dependencies?

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.protocol.tri.rest.mapping;

import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.config.RestConfig;
import org.apache.dubbo.remoting.http12.HttpRequest;
import org.apache.dubbo.remoting.http12.message.MethodMetadata;
import org.apache.dubbo.rpc.Invoker;
Expand Down Expand Up @@ -48,8 +49,8 @@

public final class DefaultRequestMappingRegistry implements RequestMappingRegistry {

private RestConfig restConfig;
private final List<RequestMappingResolver> resolvers;

private final RadixTree<Registration> tree = new RadixTree<>();
private final ReadWriteLock lock = new ReentrantReadWriteLock();

Expand Down Expand Up @@ -79,6 +80,34 @@ public void register(Invoker<?> invoker) {
methodMapping = classMapping.combine(methodMapping);
}
register0(methodMapping, buildHandlerMeta(invoker, methodMeta));
// UseSuffixPatternMatch
if (restConfig != null
&& restConfig.getSuffixPatternMatch()
&& !invoker.getUrl().getPath().contains(".")) {
String newPath = invoker.getUrl().getPath() + ".*";
RequestMapping suffixMapping = new RequestMapping.Builder()
.name(methodMapping.getName() + "-suffix")
.path(newPath)
.build();
if (classMapping != null) {
suffixMapping = classMapping.combine(suffixMapping);
}
register0(suffixMapping, buildHandlerMeta(invoker, methodMeta));
}
// UseTrailingSlashMatch
if (restConfig != null
&& restConfig.getTrailingSlashMatch()
&& !invoker.getUrl().getPath().endsWith("/")) {
String newPath = invoker.getUrl().getPath() + "/";
RequestMapping trailingSlashMapping = new RequestMapping.Builder()
.name(methodMapping.getName() + "-trailingSlash")
.path(newPath)
.build();
if (classMapping != null) {
trailingSlashMapping = classMapping.combine(trailingSlashMapping);
}
register0(trailingSlashMapping, buildHandlerMeta(invoker, methodMeta));
}
});
}
});
Expand Down Expand Up @@ -206,6 +235,10 @@ public HandlerMeta lookup(HttpRequest request) {
return handler;
}

public void setRestConfig(RestConfig restConfig) {
this.restConfig = restConfig;
}

private static final class Registration {
RequestMapping mapping;
HandlerMeta meta;
Expand Down
Loading