You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nick Williams <ni...@nicholaswilliams.net> on 2013/03/17 23:56:23 UTC

Getting HttpSession from HandshakeRequest/Configurator

Based on my reading of the WebSocket spec mailing lists and API documentation, if I want to get the HttpSession that exists when a WebSocket connection is negotiated I need to extend ServerEndpointConfig.Configurator, override #modifyHandshake(), and call #getHttpSession() on the HandshakeRequest. However, I need a little clarification, because I'm not seeing how this is going to work:

1) Tomcat doesn't implement HandshakeRequest ... anywhere. So I'm not even seeing how that method could ever be called with a non-null argument. (Admittedly, I haven't run this yet ... I'm sending this preemptively while I complete my code, to go ahead and get some feedback).

2) None of the arguments to #modifyHandshake() provide access to the Session. So how am I supposed to do anything with it? How can I associate the HttpSession with the Session?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Getting HttpSession from HandshakeRequest/Configurator

Posted by Mark Thomas <ma...@apache.org>.
On 18/03/2013 00:22, Nick Williams wrote:
> Martin,
> 
> Don't believe we've spoken before. Good to meet you.
> 
> I'm working on a book on Servlet 3.1 + WebSockets + Spring Framework
> 4 + Hibernate + Spring Security. My interest is purely the new Java
> WebSockets API. The existing Comet implementation in Tomcat 7.0 will
> be deprecated in 7.0 once the official API is complete and ported,
> and it will not be present in Tomcat 8.0.

The link Martin posted has no relation to the WebSocket implementation
in Tomcat 7.

If you build on top of Comet each WebSocket connection automatically
gets a lot of unwanted baggage (requests/responses) that potentially
hampers scalability. The Tomcat 7 implementation is built on top of
Tomcat's low-level I/O and is relatively baggage free.

In Tomcat 8 it is built on top of the Servlet 3.1 HTTP Upgrade but the
Servlet[Input|Output]Stream objects used are not the same ones you'd get
if you requested them from an HttpServlet[Request|Response]. Again, for
scalability, the Servlet[Input|Output]Stream implementations used by
HTTP upgrade are built on top of Tomcat's low-level I/O.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Getting HttpSession from HandshakeRequest/Configurator

Posted by Nick Williams <ni...@nicholaswilliams.net>.
Martin,

Don't believe we've spoken before. Good to meet you.

I'm working on a book on Servlet 3.1 + WebSockets + Spring Framework 4 + Hibernate + Spring Security. My interest is purely the new Java WebSockets API. The existing Comet implementation in Tomcat 7.0 will be deprecated in 7.0 once the official API is complete and ported, and it will not be present in Tomcat 8.0.

Thanks, though, for replying.

Nick

On Mar 17, 2013, at 7:18 PM, Martin Gainty wrote:

> Nick
> if you dont mind Comet's implementation of WebSocket events to Servlet-3.0 POST and GET then checkout http://java.dzone.com/articles/tomcat-websockets-html5
> 
> I'll let you test drive to see if Ant 's WebSocketServlet fully supports all aspects of the WebSocket spechttp://en.wikipedia.org/wiki/WebSocket
> 
> Keep us apprised,
> Happy Driving
> Martin ______________________________________________ Place Long-winded disclaimer here
> 
>> From: nicholas@nicholaswilliams.net
>> Subject: Getting HttpSession from HandshakeRequest/Configurator
>> Date: Sun, 17 Mar 2013 17:56:23 -0500
>> To: users@tomcat.apache.org
>> 
>> Based on my reading of the WebSocket spec mailing lists and API documentation, if I want to get the HttpSession that exists when a WebSocket connection is negotiated I need to extend ServerEndpointConfig.Configurator, override #modifyHandshake(), and call #getHttpSession() on the HandshakeRequest. However, I need a little clarification, because I'm not seeing how this is going to work:
>> 
>> 1) Tomcat doesn't implement HandshakeRequest ... anywhere. So I'm not even seeing how that method could ever be called with a non-null argument. (Admittedly, I haven't run this yet ... I'm sending this preemptively while I complete my code, to go ahead and get some feedback).
>> 
>> 2) None of the arguments to #modifyHandshake() provide access to the Session. So how am I supposed to do anything with it? How can I associate the HttpSession with the Session?
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 		 	   		  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Getting HttpSession from HandshakeRequest/Configurator

Posted by Martin Gainty <mg...@hotmail.com>.
Nick
if you dont mind Comet's implementation of WebSocket events to Servlet-3.0 POST and GET then checkout http://java.dzone.com/articles/tomcat-websockets-html5

I'll let you test drive to see if Ant 's WebSocketServlet fully supports all aspects of the WebSocket spechttp://en.wikipedia.org/wiki/WebSocket

Keep us apprised,
Happy Driving
Martin ______________________________________________ Place Long-winded disclaimer here

 > From: nicholas@nicholaswilliams.net
> Subject: Getting HttpSession from HandshakeRequest/Configurator
> Date: Sun, 17 Mar 2013 17:56:23 -0500
> To: users@tomcat.apache.org
> 
> Based on my reading of the WebSocket spec mailing lists and API documentation, if I want to get the HttpSession that exists when a WebSocket connection is negotiated I need to extend ServerEndpointConfig.Configurator, override #modifyHandshake(), and call #getHttpSession() on the HandshakeRequest. However, I need a little clarification, because I'm not seeing how this is going to work:
> 
> 1) Tomcat doesn't implement HandshakeRequest ... anywhere. So I'm not even seeing how that method could ever be called with a non-null argument. (Admittedly, I haven't run this yet ... I'm sending this preemptively while I complete my code, to go ahead and get some feedback).
> 
> 2) None of the arguments to #modifyHandshake() provide access to the Session. So how am I supposed to do anything with it? How can I associate the HttpSession with the Session?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Getting HttpSession from HandshakeRequest/Configurator

Posted by Nick Williams <ni...@nicholaswilliams.net>.
On Mar 17, 2013, at 5:56 PM, Nick Williams wrote:

> Based on my reading of the WebSocket spec mailing lists and API documentation, if I want to get the HttpSession that exists when a WebSocket connection is negotiated I need to extend ServerEndpointConfig.Configurator, override #modifyHandshake(), and call #getHttpSession() on the HandshakeRequest. However, I need a little clarification, because I'm not seeing how this is going to work:
> 
> 1) Tomcat doesn't implement HandshakeRequest ... anywhere. So I'm not even seeing how that method could ever be called with a non-null argument. (Admittedly, I haven't run this yet ... I'm sending this preemptively while I complete my code, to go ahead and get some feedback).
> 
> 2) None of the arguments to #modifyHandshake() provide access to the Session. So how am I supposed to do anything with it? How can I associate the HttpSession with the Session?

I answered my own questions:

1) That's because it didn't, and it wasn't ever calling modifyHandshake(). I created a bug and submitted a patch for this.

2) Apparently userProperties is the way to go. userProperties can be accessed from the EndpointConfig argument to #modifyHandshake() or from Session. I can store the HttpSession in there. Wish there were a less roundabout way of getting there...
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org