Friday, December 13, 2013

I am trying to learn about J2EE and web services (in GlassFish 3.1). This question is a bit of a follow up to this.
I have figured out how to use Stateless Session Beans and the Web Service. I am really only using the Web Service (@WebService) out of convenience since I would rather not parse messages by hand. Although I would prefer something lighter than SOAP if possible. I have however run into a problem when I want to maintain a state of some sort (such as through Stateful Session Beans). I have searched this site and several others recommending me to avoid this because it can lead to difficult to find bugs and limits scalability.
Suppose I have a user who has just executed the "userLogin" method and it has succeeded. How do I then know on the server that the user has already logged in. For example, after logging in the user might call "getProfile()" through SOAP (without any arguments), and I would return the correct information for that user. I know this isn't possible by appending @WebService to my Stateful Session Bean since that's only valid with @Stateless.
I know how to store the state if I use an HttpSession (with an HttpServlet) along with Stateless Session Beans, but then I cannot use the nicely generated SOAP messages.
So my question is: how would I solve this problem of maintaining user state, or adapt the problem so that I do not require state?
share|improve this question
add comment
WS can be stateful: use @Stateful annotation and WS-Addressing (see my old question for example)
There is nothing criminal in having a stateful server. After all, if statefulness is required, why avoid it? It is true that stateless are easier to scale and debug, but if you need to keep state (as in shopping card, for instance) -- then keep it.
Thing to consider though is the cleaning up the stateful service instance after a timeout. Use StatefulWebServiceManager instance and its setTimeout() method.
Also, state can be kept outside of WS (e.g. database) and the state (session) identifier passed as one of the parameters. Works just fine.
Using HTTP session is a pretty easy way to keep state for a stateless service, but I consider it outdated comparing to @Stateful. The rationale is that the request not necessary have to come via HTTP; @Stateful/WS-Addressing works for any channel, while HTTP session requires HTTP transport. In the real world, of course, HTTP is the prevailing one, so this argument is quite purist.
share|improve this answer
 
another thing to consider with stateful stuff is if your system gets big enough to be clustered. You either have to have a way to transmit state between boxes or a way to garentee that requests from the same source end up on the same box. All quite doable, but it's a consideration. –  drekka Jun 28 '11 at 3:52
 
Thanks, but unfortunately it doesn't appear to do the job I want. It may just be my unfamiliarity with the API, but I read here ([blogs.oracle.com/sujit/entry/…) about the @Addressing annotation and found that it provides the user with access to a cached resource. Want I wanted was something that I could easily access without the user knowing that is is tracked. –  Level9000 Jun 28 '11 at 22:49 
 
Even HTTP session requires a cookie. User will know. In case of WS user (client) will have to read and add cookie explicitely, via not less than hacks. Comparing to that @Stateful is neat. –  Vladimir Dyuzhev Jun 29 '11 at 2:33
add comment

6 comments:

oakleyses said...

louis vuitton handbags, oakley sunglasses, louboutin, longchamp outlet, nike shoes, louis vuitton outlet stores, chanel handbags, burberry outlet, prada outlet, jordan shoes, tiffany and co, michael kors outlet, tory burch outlet, louis vuitton outlet, longchamp handbags, nike free, true religion jeans, michael kors outlet, kate spade outlet, polo ralph lauren outlet, tiffany and co, prada handbags, polo ralph lauren outlet, michael kors outlet, michael kors outlet, longchamp handbags, oakley sunglasses, ray ban sunglasses, kate spade handbags, burberry outlet, louis vuitton outlet, louboutin outlet, louboutin, coach factory outlet, air max, air max, coach outlet, gucci outlet, christian louboutin shoes, michael kors outlet, coach purses, ray ban sunglasses, michael kors outlet, louis vuitton, coach outlet store online, true religion jeans, oakley sunglasses cheap

oakleyses said...

ralph lauren, lululemon, air max, hollister, north face, nike air max, polo lacoste, vanessa bruno, timberland, vans pas cher, louboutin, louis vuitton, oakley pas cher, air max pas cher, nike roshe run, air max, true religion outlet, barbour, sac longchamp, air force, hollister, sac louis vuitton, nike free, polo ralph lauren, nike trainers, louis vuitton uk, nike roshe, sac hermes, longchamp, michael kors, sac burberry, sac guess, mulberry, new balance pas cher, converse pas cher, sac louis vuitton, hogan outlet, nike tn, north face, true religion outlet, ray ban pas cher, michael kors, air jordan, nike blazer, nike free pas cher, michael kors pas cher, abercrombie and fitch, ray ban sunglasses

oakleyses said...

mac cosmetics, mont blanc, marc jacobs, canada goose outlet, nike huarache, vans shoes, soccer jerseys, hollister, giuseppe zanotti, beats by dre, abercrombie and fitch, longchamp, insanity workout, celine handbags, bottega veneta, ghd, nfl jerseys, north face outlet, chi flat iron, ugg boots, birkin bag, ugg australia, canada goose, herve leger, ugg pas cher, rolex watches, valentino shoes, canada goose uk, canada goose, ferragamo shoes, canada goose, ugg boots, uggs outlet, north face jackets, soccer shoes, asics running shoes, new balance shoes, p90x, lululemon outlet, canada goose jackets, mcm handbags, instyler, babyliss pro, ugg, wedding dresses, jimmy choo outlet, reebok outlet, nike roshe run

oakleyses said...

parajumpers, karen millen, air max, converse, pandora charms, moncler, louboutin, moncler, links of london, lancel, juicy couture outlet, oakley, hollister, pandora charms, supra shoes, thomas sabo, canada goose, gucci, wedding dresses, timberland boots, swarovski crystal, air max, coach outlet store online, moncler, ray ban, canada goose, moncler, ugg, louis vuitton, swarovski, hollister, montre homme, moncler, hollister clothing store, ralph lauren, rolex watches, moncler outlet, moncler, iphone 6 cases, baseball bats, juicy couture outlet, toms shoes, vans, pandora jewelry, ugg, converse shoes

Zheng junxai5 said...


zhengjx20160721
michael kors outlet
ray bans
adidas stan smith
michael kors outlet online
michael kors outlet
christian louboutin sale clearance
michael kors outlet clearance
michael kors canada outlet
christian louboutin sale
christian louboutin wedges
toms outlet
michael kors outlet
polo ralph lauren
pandora charms
louis vuitton purses
gucci outlet
gucci outlet
louis vuitton purses
cheap toms
lebron james shoes 13
michael kors outlet clearance
copy watches
adidas superstar
ralph lauren outlet
giuseppe zanotti outlet
air max 95
jordan 3 retro
cheap louis vuitton handbags
louis vuitton outlet
christian louboutin sale
coach factory outlet
fitflops
michael kors outlet
kate spade handbags
tory burch flats
kobe shoes
ray bans
louis vuitton outlet stores
christian louboutin shoes
oakley sunglasses wholesale

raybanoutlet001 said...

michael kors handbags
tiffany and co
kobe basketball shoes
ray ban sunglasses
michael kors outlet store
fitflops clearance
cheap rolex watches
fitflops outlet
adidas tubular UK
cheap nfl jerseys
yeezy boost 350
jordans for cheap
tiffany and co jewellery
cheap jordan shoes
nike huarache
adidas tubular
cheap oakleys
adidas nmd runner
michael kors handbags clearamce
coach outlet online
jordans for cheap