Reputation: 319
Can CDI-@Sessionscoped be used when no http-session is available (for example when a RESTful-WS is used?). And if not, is there an alternative to @SessionScoped? I'm asking because I need to have an application-state but I'm also forced to use JAX-RS.
For some reason, I can inject @SessionScoped beans in the RESTful-Service but I know that this, at least by convention, is not allowed. Also using @SessionScoped requires the JSessionID-Cookie to be send in the headers of each client-request and since the service is consumed in a non-browser-environment, I can't be sure that cookies can be used...
Upvotes: 2
Views: 2954
Reputation: 3775
In case of REST enviroment @SessionScoped
will work as excepted in case of browser client (if REST server supports sessions) but will create new bean on every call in case of non-browser client (if client ignores coockies).
Maybe @ApplicationScoped
is good for your?
Upvotes: 3