I have tried dynamic headers sending them as HashMap like this:
Map<String, String> headers = new HashMap<>();
headers.put("x-country", "CL");
and all works fine, but I need to send them as static headers, and I am doing it this way:
//feign client interface:
@FeignClient(name = "ms-enterprise-api", url = "http://localhost:8082")
public interface ApiFeignClient {
@PostMapping(value = "/v1/msService/getData", consumes = MediaType.APPLICATION_JSON_VALUE)
@Headers({"Content-Type: application/json","x-country: CL"})
ResponseEntity<PayResponseDTO> getVoucher(@RequestBody PayRequestDTO request);
@PostMapping(value = "/v1/msService/getData", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PayResponseDTO> getVoucherOld(@RequestHeader Map<String, String> headerMap, @RequestBody PayRequestDTO request);
}
The error I get in the API requested:
feign.FeignException$BadRequest: [400] during [POST] to [http://localhost:8082/v1/...getData] [ApiFeignClient#getVoucher(PayRequestDTO)]: [{"timestamp":"2022-09-02T14:33:57.360+00:00","status":400,"error":"Bad Request","trace":"org.springframework.web.bind.MissingRequestHeaderException: Required request header 'x-country' for method para... (6239 bytes)]
Am I doing something bad?