Skip to content

Commit

Permalink
Merge branch '3.3' into 0913-triple-bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean authored Sep 27, 2024
2 parents b1045aa + 70f6e03 commit 6244804
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public class RestConfig implements Serializable {
*/
private String jsonFramework;

/**
* The disallowed content-types.
*/
private String[] disallowedContentTypes;

/**
* The cors configuration.
*/
Expand Down Expand Up @@ -133,6 +138,14 @@ public void setJsonFramework(String jsonFramework) {
this.jsonFramework = jsonFramework;
}

public String[] getDisallowedContentTypes() {
return disallowedContentTypes;
}

public void setDisallowedContentTypes(String[] disallowedContentTypes) {
this.disallowedContentTypes = disallowedContentTypes;
}

public CorsConfig getCors() {
return cors;
}
Expand Down
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-spring6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring.version>6.0.11</spring.version>
<spring.version>6.1.13</spring.version>
<spring-boot.version>3.0.9</spring-boot.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,17 @@ private CodeBlock generateStatementForElement(
Class<?> c = referenceElement.getInjectedType();
AotUtils.registerSerializationForService(c, hints);
hints.reflection().registerType(TypeReference.of(c), MemberCategory.INVOKE_PUBLIC_METHODS);
// need to enumerate all interfaces by the proxy
hints.proxies().registerJdkProxy(c, EchoService.class, Destroyable.class);
hints.proxies().registerJdkProxy(c, EchoService.class, Destroyable.class, GenericService.class);
hints.proxies()
.registerJdkProxy(
c,
EchoService.class,
Destroyable.class,
SpringProxy.class,
Advised.class,
DecoratingProxy.class);
hints.proxies()
.registerJdkProxy(
c,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<curator5_version>5.1.0</curator5_version>
<curator5_version>5.7.0</curator5_version>
<zookeeper_version>3.8.4</zookeeper_version>
</properties>

Expand Down Expand Up @@ -199,7 +199,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.2</version>
<version>0.10.3</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<curator5_version>5.1.0</curator5_version>
<curator5_version>5.7.0</curator5_version>
<zookeeper_version>3.8.4</zookeeper_version>
</properties>

Expand Down Expand Up @@ -199,7 +199,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.2</version>
<version>0.10.3</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
Expand Down
36 changes: 18 additions & 18 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@
<httpclient_version>4.5.14</httpclient_version>
<httpcore_version>4.4.16</httpcore_version>
<fastjson_version>1.2.83</fastjson_version>
<fastjson2_version>2.0.52</fastjson2_version>
<fastjson2_version>2.0.53</fastjson2_version>
<zookeeper_version>3.7.2</zookeeper_version>
<curator_version>5.1.0</curator_version>
<curator_version>5.7.0</curator_version>
<curator_test_version>2.12.0</curator_test_version>
<jedis_version>3.10.0</jedis_version>
<hessian_version>4.0.66</hessian_version>
<protobuf-java_version>3.25.4</protobuf-java_version>
<protobuf-java_version>3.25.5</protobuf-java_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<jakarta_servlet_version>6.1.0</jakarta_servlet_version>
Expand All @@ -120,14 +120,14 @@
<snakeyaml_version>2.3</snakeyaml_version>
<commons_lang3_version>3.17.0</commons_lang3_version>
<envoy_api_version>0.1.35</envoy_api_version>
<micrometer.version>1.13.3</micrometer.version>
<micrometer.version>1.13.4</micrometer.version>
<opentelemetry.version>1.39.0</opentelemetry.version>
<zipkin-reporter.version>3.4.0</zipkin-reporter.version>
<micrometer-tracing.version>1.3.3</micrometer-tracing.version>
<zipkin-reporter.version>3.4.2</zipkin-reporter.version>
<micrometer-tracing.version>1.3.4</micrometer-tracing.version>
<t_digest.version>3.3</t_digest.version>
<prometheus_client.version>0.16.0</prometheus_client.version>
<reactive.version>1.0.4</reactive.version>
<reactor.version>3.6.9</reactor.version>
<reactor.version>3.6.10</reactor.version>
<rxjava.version>2.2.21</rxjava.version>
<okhttp_version>3.14.9</okhttp_version>

Expand All @@ -136,27 +136,27 @@
<codehaus-jackson_version>1.9.13</codehaus-jackson_version>
<tomcat_embed_version>8.5.100</tomcat_embed_version>
<nacos_version>2.4.2</nacos_version>
<sentinel.version>1.8.6</sentinel.version>
<seata.version>1.6.1</seata.version>
<grpc.version>1.66.0</grpc.version>
<sentinel.version>1.8.8</sentinel.version>
<seata.version>1.8.0</seata.version>
<grpc.version>1.68.0</grpc.version>
<grpc_contrib_verdion>0.8.1</grpc_contrib_verdion>
<jprotoc_version>1.2.2</jprotoc_version>
<mustache_version>0.9.10</mustache_version>
<mustache_version>0.9.14</mustache_version>
<!-- Log libs -->
<slf4j_version>1.7.36</slf4j_version>
<jcl_version>1.3.4</jcl_version>
<log4j_version>1.2.17</log4j_version>
<logback_version>1.2.13</logback_version>
<!-- Fix the bug of log4j refer:https://github.com/apache/logging-log4j2/pull/608 -->
<log4j2_version>2.24.0</log4j2_version>
<commons_io_version>2.16.1</commons_io_version>
<commons_io_version>2.17.0</commons_io_version>
<commons-codec_version>1.16.0</commons-codec_version>
<groovy_version>4.0.21</groovy_version>
<groovy_version>4.0.23</groovy_version>

<!-- Test libs -->
<junit_jupiter_version>5.9.3</junit_jupiter_version>
<junit_version>4.13.2</junit_version>
<awaitility_version>4.2.0</awaitility_version>
<awaitility_version>4.2.2</awaitility_version>
<hamcrest_version>2.2</hamcrest_version>
<cglib_version>2.2.2</cglib_version>
<embedded_redis_version>1.4.3</embedded_redis_version>
Expand All @@ -169,7 +169,7 @@
<hessian_lite_version>4.0.3</hessian_lite_version>
<swagger_version>1.6.14</swagger_version>

<snappy_java_version>1.1.10.6</snappy_java_version>
<snappy_java_version>1.1.10.7</snappy_java_version>
<bouncycastle-bcprov_version>1.70</bouncycastle-bcprov_version>
<sofa_registry_version>5.4.3</sofa_registry_version>
<metrics_version>2.0.6</metrics_version>
Expand All @@ -183,9 +183,9 @@
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>
<open_feign_version>3.1.5</open_feign_version>
<jakarta.xml.bind-api.version>4.0.1</jakarta.xml.bind-api.version>
<jaxb-runtime.version>2.3.3-b02</jaxb-runtime.version>
<open_feign_version>3.1.9</open_feign_version>
<jakarta.xml.bind-api.version>4.0.2</jakarta.xml.bind-api.version>
<jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>

<revision>3.3.1-SNAPSHOT</revision>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions dubbo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<properties>
<dubbo.version>${revision}</dubbo.version>
<protobuf-java.version>3.25.0</protobuf-java.version>
<protobuf-java.version>3.25.5</protobuf-java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
<version>2.17.0</version>
</dependency>

<!-- Takes no effect for this dependency. To notify github dependencies bot to update ${protobuf-java.version} property. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ private List<PluginProtos.CodeGeneratorResponse.File> generateFiles(List<Service
return allServiceFiles;
}

protected boolean enableMultipleTemplateFiles() {
protected boolean useMultipleTemplate(boolean multipleFiles) {
return false;
}

private List<PluginProtos.CodeGeneratorResponse.File> buildFile(ServiceContext context) {
List<PluginProtos.CodeGeneratorResponse.File> files = new ArrayList<>();

if (context.multipleFiles && enableMultipleTemplateFiles()) {
if (useMultipleTemplate(context.multipleFiles)) {
String content = applyTemplate(getTemplateFileName(), context);
String dir = absoluteDir(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected String getSingleTemplateFileName() {
}

@Override
protected boolean enableMultipleTemplateFiles() {
protected boolean useMultipleTemplate(boolean multipleFiles) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected String getSingleTemplateFileName() {
}

@Override
protected boolean enableMultipleTemplateFiles() {
protected boolean useMultipleTemplate(boolean multipleFiles) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ private void handleHttp1(HttpServletRequest request, HttpServletResponse respons
channel, ServletExchanger.getUrl(), FrameworkModel.defaultModel());
channel.setGrpc(false);
context.setTimeout(resolveTimeout(request, false));
listener.onMetadata(new HttpMetadataAdapter(request));
ServletInputStream is = request.getInputStream();
response.getOutputStream().setWriteListener(new TripleWriteListener(channel));

listener.onMetadata(new HttpMetadataAdapter(request));
listener.onData(new Http1InputMessage(
is.available() == 0 ? StreamUtils.EMPTY : new ByteArrayInputStream(StreamUtils.readBytes(is))));
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
package org.apache.dubbo.remoting.http12.message.codec;

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.utils.Assert;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.http12.exception.UnsupportedMediaTypeException;
import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
import org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory;
import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder;
import org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory;
import org.apache.dubbo.rpc.Constants;
import org.apache.dubbo.rpc.model.FrameworkModel;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public final class CodecUtils {
Expand All @@ -37,13 +44,18 @@ public final class CodecUtils {
private final List<HttpMessageEncoderFactory> encoderFactories;
private final Map<String, Optional<HttpMessageEncoderFactory>> encoderCache = new ConcurrentHashMap<>();
private final Map<String, Optional<HttpMessageDecoderFactory>> decoderCache = new ConcurrentHashMap<>();
private Set<String> disallowedContentTypes = Collections.emptySet();

public CodecUtils(FrameworkModel frameworkModel) {
this.frameworkModel = frameworkModel;
decoderFactories = frameworkModel.getActivateExtensions(HttpMessageDecoderFactory.class);
encoderFactories = frameworkModel.getActivateExtensions(HttpMessageEncoderFactory.class);
decoderFactories.forEach(f -> decoderCache.putIfAbsent(f.mediaType().getName(), Optional.of(f)));
encoderFactories.forEach(f -> encoderCache.putIfAbsent(f.mediaType().getName(), Optional.of(f)));

Configuration configuration = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication());
String contentTypes = configuration.getString(Constants.H2_SETTINGS_DISALLOWED_CONTENT_TYPES, null);
if (contentTypes != null) {
disallowedContentTypes = new HashSet<>(StringUtils.tokenizeToList(contentTypes));
}
}

public HttpMessageDecoder determineHttpMessageDecoder(URL url, String mediaType) {
Expand All @@ -69,9 +81,10 @@ public HttpMessageEncoder determineHttpMessageEncoder(String mediaType) {
public Optional<HttpMessageDecoderFactory> determineHttpMessageDecoderFactory(String mediaType) {
Assert.notNull(mediaType, "mediaType must not be null");
return decoderCache.computeIfAbsent(mediaType, k -> {
for (HttpMessageDecoderFactory decoderFactory : decoderFactories) {
if (decoderFactory.supports(k)) {
return Optional.of(decoderFactory);
for (HttpMessageDecoderFactory factory : decoderFactories) {
if (factory.supports(k)
&& !disallowedContentTypes.contains(factory.mediaType().getName())) {
return Optional.of(factory);
}
}
return Optional.empty();
Expand All @@ -81,9 +94,10 @@ public Optional<HttpMessageDecoderFactory> determineHttpMessageDecoderFactory(St
public Optional<HttpMessageEncoderFactory> determineHttpMessageEncoderFactory(String mediaType) {
Assert.notNull(mediaType, "mediaType must not be null");
return encoderCache.computeIfAbsent(mediaType, k -> {
for (HttpMessageEncoderFactory encoderFactory : encoderFactories) {
if (encoderFactory.supports(k)) {
return Optional.of(encoderFactory);
for (HttpMessageEncoderFactory factory : encoderFactories) {
if (factory.supports(k)
&& !disallowedContentTypes.contains(factory.mediaType().getName())) {
return Optional.of(factory);
}
}
return Optional.empty();
Expand Down
2 changes: 1 addition & 1 deletion dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
<zookeeper_version>3.7.2</zookeeper_version>
<curator5_version>5.1.0</curator5_version>
<curator5_version>5.7.0</curator5_version>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public interface Constants {
String H2_SETTINGS_BUILTIN_SERVICE_INIT = "dubbo.tri.builtin.service.init";

String H2_SETTINGS_JSON_FRAMEWORK_NAME = "dubbo.protocol.triple.rest.json-framework";
String H2_SETTINGS_DISALLOWED_CONTENT_TYPES = "dubbo.protocol.triple.rest.disallowed-content-types";

String H2_SETTINGS_VERBOSE_ENABLED = "dubbo.protocol.triple.verbose";
String H2_SETTINGS_SERVLET_ENABLED = "dubbo.protocol.triple.servlet.enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.apache.dubbo.rpc.protocol.tri.ExceptionUtils;
import org.apache.dubbo.rpc.protocol.tri.TripleProtocol;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import io.netty.buffer.ByteBufOutputStream;

public final class Http1UnaryServerChannelObserver extends Http1ServerChannelObserver {
Expand Down Expand Up @@ -52,7 +55,17 @@ protected void doOnError(Throwable throwable) throws Throwable {
@Override
protected void customizeHeaders(HttpHeaders headers, Throwable throwable, HttpOutputMessage message) {
super.customizeHeaders(headers, throwable, message);
int contentLength = message == null ? 0 : ((ByteBufOutputStream) message.getBody()).writtenBytes();
int contentLength = 0;
if (message != null) {
OutputStream body = message.getBody();
if (body instanceof ByteBufOutputStream) {
contentLength = ((ByteBufOutputStream) body).writtenBytes();
} else if (body instanceof ByteArrayOutputStream) {
contentLength = ((ByteArrayOutputStream) body).size();
} else {
throw new IllegalArgumentException("Unsupported body type: " + body.getClass());
}
}
headers.set(HttpHeaderNames.CONTENT_LENGTH.getKey(), String.valueOf(contentLength));
}

Expand Down
Loading

0 comments on commit 6244804

Please sign in to comment.