@PostMapping(value = "hi") public String postHi(@RequestHeader HttpHeaders headers, HttpServletRequest request) { return request.getHeader("Content-Length"); }
Spring cloud gateway route configuration :
spring:
cloud:
gateway:
routes:
- id: hi
uri: http://localhost:8080/hi predicates: - Path=/hi/**
So when I upload small file (size:1000 KB) via a postman request I get no error but when the file is large (size :10 MO) I get the following error :
{
"timestamp": "2019-12-10T20:52:33.554+0000", "path": "/hi", "status": 500, "error": "Internal Server Error", "message": "Connection has been closed BEFORE response, while sending request body", "requestId": "ad589017" }
with this stack :
reactor.netty.http.client.PrematureCloseException: Connection has been closed BEFORE response, while sending request body Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s): |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain] |_ checkpoint ⇢ HTTP POST "/hi" [ExceptionHandlingWebHandler] Stack trace:
[reactor-http-epoll-8] ERROR [studyX-gateway,cf0edfec528a956e,cf0edfec528a956e,true] o.s.b.a.w.r.error.AbstractErrorWebExceptionHandler:122 - [840b107e-14] 500 Server Error for HTTP POST "/api/xxx/"
reactor.netty.http.client.PrematureCloseException: Connection has been closed BEFORE response, while sending request body
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.web.cors.reactive.CorsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.cloud.sleuth.instrument.web.TraceWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/api/xxx/" [ExceptionHandlingWebHandler]
Stack trace:
解決:下游配置超時時間
server:
port: 6000
tomcat:
connection-timeout: 6000