I am trying to make Rest Web-service POST method call with custom header . Tried to add the custom header in enrichHeaders still getting HTTP 403 Forbidden response. Could you please help with right code snippet?
.enrichHeaders(h -> h.header("X-API-Key","ABCEDABCED").header(CONTENT_TYPE, APPLICATION_JSON_VALUE).header(APP_NAME, XXX).header(ACCEPT,
APPLICATION_JSON_VALUE))
.handle(Http.outboundGateway(config.getXxxWebServiceUrl()).httpMethod(HttpMethod.POST)
.expectedResponseType(String.class).requestFactory(xxxRequestFactory()),
c -> c.advice(sendToArchive.sendToArhive()))
.log().get();
Error Logs :-
[bean 'xxxDispatcher1.http:outbound-gateway#0' for component 'xxxDispatcher1.org.springframework.integration.config.ConsumerEndpointFactoryBean#2'; defined in: 'class path resource [service/xxxDispatcher.class]'; from source: 'bean method xxxDispatcher1']; nested exception is org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [{"message":"Forbidden"}]
at
See Header mappings section in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-header-mapping
By default, all standard HTTP headers are mapped from the message to HTTP request or response headers without further configuration.
So, since you don't provide a mappedRequestHeaders()
option for the Http.outboundGateway()
therefore your APP_NAME
custom header is not mapped and not transferred over the HTTP to the REST service.