Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0F67110E30 for ; Sat, 1 Mar 2014 08:23:50 +0000 (UTC) Received: (qmail 18840 invoked by uid 500); 1 Mar 2014 08:23:45 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 18509 invoked by uid 500); 1 Mar 2014 08:23:44 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 18500 invoked by uid 99); 1 Mar 2014 08:23:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Mar 2014 08:23:43 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jforjava1981@gmail.com designates 209.85.213.54 as permitted sender) Received: from [209.85.213.54] (HELO mail-yh0-f54.google.com) (209.85.213.54) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Mar 2014 08:23:39 +0000 Received: by mail-yh0-f54.google.com with SMTP id c41so1821634yho.41 for ; Sat, 01 Mar 2014 00:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=RZRWT5HgX7PjHJIIKBnHYdjwsgGOpVchjcldfBgPwqY=; b=GcWejOU97jXyamQgmR3nEwBfqXFW6ITXPZvmT4KR6srTQbfKgd5egSYJjw2U1MshD0 LmrP1ifSW6MhCN35+PYbmQNixeER8xDU9JkLmhD/6+hOe+RvLzN5eKnqC2aPLJgzKv0t bl9tMHLZnbhqOAhLYvfxMD4T+krEuOF61ih+jLQumJenwg6YRnvBINVqs4wJSykrikJp U2heeDBLNB3IJgwDuECkaUIszjPpYccImAueJX+RUtVEr+3kSKyokM6ePgs1idpdxFLt D5EpC+7CjSFntK2WDA6vQHxjbwGv2iPx8FuSByvIzKT/EzopRDs2vN0VgtRZ2BFRPmc4 uryg== MIME-Version: 1.0 X-Received: by 10.236.88.179 with SMTP id a39mr568564yhf.83.1393662198142; Sat, 01 Mar 2014 00:23:18 -0800 (PST) Received: by 10.170.176.3 with HTTP; Sat, 1 Mar 2014 00:23:18 -0800 (PST) Date: Sat, 1 Mar 2014 13:53:18 +0530 Message-ID: Subject: Websocket stopped working on tomcat 7.0.50 From: J Java To: Tomcat Users List Content-Type: multipart/alternative; boundary=14dae9d2fb3441d9fe04f387440a X-Virus-Checked: Checked by ClamAV on apache.org --14dae9d2fb3441d9fe04f387440a Content-Type: text/plain; charset=ISO-8859-1 I had recently implemented websocket on tomcat 7.0.50. my tomcat runs behind apache 2.4. I use Strtus 2 and Spring Security. It has stopped working. Problem : Websocket connection is opened successfully. Javascript event handler get fires successfully. Apache logs show that request was accepted as an protocol upgrade request with 101 code Tomcat access logs also show the same code 101 for protocol upgrade However on server side onOpen message is not fired. I tried sending the message as soon as connection is opened in javascript's event handler.. There is no error in javascript but Server side endPoint's onmessage is never called just like onOpen is never called. Here are the changes I made after which it has stopped working: Windows Host file : I use dummy host name through Windows host file: 127.0.0.1 phasingapp.com 127.0.0.1 pricer.com URL of wesocket : old : ws://localhost:86/websocket/filuploadtrackerendpoint new : ws://phasingapp.com:86/websocket/filuploadtrackerendpoint Added virtual host config for apache : Require host phasingapp.com granted 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/ Struts 2 : changed url pattern for Struts 2 filter from ".action to " /* ". Also added exclusion filters to strtus2 for webscoket urls : Everything seems to be working fine as i am gettting no error anywhere in apache,tomcat,spring security and Struts2 logs. However on server side no handlers are called? Earlier I had faced similar problem but it was because I had put websocket-api jar in my WEB-INF/lib which was preventing websocket connection from getting opened. No connection is opened but no handler is called after that and after some time connection is closed obviously because of timout I suppose. Here is my ServerEndPoint class : 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 socketConnectionMap = new HashMap(); @OnOpen public void open(Session session) { Map> paramMap = session.getRequestParameterMap(); List 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()); } } } and my javascript code : 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 ); }; }, Thanks, Shailesh. --14dae9d2fb3441d9fe04f387440a--