GeeCON Prague 2014*
The moose likes Tomcat and the fly likes Websocket servlet context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Websocket servlet context" Watch "Websocket servlet context" New topic
Author

Websocket servlet context

Paolo Rodeo
Greenhorn

Joined: Dec 11, 2010
Posts: 18

Hi,

I'm currently checking out the Tomcat 7 websockets and got them working smoothly. But I have a design question about the different contexts: The websocket handling is done in a separate servlet context from where I don't have access to the current View context of the page bean. Is there a way to access the data on the view scoped bean related to the page that initiated the websocket message? Or am I following a wrong design pattern? I couldn't find any examples on the web that illustrate this point.

Regards, Paul.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16103
    
  21

"View scope"? Is this supposed to be JSF?

In any event, if you have other servlets/JSPs active while a websocket is in play, they can share data via the HttpSession and/or Application scope objects.

I would not include the websocket code directly in a servlet, JSP or GUI interface objects (Model, View definitions) for the same reason that I don't include complex business functions there. It's cleaner to have one function/one module.


Customer surveys are for companies who didn't pay proper attention to begin with.
Paolo Rodeo
Greenhorn

Joined: Dec 11, 2010
Posts: 18

Hi Tim,

Thanks for your answer. Indeed, I forgot to mention I'm talking JSF. Could you please elaborate a bit more about how to use session or application objects to communicate? For instance, if a message arrives on the websocket, the socket's servlet callback "MessageInbound.onTextMessage(CharBuffer)" is called. You suggest not to include any business login in there. Sounds good, but then allow me to rephrase my original question: What's then the proper way to activate the business logic in the view scoped bean? Or: How to pass messages asynchronoulsy from one context (socket servlet) to another (view bean), v.v.?

Regards, Paul
 
GeeCON Prague 2014
 
subject: Websocket servlet context