-
1. Re: REST, Weld and stateful apps
jharting Jul 28, 2010 9:12 AM (in response to cjalmeida)You do not need to do this programatically. By default, stateless requests do not create an HTTP session. However, if your service invokes a @SessionScoped component, a new session is created and a matching Set-Cookie response parameter sent with the response. On the client side, you use the cookie value to connect to the session in the following request. Again, you do not need to catch the JSESSIONID parameter on the server. This is done automatically.
To sum it up, all you need to do to carry a state across multiple requests is to place @SessionScoped on your JAX-RS resource.
-
2. Re: REST, Weld and stateful apps
cjalmeida Jul 29, 2010 12:41 PM (in response to cjalmeida)Thanks, I'll try it out!
-
3. Re: REST, Weld and stateful apps
ndipiazza Oct 20, 2010 3:18 PM (in response to cjalmeida)I have a session scoped bean and I'm not able to keep session for authentication.
I have <resteasy:application destroy-session-after-request="false"/> set in my components.xml file.
Why is my session lost in between each invocation?
My code is below.
@Scope(ScopeType.SESSION)
@Transactional
public class MyClass {
@In(required=false) private User currentUser; // don't have to be logged in to use this class
/**
* Do the login as a REST service.
*/
@GET
@Path("/doLogin")
public String doLoginRest(@QueryParam("userId") String userId, @QueryParam("password") String password) throws IOException {
Credentials creds = identity.getCredentials();
creds.setUsername(userId);
creds.setPassword(password);
identity.setRememberMe(true);
Context session = Contexts.getSessionContext();
currentUser = (User) session.get("currentUser"); // This at this point is NOT null, login worked!!!
return identity.login();
}
/**
* Test if the login worked
*/
@GET
@Path("/testLogin")
public String doTestLogin() {
Context session = Contexts.getSessionContext();
currentUser = (User) session.get("currentUser");
return ""+(currentUser != null); // This is false everytime
} -
4. Re: REST, Weld and stateful apps
jharting Oct 20, 2010 6:55 PM (in response to cjalmeida)Your question is related to Seam 2 whereas this is Weld forum. Anyway, I think the problem in your code is that you are not pushing the user to the session anywhere. Try using this:
@In(required=false) @Out(required=false) private User currentUser;