未验证 提交 c24dbd6e 编写于 作者: Z zifeihan 提交者: GitHub

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.
上级 6eb5648b
......@@ -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.
......
......@@ -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());
}
......
......@@ -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());
}
}
......
......@@ -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;
}
......
......@@ -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();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册