7

In a working Spring MVC 4.0.2 project running under Tomcat 7.0.50, I'm trying to implement Spring Websocket with simple broker and sockjs stomp endpoint, following the official reference. So, in the contextConfigLocation (DistpacherServlet property) I've add a value "websocket-config.xml" which contains:

>     <websocket:message-broker application-destination-prefix="/app" >
>           <websocket:stomp-endpoint path="/monitor">
>             <websocket:sockjs />
>           </websocket:stomp-endpoint>
>           <websocket:simple-broker prefix="/topic"/>
>     </websocket:message-broker>

In eclipse console (catalina log) when I start Tomcat, appear the rows

  • Initializing ExecutorService 'clientInboundChannelExecutor'
  • Initializing ExecutorService 'clientOutboundChannelExecutor'
  • Initializing ExecutorService 'messageBrokerSockJsScheduler'
  • Mapped URL path [/monitor/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]

In the jsp page I put the code

. . . .
var socket = new SockJS("monitor");
var stompClient = Stomp.over(socket); . . . .

Unfortunately when I load the jsp page from Chrome (v32), I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found)

http ://localhost:8080/(ProjectName)/monitor/info

Obviously I'm doing this test locally, then all other webapp resources are reachable at http ://localhost/(ProjectName) correctly.

What's wrong?

**** Update 20 Feb 2014 I've tried to follow this resolved stack question, which suggests to use Tomcat8 for Spring Websocket, unfortunately it doesn't work

2 Answers 2

6

Any log output on the server side as a result of the request to /monitor/info? How is the DispatcherServlet itself mapped? I would expect to "/" from what you have above.

The SockJS endpoint is basically a URL mapped in Spring MVC (with a SimpleUrlHandlerMapping) so try other Spring MVC mapped controller methods. And turn up logging, could there be a filter or something else returning the 404?

Sign up to request clarification or add additional context in comments.

9 Comments

WONDERFUL! :)) I've spent so much time trying to fix this problem and you solved it in a while. My mistake is the usage of Dispatcher url-pattern "*.do", so the Servlet doesn't catch websocket client request. I changed it in "/", (but I had to add others fake url pattern for resource files, as suggested by @Gofier here and it worked! I love you :) Many thanks
Glad it's working now :) Keep in mind that for serving resource files we also have a resource handling mechanism. See docs.spring.io/spring-framework/docs/current/….
Could you expand on your answer a little? Are you saying the dispatcher servlet needs to also handle the requests for the SockJS endpoint?
Paul, yes the SockJS endpoint is an HTTP endpoint mapped with and served by Spring MVC. See SockJsHttpRequestHandler.
Hi there! I'm having the same issue, but unfortunately haven't used websockets for long and am wondering what you mean by changing things in "/"? Could you possibly walk me through what you had to do to fix the issue?
|
1

For those who struggle with this issue this might helps. I had following in web.xml:

<servlet>
 <servlet-name>rest</servlet-name> 
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> 
 <servlet-name>rest</servlet-name> 
 <url-pattern>/rest/*</url-pattern> 
</servlet-mapping>

And had 404 response for this url: http ://localhost:8080/(ProjectName)/monitor

But this one works like charm: http ://localhost:8080/(ProjectName)/rest/monitor

Cheers!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.