HTTP Header Mappings
Spring Integration 为 HTTP 请求和响应提供 HTTP 标头映射的支持。
Spring Integration provides support for HTTP header mapping for both HTTP Request and HTTP Responses.
默认情况下,所有标准 HTTP headers都从消息映射到 HTTP 请求或响应头,无需进一步配置。但是,如果您确实需要进一步定制,则可以利用命名空间支持提供其他配置。您可以提供以逗号分隔的头名称列表,并且您可以将具有作为通配符的 '*' 字符的简单模式包括在内。提供此类值会覆盖默认行为。基本上,它假设您在这一点上完全控制。但是,如果您确实想要包含所有标准的 HTTP 头,则可以使用快捷方式模式: HTTP_REQUEST_HEADERS`和 `HTTP_RESPONSE_HEADERS
。以下列表显示了两个示例(第一个示例使用通配符):
By default, all standard HTTP headers are mapped from the message to HTTP request or response headers without further configuration.
However, if you do need further customization, you can provide additional configuration by taking advantage of the namespace support.
You can provide a comma-separated list of header names, and you can include simple patterns with the '*' character acting as a wildcard.
Provide such values overrides the default behavior.
Basically, it assumes you are in complete control at that point.
However, if you do want to include all the standard HTTP headers, you can use the shortcut patterns: HTTP_REQUEST_HEADERS
and HTTP_RESPONSE_HEADERS
.
The following listing shows two examples (the first of which uses a wildcard):
<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 请求和响应)。
The adapters and gateways use the DefaultHttpHeaderMapper
, which now provides two static factory methods for inbound and outbound adapters so that the proper direction can be applied (mapping HTTP requests and responses either in or out, as appropriate).
如果您需要进一步自定义,您还可以在单独的情况下配置一个 DefaultHttpHeaderMapper
,并通过 header-mapper
属性将其注入到适配器中。
If you need further customization, you can also configure a DefaultHttpHeaderMapper
independently and inject it into the adapter through the header-mapper
attribute.
5.0 版之前,用户定义的非标准 HTTP 头的默认前缀为 X-
。5.0 版将默认前缀更改为空字符串。根据 RFC-6648,现在不建议使用此类前缀。您仍然可以通过设置 `DefaultHttpHeaderMapper.setUserDefinedHeaderPrefix()`属性来自定义此选项。以下示例为 HTTP 网关配置了一个头映射器:
Before version 5.0, the DefaultHttpHeaderMapper
the default prefix for user-defined, non-standard HTTP headers was X-
.
Version 5.0 changed the default prefix to an empty string.
According to RFC-6648, the use of such prefixes is now discouraged.
You can still customize this option by setting the DefaultHttpHeaderMapper.setUserDefinedHeaderPrefix()
property.
The following example configures a header mapper for an HTTP gateway:
<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
策略接口,并提供对实现的引用。
If you need to do something other than what the DefaultHttpHeaderMapper
supports, you can implement the HeaderMapper
strategy interface directly and provide a reference to your implementation.