Fix jdk-http and okhttp-3.x plugin did not overwrite the old trace header. (#5958)

* Fix jdk-http and okhttp-3.x did not overwrite the old trace header.

* Update CHANGES.md.
This commit is contained in:
zifeihan 2020-12-06 21:14:12 +08:00 committed by GitHub
parent 6eb5648ba8
commit c24dbd6ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 4 deletions

View File

@ -8,7 +8,7 @@ Release Notes.
* Chore: adapt `create_source_release.sh` to make it runnable on Linux.
#### Java Agent
* Fix jdk-http and okhttp-3.x plugin did not overwrite the old trace header.
#### OAP-Backend
* Make meter receiver support MAL.

View File

@ -74,7 +74,7 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
headerBuilder.add(next.getHeadKey(), next.getHeadValue());
headerBuilder.set(next.getHeadKey(), next.getHeadValue());
}
headersField.set(request, headerBuilder.build());
}

View File

@ -52,7 +52,7 @@ public class HttpClientWriteRequestInterceptor implements InstanceMethodsAroundI
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
headers.add(next.getHeadKey(), next.getHeadValue());
headers.set(next.getHeadKey(), next.getHeadValue());
}
}

View File

@ -38,9 +38,11 @@ public class CaseController {
@RequestMapping("/jdk-http-scenario")
@ResponseBody
public String testcase() throws IOException {
// Like gateway forward trace header.
URL url = new URL("http://localhost:8080/jdk-http-scenario/case/receiveContext-0");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("key", "value");
connection.addRequestProperty("sw8", "123456");
int responseCode = connection.getResponseCode();
return "Success:" + responseCode;
}

View File

@ -47,7 +47,9 @@ public class CaseController {
@RequestMapping("/okhttp-case")
@ResponseBody
public String okHttpScenario() {
Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-0").build();
// Like gateway forward trace header.
Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-0")
.header("sw8", "123456").build();
new OkHttpClient().newCall(request).enqueue(new Callback() {
@Override
@ -58,6 +60,7 @@ public class CaseController {
@Override
public void onResponse(Call call, Response response) throws IOException {
Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-1")
.header("sw8", "123456")
.build();
new OkHttpClient().newCall(request).execute();
}