简体   繁体   English

具有多个http出站网关的Spring Integration不会清除标头

[英]Spring Integration with multiple http outbound gateway does not clear the header

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. 发送第三个请求时不会清除第一个和第二个请求的标头 ,从而导致Http 400响应。

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. 我尝试清理标头,但发现的唯一解决方案是重写负责实际HTTP请求的RestTemplate类,并在那里清除标头,这是一个丑陋的解决方案。

Do you have a better way to do it with Spring Integration? 您是否有更好的方法来使用Spring Integration?

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. DefaultHttpHeaderMapper有一个setExcludedOutboundStandardRequestHeaderNames方法,您可以在其中传递一个不想从出站消息传播的标头名称数组。

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. 如果使用Java配置,只需将该映射器定义为@Bean ,如该答案所示。

If you are using XML configuration: 如果使用XML配置:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM