tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Java <jforjava1...@gmail.com>
Subject Re: Websocket stopped working on tomcat 7.0.50
Date Sat, 01 Mar 2014 13:03:42 GMT
When  I revert to earlier config with localhost it starts working.


On Sat, Mar 1, 2014 at 6:18 PM, J Java <jforjava1981@gmail.com> wrote:

> 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
>
> Updated configuration..above is the complete configuration for my
> virtualhost.
>
>
>
> On Sat, Mar 1, 2014 at 6:14 PM, J Java <jforjava1981@gmail.com> wrote:
>
>> Mark,
>>
>>  following is how i have configured reverse proxy :
>>
>> 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
>>
>> I am using Apache 2.4 which comes with  mod_proxy_wstunnel module to support http
upgrade to Websocket.
>>
>> Also my code works fine if I configure localhost everywhere, its just when I change
it to use dummy host using window's hosts file and virtual host it stops working. And it upgrades
to WebSocket but cant send or receive messages after that. Please find in detail configuration
and code in my first post. Any pointers how to go about it will really help. Or let me know
the right place to open bug for this.
>>
>> Thanks,
>>
>> Shailesh.
>>
>>
>>
>> On Sat, Mar 1, 2014 at 4:10 PM, Mark Thomas <markt@apache.org> wrote:
>>
>>> On 1 March 2014 10:02:48 GMT, J Java <jforjava1981@gmail.com> wrote:
>>> >I tried debuggin tomcat sources. And compared the difference I am
>>> >getting
>>> >between normal tomcat websocket examples and my code. Only difference i
>>> >could found was tomcat example uses Abstract Protocol class to fire the
>>> >register session event and mine uses AjpProcessor(because I am using
>>> >tomcat
>>> >behind apache). but in AJpProcessor class it gets stuck and never calls
>>> >registersession for Websocket.
>>> >
>>> >I know above information might be utterlyt useless but this waht i have
>>> >understood ..guys I need this to be resolved ASAP. it was working fine
>>> >when
>>> >i was using localhost everywhere. since I changed it to dummy host it
>>> >has
>>> >stopped working
>>>
>>> How is your reverse proxy configured? mod_jk doesn't support HTTP
>>> upgrade and the last time I looked mod_proxy support for WebSocket wasn't
>>> fit for purpose.
>>>
>>> Mark
>>>
>>>
>>> >On Sat, Mar 1, 2014 at 2:31 PM, J Java <jforjava1981@gmail.com> wrote:
>>> >
>>> >>
>>> >> 127.0.0.1 - - [01/Mar/2014:14:20:12 +0530] "GET
>>> >> /jkweb/js/angle/addAngle.js?_=1393663610411 HTTP/1.1" 200 4278
>>> >> 127.0.0.1 - - [01/Mar/2014:14:20:41 +0530] "GET
>>> >> /jkweb/angle/validateDuplicateAngleName.action?angleName=angle7
>>> >HTTP/1.1"
>>> >> 200 -
>>> >> phasingapp.com - - [01/Mar/2014:14:21:15 +0530] "GET
>>> >>
>>>
>>> >/jkweb/websocket/fileuploadtracker?uniqueTocken=9c9e740c-7171-4c33-bc92-e0a46cb2d2b5
>>> >> HTTP/1.1" 101 -
>>> >>
>>> >> Above is the relevant log section of apache : could it be the cause
>>> >that
>>> >> websocket request is coming from phasingapp.com and others from
>>> >127.0.01
>>> >>
>>> >>
>>> >> On Sat, Mar 1, 2014 at 1:53 PM, J Java <jforjava1981@gmail.com>
>>> >wrote:
>>> >>
>>> >>>  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 :
>>> >>>
>>> >>>  <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/
>>> >>>
>>> >>> Struts 2 :
>>> >>>
>>> >>>  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/.*"/>
>>> >>>
>>> >>> 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<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());
>>> >>>         }
>>> >>>     }
>>> >>> }
>>> >>>
>>> >>> 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.
>>> >>>
>>> >>
>>> >>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message