From 02846491e0b19e610c8fa93ba953eace1277f213 Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Mon, 26 Aug 2024 09:44:59 +0800 Subject: [PATCH 1/6] Tripe demo with dubbo-maven-plugin (#14572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “JermaineHua” --- dubbo-demo/dubbo-demo-triple/pom.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dubbo-demo/dubbo-demo-triple/pom.xml b/dubbo-demo/dubbo-demo-triple/pom.xml index 8d81d57de2a..8fa55a99fbe 100644 --- a/dubbo-demo/dubbo-demo-triple/pom.xml +++ b/dubbo-demo/dubbo-demo-triple/pom.xml @@ -158,13 +158,9 @@ - org.xolstice.maven.plugins - protobuf-maven-plugin - ${maven_protobuf_plugin_version} - - com.google.protobuf:protoc:${protobuf-protoc_version}:exe:${os.detected.classifier} - triple-java - + org.apache.dubbo + dubbo-maven-plugin + ${project.version} From 8467329b9ea98f39b8f3c8462f1e6d735619a428 Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Mon, 26 Aug 2024 09:45:20 +0800 Subject: [PATCH 2/6] Native support generic service (#14573) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “JermaineHua” --- .../ReferenceAnnotationWithAotBeanPostProcessor.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dubbo-config/dubbo-config-spring6/src/main/java/org/apache/dubbo/config/spring6/beans/factory/annotation/ReferenceAnnotationWithAotBeanPostProcessor.java b/dubbo-config/dubbo-config-spring6/src/main/java/org/apache/dubbo/config/spring6/beans/factory/annotation/ReferenceAnnotationWithAotBeanPostProcessor.java index ca3435eb9ab..971e010e418 100644 --- a/dubbo-config/dubbo-config-spring6/src/main/java/org/apache/dubbo/config/spring6/beans/factory/annotation/ReferenceAnnotationWithAotBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring6/src/main/java/org/apache/dubbo/config/spring6/beans/factory/annotation/ReferenceAnnotationWithAotBeanPostProcessor.java @@ -29,6 +29,7 @@ import org.apache.dubbo.config.spring6.utils.AotUtils; import org.apache.dubbo.rpc.service.Destroyable; import org.apache.dubbo.rpc.service.EchoService; +import org.apache.dubbo.rpc.service.GenericService; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -237,19 +238,19 @@ private CodeBlock generateMethodCode(ClassName targetClassName, RuntimeHints hin CodeBlock.Builder code = CodeBlock.builder(); if (!CollectionUtils.isEmpty(this.annotatedInjectionMetadata.getFieldElements())) { for (AnnotatedInjectElement referenceElement : this.annotatedInjectionMetadata.getFieldElements()) { - code.addStatement(generateMethodStatementForElement(targetClassName, referenceElement, hints)); + code.addStatement(generateStatementForElement(targetClassName, referenceElement, hints)); } } if (!CollectionUtils.isEmpty(this.annotatedInjectionMetadata.getMethodElements())) { for (AnnotatedInjectElement referenceElement : this.annotatedInjectionMetadata.getMethodElements()) { - code.addStatement(generateMethodStatementForElement(targetClassName, referenceElement, hints)); + code.addStatement(generateStatementForElement(targetClassName, referenceElement, hints)); } } code.addStatement("return $L", INSTANCE_PARAMETER); return code.build(); } - private CodeBlock generateMethodStatementForElement( + private CodeBlock generateStatementForElement( ClassName targetClassName, AnnotatedInjectElement referenceElement, RuntimeHints hints) { Member member = referenceElement.getMember(); @@ -260,11 +261,12 @@ private CodeBlock generateMethodStatementForElement( Class c = referenceElement.getInjectedType(); AotUtils.registerSerializationForService(c, hints); hints.reflection().registerType(TypeReference.of(c), MemberCategory.INVOKE_PUBLIC_METHODS); - hints.proxies().registerJdkProxy(c, EchoService.class, Destroyable.class); + hints.proxies().registerJdkProxy(c, EchoService.class, Destroyable.class, GenericService.class); hints.proxies() .registerJdkProxy( c, EchoService.class, + GenericService.class, Destroyable.class, SpringProxy.class, Advised.class, From 9600dc9ce67121579bb4680a5121e674791c2858 Mon Sep 17 00:00:00 2001 From: TomlongTK Date: Mon, 26 Aug 2024 09:54:32 +0800 Subject: [PATCH 3/6] Remove triple parameter in metadata (#14518) * Remove triple parameter in metadata * Refine default value get * Remove triple default value test * Remove unused import --------- Co-authored-by: Sean Yang --- .../common/constants/CommonConstants.java | 2 + .../apache/dubbo/config/ProtocolConfig.java | 15 +- .../dubbo/config/context/ConfigManager.java | 27 +++- .../dubbo/config/nested/Http3Config.java | 64 ++++++--- .../dubbo/config/nested/RestConfig.java | 34 +++++ .../dubbo/config/nested/TripleConfig.java | 129 ++++++++++++------ .../dubbo/config/ProtocolConfigTest.java | 26 ---- .../config/bootstrap/DubboBootstrapTest.java | 24 ++-- .../DefaultServiceURLCustomizer.java | 12 +- .../http12/netty4/h1/NettyHttp1Channel.java | 4 +- .../netty4/h2/NettyH2StreamChannel.java | 2 +- .../remoting/transport/netty4/Helper.java | 21 ++- .../tri/TriHttp2RemoteFlowController.java | 2 +- .../rpc/protocol/tri/TripleHttp2Protocol.java | 38 +++--- .../rpc/protocol/tri/rest/cors/CorsUtils.java | 24 ++-- .../tri/rest/mapping/ContentNegotiator.java | 4 +- .../DefaultRequestMappingRegistry.java | 30 ++-- 17 files changed, 282 insertions(+), 176 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index 61537707e3e..b13782dfc6c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -635,6 +635,8 @@ public interface CommonConstants { String DUBBO_VERSIONS_KEY = "META-INF/dubbo-versions"; + String TRIPLE_PREFIX = "triple."; + /** * System-related VM properties */ diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java index 08ca5523513..0d04ef328ea 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ProtocolConfig.java @@ -36,8 +36,6 @@ /** * Configuration for the protocol. - * - * @export */ public class ProtocolConfig extends AbstractConfig { @@ -282,11 +280,6 @@ protected void checkDefault() { .getBean(PreferSerializationProvider.class) .getPreferSerialization(); } - - if (triple == null) { - triple = new TripleConfig(); - } - triple.checkDefault(); } @Parameter(excluded = true) @@ -635,6 +628,14 @@ public TripleConfig getTriple() { return triple; } + @Parameter(excluded = true) + public TripleConfig getTripleOrDefault() { + if (triple == null) { + triple = new TripleConfig(); + } + return triple; + } + public void setTriple(TripleConfig triple) { this.triple = triple; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java index 296f846668f..7113d67d5e9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java @@ -73,8 +73,16 @@ public ConfigManager(ApplicationModel applicationModel) { TracingConfig.class)); } - public static ProtocolConfig getProtocol(URL url) { - return url.getOrDefaultApplicationModel().getApplicationConfigManager().getOrAddProtocol(url.getProtocol()); + public static ProtocolConfig getProtocolOrDefault(URL url) { + return getProtocolOrDefault(url.getOrDefaultApplicationModel(), url.getProtocol()); + } + + public static ProtocolConfig getProtocolOrDefault(String idOrName) { + return getProtocolOrDefault(ApplicationModel.defaultModel(), idOrName); + } + + private static ProtocolConfig getProtocolOrDefault(ApplicationModel applicationModel, String idOrName) { + return applicationModel.getApplicationConfigManager().getOrAddProtocol(idOrName); } // ApplicationConfig correlative methods @@ -204,10 +212,19 @@ public ProtocolConfig getOrAddProtocol(String idOrName) { if (protocol.isPresent()) { return protocol.get(); } - ProtocolConfig protocolConfig = new ProtocolConfig(idOrName); - addProtocol(protocolConfig); + + // Avoiding default protocol configuration overriding custom protocol configuration + // due to `getOrAddProtocol` being called when they are not loaded + idOrName = idOrName + ".default"; + protocol = getProtocol(idOrName); + if (protocol.isPresent()) { + return protocol.get(); + } + + ProtocolConfig protocolConfig = addConfig(new ProtocolConfig(idOrName)); + // addProtocol triggers refresh when other protocols exist in the ConfigManager. - // So refresh is only done when ProtocolConfig is not refreshed. + // so refresh is only done when ProtocolConfig is not refreshed. if (!protocolConfig.isRefreshed()) { protocolConfig.refresh(); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/Http3Config.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/Http3Config.java index 03a05012d1a..72871e09249 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/Http3Config.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/Http3Config.java @@ -16,12 +16,21 @@ */ package org.apache.dubbo.config.nested; +import org.apache.dubbo.config.support.Parameter; + import java.io.Serializable; public class Http3Config implements Serializable { private static final long serialVersionUID = -4443828713331129834L; + public static final int DEFAULT_INITIAL_MAX_DATA = 8_388_608; + public static final int DEFAULT_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL = 1_048_576; + public static final int DEFAULT_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE = 1_048_576; + public static final int DEFAULT_INITIAL_MAX_STREAM_DATA_UNI = 1_048_576; + public static final long DEFAULT_INITIAL_MAX_STREAMS_BIDI = 1_073_741_824; + public static final long DEFAULT_INITIAL_MAX_STREAMS_UNI = 1_073_741_824; + /** * Whether to enable HTTP/3 support *

The default value is false. @@ -142,6 +151,11 @@ public Integer getInitialMaxData() { return initialMaxData; } + @Parameter(excluded = true) + public int getInitialMaxDataOrDefault() { + return initialMaxData == null ? DEFAULT_INITIAL_MAX_DATA : initialMaxData; + } + public void setInitialMaxData(Integer initialMaxData) { this.initialMaxData = initialMaxData; } @@ -166,6 +180,13 @@ public Integer getInitialMaxStreamDataBidiLocal() { return initialMaxStreamDataBidiLocal; } + @Parameter(excluded = true) + public int getInitialMaxStreamDataBidiLocalOrDefault() { + return initialMaxStreamDataBidiLocal == null + ? DEFAULT_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL + : initialMaxStreamDataBidiLocal; + } + public void setInitialMaxStreamDataBidiLocal(Integer initialMaxStreamDataBidiLocal) { this.initialMaxStreamDataBidiLocal = initialMaxStreamDataBidiLocal; } @@ -174,6 +195,13 @@ public Integer getInitialMaxStreamDataBidiRemote() { return initialMaxStreamDataBidiRemote; } + @Parameter(excluded = true) + public int getInitialMaxStreamDataBidiRemoteOrDefault() { + return initialMaxStreamDataBidiRemote == null + ? DEFAULT_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE + : initialMaxStreamDataBidiRemote; + } + public void setInitialMaxStreamDataBidiRemote(Integer initialMaxStreamDataBidiRemote) { this.initialMaxStreamDataBidiRemote = initialMaxStreamDataBidiRemote; } @@ -182,6 +210,11 @@ public Integer getInitialMaxStreamDataUni() { return initialMaxStreamDataUni; } + @Parameter(excluded = true) + public int getInitialMaxStreamDataUniOrDefault() { + return initialMaxStreamDataUni == null ? DEFAULT_INITIAL_MAX_STREAM_DATA_UNI : initialMaxStreamDataUni; + } + public void setInitialMaxStreamDataUni(Integer initialMaxStreamDataUni) { this.initialMaxStreamDataUni = initialMaxStreamDataUni; } @@ -190,6 +223,11 @@ public Long getInitialMaxStreamsBidi() { return initialMaxStreamsBidi; } + @Parameter(excluded = true) + public long getInitialMaxStreamsBidiOrDefault() { + return initialMaxStreamsBidi == null ? DEFAULT_INITIAL_MAX_STREAMS_BIDI : initialMaxStreamsBidi; + } + public void setInitialMaxStreamsBidi(Long initialMaxStreamsBidi) { this.initialMaxStreamsBidi = initialMaxStreamsBidi; } @@ -198,6 +236,11 @@ public Long getInitialMaxStreamsUni() { return initialMaxStreamsUni; } + @Parameter(excluded = true) + public long getInitialMaxStreamsUniOrDefault() { + return initialMaxStreamsUni == null ? DEFAULT_INITIAL_MAX_STREAMS_UNI : initialMaxStreamsUni; + } + public void setInitialMaxStreamsUni(Long initialMaxStreamsUni) { this.initialMaxStreamsUni = initialMaxStreamsUni; } @@ -241,25 +284,4 @@ public String getCcAlgorithm() { public void setCcAlgorithm(String ccAlgorithm) { this.ccAlgorithm = ccAlgorithm; } - - public void checkDefault() { - if (initialMaxData == null) { - initialMaxData = 1 << 23; - } - if (initialMaxStreamDataBidiLocal == null) { - initialMaxStreamDataBidiLocal = 1 << 20; - } - if (initialMaxStreamDataBidiRemote == null) { - initialMaxStreamDataBidiRemote = 1 << 20; - } - if (initialMaxStreamDataUni == null) { - initialMaxStreamDataUni = 1 << 20; - } - if (initialMaxStreamsBidi == null) { - initialMaxStreamsBidi = (long) 1 << 30; - } - if (initialMaxStreamsUni == null) { - initialMaxStreamsUni = (long) 1 << 30; - } - } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java index 51d0a236f53..88011e19bb1 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.nested; import org.apache.dubbo.config.support.Nested; +import org.apache.dubbo.config.support.Parameter; import java.io.Serializable; @@ -27,6 +28,11 @@ public class RestConfig implements Serializable { private static final long serialVersionUID = -8068568976367034755L; + public static final boolean DEFAULT_TRAILING_SLASH_MATCH = true; + public static final boolean DEFAULT_SUFFIX_PATTERN_MATCH = true; + public static final boolean DEFAULT_CASE_SENSITIVE_MATCH = true; + public static final String DEFAULT_FORMAT_PARAMETER_NAME = "format"; + /** * Whether path matching should be match paths with a trailing slash. * If enabled, a method mapped to "/users" also matches to "/users/". @@ -66,6 +72,11 @@ public Boolean getTrailingSlashMatch() { return trailingSlashMatch; } + @Parameter(excluded = true) + public boolean getTrailingSlashMatchOrDefault() { + return trailingSlashMatch == null ? DEFAULT_TRAILING_SLASH_MATCH : trailingSlashMatch; + } + public void setTrailingSlashMatch(Boolean trailingSlashMatch) { this.trailingSlashMatch = trailingSlashMatch; } @@ -74,6 +85,11 @@ public Boolean getSuffixPatternMatch() { return suffixPatternMatch; } + @Parameter(excluded = true) + public boolean getSuffixPatternMatchOrDefault() { + return suffixPatternMatch == null ? DEFAULT_SUFFIX_PATTERN_MATCH : suffixPatternMatch; + } + public void setSuffixPatternMatch(Boolean suffixPatternMatch) { this.suffixPatternMatch = suffixPatternMatch; } @@ -82,6 +98,11 @@ public Boolean getCaseSensitiveMatch() { return caseSensitiveMatch; } + @Parameter(excluded = true) + public boolean getCaseSensitiveMatchOrDefault() { + return caseSensitiveMatch == null ? DEFAULT_CASE_SENSITIVE_MATCH : caseSensitiveMatch; + } + public void setCaseSensitiveMatch(Boolean caseSensitiveMatch) { this.caseSensitiveMatch = caseSensitiveMatch; } @@ -90,6 +111,11 @@ public String getFormatParameterName() { return formatParameterName; } + @Parameter(excluded = true) + public String getFormatParameterNameOrDefault() { + return formatParameterName == null ? DEFAULT_FORMAT_PARAMETER_NAME : formatParameterName; + } + public void setFormatParameterName(String formatParameterName) { this.formatParameterName = formatParameterName; } @@ -98,6 +124,14 @@ public CorsConfig getCors() { return cors; } + @Parameter(excluded = true) + public CorsConfig getCorsOrDefault() { + if (cors == null) { + cors = new CorsConfig(); + } + return cors; + } + public void setCors(CorsConfig cors) { this.cors = cors; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/TripleConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/TripleConfig.java index 745e5286395..2cf3d79543b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/TripleConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/TripleConfig.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.nested; import org.apache.dubbo.config.support.Nested; +import org.apache.dubbo.config.support.Parameter; import java.io.Serializable; @@ -27,6 +28,19 @@ public class TripleConfig implements Serializable { private static final long serialVersionUID = -3682252713701362155L; + public static final int DEFAULT_MAX_BODY_SIZE = 8_388_608; + public static final int DEFAULT_MAX_RESPONSE_BODY_SIZE = 8_388_608; + public static final int DEFAULT_MAX_CHUNK_SIZE = 8_388_608; + public static final int DEFAULT_MAX_HEADER_SIZE = 8_192; + public static final int DEFAULT_MAX_INITIAL_LINE_LENGTH = 4_096; + public static final int DEFAULT_INITIAL_BUFFER_SIZE = 16_384; + public static final int DEFAULT_HEADER_TABLE_SIZE = 4_096; + public static final boolean DEFAULT_ENABLE_PUSH = false; + public static final int DEFAULT_MAX_CONCURRENT_STREAMS = Integer.MAX_VALUE; + public static final int DEFAULT_INITIAL_WINDOW_SIZE = 8_388_608; + public static final int DEFAULT_MAX_FRAME_SIZE = 8_388_608; + public static final int DEFAULT_MAX_HEADER_LIST_SIZE = 32_768; + /** * Whether enable verbose mode. * When true, the application will produce detailed logging output @@ -143,6 +157,11 @@ public Integer getMaxBodySize() { return maxBodySize; } + @Parameter(excluded = true) + public int getMaxBodySizeOrDefault() { + return maxBodySize == null ? DEFAULT_MAX_BODY_SIZE : maxBodySize; + } + public void setMaxBodySize(Integer maxBodySize) { this.maxBodySize = maxBodySize; } @@ -151,6 +170,11 @@ public Integer getMaxResponseBodySize() { return maxResponseBodySize; } + @Parameter(excluded = true) + public int getMaxResponseBodySizeOrDefault() { + return maxResponseBodySize == null ? DEFAULT_MAX_RESPONSE_BODY_SIZE : maxResponseBodySize; + } + public void setMaxResponseBodySize(Integer maxResponseBodySize) { this.maxResponseBodySize = maxResponseBodySize; } @@ -159,6 +183,11 @@ public Integer getMaxChunkSize() { return maxChunkSize; } + @Parameter(excluded = true) + public int getMaxChunkSizeOrDefault() { + return maxChunkSize == null ? DEFAULT_MAX_CHUNK_SIZE : maxChunkSize; + } + public void setMaxChunkSize(Integer maxChunkSize) { this.maxChunkSize = maxChunkSize; } @@ -167,6 +196,11 @@ public Integer getMaxHeaderSize() { return maxHeaderSize; } + @Parameter(excluded = true) + public int getMaxHeaderSizeOrDefault() { + return maxHeaderSize == null ? DEFAULT_MAX_HEADER_SIZE : maxHeaderSize; + } + public void setMaxHeaderSize(Integer maxHeaderSize) { this.maxHeaderSize = maxHeaderSize; } @@ -175,6 +209,11 @@ public Integer getMaxInitialLineLength() { return maxInitialLineLength; } + @Parameter(excluded = true) + public int getMaxInitialLineLengthOrDefault() { + return maxInitialLineLength == null ? DEFAULT_MAX_INITIAL_LINE_LENGTH : maxInitialLineLength; + } + public void setMaxInitialLineLength(Integer maxInitialLineLength) { this.maxInitialLineLength = maxInitialLineLength; } @@ -183,6 +222,11 @@ public Integer getInitialBufferSize() { return initialBufferSize; } + @Parameter(excluded = true) + public int getInitialBufferSizeOrDefault() { + return initialBufferSize == null ? DEFAULT_INITIAL_BUFFER_SIZE : initialBufferSize; + } + public void setInitialBufferSize(Integer initialBufferSize) { this.initialBufferSize = initialBufferSize; } @@ -191,6 +235,11 @@ public Integer getHeaderTableSize() { return headerTableSize; } + @Parameter(excluded = true) + public int getHeaderTableSizeOrDefault() { + return headerTableSize == null ? DEFAULT_HEADER_TABLE_SIZE : headerTableSize; + } + public void setHeaderTableSize(Integer headerTableSize) { this.headerTableSize = headerTableSize; } @@ -199,6 +248,11 @@ public Boolean getEnablePush() { return enablePush; } + @Parameter(excluded = true) + public boolean getEnablePushOrDefault() { + return enablePush == null ? DEFAULT_ENABLE_PUSH : enablePush; + } + public void setEnablePush(Boolean enablePush) { this.enablePush = enablePush; } @@ -207,6 +261,11 @@ public Integer getMaxConcurrentStreams() { return maxConcurrentStreams; } + @Parameter(excluded = true) + public int getMaxConcurrentStreamsOrDefault() { + return maxConcurrentStreams == null ? DEFAULT_MAX_CONCURRENT_STREAMS : maxConcurrentStreams; + } + public void setMaxConcurrentStreams(Integer maxConcurrentStreams) { this.maxConcurrentStreams = maxConcurrentStreams; } @@ -215,6 +274,11 @@ public Integer getInitialWindowSize() { return initialWindowSize; } + @Parameter(excluded = true) + public int getInitialWindowSizeOrDefault() { + return initialWindowSize == null ? DEFAULT_INITIAL_WINDOW_SIZE : initialWindowSize; + } + public void setInitialWindowSize(Integer initialWindowSize) { this.initialWindowSize = initialWindowSize; } @@ -223,6 +287,11 @@ public Integer getMaxFrameSize() { return maxFrameSize; } + @Parameter(excluded = true) + public int getMaxFrameSizeOrDefault() { + return maxFrameSize == null ? DEFAULT_MAX_FRAME_SIZE : maxFrameSize; + } + public void setMaxFrameSize(Integer maxFrameSize) { this.maxFrameSize = maxFrameSize; } @@ -231,6 +300,11 @@ public Integer getMaxHeaderListSize() { return maxHeaderListSize; } + @Parameter(excluded = true) + public int getMaxHeaderListSizeOrDefault() { + return maxHeaderListSize == null ? DEFAULT_MAX_HEADER_LIST_SIZE : maxHeaderListSize; + } + public void setMaxHeaderListSize(Integer maxHeaderListSize) { this.maxHeaderListSize = maxHeaderListSize; } @@ -239,6 +313,14 @@ public RestConfig getRest() { return rest; } + @Parameter(excluded = true) + public RestConfig getRestOrDefault() { + if (rest == null) { + rest = new RestConfig(); + } + return rest; + } + public void setRest(RestConfig rest) { this.rest = rest; } @@ -247,6 +329,14 @@ public Http3Config getHttp3() { return http3; } + @Parameter(excluded = true) + public Http3Config getHttp3OrDefault() { + if (http3 == null) { + http3 = new Http3Config(); + } + return http3; + } + public void setHttp3(Http3Config http3) { this.http3 = http3; } @@ -258,43 +348,4 @@ public ServletConfig getServlet() { public void setServlet(ServletConfig servlet) { this.servlet = servlet; } - - public void checkDefault() { - if (maxBodySize == null) { - maxBodySize = 1 << 23; - } - if (maxResponseBodySize == null) { - maxResponseBodySize = 1 << 23; - } - if (maxChunkSize == null) { - maxChunkSize = 1 << 23; - } - if (maxHeaderSize == null) { - maxHeaderSize = 8192; - } - if (maxInitialLineLength == null) { - maxInitialLineLength = 4096; - } - if (initialBufferSize == null) { - initialBufferSize = 16384; - } - if (headerTableSize == null) { - headerTableSize = 4096; - } - if (enablePush == null) { - enablePush = false; - } - if (maxConcurrentStreams == null) { - maxConcurrentStreams = Integer.MAX_VALUE; - } - if (initialWindowSize == null) { - initialWindowSize = 1 << 23; - } - if (maxFrameSize == null) { - maxFrameSize = 1 << 23; - } - if (maxHeaderListSize == null) { - maxHeaderListSize = 1 << 15; - } - } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java index ef198ebf6c7..31e3679c271 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java @@ -35,8 +35,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; class ProtocolConfigTest { @@ -57,30 +55,6 @@ public static void afterAll() { DubboBootstrap.reset(); } - @Test - void testDefaultTripleConfig() { - ProtocolConfig protocol = new ProtocolConfig(); - protocol.refresh(); - Map parameters = new HashMap<>(); - ProtocolConfig.appendParameters(parameters, protocol); - assertThat(parameters.isEmpty(), is(false)); - // http2 default config - assertEquals(4096, Integer.parseInt(parameters.get("triple.header.table.size"))); - assertFalse(Boolean.parseBoolean(parameters.get("triple.enable.push"))); - assertEquals(Integer.MAX_VALUE, Integer.parseInt(parameters.get("triple.max.concurrent.streams"))); - assertEquals(1 << 23, Integer.parseInt(parameters.get("triple.initial.window.size"))); - assertEquals(1 << 23, Integer.parseInt(parameters.get("triple.max.frame.size"))); - assertEquals(1 << 15, Integer.parseInt(parameters.get("triple.max.header.list.size"))); - - // http1 default config - assertEquals(1 << 23, Integer.parseInt(parameters.get("triple.max.body.size"))); - assertEquals(1 << 23, Integer.parseInt(parameters.get("triple.max.response.body.size"))); - assertEquals(1 << 23, Integer.parseInt(parameters.get("triple.max.chunk.size"))); - assertEquals(8192, Integer.parseInt(parameters.get("triple.max.header.size"))); - assertEquals(4096, Integer.parseInt(parameters.get("triple.max.initial.line.length"))); - assertEquals(16384, Integer.parseInt(parameters.get("triple.initial.buffer.size"))); - } - @Test void testName() { ProtocolConfig protocol = new ProtocolConfig(); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java index d46740eb95c..05ea2052383 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java @@ -502,20 +502,20 @@ void testDefaultTriple() { .orElse(null); // check custom value - Assertions.assertEquals(50, tripleConfig.getMaxBodySize()); - Assertions.assertEquals(100, tripleConfig.getMaxResponseBodySize()); + Assertions.assertEquals(50, tripleConfig.getMaxBodySizeOrDefault()); + Assertions.assertEquals(100, tripleConfig.getMaxResponseBodySizeOrDefault()); // check default value - Assertions.assertEquals(1 << 23, tripleConfig.getMaxChunkSize()); - Assertions.assertEquals(8192, tripleConfig.getMaxHeaderSize()); - Assertions.assertEquals(4096, tripleConfig.getMaxInitialLineLength()); - Assertions.assertEquals(16384, tripleConfig.getInitialBufferSize()); - Assertions.assertEquals(4096, tripleConfig.getHeaderTableSize()); - Assertions.assertFalse(tripleConfig.getEnablePush()); - Assertions.assertEquals(Integer.MAX_VALUE, tripleConfig.getMaxConcurrentStreams()); - Assertions.assertEquals(1 << 23, tripleConfig.getInitialWindowSize()); - Assertions.assertEquals(1 << 23, tripleConfig.getMaxFrameSize()); - Assertions.assertEquals(1 << 15, tripleConfig.getMaxHeaderListSize()); + Assertions.assertEquals(1 << 23, tripleConfig.getMaxChunkSizeOrDefault()); + Assertions.assertEquals(8192, tripleConfig.getMaxHeaderSizeOrDefault()); + Assertions.assertEquals(4096, tripleConfig.getMaxInitialLineLengthOrDefault()); + Assertions.assertEquals(16384, tripleConfig.getInitialBufferSizeOrDefault()); + Assertions.assertEquals(4096, tripleConfig.getHeaderTableSizeOrDefault()); + Assertions.assertFalse(tripleConfig.getEnablePushOrDefault()); + Assertions.assertEquals(Integer.MAX_VALUE, tripleConfig.getMaxConcurrentStreamsOrDefault()); + Assertions.assertEquals(1 << 23, tripleConfig.getInitialWindowSizeOrDefault()); + Assertions.assertEquals(1 << 23, tripleConfig.getMaxFrameSizeOrDefault()); + Assertions.assertEquals(1 << 15, tripleConfig.getMaxHeaderListSizeOrDefault()); } private ExporterDeployListener getListener(ApplicationModel model) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DefaultServiceURLCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DefaultServiceURLCustomizer.java index 2473df54b70..f900abe2457 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DefaultServiceURLCustomizer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DefaultServiceURLCustomizer.java @@ -42,6 +42,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE_PREFIX; import static org.apache.dubbo.common.constants.FilterConstants.VALIDATION_KEY; import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP; import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE; @@ -80,6 +81,8 @@ public class DefaultServiceURLCustomizer implements ServiceURLCustomizer { THREADS_KEY }; + private static final String[] excludedPrefixes = new String[] {HIDE_KEY_PREFIX, TRIPLE_PREFIX}; + @Override public URL customize(URL serviceURL, ApplicationModel applicationModel) { boolean simplified = (boolean) serviceURL.getAttribute(SIMPLIFIED_KEY, false); @@ -112,7 +115,14 @@ private String[] getFilteredKeys(URL url) { Map params = url.getParameters(); if (CollectionUtils.isNotEmptyMap(params)) { return params.keySet().stream() - .filter(k -> k.startsWith(HIDE_KEY_PREFIX)) + .filter(k -> { + for (String excludedPrefix : excludedPrefixes) { + if (k.startsWith(excludedPrefix)) { + return true; + } + } + return false; + }) .toArray(String[]::new); } return new String[0]; diff --git a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java index 086dde1afdc..19d0c807d05 100644 --- a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java +++ b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java @@ -56,8 +56,8 @@ public CompletableFuture writeMessage(HttpOutputMessage httpOutputMessage) @Override public HttpOutputMessage newOutputMessage() { - return new Http1OutputMessage( - new LimitedByteBufOutputStream(channel.alloc().buffer(), tripleConfig.getMaxResponseBodySize())); + return new Http1OutputMessage(new LimitedByteBufOutputStream( + channel.alloc().buffer(), tripleConfig.getMaxResponseBodySizeOrDefault())); } @Override diff --git a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h2/NettyH2StreamChannel.java b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h2/NettyH2StreamChannel.java index edebd985ccf..c28449d28bb 100644 --- a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h2/NettyH2StreamChannel.java +++ b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h2/NettyH2StreamChannel.java @@ -63,7 +63,7 @@ public CompletableFuture writeMessage(HttpOutputMessage httpOutputMessage) public Http2OutputMessage newOutputMessage(boolean endStream) { ByteBuf buffer = http2StreamChannel.alloc().buffer(); ByteBufOutputStream outputStream = - new LimitedByteBufOutputStream(buffer, tripleConfig.getMaxResponseBodySize()); + new LimitedByteBufOutputStream(buffer, tripleConfig.getMaxResponseBodySizeOrDefault()); return new Http2OutputMessageFrame(outputStream, endStream); } diff --git a/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Helper.java b/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Helper.java index 6df29c4f06f..654831fa14a 100644 --- a/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Helper.java +++ b/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Helper.java @@ -19,7 +19,6 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.nested.Http3Config; -import org.apache.dubbo.config.nested.TripleConfig; import io.netty.incubator.codec.quic.QuicCodecBuilder; import io.netty.incubator.codec.quic.QuicCongestionControlAlgorithm; @@ -30,18 +29,14 @@ final class Helper { @SuppressWarnings("unchecked") static > T configCodec(QuicCodecBuilder builder, URL url) { - TripleConfig tripleConfig = ConfigManager.getProtocol(url).getTriple(); - Http3Config config = tripleConfig.getHttp3(); - if (config == null) { - config = new Http3Config(); - } - config.checkDefault(); - builder.initialMaxData(config.getInitialMaxData()) - .initialMaxStreamDataBidirectionalLocal(config.getInitialMaxStreamDataBidiLocal()) - .initialMaxStreamDataBidirectionalRemote(config.getInitialMaxStreamDataBidiRemote()) - .initialMaxStreamDataUnidirectional(config.getInitialMaxStreamDataUni()) - .initialMaxStreamsBidirectional(config.getInitialMaxStreamsBidi()) - .initialMaxStreamsUnidirectional(config.getInitialMaxStreamsUni()); + Http3Config config = + ConfigManager.getProtocolOrDefault(url).getTripleOrDefault().getHttp3OrDefault(); + builder.initialMaxData(config.getInitialMaxDataOrDefault()) + .initialMaxStreamDataBidirectionalLocal(config.getInitialMaxStreamDataBidiLocalOrDefault()) + .initialMaxStreamDataBidirectionalRemote(config.getInitialMaxStreamDataBidiRemoteOrDefault()) + .initialMaxStreamDataUnidirectional(config.getInitialMaxStreamDataUniOrDefault()) + .initialMaxStreamsBidirectional(config.getInitialMaxStreamsBidiOrDefault()) + .initialMaxStreamsUnidirectional(config.getInitialMaxStreamsUniOrDefault()); if (config.getRecvQueueLen() != null && config.getSendQueueLen() != null) { builder.datagram(config.getRecvQueueLen(), config.getSendQueueLen()); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriHttp2RemoteFlowController.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriHttp2RemoteFlowController.java index e2eb02f6f0c..fc08bc94cc2 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriHttp2RemoteFlowController.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriHttp2RemoteFlowController.java @@ -82,7 +82,7 @@ public TriHttp2RemoteFlowController( TripleConfig config) { this.connection = checkNotNull(connection, "connection"); this.streamByteDistributor = checkNotNull(streamByteDistributor, "streamWriteDistributor"); - this.initialWindowSize = config.getInitialWindowSize(); + this.initialWindowSize = config.getInitialWindowSizeOrDefault(); // Add a flow state for the connection. stateKey = connection.newKey(); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHttp2Protocol.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHttp2Protocol.java index aeb3e7f3be4..a04f4a9d217 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHttp2Protocol.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHttp2Protocol.java @@ -87,16 +87,16 @@ public void close() { @Override public void configClientPipeline(URL url, ChannelOperator operator, ContextOperator contextOperator) { - TripleConfig tripleConfig = ConfigManager.getProtocol(url).getTriple(); + TripleConfig tripleConfig = ConfigManager.getProtocolOrDefault(url).getTripleOrDefault(); Http2FrameCodec codec = Http2FrameCodecBuilder.forClient() .gracefulShutdownTimeoutMillis(10000) .initialSettings(new Http2Settings() - .headerTableSize(tripleConfig.getHeaderTableSize()) - .pushEnabled(tripleConfig.getEnablePush()) - .maxConcurrentStreams(tripleConfig.getMaxConcurrentStreams()) - .initialWindowSize(tripleConfig.getInitialWindowSize()) - .maxFrameSize(tripleConfig.getMaxFrameSize()) - .maxHeaderListSize(tripleConfig.getMaxHeaderListSize())) + .headerTableSize(tripleConfig.getHeaderTableSizeOrDefault()) + .pushEnabled(tripleConfig.getEnablePushOrDefault()) + .maxConcurrentStreams(tripleConfig.getMaxConcurrentStreamsOrDefault()) + .initialWindowSize(tripleConfig.getInitialWindowSizeOrDefault()) + .maxFrameSize(tripleConfig.getMaxFrameSizeOrDefault()) + .maxHeaderListSize(tripleConfig.getMaxHeaderListSizeOrDefault())) .frameLogger(CLIENT_LOGGER) .validateHeaders(false) .build(); @@ -132,13 +132,13 @@ public void configServerProtocolHandler(URL url, ChannelOperator operator) { @SuppressWarnings("deprecation") private void configurerHttp1Handlers(URL url, List handlers) { - TripleConfig tripleConfig = ConfigManager.getProtocol(url).getTriple(); + TripleConfig tripleConfig = ConfigManager.getProtocolOrDefault(url).getTripleOrDefault(); HttpServerCodec sourceCodec = new HttpServerCodec( - tripleConfig.getMaxInitialLineLength(), - tripleConfig.getMaxHeaderSize(), - tripleConfig.getMaxChunkSize(), + tripleConfig.getMaxInitialLineLengthOrDefault(), + tripleConfig.getMaxHeaderSizeOrDefault(), + tripleConfig.getMaxChunkSizeOrDefault(), false, - tripleConfig.getInitialBufferSize()); + tripleConfig.getInitialBufferSizeOrDefault()); handlers.add(new ChannelHandlerPretender(sourceCodec)); // Triple protocol http1 upgrade support handlers.add(new ChannelHandlerPretender(new HttpServerUpgradeHandler( @@ -160,7 +160,7 @@ private void configurerHttp1Handlers(URL url, List handlers) { // If the upgrade was successful, remove the message from the output list // so that it's not propagated to the next handler. This request will // be propagated as a user event instead. - handlers.add(new ChannelHandlerPretender(new HttpObjectAggregator(tripleConfig.getMaxBodySize()))); + handlers.add(new ChannelHandlerPretender(new HttpObjectAggregator(tripleConfig.getMaxBodySizeOrDefault()))); handlers.add(new ChannelHandlerPretender(new NettyHttp1Codec())); handlers.add(new ChannelHandlerPretender(new NettyHttp1ConnectionHandler( url, frameworkModel, tripleConfig, DefaultHttp11ServerTransportListenerFactory.INSTANCE))); @@ -179,7 +179,7 @@ protected void initChannel(Http2StreamChannel ch) { } private void configurerHttp2Handlers(URL url, List handlers) { - TripleConfig tripleConfig = ConfigManager.getProtocol(url).getTriple(); + TripleConfig tripleConfig = ConfigManager.getProtocolOrDefault(url).getTripleOrDefault(); Http2FrameCodec codec = buildHttp2FrameCodec(tripleConfig); Http2MultiplexHandler handler = buildHttp2MultiplexHandler(url, tripleConfig); handlers.add(new ChannelHandlerPretender(new HttpWriteQueueHandler())); @@ -196,11 +196,11 @@ private Http2FrameCodec buildHttp2FrameCodec(TripleConfig tripleConfig) { connection.remote().flowController(new TriHttp2RemoteFlowController(connection, tripleConfig))) .gracefulShutdownTimeoutMillis(10000) .initialSettings(new Http2Settings() - .headerTableSize(tripleConfig.getHeaderTableSize()) - .maxConcurrentStreams(tripleConfig.getMaxConcurrentStreams()) - .initialWindowSize(tripleConfig.getInitialWindowSize()) - .maxFrameSize(tripleConfig.getMaxFrameSize()) - .maxHeaderListSize(tripleConfig.getMaxHeaderListSize())) + .headerTableSize(tripleConfig.getHeaderTableSizeOrDefault()) + .maxConcurrentStreams(tripleConfig.getMaxConcurrentStreamsOrDefault()) + .initialWindowSize(tripleConfig.getInitialWindowSizeOrDefault()) + .maxFrameSize(tripleConfig.getMaxFrameSizeOrDefault()) + .maxHeaderListSize(tripleConfig.getMaxHeaderListSizeOrDefault())) .frameLogger(SERVER_LOGGER) .validateHeaders(false) .build(); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java index a9aab0bd91d..a71cf9ec00e 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java @@ -17,10 +17,11 @@ package org.apache.dubbo.rpc.protocol.tri.rest.cors; import org.apache.dubbo.common.config.Configuration; -import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.context.ConfigManager; +import org.apache.dubbo.config.nested.CorsConfig; import org.apache.dubbo.rpc.model.FrameworkModel; -import org.apache.dubbo.rpc.protocol.tri.rest.RestConstants; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.CorsMeta; public class CorsUtils { @@ -28,16 +29,17 @@ public class CorsUtils { private CorsUtils() {} public static CorsMeta getGlobalCorsMeta(FrameworkModel frameworkModel) { - Configuration config = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication()); - - String maxAge = config.getString(RestConstants.MAX_AGE); + CorsConfig config = ConfigManager.getProtocolOrDefault(CommonConstants.TRIPLE) + .getTripleOrDefault() + .getRestOrDefault() + .getCorsOrDefault(); return CorsMeta.builder() - .allowedOrigins(getValues(config, RestConstants.ALLOWED_ORIGINS)) - .allowedMethods(getValues(config, RestConstants.ALLOWED_METHODS)) - .allowedHeaders(getValues(config, RestConstants.ALLOWED_HEADERS)) - .allowCredentials(config.getString(RestConstants.ALLOW_CREDENTIALS)) - .exposedHeaders(getValues(config, RestConstants.EXPOSED_HEADERS)) - .maxAge(maxAge == null ? null : Long.valueOf(maxAge)) + .allowedOrigins(config.getAllowedOrigins()) + .allowedMethods(config.getAllowedMethods()) + .allowedHeaders(config.getAllowedHeaders()) + .allowCredentials(config.getAllowCredentials()) + .exposedHeaders(config.getExposedHeaders()) + .maxAge(config.getMaxAge()) .build(); } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/ContentNegotiator.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/ContentNegotiator.java index e92b0bd5644..acc27fafee5 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/ContentNegotiator.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/ContentNegotiator.java @@ -30,6 +30,8 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.config.nested.RestConfig.DEFAULT_FORMAT_PARAMETER_NAME; + public class ContentNegotiator { private final FrameworkModel frameworkModel; @@ -119,7 +121,7 @@ public String getParameterName() { String parameterName = this.parameterName; if (parameterName == null) { Configuration conf = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication()); - parameterName = conf.getString(RestConstants.FORMAT_PARAMETER_NAME_KEY, "format"); + parameterName = conf.getString(RestConstants.FORMAT_PARAMETER_NAME_KEY, DEFAULT_FORMAT_PARAMETER_NAME); this.parameterName = parameterName; } return parameterName; diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java index eb7eb2e49c0..44b034d17c6 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java @@ -17,10 +17,9 @@ package org.apache.dubbo.rpc.protocol.tri.rest.mapping; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.config.Configuration; -import org.apache.dubbo.common.config.ConfigurationUtils; import org.apache.dubbo.common.logger.FluentLogger; import org.apache.dubbo.common.utils.ClassUtils; +import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.remoting.http12.HttpRequest; import org.apache.dubbo.remoting.http12.message.MethodMetadata; @@ -71,15 +70,12 @@ public DefaultRequestMappingRegistry(FrameworkModel frameworkModel) { contentNegotiator = frameworkModel.getBeanFactory().getOrRegisterBean(ContentNegotiator.class); } - private void init() { - Configuration conf = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication()); - restConfig = new RestConfig(); - restConfig.setSuffixPatternMatch(conf.getBoolean(RestConstants.SUFFIX_PATTERN_MATCH_KEY, true)); - restConfig.setTrailingSlashMatch(conf.getBoolean(RestConstants.TRAILING_SLASH_MATCH_KEY, true)); - restConfig.setCaseSensitiveMatch(conf.getBoolean(RestConstants.CASE_SENSITIVE_MATCH_KEY, true)); - + private void init(Invoker invoker) { + restConfig = ConfigManager.getProtocolOrDefault(invoker.getUrl()) + .getTripleOrDefault() + .getRestOrDefault(); resolvers = frameworkModel.getActivateExtensions(RequestMappingResolver.class); - tree = new RadixTree<>(restConfig.getCaseSensitiveMatch()); + tree = new RadixTree<>(restConfig.getCaseSensitiveMatchOrDefault()); } @Override @@ -88,7 +84,7 @@ public void register(Invoker invoker) { lock.writeLock().lock(); try { if (initialized.compareAndSet(false, true)) { - init(); + init(invoker); } } finally { lock.writeLock().unlock(); @@ -208,13 +204,13 @@ public HandlerMeta lookup(HttpRequest request) { request.setAttribute(RestConstants.PATH_ATTRIBUTE, path); List candidates = new ArrayList<>(); - boolean cs = restConfig.getCaseSensitiveMatch(); + boolean cs = restConfig.getCaseSensitiveMatchOrDefault(); tryMatch(request, new KeyString(path, cs), candidates); if (candidates.isEmpty()) { int end = path.length(); - if (restConfig.getTrailingSlashMatch()) { + if (restConfig.getTrailingSlashMatchOrDefault()) { if (path.charAt(end - 1) == '/') { end--; tryMatch(request, new KeyString(path, end, cs), candidates); @@ -227,7 +223,7 @@ public HandlerMeta lookup(HttpRequest request) { if (ch == '/') { break; } - if (ch == '.' && restConfig.getSuffixPatternMatch()) { + if (ch == '.' && restConfig.getSuffixPatternMatchOrDefault()) { if (contentNegotiator.supportExtension(path.substring(i + 1, end))) { tryMatch(request, new KeyString(path, i, cs), candidates); if (!candidates.isEmpty()) { @@ -323,13 +319,13 @@ private void tryMatch(HttpRequest request, KeyString path, List candi @Override public boolean exists(String path, String method) { - boolean cs = restConfig.getCaseSensitiveMatch(); + boolean cs = restConfig.getCaseSensitiveMatchOrDefault(); if (tryExists(new KeyString(path, cs), method)) { return true; } int end = path.length(); - if (restConfig.getTrailingSlashMatch()) { + if (restConfig.getTrailingSlashMatchOrDefault()) { if (path.charAt(end - 1) == '/') { end--; if (tryExists(new KeyString(path, end, cs), method)) { @@ -343,7 +339,7 @@ public boolean exists(String path, String method) { if (ch == '/') { break; } - if (ch == '.' && restConfig.getSuffixPatternMatch()) { + if (ch == '.' && restConfig.getSuffixPatternMatchOrDefault()) { if (contentNegotiator.supportExtension(path.substring(i + 1, end))) { if (tryExists(new KeyString(path, i, cs), method)) { return true; From e6d7aac74df36f4b6ae692688f21f2de0b40df9e Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 26 Aug 2024 14:30:30 +0800 Subject: [PATCH 4/6] Fix CtrlCHandler release ByteBuf twice (#14577) --- .../org/apache/dubbo/qos/server/handler/CtrlCHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/CtrlCHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/CtrlCHandler.java index 9a4a203a04b..add29b94fab 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/CtrlCHandler.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/CtrlCHandler.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.CharsetUtil; +import io.netty.util.ReferenceCountUtil; public class CtrlCHandler extends SimpleChannelInboundHandler { /** @@ -41,6 +42,10 @@ public class CtrlCHandler extends SimpleChannelInboundHandler { private byte[] RESPONSE_SEQUENCE = new byte[] {(byte) 0xff, (byte) 0xfc, 0x06}; + public CtrlCHandler() { + super(false); + } + @Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { // find ctrl+c @@ -63,6 +68,7 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Ex ctx.writeAndFlush(Unpooled.wrappedBuffer( (QosConstants.BR_STR + QosProcessHandler.PROMPT).getBytes(CharsetUtil.UTF_8))); + ReferenceCountUtil.release(buffer); return; } } From 32431d5a2c52d97b7d98b3ea9d709bd99ae3db55 Mon Sep 17 00:00:00 2001 From: Ken Liu Date: Tue, 27 Aug 2024 10:16:56 +0800 Subject: [PATCH 5/6] Remove spring related transitive dependencies from dubbo-all (#14137) * remove spring related transitive dependencies * remove spring-context-support * remove protobuf-java-util --------- Co-authored-by: Jermaine Hua Co-authored-by: Albumen Kevin --- dubbo-distribution/dubbo-all/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index e645d05ea90..d3b31cc05ab 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -447,6 +447,10 @@ com.alibaba.fastjson2 fastjson2 + + com.google.protobuf + protobuf-java + From 392baa3f7181249b478a4ea42937fb3d438b717b Mon Sep 17 00:00:00 2001 From: lazy <65394407+liuzg-coder@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:34:09 +0800 Subject: [PATCH 6/6] Optimize code (#14594) Co-authored-by: lazy --- .../main/java/org/apache/dubbo/config/ServiceConfigBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index d527618b6dc..0670034b1e0 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -119,7 +119,7 @@ protected void postProcessAfterScopeModelChanged(ScopeModel oldScopeModel, Scope public boolean shouldExport() { Boolean export = getExport(); // default value is true - return export == null ? true : export; + return export == null || export; } @Override @@ -238,7 +238,7 @@ protected void convertProtocolIdsToProtocols() { if (StringUtils.isEmpty(protocolIds)) { if (CollectionUtils.isEmpty(protocols)) { List protocolConfigs = getConfigManager().getDefaultProtocols(); - if (protocolConfigs.isEmpty()) { + if (CollectionUtils.isEmpty(protocolConfigs)) { throw new IllegalStateException("The default protocol has not been initialized."); } setProtocols(protocolConfigs);