Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.2' into rest
Browse files Browse the repository at this point in the history
* origin/3.2:
  Observability task: metadata center (apache#11593)
  Enhance the way to get dubbo version (apache#11574)
  Bump protobuf-java from 3.21.12 to 3.22.0 (apache#11615)
  Bump maven-surefire-plugin from 3.0.0-M8 to 3.0.0-M9 (apache#11613)
  Bump micrometer-bom from 1.10.3 to 1.10.4 (apache#11611)
  Bump libthrift from 0.17.0 to 0.18.0 (apache#11614)
  Bump maven-failsafe-plugin from 3.0.0-M8 to 3.0.0-M9 (apache#11612)
  Bump reactor-core from 3.5.2 to 3.5.3 (apache#11610)
  Bump byte-buddy from 1.13.0 to 1.14.0 (apache#11609)
  Bump maven-javadoc-plugin from 3.4.1 to 3.5.0 (apache#11608)
  Bump micrometer-tracing-bom from 1.0.1 to 1.0.2 (apache#11607)
  3.2 consumer proxy invocation handler (apache#11108)
  Update DubboReference.java (apache#11621)

# Conflicts:
#	dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
#	dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/JaxrsRestProtocolTest.java
  • Loading branch information
mytang0 committed Feb 22, 2023
2 parents edf3ed2 + 671e0f8 commit e869c6f
Show file tree
Hide file tree
Showing 188 changed files with 7,961 additions and 428 deletions.
34 changes: 32 additions & 2 deletions dubbo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,38 @@
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>get-version-infos</id>
<phase>compile</phase>
<configuration>
<failOnError>true</failOnError>
<target>
<property name="version_file"
value="${project.build.outputDirectory}/META-INF/version"/>
<!-- get the current version of dubbo -->
<echo message="revision=${revision}${line.separator}" file="${version_file}"/>
<echo message="git.commit.id=" file="${version_file}" append="true"/>
<!-- get the latest commit id -->
<exec executable="git" output="${version_file}" error=".git.exec.error" append="true"
timeout="3000" failifexecutionfails="false">
<arg line="rev-parse HEAD"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
28 changes: 26 additions & 2 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.StringUtils;

import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -46,8 +50,9 @@ public final class Version {
public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2";
// version 1.0.0 represents Dubbo rpc protocol before v2.6.2
public static final int LEGACY_DUBBO_PROTOCOL_VERSION = 10000; // 1.0.0
// Dubbo implementation version, usually is jar version.
private static final String VERSION = getVersion(Version.class, "");
// Dubbo implementation version.
private static String VERSION;
private static String LATEST_COMMIT_ID;

/**
* For protocol compatibility purpose.
Expand All @@ -61,6 +66,21 @@ public final class Version {
static {
// check if there's duplicated jar
Version.checkDuplicate(Version.class);

// get dubbo version and last commit id
try {
Properties properties =
ConfigUtils.loadProperties(Collections.emptySet(), "META-INF/version");

VERSION = Optional.ofNullable(properties.getProperty("revision"))
.filter(StringUtils::isNotBlank)
.orElseGet(() -> getVersion(Version.class, ""));
LATEST_COMMIT_ID = Optional.ofNullable(properties.getProperty("git.commit.id")).orElse("");
} catch (Throwable e) {
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "continue the old logic, ignore exception " + e.getMessage(), e);
VERSION = getVersion(Version.class, "");
LATEST_COMMIT_ID = "";
}
}

private Version() {
Expand All @@ -74,6 +94,10 @@ public static String getVersion() {
return VERSION;
}

public static String getLastCommitId() {
return LATEST_COMMIT_ID;
}

/**
* Compare versions
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public interface JSON {
List<Map<String, ?>> checkObjectList(List<?> rawList);

List<String> checkStringList(List<?> rawList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;

public class FastJson2Impl extends AbstractJSONImpl {

@Override
public <T> T toJavaObject(String json, Type type) {
return com.alibaba.fastjson2.JSON.parseObject(json, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ public <T> List<T> toJavaList(String json, Class<T> clazz) {
public String toJson(Object obj) {
return com.alibaba.fastjson.JSON.toJSONString(obj, SerializerFeature.DisableCircularReferenceDetect);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
*/
package org.apache.dubbo.common.json.impl;


import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.lang.reflect.Type;
import java.util.List;

public class JacksonImpl extends AbstractJSONImpl {
private ObjectMapper objectMapper = new ObjectMapper();

private volatile Object jacksonCache = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/
package org.apache.dubbo.config;

import java.util.HashMap;
import java.util.Map;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.config.nested.AggregationConfig;
import org.apache.dubbo.config.nested.PrometheusConfig;
import org.apache.dubbo.config.support.Nested;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.HashMap;
import java.util.Map;

/**
* MetricsConfig
*/
Expand All @@ -40,6 +40,11 @@ public class MetricsConfig extends AbstractConfig {
*/
private Boolean enableJvmMetrics;

/**
* Enable jvm metrics when collecting.
*/
private Boolean enableMetadataMetrics;

/**
* @deprecated After metrics config is refactored.
* This parameter should no longer use and will be deleted in the future.
Expand Down Expand Up @@ -137,5 +142,13 @@ public Integer getExportServicePort() {
public void setExportServicePort(Integer exportServicePort) {
this.exportServicePort = exportServicePort;
}

public Boolean getEnableMetadataMetrics() {
return enableMetadataMetrics;
}

public void setEnableMetadataMetrics(Boolean enableMetadataMetrics) {
this.enableMetadataMetrics = enableMetadataMetrics;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
String proxy() default "";

/**
* Service stub name, use interface name + Local if not set
* Service stub name, use interface name + Stub if not set
*/
String stub() default "";

Expand Down
1 change: 1 addition & 0 deletions dubbo-common/src/main/resources/META-INF/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a placeholder file, the real file will be output when the project compiles
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ void testIsFramework263OrHigher() {
Assertions.assertTrue(Version.isRelease263OrHigher("2.6.3"));
Assertions.assertTrue(Version.isRelease263OrHigher("2.6.3.0"));
}
}

@Test
void testGetVersion() {
Assertions.assertEquals("1.0.0", Version.getVersion());
}

@Test
void testGetLastCommitId() {
Assertions.assertEquals("82a29fcd674216fe9bea10b6efef3196929dd7ca", Version.getLastCommitId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.apache.dubbo.metadata.definition.model.TypeDefinition;
import org.apache.dubbo.metadata.definition.service.ComplexObject;
import org.apache.dubbo.metadata.definition.service.DemoService;
import org.apache.dubbo.rpc.model.FrameworkModel;

import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -134,4 +132,4 @@ void checkComplexObjectAsParam(FullServiceDefinition fullServiceDefinition) {
Assertions.assertEquals(Integer.class.getCanonicalName(), listTypeDefinition.getItems().get(0));
}

}
}
3 changes: 3 additions & 0 deletions dubbo-common/src/test/resources/META-INF/version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is a test file
revision=1.0.0
git.commit.id=82a29fcd674216fe9bea10b6efef3196929dd7ca
6 changes: 6 additions & 0 deletions dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-metadata</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-monitor-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void initMetricsService() {

private void initMetricsReporter() {
DefaultMetricsCollector collector =
applicationModel.getFrameworkModel().getBeanFactory().getBean(DefaultMetricsCollector.class);
applicationModel.getBeanFactory().getBean(DefaultMetricsCollector.class);
MetricsConfig metricsConfig = configManager.getMetrics().orElse(null);
// TODO compatible with old usage of metrics, remove protocol check after new metrics is ready for use.
if (metricsConfig != null && PROTOCOL_PROMETHEUS.equals(metricsConfig.getProtocol())) {
Expand Down
14 changes: 14 additions & 0 deletions dubbo-demo/dubbo-demo-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,19 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-rest</artifactId>
</dependency>

<!-- Spring Web MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>

<!-- Spring Web MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@
*/
package org.apache.dubbo.demo;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;

import po.TestPO;

import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.POST;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;


@Path("/demoService")
public interface RestDemoService {
@GET
@Path("/hello")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
Integer hello(@QueryParam("a") Integer a, @QueryParam("b") Integer b);

@GET
Expand All @@ -42,4 +50,44 @@ public interface RestDemoService {
@GET
@Path("/getRemoteApplicationName")
String getRemoteApplicationName();

@POST
@Path("/testBody1")
@Consumes({MediaType.TEXT_PLAIN})
Integer testBody(Integer b);

@POST
@Path("/testBody2")
@Consumes({MediaType.TEXT_PLAIN})
String testBody2(String b);

@POST
@Path("/testBody3")
@Consumes({MediaType.TEXT_PLAIN})
Boolean testBody2(Boolean b);

@POST
@Path("/testBody3")
@Consumes({MediaType.TEXT_PLAIN})
TestPO testBody2(TestPO b);


@POST
@Path("/testBody5")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
TestPO testBody5(TestPO testPO);

@POST
@Path("/testForm1")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
String testForm1(@FormParam("name") String test);


@POST
@Path("/testForm2")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_FORM_URLENCODED)
MultivaluedMap testForm2(MultivaluedMap map);
}
Loading

0 comments on commit e869c6f

Please sign in to comment.