RESTEasy stateful beans(SessionScoped)
sirwayne May 19, 2011 8:50 AMHello,
Does anybody know how i can use SessionScopes beans?
Example:
Client
public class RestClient { private static final String uri = "http://localhost:8080/xxRest"; public static void main(String[] args) { // this initialization only needs to be done once per VM RegisterBuiltin.register(ResteasyProviderFactory.getInstance()); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); Service1 service1 = ProxyFactory.create(Service1.class, uri); Service2 service2 = ProxyFactory.create(Service2.class, uri); service1.putName("Hallo Welt"); System.out.println( service1.getName()); System.out.println(service2.getName()); } }
Server side:
Service 1
public class Service1Impl implements Service1{ @Inject private ParamBean bean; @Override public String getName() { return bean.getName(); } @Override public void putName(String name) { bean.setName(name); } }
Service 2
public class Service2Impl implements Service2{ @Inject private ParamBean bean; @Override public String getName() { return bean.getName(); } }
Bean
@SessionScoped public class ParamBean implements Serializable{ private static final long serialVersionUID = -3890162219225972547L; private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } }
But i get always a new ParamBean in Service 2. So the log output is:
Hallo Welt
null
=(
Does anybody know how i can inject the session scoped param bean in a second serivce?
EDIT: With JSF it works. So i think the magic is in the FacesServlet
-
client.zip 1.8 MB
-
server.zip 11.8 KB