I am trying to make a PUT on a remote REST endpoint for which I need to provide the credentials as part of the headers without success so far.
Approach 1:
@Bean
public IntegrationFlow outboundGateway() {
return flow -> flow
.transform(transformer)
.enrichHeaders(h -> h.header("x-api-key", "secret123")
.header("contentType", MediaType.APPLICATION_JSON))
.handle(Http.outboundGateway("https://remote-service.com/car")
.mappedRequestHeaders()
.httpMethod(HttpMethod.PUT)
.expectedResponseType(String.class))
.log();
}
I keep getting a 403 Forbidden.
I achieved the same with a RestTemplate so easily:
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(getHeaders());
restTemplate.put("https://remote-service.com/car", request);
...
private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.add("x-api-key", "secret123");
return headers;
}
How can I send this x-api-key header and its value with the Http OutboundGateway?
Thanks.