Shared SessionScoped Bean with Rest

2011-05-19
2013-06-06
  • Michael Müller

    Michael Müller - 2011-05-19

    Hello,

    i have a sesscion scoped bean in 2 Rest-Services, but the bean isn't SessionScoped. With JSF all works fine, but if i use RestEasy i get 2 different instances in the Services. The SessionScoped doesn't work =(.
    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("Hello World");
            System.out.println( service1.getName());
            System.out.println(service2.getName());
            
        }
    
    }
    

    On server side:
    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;
        }
    
    }
    

    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();
        }
    }
    

    The log output is
    Hello World
    null -> =(

    if it helps, i can send the java project.
    I think the magic is in the FacesServlet, because with JSF it works fantasticly.
    Thanks for help =)

     
  • Jozef Hartinger

    Jozef Hartinger - 2011-05-19

    Could you please raise a JIRA issue in the official RESTEasy issue tracker? https://issues.jboss.org/browse/RESTEASY
    I will take a look. Also, If you could attach the java project there, it would be awesome.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks