Spring-Integration websocket异常"没有适用于处理程序SockJsHttpRequestHandler"

时间:2015-03-14 00:18:27

标签: spring-integration spring-websocket

我试图基于Spring-Integration创建一个websockets服务器。我使用以下配置文件(暂时):

<int-websocket:server-container 
            id="serverWebSocketContainer" 
            path="websocket">
    <int-websocket:sockjs />
</int-websocket:server-container>

<int:channel id="receiveMessage"/>

<int-websocket:inbound-channel-adapter 
            channel="receiveMessage" 
            container="serverWebSocketContainer" />

<int:service-activator 
                       input-channel="receiveMessage"
                       output-channel="nullChannel"
                       ref="websocketActivator"
                       method="onReceiveMessage"
                       requires-reply="true"
                       send-timeout="60000"/>

问题在于我总是面临以下例外:

2015-03-14 01:11:01,283 DEBUG SimpleUrlHandlerMapping:  124 - Mapping [/websocket/fingervein] to HandlerExecutionChain with handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a] and 1 interceptor
2015-03-14 01:11:01,283 DEBUG AnnotationMethodHandlerExceptionResolver:  134 - Resolving exception from handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: javax.servlet.ServletException: No adapter for handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
2015-03-14 01:11:01,286 DEBUG ResponseStatusExceptionResolver:  134 - Resolving exception from handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: javax.servlet.ServletException: No adapter for handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
2015-03-14 01:11:01,287 DEBUG DefaultHandlerExceptionResolver:  134 - Resolving exception from handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: javax.servlet.ServletException: No adapter for handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
2015-03-14 01:11:01,291 DEBUG DispatcherServlet:  989 - Could not complete request
javax.servlet.ServletException: No adapter for handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@1a767c6a]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
    at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1147)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

您的DispatcherServlet似乎无法检测DispatcherServlet.properties的{​​{1}}。

defaultStrategies的{​​{1}}实际上是默认的第一个:

HandlerAdapter

或者您的应用程序上下文中有一些自定义SockJsHttpRequestHandler bean,它们无法处理org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\ org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\ org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 实现。在这种情况下,您还应该为HandlerAdapter添加一个bean。

答案 1 :(得分:0)

SockJsHttpRequestHandler / WebSocketHttpRequestHandlerHttpRequestHandler

的子类

所以HttpRequestHandlerAdapter可以用来作为它的适配器。确保DispatcherServlet配置文件包含此类型的bean

例如: 将以下行添加到dispatch-servlet.xml(或用于dispatcher-servlet的其他xml文件) <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/>