3

I couldn't find a function to add headers to outboundGateway in spring integration dsl.

.handle(outboundGateway("localhost:8080/search")
       .httpMethod(HttpMethod.GET)
       .expectedResponseType(Order.class))

The headers that i would like to add to request are

HttpHeaders headers = new HttpHeaders();
headers.setAccept(newArrayList(APPLICATION_JSON));
headers.setContentType(APPLICATION_JSON);
headers.add("Client-Id", "test");

Can someone help me here

nagendra
  • 593
  • 1
  • 9
  • 29

1 Answers1

3

That's correct: Spring Integration doesn't allow to manipulate HttpHeaders object directly. Instead you should follow the canonical messaging approach - protocol free .enrichHeaders():

.enrichHeaders(e -> e
                        .header(DefaultHttpHeaderMapper.ACCEPT, APPLICATION_JSON)
                        .header(DefaultHttpHeaderMapper.CONTENT_TYPE, APPLICATION_JSON)
                        .header("Client-Id", "test"))
.handle(outboundGateway("localhost:8080/search")
   .httpMethod(HttpMethod.GET)
   .expectedResponseType(Order.class))
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Sorry it didnt work these headers are not passed to the client, my wiremock complained saying "Header is not present" to match to the stub. – nagendra May 04 '18 at 14:53
  • 3
    I made it to work by adding `.mappedRequestHeaders("Client-Id", DefaultHttpHeaderMapper.ACCEPT, DefaultHttpHeaderMapper.CONTENT_TYPE)` to outboundGateway – nagendra May 04 '18 at 15:00
  • Or you can use `*`. Sorry, been busy, but glad that you have figured out without the help! – Artem Bilan May 04 '18 at 15:07
  • Thanks anyway for the help, i dont want to use * as i have some flow header variables which i don't want to send to client – nagendra May 04 '18 at 15:18