title: Spring Websocket: Error during WebSocket handshake: Unexpected response code: 404
body: <p>I implemented my own Websocket application based on Spring framework and used the same configuration: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html" rel="noreferrer">http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html</a></p>
  
  <p>Server side code:</p>
  
  <pre><code>import org.springframework.context.annotation.Configuration;
  import org.springframework.messaging.simp.config.MessageBrokerRegistry;
  import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
  import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
  import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
  
  @Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry config) {
          config.enableSimpleBroker("/topic");
          config.setApplicationDestinationPrefixes("/app");
      }
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint("/ws").withSockJS();
      }
  
  }
  </code></pre>
  
  <p>client side code: *.jsp file</p>
  
  <pre><code>        /*
           *connect to websocket
           */
          function connect() {
              var socket = new SockJS("&lt;c:url value='/ws'/&gt;");
              stompClient = Stomp.over(socket);
              stompClient.connect();
          }
  
          function disconnect() {
              stompClient.disconnect();
              setConnected(false);
              console.log("Disconnected");
          }
  </code></pre>
  
  <p>pom.xml dependencies:</p>
  
  <pre><code>        &lt;!-- Spring websocket and messaging --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-messaging&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-websocket&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>The application can run on Spring Tools Suite's Pivotal tc Server Developer Edition v3.0 (blinding with Tomcat8.0.15) or Tomcat7.0.53. However, when I deploy this application to server, the websocket is not working. The console shows:</p>
  
  <pre><code>stomp.min.js:8 Opening Web Socket...
  sockjs.min.js:27 WebSocket connection to 'ws://serverip/ws/331/xsooi48g/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
  sockjs.min.js:27 POST http://serverip/ws/331/1mg08452/xhr_streaming 500 (Internal Server Error)
  sockjs.min.js:27 POST http://serverip/ws/331/mmodvswk/xhr 500 (Internal Server Error)
  stomp.min.js:8 Whoops! Lost connection to undefined
  </code></pre>
  
  <p>Did I miss something else?</p>
  
  <p>UPDATE: 
  Tomcat version 7.0.52.0
  Server side log:</p>
  
  <pre><code> WARN : org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService - Failed to create a default WebSocketTransportHandler
  java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found
          at org.springframework.web.socket.server.support.DefaultHandshakeHandler.initRequestUpgradeStrategy(DefaultHandshakeHandler.java:127)
          at org.springframework.web.socket.server.support.DefaultHandshakeHandler.&lt;init&gt;(DefaultHandshakeHandler.java:96)
          at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.getDefaultTransportHandlers(DefaultSockJsService.java:88)
          at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.&lt;init&gt;(DefaultSockJsService.java:74)
          at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.createSockJsService(SockJsServiceRegistration.java:286)
          at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.getSockJsService(SockJsServiceRegistration.java:244)
          at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration$StompSockJsServiceRegistration.getSockJsService(WebMvcStompWebSocketEndpointRegistration.java:161)
          at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration.getMappings(WebMvcStompWebSocketEndpointRegistration.java:127)
          at org.springframework.web.socket.config.annotation.WebMvcStompEndpointRegistry.getHandlerMapping(WebMvcStompEndpointRegistry.java:142)
          at org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport.stompWebSocketHandlerMapping(WebSocketMessageBrokerConfigurationSupport.java:59)
          at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58.CGLIB$stompWebSocketHandlerMapping$9(&lt;generated&gt;)
          at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58$$FastClassBySpringCGLIB$$59d52b8d.invoke(&lt;generated&gt;)
          at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
          at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
          at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58.stompWebSocketHandlerMapping(&lt;generated&gt;)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
          at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
          at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
          at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
          at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
          at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
          at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
          at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229)
          at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          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)
  INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/ws/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]
  INFO : org.springframework.context.support.DefaultLifecycleProcessor - Starting beans in phase 2147483647
  </code></pre>