Skip to content

Commit 7b0ae12

Browse files
authored
2.7.6 REST Metadata (#5738)
* Polish /#4687 : Remove the duplicated test code in dubbo-config-spring * Polish /#4674 & /#4470 * Polish /#5093 : Revert the previous commit * Polish #5093 : [Feature] Dubbo Services generate the metadata of REST services * Polish #5306 : [Migration] Upgrade the @SInCE tags in Javadoc migration cloud native to master * Polish #5306 : [Migration] Upgrade the @SInCE tags in Javadoc migration cloud native to master * Polish #5309 : [ISSURE] The beans of Dubbo's Config can't be found on the ReferenceBean's initialization * Polish #5312 : Resolve the demos' issues of zookeeper and nacos * Polish #5313 : [Migration] migrate the code in common module from cloud-native branch to master * Polish #5316 : [Refactor] Replace @EnableDubboConfigBinding Using spring-context-support * Polish #5317 : [Refactor] Refactor ReferenceAnnotationBeanPostProcessor using Alibaba spring-context-suuport API * Polish #5321 : Remove BeanFactoryUtils * Polish #5321 : Remove AnnotatedBeanDefinitionRegistryUtils * Polish #5321 : Remove AnnotationUtils * Polish #5321 : Remove ClassUtils * Polish #5321 : Remove BeanRegistrar * Polish #5321 : Remove ObjectUtils * Polish #5321 : Remove PropertySourcesUtils * Polish #5325 : [Migration] To migrate dubbo-metadata-api from cloud-native branch * Polish #5326 : [Migration] To migrate dubbo-metadata-processor from cloud-native branch * Polish #5329 : [Feature] To add the default metadata into ServiceInstance * Polish #5339 : [Refactor] Refactor the DynamicConfiguration interface * Polish bugfix * Fixes test cases * Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5 # Conflicts: # dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java * Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5 # Conflicts: # dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java * Polish /#5721 : [Enhancement] Setting the default IDs for Dubbo's Config Beans * Polish /#5729 : [Optimization] To remove EnableDubboConfigBinding and EnableDubboConfigBindings * Polish /#5594 : [Feature] Add the resolver of ServiceRestMetadata based on Java Reflection * Polish /#5736 : [Feature] Introducing Conversion features * Polish /#5737 : [Feature] Introducing "dubbo-metadata-processor" module * Polish /#5594 : Change the Metadata implementation * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases * Polish /#5594 : Fixed test cases
1 parent d30ca86 commit 7b0ae12

File tree

192 files changed

+16107
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+16107
-85
lines changed

dubbo-all/pom.xml

Lines changed: 144 additions & 47 deletions
Large diffs are not rendered by default.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import org.apache.dubbo.common.extension.ExtensionLoader;
20+
import org.apache.dubbo.common.extension.SPI;
21+
import org.apache.dubbo.common.lang.Prioritized;
22+
23+
import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
24+
import static org.apache.dubbo.common.utils.ClassUtils.isAssignableFrom;
25+
import static org.apache.dubbo.common.utils.TypeUtils.findActualTypeArgument;
26+
27+
/**
28+
* A class to convert the source-typed value to the target-typed value
29+
*
30+
* @param <S> The source type
31+
* @param <T> The target type
32+
* @since 2.7.6
33+
*/
34+
@SPI
35+
@FunctionalInterface
36+
public interface Converter<S, T> extends Prioritized {
37+
38+
/**
39+
* Accept the source type and target type or not
40+
*
41+
* @param sourceType the source type
42+
* @param targetType the target type
43+
* @return if accepted, return <code>true</code>, or <code>false</code>
44+
*/
45+
default boolean accept(Class<?> sourceType, Class<?> targetType) {
46+
return isAssignableFrom(sourceType, getSourceType()) && isAssignableFrom(targetType, getTargetType());
47+
}
48+
49+
/**
50+
* Convert the source-typed value to the target-typed value
51+
*
52+
* @param source the source-typed value
53+
* @return the target-typed value
54+
*/
55+
T convert(S source);
56+
57+
/**
58+
* Get the source type
59+
*
60+
* @return non-null
61+
*/
62+
default Class<S> getSourceType() {
63+
return findActualTypeArgument(getClass(), Converter.class, 0);
64+
}
65+
66+
/**
67+
* Get the target type
68+
*
69+
* @return non-null
70+
*/
71+
default Class<T> getTargetType() {
72+
return findActualTypeArgument(getClass(), Converter.class, 1);
73+
}
74+
75+
/**
76+
* Get the Converter instance from {@link ExtensionLoader} with the specified source and target type
77+
*
78+
* @param sourceType the source type
79+
* @param targetType the target type
80+
* @return
81+
* @see ExtensionLoader#getSupportedExtensionInstances()
82+
*/
83+
static Converter<?, ?> getConverter(Class<?> sourceType, Class<?> targetType) {
84+
return getExtensionLoader(Converter.class)
85+
.getSupportedExtensionInstances()
86+
.stream()
87+
.filter(converter -> converter.accept(sourceType, targetType))
88+
.findFirst()
89+
.orElse(null);
90+
}
91+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
/**
20+
* A class to covert {@link String} to the target-typed value
21+
*
22+
* @see Converter
23+
* @since 2.7.6
24+
*/
25+
@FunctionalInterface
26+
public interface StringConverter<T> extends Converter<String, T> {
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import static java.lang.Boolean.valueOf;
20+
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
21+
22+
/**
23+
* The class to convert {@link String} to {@link Boolean}
24+
*
25+
* @since 2.7.6
26+
*/
27+
public class StringToBooleanConverter implements StringConverter<Boolean> {
28+
29+
@Override
30+
public Boolean convert(String source) {
31+
return isNotEmpty(source) ? valueOf(source) : null;
32+
}
33+
34+
@Override
35+
public int getPriority() {
36+
return NORMAL_PRIORITY + 5;
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
20+
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
21+
22+
/**
23+
* The class to convert {@link String} to <code>char[]</code>
24+
*
25+
* @since 2.7.6
26+
*/
27+
public class StringToCharArrayConverter implements StringConverter<char[]> {
28+
29+
@Override
30+
public char[] convert(String source) {
31+
return isNotEmpty(source) ? source.toCharArray() : null;
32+
}
33+
34+
35+
@Override
36+
public int getPriority() {
37+
return NORMAL_PRIORITY + 7;
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import static org.apache.dubbo.common.utils.StringUtils.length;
20+
21+
/**
22+
* The class to convert {@link String} to {@link Character}
23+
*
24+
* @since 2.7.6
25+
*/
26+
public class StringToCharacterConverter implements StringConverter<Character> {
27+
28+
@Override
29+
public Character convert(String source) {
30+
int length = length(source);
31+
if (length == 0) {
32+
return null;
33+
}
34+
if (length > 1) {
35+
throw new IllegalArgumentException("The source String is more than one character!");
36+
}
37+
return source.charAt(0);
38+
}
39+
40+
@Override
41+
public int getPriority() {
42+
return NORMAL_PRIORITY + 8;
43+
}
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import static java.lang.Double.valueOf;
20+
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
21+
22+
/**
23+
* The class to convert {@link String} to {@link Double}
24+
*
25+
* @since 2.7.6
26+
*/
27+
public class StringToDoubleConverter implements StringConverter<Double> {
28+
29+
@Override
30+
public Double convert(String source) {
31+
return isNotEmpty(source) ? valueOf(source) : null;
32+
}
33+
34+
35+
@Override
36+
public int getPriority() {
37+
return NORMAL_PRIORITY + 3;
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import static java.lang.Float.valueOf;
20+
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
21+
22+
/**
23+
* The class to convert {@link String} to {@link Float}
24+
*
25+
* @since 2.7.6
26+
*/
27+
public class StringToFloatConverter implements StringConverter<Float> {
28+
29+
@Override
30+
public Float convert(String source) {
31+
return isNotEmpty(source) ? valueOf(source) : null;
32+
}
33+
34+
@Override
35+
public int getPriority() {
36+
return NORMAL_PRIORITY + 4;
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.convert;
18+
19+
import static java.lang.Integer.valueOf;
20+
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
21+
22+
/**
23+
* The class to convert {@link String} to {@link Integer}
24+
*
25+
* @since 2.7.6
26+
*/
27+
public class StringToIntegerConverter implements StringConverter<Integer> {
28+
29+
@Override
30+
public Integer convert(String source) {
31+
return isNotEmpty(source) ? valueOf(source) : null;
32+
}
33+
34+
@Override
35+
public int getPriority() {
36+
return NORMAL_PRIORITY;
37+
}
38+
}

0 commit comments

Comments
 (0)