如何解决氛围+ Spring MVC 5集成
我试图运行Atmosphere(2.5.12)+ Spring MVC(5.2.8),但是遇到了一个问题。
由于某些Spring发布了AbstractMessageConverterMethodProcessor类,因此writeWithMessageConverters方法已开始检查请求的响应标头“ Content-Type”,而不是请求的“ Accept”标头,以查找适当的消息转换器。
请参阅:
MediaType selectedMediaType = null;
MediaType contentType = outputMessage.getHeaders().getContentType();
boolean isContentTypePreset = contentType != null && contentType.isConcrete();
if (isContentTypePreset) {
if (logger.isDebugEnabled()) {
logger.debug("Found 'Content-Type:" + contentType + "' in response");
}
selectedMediaType = contentType;
}
else {
HttpServletRequest request = inputMessage.getServletRequest();
List<MediaType> acceptableTypes = getAcceptableMediaTypes(request);
List<MediaType> producibleTypes = getProducibleMediaTypes(request,valueType,targetType);
问题在于,Atmosphere Framework也设置了Content-Type标头。并且始终为“文本/纯文本”,它是在AtmosphereFramework configureRequestResponse方法中设置的。
请参阅: https://github.com/Atmosphere/atmosphere/issues/2312
即使未在此处设置标题,它也是AtmosphereResponseImpl中的默认contentType,即text / html ...
在这种情况下,Spring永远找不到正确的转换器,并且会引发异常:
DefaultHandlerExceptionResolver]:已解决的[org.springframework.http.converter.HttpMessageNotWritableException:没有带有预设Content-Type'text / plain; charset = utf-8'的[class com.Connection]转换器
我正在使用web.xml中的当前配置:
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.servlet</param-name>
<param-value>org.springframework.web.servlet.DispatcherServlet</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.CometSupport.maxInactiveActivity</param-name>
<param-value>3600000000</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useStream</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useWebSocket</param-name>
<param-value>true</param-value>
</init-param>
<!-- <init-param> -->
<!-- <param-name>org.atmosphere.useNative</param-name> -->
<!-- <param-value>true</param-value> -->
<!-- </init-param> -->
<init-param>
<param-name>org.atmosphere.cpr.supportSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.filter</param-name>
<param-value>org.springframework.web.filter.DelegatingFilterProxy</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.filter.name</param-name>
<param-value>springSecurityFilterChain</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.websocket.suppressJSR356</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>
<param-value>org.atmosphere.client.TrackMessageSizeFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
...........
我的配置正确吗? 是否所有请求都必须通过公共AtmosphereFramework configureRequestResponse(AtmosphereRequest req,AtmosphereResponse res)方法进行处理? 有什么方法可以让Spring忽略AtmosphereResponseImpl中的Content-Type标头?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。