对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

Spring Integration 为 HTTP 请求和 HTTP 响应提供对 HTTP 标头映射的支持。Spring中文文档

默认情况下,所有标准 HTTP 标头都从消息映射到 HTTP 请求或响应标头,无需进一步配置。 但是,如果确实需要进一步自定义,则可以利用命名空间支持来提供其他配置。 您可以提供以逗号分隔的标头名称列表,并且可以包含带有“*”字符作为通配符的简单模式。 提供此类值将覆盖默认行为。 基本上,它假设您此时处于完全控制之中。 但是,如果确实要包含所有标准 HTTP 标头,则可以使用快捷方式模式: 和 . 以下列表显示了两个示例(第一个示例使用通配符):HTTP_REQUEST_HEADERSHTTP_RESPONSE_HEADERSSpring中文文档

<int-http:outbound-gateway id="httpGateway"
    url="http://localhost/test2"
    mapped-request-headers="thing1, thing2"
    mapped-response-headers="X-*, HTTP_RESPONSE_HEADERS"
    channel="someChannel"/>

<int-http:outbound-channel-adapter id="httpAdapter"
    url="http://localhost/test2"
    mapped-request-headers="thing1, thing2, HTTP_REQUEST_HEADERS"
    channel="someChannel"/>

适配器和网关使用 ,它现在为入站和出站适配器提供了两种静态工厂方法,以便可以应用正确的方向(根据需要将 HTTP 请求和响应映射到或传出)。DefaultHttpHeaderMapperSpring中文文档

如果需要进一步自定义,还可以独立配置,并通过属性将其注入适配器。DefaultHttpHeaderMapperheader-mapperSpring中文文档

在版本 5.0 之前,用户定义的非标准 HTTP 标头的默认前缀是 。 V5.0 将默认前缀更改为空字符串。 根据 RFC-6648,现在不鼓励使用此类前缀。 您仍可以通过设置属性来自定义此选项。 以下示例为 HTTP 网关配置标头映射器:DefaultHttpHeaderMapperX-DefaultHttpHeaderMapper.setUserDefinedHeaderPrefix()Spring中文文档

<int-http:outbound-gateway id="httpGateway"
    url="http://localhost/test2"
    header-mapper="headerMapper"
    channel="someChannel"/>

<bean id="headerMapper" class="o.s.i.http.support.DefaultHttpHeaderMapper">
    <property name="inboundHeaderNames" value="thing1*, *thing2, thing3"/>
    <property name="outboundHeaderNames" value="a*b, d"/>
</bean>

如果你需要做一些不支持的事情,你可以直接实现策略接口,并提供对你的实现的参考。DefaultHttpHeaderMapperHeaderMapperSpring中文文档