achingfingers
achingfingers

Reputation: 1936

Spring 4.0 WebSocket example-application: Fails to establish websocket connection

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 ...

Upvotes: 1

Views: 1305

Answers (2)

Justin
Justin

Reputation: 11

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)

Upvotes: 1

Steve
Steve

Reputation: 9480

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.

Upvotes: 1

Related Questions