Hey,
I have a GAE Java project where I use Jersey (1.17) and Guice (3.0). 
SessionScoped beans work in local dev, but don't work when deployed on GAE. 
The problem is that they don't keep session state.

Sessions are enabled in web.xml:  <sessions-enabled>true</sessions-enabled>

My Session bean (SessionService) is:

@SessionScoped
public class SessionService implements Serializable {
    @Inject transient Logger log;
    private Locale locale = Locale.US;
    public synchronized Locale getLocale() { return locale; }
    public synchronized void setLocale(Locale locale) { this.locale = 
locale; }
}

and it's bound to Session scope in ServletModule : 
bind(SessionService.class).in(ServletScopes.SESSION);

Controller where I use it is:

@Path("/settings")  
public class SettingsController {
    @Inject SessionService sessionService;
    
@GET
    @Path("/setLocale")
    public Object setLocale(@QueryParam("languageTag") String languageTag) {
sessionService.setLocale(Locale.forLanguageTag(languageTag));
return "OK";
    }

@GET
    @Path("/getLocale")
    public Object getLocale() { return 
sessionService.getLocale().getLanguage(); }
}

With local dev server it works fine. When deployed on GAE (1.9.5) it sets 
the locale the first time and then it stays the same forever even though I 
call setLocale again and again. Why does it not work ?

Strangely enough, I found an obscure way to make it work, but I don't know 
why it makes it work. To have it running, it's necessary to touch 
HttpSession before setting locale. Like 
request.getSession(true).setAttribute("whatever", "bar"). As if server 
needed to be recalled that SessionService wants to do something with 
Session. Why is that?

Cheers,
Michal

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to