Skip to content

Commit

Permalink
Merge branch 'refs/heads/3.3' into feat/refactor-spring-boot
Browse files Browse the repository at this point in the history
# Conflicts:
#	dubbo-spring-boot/pom.xml
  • Loading branch information
CrazyHZM committed Oct 26, 2024
2 parents 1f66713 + 164c1e4 commit 32d9bb6
Show file tree
Hide file tree
Showing 36 changed files with 249 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
strategy:
fail-fast: false
env:
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- name: "Cache zookeeper binary archive"
uses: actions/cache@v3
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
env:
DISABLE_FILE_SYSTEM_TEST: true
CURRENT_ROLE: ${{ matrix.case-role }}
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- name: "Checkout code"
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-scheduled-3.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest ]
env:
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- uses: actions/cache@v3
name: "Cache zookeeper binary archive"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-scheduled-3.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest ]
env:
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- uses: actions/cache@v3
name: "Cache zookeeper binary archive"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-scheduled-3.3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest ]
env:
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- uses: actions/cache@v3
name: "Cache zookeeper binary archive"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest ]
env:
ZOOKEEPER_VERSION: 3.6.3
ZOOKEEPER_VERSION: 3.7.2
steps:
- uses: actions/cache@v3
name: "Cache zookeeper binary archive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.apache.dubbo.common.extension.Activate;

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

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.json.JsonMapper.Builder;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -34,6 +36,7 @@
public class JacksonImpl extends AbstractJsonUtilImpl {

private volatile JsonMapper mapper;
private final List<Module> customModules = new ArrayList<>();

@Override
public String getName() {
Expand Down Expand Up @@ -113,10 +116,24 @@ protected JsonMapper getMapper() {
}

protected Builder createBuilder() {
return JsonMapper.builder()
Builder builder = JsonMapper.builder()
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.serializationInclusion(Include.NON_NULL)
.addModule(new JavaTimeModule());

for (Module module : customModules) {
builder.addModule(module);
}

return builder;
}

public void addModule(Module module) {
synchronized (this) {
customModules.add(module);
// Invalidate the mapper to rebuild it
this.mapper = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.dubbo.config.support.Nested;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
Expand All @@ -49,6 +50,7 @@
import java.beans.Transient;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -325,6 +327,23 @@ private static boolean isParametersGetter(Method method) {
&& method.getReturnType() == Map.class);
}

private static boolean isPropertySetter(Method method) {
String name = method.getName();
if (name.startsWith("set")
&& name.length() > 3
&& Modifier.isPublic(method.getModifiers())
&& method.getParameterCount() == 1) {
Class<?> paramType = method.getParameterTypes()[0];
if (paramType.isArray()) {
Class<?> componentType = paramType.getComponentType();
return componentType.isPrimitive() || isSimpleType(componentType);
} else {
return paramType.isPrimitive() || isSimpleType(paramType);
}
}
return false;
}

private static boolean isParametersSetter(Method method) {
return ("setParameters".equals(method.getName())
&& Modifier.isPublic(method.getModifiers())
Expand Down Expand Up @@ -770,11 +789,13 @@ private void assignProperties(
// even if old one (this) contains non-null value, do override
boolean overrideAll = configMode == ConfigMode.OVERRIDE_ALL;

FrameworkModel frameworkModel = ScopeModelUtil.getFrameworkModel(getScopeModel());

// loop methods, get override value and set the new value back to method
List<Method> methods =
MethodUtils.getMethods(obj.getClass(), method -> method.getDeclaringClass() != Object.class);
for (Method method : methods) {
if (MethodUtils.isSetter(method)) {
if (isPropertySetter(method)) {
String propertyName = extractPropertyName(method.getName());

// if config mode is OVERRIDE_IF_ABSENT and property has set, skip
Expand All @@ -787,17 +808,55 @@ private void assignProperties(

try {
String value = StringUtils.trim(configuration.getString(kebabPropertyName));

Class<?> paramType = method.getParameterTypes()[0];
if (paramType.isArray()) {
if (isIgnoredAttribute(obj.getClass(), propertyName)) {
continue;
}

Class<?> itemType = paramType.getComponentType();
List<Object> items = new ArrayList<>();
if (StringUtils.hasText(value)) {
value = environment.resolvePlaceholders(value);
if (StringUtils.hasText(value)) {
for (String item : StringUtils.tokenize(value, ',')) {
items.add(ClassUtils.convertPrimitive(frameworkModel, itemType, item));
}
}
} else {
for (int i = 0; ; i++) {
value = StringUtils.trim(configuration.getString(kebabPropertyName + '[' + i + ']'));
if (value == null) {
break;
}
if (StringUtils.hasText(value)) {
value = environment.resolvePlaceholders(value);
if (StringUtils.hasText(value)) {
items.add(ClassUtils.convertPrimitive(frameworkModel, itemType, value));
}
}
}
}
int len = items.size();
if (len > 0) {
Object array = Array.newInstance(itemType, len);
for (int i = 0; i < len; i++) {
Array.set(array, i, items.get(i));
}
method.invoke(obj, array);
}
continue;
}

// isTypeMatch() is called to avoid duplicate and incorrect update, for example, we have two
// 'setGeneric' methods in ReferenceConfig.
if (StringUtils.hasText(value)
&& ClassUtils.isTypeMatch(method.getParameterTypes()[0], value)
&& ClassUtils.isTypeMatch(paramType, value)
&& !isIgnoredAttribute(obj.getClass(), propertyName)) {
value = environment.resolvePlaceholders(value);
if (StringUtils.hasText(value)) {
Object arg = ClassUtils.convertPrimitive(
ScopeModelUtil.getFrameworkModel(getScopeModel()),
method.getParameterTypes()[0],
value);
Object arg = ClassUtils.convertPrimitive(frameworkModel, paramType, value);
if (arg != null) {
method.invoke(obj, arg);
}
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.1.13</spring.version>
<spring.version>6.1.14</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 @@ -152,7 +152,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.10</version>
<version>1.5.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.10</version>
<version>1.5.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<artifactId>dubbo-serialization-hessian2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot.version>2.7.18</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.18</spring-boot-maven-plugin.version>
<micrometer-core.version>1.13.5</micrometer-core.version>
<micrometer-core.version>1.13.6</micrometer-core.version>
</properties>

<dependencyManagement>
Expand Down
8 changes: 4 additions & 4 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<spring_version>5.3.39</spring_version>
<spring_security_version>5.8.14</spring_security_version>
<javassist_version>3.30.2-GA</javassist_version>
<byte-buddy_version>1.15.4</byte-buddy_version>
<byte-buddy_version>1.15.5</byte-buddy_version>
<netty_version>3.2.10.Final</netty_version>
<netty4_version>4.1.114.Final</netty4_version>
<netty_http3_version>0.0.28.Final</netty_http3_version>
Expand All @@ -101,7 +101,7 @@
<fastjson_version>1.2.83_noneautotype</fastjson_version>
<fastjson2_version>2.0.53</fastjson2_version>
<zookeeper_version>3.7.2</zookeeper_version>
<curator_version>5.7.0</curator_version>
<curator_version>5.7.1</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>
Expand All @@ -123,11 +123,11 @@
<micrometer.version>1.13.5</micrometer.version>
<opentelemetry.version>1.43.0</opentelemetry.version>
<zipkin-reporter.version>3.4.2</zipkin-reporter.version>
<micrometer-tracing.version>1.3.4</micrometer-tracing.version>
<micrometer-tracing.version>1.3.5</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.10</reactor.version>
<reactor.version>3.6.11</reactor.version>
<rxjava.version>2.2.21</rxjava.version>
<okhttp_version>3.14.9</okhttp_version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void authenticate(Invocation invocation, URL url) throws RpcAuthenticatio
try {
accessKeyPair = getAccessKeyPair(invocation, url);
} catch (Exception e) {
throw new RpcAuthenticationException("Failed to authenticate , can't load the accessKeyPair", e);
throw new RpcAuthenticationException("Failed to authenticate , can't load the accessKeyPair");
}

String computeSignature = getSignature(url, invocation, accessKeyPair.getSecretKey(), requestTimestamp);
Expand All @@ -85,7 +85,7 @@ AccessKeyPair getAccessKeyPair(Invocation invocation, URL url) {
throw new AccessKeyNotFoundException("AccessKeyId or secretAccessKey not found");
}
} catch (Exception e) {
throw new RuntimeException("Can't load the AccessKeyPair from accessKeyStorage", e);
throw new RuntimeException("Can't load the AccessKeyPair from accessKeyStorage");
}
return accessKeyPair;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.HeaderFilter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.support.RpcUtils;

import static org.apache.dubbo.rpc.RpcException.AUTHORIZATION_EXCEPTION;

Expand All @@ -49,13 +47,7 @@ public RpcInvocation invoke(Invoker<?> invoker, RpcInvocation invocation) throws
try {
authenticator.authenticate(invocation, url);
} catch (Exception e) {
Class<?> serviceType = invoker.getInterface();
throw new RpcException(
AUTHORIZATION_EXCEPTION,
"Forbid invoke remote service " + serviceType + " method " + RpcUtils.getMethodName(invocation)
+ "() from consumer "
+ invocation.getAttributes().get(Constants.REMOTE_ADDRESS_KEY) + " to provider "
+ RpcContext.getServiceContext().getLocalHost());
throw new RpcException(AUTHORIZATION_EXCEPTION, "No Auth.");
}
invocation.getAttributes().put(Constants.AUTH_SUCCESS, Boolean.TRUE);
}
Expand Down
2 changes: 1 addition & 1 deletion dubbo-plugin/dubbo-compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.apache.dubbo.gen.grpc.DubboGrpcGenerator</mainClass>
<mainClass>org.apache.dubbo.gen.tri.Dubbo3TripleGenerator</mainClass>
</manifest>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public boolean map(URL url) {
+ waitTime + ". " + "Service Interface: "
+ serviceInterface + ". " + "Origin Content: "
+ oldConfigContent + ". " + "Ticket: "
+ configItem.getTicket() + ". " + "Excepted context: "
+ configItem.getTicket() + ". " + "Expected Content: "
+ newConfigContent);
Thread.sleep(waitTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public static String encodeCookie(HttpCookie cookie) {
}

public static List<String> parseAccept(String header) {
List<Item<String>> mediaTypes = new ArrayList<>();
if (header == null) {
return Collections.emptyList();
}
List<Item<String>> mediaTypes = new ArrayList<>();
for (String item : StringUtils.tokenize(header, ',')) {
int index = item.indexOf(';');
mediaTypes.add(new Item<>(StringUtils.substring(item, 0, index), parseQuality(item, index)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ public boolean isContentEmpty() {
if (body != null) {
return false;
}
if (outputStream != null && outputStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream) outputStream).size() == 0;
if (outputStream != null) {
return outputStream instanceof ByteArrayOutputStream && ((ByteArrayOutputStream) outputStream).size() == 0;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Builder<T> headers(HttpHeaders headers) {
}
Map<String, List<String>> hrs = this.headers;
if (hrs == null) {
hrs = new LinkedHashMap<>(headers.size());
this.headers = hrs = new LinkedHashMap<>(headers.size());
}
for (Entry<CharSequence, String> entry : headers) {
CharSequence key = entry.getKey();
Expand Down
Loading

0 comments on commit 32d9bb6

Please sign in to comment.