Foros de discusión

Implementing Web socket using liferay 6.2-ce-ga6 and spring

Ahmed Bouzaien, modificado hace 7 años.

Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 4 Fecha de incorporación: 13/11/16 Mensajes recientes
Hello,
I am trying to implement socket using liferay 6.2-ce-ga6 and spring implementation, but I am getting 404 error. Could you please support.
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
	
	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		SockJsServiceRegistration var = registry.addEndpoint("/gs-guide-websocket").withSockJS();
	}

	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry) {
		registry.enableSimpleBroker("/topic");
		registry.setApplicationDestinationPrefixes("/app");
	}
}


And in the client side I am using SockJs :
 <script type="text/javascript">
	var url = "<c:url value='/gs-guide-websocket' />"; 

	var socket = new SockJS(url);
	stompClient = Stomp.over(socket);
	stompClient.connect({}, function (frame) {
       	    console.log('Connected: ' + frame);
	 });
</script>

I am always getting 404 not found :
GET http://localhost:8080/UniflowEservices-portlet/gs-guide-websocket/info?t=1479106703794 404 (Not Found)
Ahmed Bouzaien, modificado hace 7 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 4 Fecha de incorporación: 13/11/16 Mensajes recientes
Any other solution to implement Web socket will be appreciated.
Davide Trevi, modificado hace 7 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 6 Fecha de incorporación: 1/03/17 Mensajes recientes
Did you find a solution?
Ahmed Bouzaien, modificado hace 7 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 4 Fecha de incorporación: 13/11/16 Mensajes recientes
Hi Davide,

Yes, I added the following method to my config class (which implements AbstractWebSocketMessageBrokerConfigurer):


	/**
	 * Configure message broker options.
	 */
	@Override
	public void configureMessageBroker(MessageBrokerRegistry config) {
		config.setApplicationDestinationPrefixes("/user", "/app");
		config.enableSimpleBroker("/queue", "/topic"/*, "/user"*/);
		config.setUserDestinationPrefix("/user");
	}


and in the client side:

	var socket = new SockJS("/MyApp/WS/stomp");
	stompClient = Stomp.over(socket);
	stompClient.connect({id: findGetParameter('id'), userId: connectedUserId}, connectCallback);


Finally in web.xml I add the following config:

  <!-- Processes application requests For Socket -->
  <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>

  <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/WS/*</url-pattern>
  </servlet-mapping>
Davide Trevi, modificado hace 7 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 6 Fecha de incorporación: 1/03/17 Mensajes recientes
Hello Ahmed, but what did you set on

registry.addEndpoint("/up").withSockJS()?

And in new SockJS("/MyApp/WS/stomp") what's the mean of stomp?

Can you paste you servlet-context.xml?

Thanks
Ahmed Bouzaien, modificado hace 7 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 4 Fecha de incorporación: 13/11/16 Mensajes recientes
Hi Davide,

In my case I used java configuration by extending AbstractWebSocketMessageBrokerConfigurer, so in order to declare your endpoint no need to modify applicationContext.xml, just you need to add the following method :

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry.addEndpoint("/stomp").withSockJS();
	}
kirti mistry, modificado hace 4 años.

RE: Implementing Web socket using liferay 6.2-ce-ga6 and spring

New Member Mensajes: 4 Fecha de incorporación: 2/06/16 Mensajes recientes
Hello Ahmed! 
<!-- Processes application requests For Socket -->
  <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>

  <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/WS/*</url-pattern>
  </servlet-mapping>

What is in servlet-context.xml ?