Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

spring-boot内嵌tomcat场景下,SpringMVC restcontroller接口内调用cse接口如何传递header(上下文)信息

未关闭
#4,632 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
java, spring-boot

调研方向

首先跟踪 Spring MVC DispatchServlet 与 RestServlet 的边界,然后检查 RestTemplate 如何处理 cse://provider/test/health 调用,以及如何填充 InvocationContext。使用 curl 的 x-cse-context header 对 actuator/health 重现该流程;当相同的 context 在下游 CSE health handler 中可用时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

场景

集成spring-boot-actuator组件,业务通过curl命令调用actuator/health接口检测服务状态,业务自定义AbstractHealthIndicator里面调用cse的health接口,代码如下:

@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");
        }
    }
}
image

curl命令:携带x-cse-context header信息

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接口中

@RestController("/")
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        RestTemplate restTemplate = RestTemplateBuilder.create();
        return  restTemplate.getForObject("cse://provider/test/health", String.class);
    }
}

image

请问有什么方案?

主要语言
Java
星标
1.9k
派生
813
平均合并
8 天 23 小时
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/servicecomb-java-chassis 的其他 Issue

查看 apache/servicecomb-java-chassis 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。