apache / apache/servicecomb-java-chassis
spring-boot内嵌tomcat场景下,SpringMVC restcontroller接口内调用cse接口如何传递header(上下文)信息
- 主要言語
- Java
- スター
- 1.9k
- フォーク
- 814
- 平均マージ
- 8日 23時間
- マージ済み PR(30日)
- 1
説明
## 场景
集成spring-boot-actuator组件,业务通过curl命令调用actuator/health接口检测服务状态,业务自定义AbstractHealthIndicator里面调用cse的health接口,代码如下:
```java
@Component
public class HealthChecker extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
RestTemplate restTemplate = RestTemplateBuilder.create();
String result = restTemplate.getForObject("cse://provider/test/health", String.class);
if ("UP".equals(result)) {
builder.up().withDetail("cseState", "UP");
} else {
builder.down().withDetail("cseState", "DOWN");
}
}
}
```
curl命令:携带x-cse-context header信息
```shell
curl -ki -H 'x-cse-context: {"x-biz-tenantId": "1002"}' http://localhost:9093/provider/actuator/health
```
## 期望
在provider/test/health 这个cse接口内可以通过handler在invocationcontext中获取到'x-cse-context: {"x-biz-tenantId": "1002"}' 信息。
## 现状
由于actuator组件的endpoint接口是由Spring MVC的DispatchServlet处理的,而cse接口是由RestServlet处理的,这个header信息无法带过来,但是是处于同一条调用链中。
其实,任何restcontroller接口调用cse接口都无法传递header信息, 我们希望在前台设置header上下文,调用rest接口的时候,将这个上下文传递到cse接口中
```java
@RestController("/")
public class HelloController {
@GetMapping("/hello")
public String hello(){
RestTemplate restTemplate = RestTemplateBuilder.create();
return restTemplate.getForObject("cse://provider/test/health", String.class);
}
}
```
请问有什么方案?
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず Spring MVC DispatchServlet と RestServlet の境界を追跡し、次に RestTemplate が cse://provider/test/health の呼び出しをどのように処理するか、また InvocationContext がどのように設定されるかを調べます。curl の x-cse-context ヘッダーを使って actuator/health に対するフローを再現します。同じコンテキストが下流の CSE health handler で利用できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, spring-boot
- 領域
- api, backend, distributed-systems
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100