fix:fix NullPointerException error when using RestTemplate with no label. (#585)

pull/588/head
Haotian Zhang 2 years ago committed by GitHub
parent 302935b70d
commit 1c5343bf5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,3 +36,4 @@
- [refactor:optimize project and code.](https://github.com/Tencent/spring-cloud-tencent/pull/570)
- [Optimize:change default dynamic config refresh type to reflect.](https://github.com/Tencent/spring-cloud-tencent/pull/574)
- [feat:optimize examples.](https://github.com/Tencent/spring-cloud-tencent/pull/577)
- [fix:fix NullPointerException error when using RestTemplate with no label.](https://github.com/Tencent/spring-cloud-tencent/pull/585)

@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.tencent.cloud.common.constant.RouterConstants;
import com.tencent.cloud.common.metadata.MetadataContext;
@ -121,8 +122,12 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI
Map<String, String> labelHeaderValuesMap = new HashMap<>();
try {
String labelHeaderValuesContent = labelHeaderValues.stream().findFirst().get();
labelHeaderValuesMap.putAll(JacksonUtils.deserialize2Map(URLDecoder.decode(labelHeaderValuesContent, UTF_8)));
Optional<String> labelHeaderValuesOptional = labelHeaderValues.stream().findFirst();
if (labelHeaderValuesOptional.isPresent()) {
String labelHeaderValuesContent = labelHeaderValuesOptional.get();
labelHeaderValuesMap.putAll(
JacksonUtils.deserialize2Map(URLDecoder.decode(labelHeaderValuesContent, UTF_8)));
}
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException("unsupported charset exception " + UTF_8);

@ -134,10 +134,6 @@ public class PolarisLoadBalancerInterceptor extends LoadBalancerInterceptor {
labels.putAll(transitiveLabels);
// pass label by header
if (labels.size() == 0) {
request.getHeaders().set(RouterConstants.ROUTER_LABEL_HEADER, null);
return;
}
String encodedLabelsContent;
try {
encodedLabelsContent = URLEncoder.encode(JacksonUtils.serialize2Json(labels), UTF_8);

@ -73,7 +73,7 @@
<revision>1.7.0-2020.0.5-SNAPSHOT</revision>
<!-- Dependencies -->
<polaris.version>1.7.4-SNAPSHOT</polaris.version>
<polaris.version>1.7.4</polaris.version>
<logback.version>1.2.11</logback.version>
<mocktio.version>4.5.1</mocktio.version>
<byte-buddy.version>1.12.10</byte-buddy.version>

Loading…
Cancel
Save