• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Websocket servlet context

 
Paolo Rodeo
Greenhorn
Posts: 18
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Paolo Rodeo
Greenhorn
Posts: 18
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic