当前位置: 首页 > 知识库问答 >
问题:

Websocket停止在tomcat 7.0.50上工作

马宜民
2023-03-14
 Windows Host file : I use dummy host name through Windows host file:
127.0.0.1    phasingapp.com
127.0.0.1    pricer.com
old  :  ws://localhost:86/websocket/filuploadtrackerendpoint
new : ws://phasingapp.com:86/websocket/filuploadtrackerendpoint
 <Location /jkweb/websocket/>
    Require host phasingapp.com granted
</Location>    

JkMount /jkweb/* localtomcat
JkUnMount /jkweb/project/content/*  localtomcat
JkUnMount /jkweb/angle/content/*  localtomcat
JkUnMount /jkweb/index.jsp localtomcat
JkUnMount /jkweb/ localtomcat

ProxyRequests Off
ProxyPreserveHost On

ProxyPass /jkweb  !
ProxyPass /jkweb/  !
ProxyPass /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
ProxyPassReverse /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
ProxyPass /  http://localhost:8080/jkweb/
ProxyPassReverse /  http://localhost:8080/jkweb/
 changed url pattern for Struts 2 filter from ".action to " /* ". Also added exclusion   filters
 to strtus2  for webscoket urls :

<constant name="struts.action.excludePattern" value=".*websocket/.*"/>

下面是我的ServerEndPoint类:

      package com.jkweb.websocket;

        import java.io.IOException;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;

        import javax.websocket.EndpointConfig;
        import javax.websocket.OnMessage;
        import javax.websocket.OnOpen;
        import javax.websocket.Session;
        import javax.websocket.server.PathParam;
        import javax.websocket.server.ServerEndpoint;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        @ServerEndpoint(value="/websocket/fileuploadtracker")
       public class FileUploadTrackerEndPoint{
       private static final Logger logger = LoggerFactory
            .getLogger(FileUploadTrackerEndPoint.class);
       private static HashMap<String,Session> socketConnectionMap = new    HashMap<String,Session>();

    @OnOpen 
    public void open(Session session) {
        Map<String,List<String>> paramMap = session.getRequestParameterMap();
        List<String> uniqueTockenValues = paramMap.get("uniqueTocken");
        if(uniqueTockenValues != null && uniqueTockenValues.size() > 0){
            socketConnectionMap.put(uniqueTockenValues.get(0),session); 
        }
    }
    @OnMessage
    public void onMessage(Session session, String msg) {
        try {
            session.getBasicRemote().sendText(msg);
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }

    public static void sendMessage(String uniqueTocken,String msg){
        try {
            Session wsSession = socketConnectionMap.get(uniqueTocken);
            wsSession.getBasicRemote().sendText(msg);
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
}

和我的javascript代码:

createFileUploadWebSocket : function(){
            var that = this;
            var uniqueTocken = $("#uniqueTocken").val(),
            wsurl =  "ws://phasingapp.com:86/jkweb/websocket/fileuploadtracker?uniqueTocken="+uniqueTocken,
            ws;
            ws = new WebSocket(wsurl);
             ws.onopen = function()
             {
                 alert("opened..") //I get this aler sothis is called
                 ws.send("test");//however this has not effect ...no error but server end point is not called
             };
             ws.onmessage = function (evt) 
             { 
                 message = evt.data;
                 if(message == "Done."){
                     alert("closing..");
                     ws.close();
                     $('#progressbar').progressbar('option','value',100);
             }
                 var currentVal = $('#progressbar').progressbar('option','value');
                 $('#progressbar').progressbar('option','value',currentVal <= 80 ?currentVal+1 : currentVal);
             };
             ws.onclose = function(evt)
             { 
                // websocket is closed.
                alert("Connection is closed..."+evt.code + ":"+evt.reason ); 
             };

             ws.onerror = function(evt){
                 alert("Connection is closed..."+evt.code + ":"+evt.reason );
             };

        },

共有1个答案

秦博达
2023-03-14

同样,对于所有其他websocket问题,我在配置错误本身找到了答案。

 ProxyPass /jkweb  !
 ProxyPass /jkweb/  !
 ProxyPass /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
 ProxyPassReverse /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
 ProxyPass /  http://localhost:8080/jkweb/
 ProxyPassReverse /  http://localhost:8080/jkweb/

我更改了proxypass指令的顺序,如下所示:

 ProxyPass /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
 ProxyPassReverse /jkweb/websocket/  ws://localhost:8080/jkweb/websocket/
 ProxyPass /jkweb  !
 ProxyPass /jkweb/  !
 ProxyPass /  http://localhost:8080/jkweb/
 ProxyPassReverse /  http://localhost:8080/jkweb/

在websocket的proxypass指令导致以jkweb/开头的每个请求绕过代理之前放置它。

 类似资料:
  • 问题内容: 我确定我的应用程序一直运行到昨天,直到出现此错误: Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@1079ff{/,/ base/data/home/apps/s~trewnewmedia/1.357617962256387950} org.spring

  • 我在IE上的css悬停有问题。 简化;我基本上有一个容器div,它将在悬停时显示一个小的div,里面有一些标记中选择一个,:hover由于某种原因将不再工作,div将消失。 在chrome/firefox等中尝试此示例以查看所需的结果&然后在IE11中再试一次以查看问题所在。 null null

  • 我们在本地安装了一台新的TFS 2017服务器。我的系统管理员设置了https并生成了自签名证书。使用VisualStudio内置的git工具,一切都可以正常工作。当我尝试从CLI执行任何操作时,会出现以下错误: 我所尝试的: > 经过一些故障排除后,我将本地证书导出为Base-64编码的x.509(.CER)文件,并将其附加到 仔细检查我的git配置以确保http。sslcainfo指向正确的c

  • null GrantPermissionRule是否停止了为其他人所宣传的工作?

  • 问题内容: 我有这个jQuery ajax调用: 我想在条件返回的情况下停止调用,但返回不会停止调用。 我如何stop在Ajax上调用beforeSend? =======更新========= return false 也可以。 问题答案: $.ajax({ url : ‘my_action’, dataType: ‘script’, beforeSend : function(xhr, opt

  • 我正在用Unity 2018.2.2(最新版本于2018年8月8日)开发一款android小游戏。我在这个游戏上工作了几周,但现在,Unity在试图找到我的JDK时毫无理由地失败了。当我分配文件夹时(编辑- [如果您看不到图像:“未能检测到Java版本。Android开发需要JDK 8(1.8)。安装JavaRunatime环境(JRE)是不够的。”] 第一个我想的是,它可能会因为JDK的更新而失