fix fegin report call result error when using fegin direct call (#621)

pull/627/head
lepdou 2 years ago committed by GitHub
parent 994f87a522
commit 008551b15f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,5 +8,6 @@
- [Automatically transmit some headers specified by a environment varaible that directly defines header keys.](https://github.com/Tencent/spring-cloud-tencent/pull/606)
- [Optimize: Maybe remove Chinese characters](https://github.com/Tencent/spring-cloud-tencent/pull/607)
- [ fix pr #606 cause ci fail](https://github.com/Tencent/spring-cloud-tencent/pull/613)
- [Bugfix: fix feign report call result error when using feign direct call](https://github.com/Tencent/spring-cloud-tencent/pull/621)
- [fix pr 606: modify a part of changes requested by review.](https://github.com/Tencent/spring-cloud-tencent/pull/620)
- [fix pr 613: modify a judgment logic](https://github.com/Tencent/spring-cloud-tencent/pull/618)

@ -22,7 +22,6 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -106,15 +105,13 @@ public class DecodeTransferMetadataReactiveFilter implements WebFilter, Ordered
String[] transHeaderArray = transHeaders.split(",");
HttpHeaders headers = serverHttpRequest.getHeaders();
Set<String> headerKeys = headers.keySet();
Iterator<String> iterator = headerKeys.iterator();
while (iterator.hasNext()) {
String httpHeader = iterator.next();
for (String httpHeader : headerKeys) {
Arrays.stream(transHeaderArray).forEach(transHeader -> {
if (transHeader.equals(httpHeader)) {
List<String> list = headers.get(httpHeader);
String httpHeaderValue = JacksonUtils.serialize2Json(list);
MetadataContextHolder.get().putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
return;
MetadataContextHolder.get()
.putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
}
});
}

@ -98,8 +98,8 @@ public class DecodeTransferMetadataServletFilter extends OncePerRequestFilter {
if (transHeader.equals(httpHeader)) {
String httpHeaderValue = httpServletRequest.getHeader(httpHeader);
// for example, {"trans-headers-kv" : {"header1":"v1","header2":"v2"...}}
MetadataContextHolder.get().putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
return;
MetadataContextHolder.get()
.putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
}
});
}

@ -22,7 +22,6 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -104,16 +103,14 @@ public class EncodeTransferMedataScgFilter implements GlobalFilter, Ordered {
String[] transHeaderArray = transHeaders.split(",");
HttpHeaders headers = serverHttpRequest.getHeaders();
Set<String> headerKeys = headers.keySet();
Iterator<String> iterator = headerKeys.iterator();
while (iterator.hasNext()) {
String httpHeader = iterator.next();
for (String httpHeader : headerKeys) {
Arrays.stream(transHeaderArray).forEach(transHeader -> {
if (transHeader.equals(httpHeader)) {
List<String> list = headers.get(httpHeader);
String httpHeaderValue = JacksonUtils.serialize2Json(list);
// for example, {"trans-headers-kv" : {"header1":"v1","header2":"v2"...}}
MetadataContextHolder.get().putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
return;
MetadataContextHolder.get()
.putContext(FRAGMENT_RAW_TRANSHEADERS_KV, httpHeader, httpHeaderValue);
}
});
}

@ -75,7 +75,8 @@ public final class ReporterUtils {
resultRequest.setCallerService(new ServiceKey(sourceNamespace, sourceService));
}
resultRequest.setHost(uri.getHost());
resultRequest.setPort(uri.getPort());
// -1 means access directly by url, and use http default port number 80
resultRequest.setPort(uri.getPort() == -1 ? 80 : uri.getPort());
return resultRequest;
}

Loading…
Cancel
Save