java - Browser can't connect with spring4 websocket server -


in working spring mvc 4.0.5 project running under tomcat 7.0.50,following the tutorial.

in eclipse console (catalina log) when start tomcat, appear rows

mapped url path [/websocket.ws] onto handler of type [class org.springframework.web.socket.server.support.websockethttprequesthandler] 

i got error "firefox can't connect ws://localhost/books/websocket.ws" [http/1.1 404 not found 6ms] firefox web console.

my configuration:

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app version="3.0"        xmlns="http://java.sun.com/xml/ns/javaee"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xsi:schemalocation="http://java.sun.com/xml/ns/javaee        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">      <display-name>archetype created web application</display-name>      <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>      <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>      <welcome-file-list>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list>  </web-app> 

applicationcontext.xml

<?xml version="1.0" encoding="utf-8"?>   <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:websocket="http://www.springframework.org/schema/websocket"     xsi:schemalocation="         http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/websocket         http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">       <bean id="websocket" class="com.example.websocket.handler.websocketendpoint" />      <websocket:handlers>         <websocket:mapping path="/websocket.ws" handler="websocket" />         <websocket:handshake-interceptors>             <bean class="com.example.websocket.handshakeinterceptor" />         </websocket:handshake-interceptors>     </websocket:handlers>  </beans> 

websocketendpoint.java

package com.example.websocket.handler;  import org.springframework.web.socket.textmessage; import org.springframework.web.socket.websocketsession; import org.springframework.web.socket.handler.textwebsockethandler;  public class websocketendpoint extends textwebsockethandler{      @override     protected void handletextmessage(websocketsession session,             textmessage message) throws exception{         super.handletextmessage(session, message);         system.out.println(message.getpayload());         textmessage returnmessage =new textmessage(message.getpayload()+"received @ server");         session.sendmessage(returnmessage);     } } 

handshakeinterceptor.java

package com.example.websocket;  import java.util.map;  import org.springframework.http.server.serverhttprequest; import org.springframework.http.server.serverhttpresponse; import org.springframework.web.socket.websockethandler; import org.springframework.web.socket.server.support.httpsessionhandshakeinterceptor;  public class handshakeinterceptor extends httpsessionhandshakeinterceptor{      @override     public boolean beforehandshake(serverhttprequest request,             serverhttpresponse response,websockethandler wshandler,             map<string,object> attributes) throws exception{         system.out.println("before handshake!");         return super.beforehandshake(request,response,wshandler,attributes);     }      @override     public void afterhandshake(serverhttprequest request,             serverhttpresponse response,websockethandler wshandler,             exception ex){         system.out.println("after handshake!");         super.afterhandshake(request,response,wshandler,ex);     } } 

javascript code:

chat.socket = new websocket('ws://127.0.0.1:80/books/websocket.ws'); 

is web.xml wrong?

"books" project name in tomcat.

thanks answer.

i did not use spring websocket. found url seems wrong. book come from? firefox wanted connect "ws://localhost/books/websocket.ws". in configuration, ws endpoint binds "/websocket.ws".


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -