此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1spring-doc.cadn.net.cn

HTTP 标头映射

Spring Integration 为 HTTP 请求和 HTTP 响应提供对 HTTP 标头映射的支持。spring-doc.cadn.net.cn

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

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

适配器和网关使用DefaultHttpHeaderMapper,现在为入站和出站适配器提供了两种静态工厂方法,以便可以应用正确的方向(根据需要映射 HTTP 请求和响应)。spring-doc.cadn.net.cn

如果您需要进一步自定义,您还可以配置DefaultHttpHeaderMapper独立并通过header-mapper属性。spring-doc.cadn.net.cn

在 5.0 版本之前,DefaultHttpHeaderMapper用户定义的非标准 HTTP 标头的默认前缀是X-. 5.0 版将默认前缀更改为空字符串。 根据 RFC-6648,现在不鼓励使用此类前缀。 您仍然可以通过设置DefaultHttpHeaderMapper.setUserDefinedHeaderPrefix()财产。 以下示例为 HTTP 网关配置标头映射器:spring-doc.cadn.net.cn

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

如果您需要执行的作不是DefaultHttpHeaderMapper支持,您可以实现HeaderMapper策略接口,并为您的实施提供参考。spring-doc.cadn.net.cn