我正在尝试为图像主机服务设置响应的内容类型,所以我有一个如下所示的 http:inbound-gateway:
<int-http:inbound-gateway request-channel="receiveChannel"
reply-channel="responseChannel"
path="/profile/photo"
mapped-response-headers="Content-Type"
message-mappers="messageConverterList"
supported-methods="GET"/>
...和一个看起来像这样的服务激活器:
<int:service-activator
input-channel="receiveChannel"
output-channel="imageResponseChannel"
expression="@profileService.getPhoto(payload.userId)"/>
...它返回一个字节[]的JPEG图像数据。我有一个看起来像这样的标题丰富器:
<int:header-enricher
input-channel="imageResponseChannel"
output-channel="responseChannel">
<int:header
name="Content-Type"
expression="'image/jpeg'"/>
</int:header-enricher>
但是当我运行该项目时,我会收到带有如下标题的响应:
< HTTP/1.1 200 OK
< Set-Cookie: JSESSIONID=9uw5c136fia6s9ivxgivy1yc;Path=/
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Type: image/jpeg
< Content-Type: application/octet-stream
< Content-Length: 6563
< Server: Jetty(8.1.3.v20120416)
请注意,内容类型是重复的,但我的理解是映射响应标头应该从消息中获取标头,而不是从有效负载中确定它。
有任何想法吗?提前致谢!
*编辑:我更改了入站网关以引用下面的自定义消息映射器,但我仍然得到相同的结果。
<util:list id="messageConverterList">
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
<property name="supportedMediaTypes">
<list><value>image/jpeg</value></list>
</property>
</bean>
</util:list>
*编辑2:原来它应该是消息转换器,但我没有收到错误,因为我修改了目标文件而不是src。我进行了更正,这是我得到的输出:
< HTTP/1.1 200 OK
< Content-Type: image/jpeg
< Content-Type: image/jpeg
< Content-Length: 209582
< Server: Jetty(6.1.10)
更好,但并不完美。这是该问题的简单再现项目:http: //dl.dropbox.com/u/92800052/http.tar.gz
你可以运行它
mvn package jetty:run
并查看输出
curl -v http://localhost:8080/http/photo > /dev/null