1

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.

1 Answer 1

1

The x-api-keyis not a standard http header, so you need to make it to be transferred:

 .mappedRequestHeaders(*)

For your Http.outboundGateway().

See docs for more info: https://docs.spring.io/spring-integration/docs/5.2.6.RELEASE/reference/html/http.html#http-header-mapping

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.