File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Websocket servlet context

Paolo Rodeo

Joined: Dec 11, 2010
Posts: 18


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: 17410

"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.

An IDE is no substitute for an Intelligent Developer.
Paolo Rodeo

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
I agree. Here's the link:
subject: Websocket servlet context
It's not a secret anymore!