XML-based configuration

The registration done in the last Java snippet can be done in XML as well. We need to register the websocket namespace in the XML, and then configure the handler as shown here:

<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.xsd"> <websocket:handlers> <websocket:mapping path="/myWebSocketHandler" handler="myWebSocketHandler"/> </websocket:handlers> <bean id="myWebSocketHandler" class="com.packt.ch10.WebsocketHandlers.MyWebSocketHandler"/> </beans>

The customized WebSocketConfigurer interface in XML can be written as follows:

<websocket:handlers> 
  <websocket:mapping path="/myWebSocketHandler"  
     handler="myWebSocketHandler"/> 
  <websocket:handshake-interceptors> 
    <bean class="org.springframework.web.socket.server.support. 
      HttpSessionHandshakeInterceptor"/> 
  </websocket:handshake-interceptors> 
</websocket:handlers> 
<!-bean for MyWebSocketHandler --> 
</beans> 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.124