简体   繁体   English

如何在WSO2 AS 5.2.1上设置和部署WebSocket?

[英]How to setup and deploy WebSocket on WSO2 AS 5.2.1?

I have a working JAX-RS webapp that implement some RESTfull services. 我有一个可运行的JAX-RS Web应用程序,该应用程序实现了一些RESTfull服务。 I have developed it under WSO2 Studio and deployed it with WSO2 AS Web interface, all very simple. 我已经在WSO2 Studio下开发了它,并使用WSO2 AS Web界面进行了部署,所有这些都非常简单。

Now I want add on my WebApp the possibility to open a WebSocket. 现在,我想在我的WebApp上添加打开WebSocket的可能性。 I don't have found a standard procedure or examples on WSO2 AS documentation. 我没有在WSO2 AS文档中找到标准过程或示例。 My question is: 我的问题是:

  1. Is possible do that? 有可能吗?
  2. Can I have RESTfull implementation and WebSocket in the same war package? 我可以在同一war软件包中包含RESTfull实现和WebSocket吗? There is an example for do that? 有这样做的例子吗? Best on WSO2 AS. 最适合WSO2 AS。
  3. How to setup a WebSocket application and deploy it on WSO2 AS? 如何设置WebSocket应用程序并将其部署在WSO2 AS上?

Thank you. 谢谢。

UPDATE 更新

I have write this extreme simple websocket application: 我已经编写了这个极其简单的websocket应用程序:

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. 如果我在Tomcat服务器上部署,则在我在WSO2 AS 5.3.0(快照)上部署时,它可以正确运行,WebSocket无法访问。 I don't understand what i do wrong. 我不明白我做错了什么。

WSO2 AS 5.2.1 have Websocket (tomcat specific) support. WSO2 AS 5.2.1具有Websocket(特定于tomcat)支持。 You can find the "example" webapp inside the $AS_HOME/repository/deployment/server/webapps folder. 您可以在$AS_HOME/repository/deployment/server/webapps文件夹中找到“示例” Webapp。

But standard (JSR356) Websocket support is not available in WSO2 AS 5.2.1. 但是WSO2 AS 5.2.1中不提供标准(JSR356)Websocket支持。 It will be available in WSO2 AS 5.3.0 which will be released very soon. 它会在即将发布的WSO2 AS 5.3.0中提供。 WSO2 AS 5.3.0 Alpha is already released and you can try out the web socket support using the alpha pack . WSO2 AS 5.3.0 Alpha已经发布,您可以使用Alpha Pack尝试Web套接字支持。 Start the server, point the browser to http://localhost:9763/example/websocket/index.xhtml and you will find four web sockets samples there. 启动服务器,将浏览器指向http:// localhost:9763 / example / websocket / index.xhtml ,您将在此处找到四个Web套接字示例。 You can have a look at the release mail for new features in WSO2 AS 5.3.0. 您可以查看WSO2 AS 5.3.0中有关新功能的发行邮件

As @Rajkumar mentioned if you need to use JSR356 based standard websocket you have to use WSO2-AS 5.3.0 Alpha. 正如@Rajkumar提到的,如果您需要使用基于JSR356的标准websocket,则必须使用WSO2-AS 5.3.0 Alpha。 But still you can use previous wso2-as versions (5.2.1) for tomcat specific websocket implementations. 但是您仍然可以将先前的wso2-as版本(5.2.1)用于特定于Tomcat的Websocket实现。

If you want to invoke websocket using jaxrs you can refer to websocket test case in the github-product-as 如果要使用jaxrs调用websocket,则可以在github-product-as中引用websocket测试用例

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 对于基于tomcat的websocket实现,您可以从tomcat来源或从https://github.com/wso2/product-as/tree/wso2appserver-parent-6.0.0/modules/samples/common/引用tomcat websocket示例webapp / src / main / java / websocket

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM