0

In a situation where I have:

<int-http:outbound-gateway request-channel="dataHubRawDataUploadChannel"
        id="raw" url-expression="headers['rawUrl']" http-method="POST"
        extract-request-payload="true" header-mapper="headerMapper"
        reply-channel="rawDataUploadResponseChannel" expected-response-type="java.lang.String" 
         error-handler="rawResponseErrorHandler" />

    <int-http:outbound-gateway request-channel="canonicalHttpChannel"
        id="canonical" url-expression="headers['canonicalUrl']"
        http-method="POST" header-mapper="headerMapper" reply-channel="targetDataUploadChannel"
        expected-response-type="java.lang.String"    rest-template="customRestTemplate"/>


    <int-http:outbound-gateway request-channel="targetHttpChannel"
        id="target" url-expression="headers['targetUrl']"
        http-method="POST" header-mapper="headerMapper" reply-channel="targetUploadResponseProcessor"
        expected-response-type="java.lang.String" />

I face the following problem:

The headers of the first and second request are not cleared when sending the third request , resulting in a Http 400 response.

I tried to clean the headers but the only solution I found is to override the RestTemplate class responsible for the actual HTTP request and clear the headers there, which is an ugly solution.

Do you have a better way to do it with Spring Integration?

Richard-Degenne
  • 2,892
  • 2
  • 26
  • 43

1 Answers1

0

The DefaultHttpHeaderMapper has a method setExcludedOutboundStandardRequestHeaderNames where you can pass it an array of header names that you don't want propagated from the outbound message.

See this answer for an example.

EDIT

If you are using Java configuration, simply define that mapper as a @Bean as shown in that answer.

If you are using XML configuration:

<bean id="mapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper"
        factory-method="outboundMapper">
    <property name="excludedInboundStandardResponseHeaderNames">
        <array>
            <value>Host</value>
            <value>User-Agent</value>
        </array>
    </property>
</bean>
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • My problem now is that when I configure this at xml level such as: ` ` It would not exclude that field called fileName – Alfredo Salvati Jul 07 '17 at 15:17
  • Don't put code in comments; it's unreadable; edit the question instead. Since you are using `*` in the outbound header names you're overriding the exclusions. You should use the factory method to create the outbound adapter as in that sample (use `factory-method` in XML). – Gary Russell Jul 07 '17 at 15:30
  • Sorry my first post on Stack Overflow! Thanks for the advices, do you happen to have a code sample for a similar case ? i am new with spring integrations .. – Alfredo Salvati Jul 07 '17 at 15:44