1

I am trying to get the Spring 4 example webapp with websockets (available on github) up and running. But I cannot get a websocket connection established.

I am deploying from STS-3.3.0 on a Tomcat-7.0.50 and everything seems to be fine on the server side. After having been successfully logged in as a User, the message broker is publishing messages. But the client fails to connect to the service!

1.Error message in the browser (originating from sockjs.js):

enter image description here

2.Console output during login request:

18:01:10 [http-bio-8080-exec-10] DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/test/] 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Looking up handler method for path /index.html 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Did not find handler method for [/index.html] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Matching patterns for request [/index.html] are [/[*][*]] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - URI Template variables for request [/index.html] are {} 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Mapping [/index.html] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@582e240a] and 1 interceptor 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Last-Modified value for [/test/] is: -1 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Successfully completed request 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/test/assets/lib/bootstrap/css/bootstrap.css] 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Looking up handler method for path /assets/lib/bootstrap/css/bootstrap.css 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Did not find handler method for [/assets/lib/bootstrap/css/bootstrap.css] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Matching patterns for request [/assets/lib/bootstrap/css/bootstrap.css] are [/[*][*]] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - URI Template variables for request [/assets/lib/bootstrap/css/bootstrap.css] are {} 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Mapping [/assets/lib/bootstrap/css/bootstrap.css] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@582e240a] and 1 interceptor 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Last-Modified value for [/test/assets/lib/bootstrap/css/bootstrap.css] is: -1 18:01:10 [http-bio-8080-exec-4] DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/test/assets/common/portfolio.css] 18:01:10 [http-bio-8080-exec-4] RequestMappingHandlerMapping - Looking up handler method for path /assets/common/portfolio.css 18:01:10 [http-bio-8080-exec-4] RequestMappingHandlerMapping - Did not find handler method for [/assets/common/portfolio.css] 18:01:10 [http-bio-8080-exec-4] SimpleUrlHandlerMapping - Matching patterns for request [/assets/common/portfolio.css] are [/[*][*]] 18:01:10 [http-bio-8080-exec-4] SimpleUrlHandlerMapping - URI Template variables for request [/assets/common/portfolio.css] are {} 18:01:10 [http-bio-8080-exec-4] SimpleUrlHandlerMapping - Mapping [/assets/common/portfolio.css] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@582e240a] and 1 interceptor 18:01:10 [http-bio-8080-exec-4] DispatcherServlet - Last-Modified value for [/test/assets/common/portfolio.css] is: -1 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Successfully completed request 18:01:10 [http-bio-8080-exec-4] DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 18:01:10 [http-bio-8080-exec-4] DispatcherServlet - Successfully completed request 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/test/assets/lib/bootstrap/img/glyphicons-halflings.png] 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Looking up handler method for path /assets/lib/bootstrap/img/glyphicons-halflings.png 18:01:10 [http-bio-8080-exec-10] RequestMappingHandlerMapping - Did not find handler method for [/assets/lib/bootstrap/img/glyphicons-halflings.png] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Matching patterns for request [/assets/lib/bootstrap/img/glyphicons-halflings.png] are [/[*][*]] 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - URI Template variables for request [/assets/lib/bootstrap/img/glyphicons-halflings.png] are {} 18:01:10 [http-bio-8080-exec-10] SimpleUrlHandlerMapping - Mapping [/assets/lib/bootstrap/img/glyphicons-halflings.png] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@582e240a] and 1 interceptor 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Last-Modified value for [/test/assets/lib/bootstrap/img/glyphicons-halflings.png] is: -1 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 18:01:10 [http-bio-8080-exec-10] DispatcherServlet - Successfully completed request 

3.Console output after login request is completed:

09:43:36 [MessageBrokerSockJS-1] ExecutorSubscribableChannel - [brokerChannel] sending message id=877832f6-d472-8b43-1cd2-555165a7bf4f 09:43:36 [MessageBrokerSockJS-1] ChannelInterceptorChain - postSend (sent=true) message id 877832f6-d472-8b43-1cd2-555165a7bf4f 09:43:36 [brokerChannel-1] DefaultUserDestinationResolver - Ignoring message to /topic/price.stock.RHT, not a "user" destination 09:43:36 [brokerChannel-1] DefaultSubscriptionRegistry - Found 0 subscriptions for destination=/topic/price.stock.RHT 

I first thought Tomcat was the problem as I read version 7.0.47+ is required. But updating didnt have the desired effect. I am quite new to Web-development, especially to WebSockets, so any help to solve my issue is greatly appreciated. Probably it's only a minor problem as i might have something overseen in configuration due to lacking experience ...

9
  • I seem to remember that it's forced anyway, but I'll double-check. When loading the web page, are you being routed through the login screen? This sets up a user session and that user gets a channel to which portfolio changes are routed. Commented Jan 28, 2014 at 9:31
  • 1
    btw ... Did you get it working with Jetty first? That project comes configured to use the Maven Jetty plugin. Just run mvn install jetty:run from the command-line. Commented Jan 28, 2014 at 9:33
  • Yes. I am able to log in. But my user does not subscribe to that channel (as you can see in the log). I have not tried Jetty yet. As i said I am new to web-development, so I only worked with Tomcat so far ... but I will try that out for sure. Commented Jan 28, 2014 at 9:45
  • actually it works just fine with jetty ... if you have any idea why it is not working with tomcat though and you post an answer to my question i will accept it. Thank you :-) Commented Jan 28, 2014 at 10:48
  • 1
    The above log output shows a message being sent with no target subscribers. What happens earlier to the subscriptions after the user logs in? Commented Jan 28, 2014 at 16:56

2 Answers 2

1

This is not an answer as such, but it should get you up and running with the example web app on Tomcat and may help diagnose your own Tomcat config. Put the following in your pom.xml next to the jetty-maven-plugin config:

<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.0</version> <configuration> <port>9090</port> <path>/${project.artifactId}</path> </configuration> </plugin> 

Now from the command-line, you can run:

mvn clean install tomcat7:run 

or when it has been built, just:

mvn tomcat7:run 

This will run the application in an embedded Tomcat 7 server. Assuming that works for you (it does for me), then it may be worth looking at your Tomcat version or config and comparing.

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

3 Comments

I will have a look at that later in the day. Thank you!
On the embedded Tomcat it is also running (version is 7.0.30) ... puzzling to me
I've added the Tomcat maven plugin to the sample. Version 2.2 of the plugin seems to be using Tomcat 7.0.47.
1

This is potentially caused by conflicting jars in your webapp and tomcat. If you have any tomcat or websocket specific jars that you are including in your build and that end up in the {TOMCAT_HOME}/webapps/{YOUR_WEBAPP}/WEB-INF/lib directory, they may be causing the conflict with jars in the {TOMCAT_HOME}/lib directory. Keep in mind that the jars might not be named precisely the same. I experienced this exact problem before and removing the duplicate jars from the {TOMCAT_HOME}/webapps/{YOUR_WEBAPP}/WEB-INF/lib directory fixed the 404 error.

As a further note, if you are using gradle to compile your webapp with the 'war' plugin, there is a 'providedCompile' dependency that you can use that will put the necessary jars on your classpath for testing, importing into eclipse, etc. but will not include them in the actual built war (to specifically avoid scenarios like this)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.