Unable to read session parameter

103 views
Skip to first unread message

Eric PROTAT

unread,
Sep 28, 2014, 5:27:18 PM9/28/14
to ninja-f...@googlegroups.com
Hi,

I searched about this issue for too long and I think the solution must be so obvious I can't see it.

This is a very simple use case, described as an example everywhere, and I can't manage to make it work !

I just can't get the parameter I just put in the session.

After a form submit :

// mapped to "/lpgin" in Routes
public Result login(
            @Param("email") String email,
            @Param("password") String password,
            Context context) {

                context.getSession().put("account", user.getAccount());
              
               return Results.redirect("/hq");

    }

// mapped to "/hq" in Routes
public Result hq(Context context) {
      logger.debug("account: "+context.getSession().get("account"));
      return Results.html();
}

This display

account; null

And obviously, the variable session.account can't be retrieved in the template.

It really can't be more simple. I'm seeing it work in every ninja framework example. I must be missing something big !

Thank you for your help.


Eric PROTAT

unread,
Sep 28, 2014, 5:34:37 PM9/28/14
to ninja-f...@googlegroups.com
Code has been simplified in my examples. Consider the "user.getAccount()" as an hardcoded string, This does not change anything to the problem.

And if I log the "account" session variable at the end of the "login" controller method, the logger displays the good value. I 'seems to be lost in the redirect.

Stéphane Cl

unread,
Sep 29, 2014, 2:47:21 AM9/29/14
to ninja-f...@googlegroups.com
I haven't used sessions much but I would check the session cookie in the browser. Is it properly created? Does it contain any value?
Another possible explanation is that "user.getAccount()" returns null but you have probably triple-checked that already. 

Eric PROTAT

unread,
Sep 29, 2014, 7:21:18 AM9/29/14
to ninja-f...@googlegroups.com
Yes consider that I hardcoded a value in the session.put() call.
 
What I'm missing is perhaps the way I create the cookie. In fact, I just did nothing explicit about it, excepted set the cookie prefix in application.conf file. Is there any thing special to do ?

Stéphane Cl

unread,
Sep 29, 2014, 8:05:34 AM9/29/14
to ninja-f...@googlegroups.com
Nothing special to do according to the docs, however it would still be interesting to inspect the cookie on client-side.

Eric PROTAT

unread,
Sep 29, 2014, 5:58:44 PM9/29/14
to ninja-f...@googlegroups.com
After submitting the login form, I can see on the server side that the user is authentified, and that the user id is set in the session.
I can see in the cookie on the client side that the user id is in it.

However, I'm unable to display anything in the current page, and in controllers after more requests.

I didn't mention I'm using Mustache templating, but, on the cookie and session management, code is the same.

Eric PROTAT

unread,
Sep 29, 2014, 6:30:16 PM9/29/14
to ninja-f...@googlegroups.com
Found it !

application.session.transferred_over_https_only=true
... and I was not in HTTPS for development.

I said it was probably dumb ... Thank you for your help.

Raphael André Bauer

unread,
Sep 30, 2014, 2:43:49 AM9/30/14
to ninja-f...@googlegroups.com
That's very cool!
I was just about to write back - but you already found the issue :)

Is there anything we could do to improve the docs in that regard?
If you have problems like that it's always cool to debug via Firebug,
curl or the debug console of Chrome. This always helps me to find
those kind of issues :)


Cheers,

Raphael
> --
> You received this message because you are subscribed to the Google Groups
> "ninja-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ninja-framewo...@googlegroups.com.
> To post to this group, send email to ninja-f...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ninja-framework/90fe5b2a-c2c8-4b62-a05a-a153e8d2f5b2%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Eric PROTAT

unread,
Sep 30, 2014, 4:43:38 AM9/30/14
to ninja-f...@googlegroups.com
Hi !
 
Just a warning point in the "Sessions" chapter describing the cookie settings in application.conf could be useful. But it seems I'm the only one having this issue :)
 
Regards,
 
Eric

Moses Gone

unread,
Jul 6, 2018, 4:30:40 AM7/6/18
to ninja-framework
No you are not the only one having this problem, I struggled for several hours with this. Just couldnt figur eout where and when my session was getting cleaned-off attributes. And indeed, I was on dev mode and I had set my application.session.transferred_over_https_only settings to true. Changing it back to false solved the issue
Reply all
Reply to author
Forward
0 new messages