'POST , PATCH , PUT calls with body not working through Spring Cloud Gateway

I have a backend service with GET and POST calls which work fine with direct end-points but when I call them through spring cloud gateway - the GET calls works fine but POST/PATCH/PUT calls return 504 gateway error. Further analyzing the logs , it is exactly the below errors that is thrown. The back-end service gets called when I remove the body for these POST/PATCH/PUT calls but with body is throwing the below error - I also have given the config snapshot below. Please can you advice what is wrong with this?

message: Http Error Code: 500. org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:310)

Http Error Code: 400. Validation failed: org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is org.apache.catalina.connector.ClientAbortException: java.io.EOFException

spring:
  cloud:
    gateway:
      routes:
        - id: backend-service
          uri: http://backend-service:8080/
          predicates:
            - Path=/backend-service/**
            - Method=GET,POST,PATCH

Here is my controller :

@PostMapping("/id/{Id}") 
public ResponseEntity<Void> modifyTableData(@PathVariable String Id,@RequestBody UpdateRequest updateRequest) {
 
    repository.updateId(Id, updateRequest.getId(), updateRequest.getCountry()); 
    return ResponseEntity.noContent().build(); 
}

Here is the request body :

{
"Id": 12345,
"country": "IN",
"email": "[email protected]",
"name":"Ravi"
}

Request DTO :

@EqualsAndHashCode
@Getter
@Setter
@ToString
public class UpdateRequest {
    @JsonProperty("Id")
    private Long Id;
    @JsonProperty("country")
    private String country;
    @JsonProperty("email")
    private String email;
    @NotBlank
    @JsonProperty("name")
    private String name;
}

Not to mention again , the same request with DELETE method works fine - it is a problem only with PATCH/PUT/POST.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source