氛围+ 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 (将#修改为@)