简体   繁体   English

使用 Spring Boot 接收 GitLab webhook 消息

[英]Receiving GitLab webhook messages using Spring Boot

I want to receive GitLab webhook messages via spring boot rest controller but i'm encountering problem with empty POST body of webhook message.我想通过 spring boot rest 控制器接收 GitLab webhook 消息,但我遇到了 webhook 消息的空 POST 正文的问题。

My testing RestController is pretty simple:我的测试 RestController 非常简单:

@SpringBootApplication
@RestController
@RequestMapping("/gitlab/project")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @PostMapping("/ok")
    public String working() {
        return "ok";
    }

    @PostMapping("/fails0")
    public String fails(@RequestBody String message) {
        return "never reaches this line";
    }

    @PostMapping("/fails1")
    public String fails(@RequestBody JsonNode message) {
        return "never reaches this line";
    }
}

When I enabled TRACE logging level on root logger, incoming request from GitLab looked like this:当我在根记录器上启用 TRACE 日志级别时,来自 GitLab 的传入请求如下所示:

[POST /gitlab/project/fails0 HTTP/1.1
Content-Type: application/json
X-Gitlab-Event: Push Hook
Connection: close
Host: 128.71.128.109:8080
Content-Length: 2065

]

After 3s timeout GitLab fails test message with exception:在 3 秒超时后 GitLab 测试失败,但出现异常:

Hook execution failed: Net::ReadTimeout

After much longer timeout Spring fails with this exception:在更长的超时时间后,Spring 失败并出现此异常:

org.springframework.http.converter.HttpMessageNotReadableException: I/O      error while reading input message; nested exception is java.net.SocketTimeoutException

If i'm not trying to receive POST payload, request and response is executed correctly, but, of course, this is not what i want.如果我不尝试接收 POST 有效负载,则请求和响应会正确执行,但是,当然,这不是我想要的。

Can someone tell me where is the problem?有人能告诉我问题出在哪里吗?

the code is correct.代码是正确的。 The problem is probably the network.问题应该是网络。 If a docker is used, do not use localhost:8080.如果使用 docker,请不要使用 localhost:8080。 Use the IP of your local machine or dns.使用本地机器的 IP 或 dns。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM