Elia
Elia

Reputation: 1443

How to setup and deploy WebSocket on WSO2 AS 5.2.1?

I have a working JAX-RS webapp that implement some RESTfull services. I have developed it under WSO2 Studio and deployed it with WSO2 AS Web interface, all very simple.

Now I want add on my WebApp the possibility to open a WebSocket. I don't have found a standard procedure or examples on WSO2 AS documentation. My question is:

  1. Is possible do that?
  2. Can I have RESTfull implementation and WebSocket in the same war package? There is an example for do that? Best on WSO2 AS.
  3. How to setup a WebSocket application and deploy it on WSO2 AS?

Thank you.

UPDATE

I have write this extreme simple websocket application:

import java.io.IOException;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/test")
public class TestSocket {

    @OnMessage
    public void onMessage(Session session, String message, boolean last) {
        try{
            if(session.isOpen()){
                session.getBasicRemote().sendText("Received -> [" + message + "]", last);
            }
        }catch(IOException e){
            try{
                session.close();
            }catch(IOException e1){

            }
        }
    }
}

If I deploy on Tomcat server it run correctly if I deploy on WSO2 AS 5.3.0 (snapshot) the websocket is unreachable. I don't understand what i do wrong.

Upvotes: 0

Views: 264

Answers (2)

As @Rajkumar mentioned if you need to use JSR356 based standard websocket you have to use WSO2-AS 5.3.0 Alpha. But still you can use previous wso2-as versions (5.2.1) for tomcat specific websocket implementations.

If you want to invoke websocket using jaxrs you can refer to websocket test case in the github-product-as

For the websocket implementation based on tomcat u can refer to tomcat websocket samples either from tomcat source or from https://github.com/wso2/product-as/tree/wso2appserver-parent-6.0.0/modules/samples/common/webapp/src/main/java/websocket

Upvotes: 0

Rajkumar Rajaratnam
Rajkumar Rajaratnam

Reputation: 925

WSO2 AS 5.2.1 have Websocket (tomcat specific) support. You can find the "example" webapp inside the $AS_HOME/repository/deployment/server/webapps folder.

But standard (JSR356) Websocket support is not available in WSO2 AS 5.2.1. It will be available in WSO2 AS 5.3.0 which will be released very soon. WSO2 AS 5.3.0 Alpha is already released and you can try out the web socket support using the alpha pack. Start the server, point the browser to http://localhost:9763/example/websocket/index.xhtml and you will find four web sockets samples there. You can have a look at the release mail for new features in WSO2 AS 5.3.0.

Upvotes: 1

Related Questions