Archived

This forum has been archived. Please start a new discussion on GitHub.

Problem passing context map with createSession()

I'm having trouble passing a context map in a call to createSession(). I'm using the chat room code from Connections #2. I modified it in two ways: first, I added the following to the Glacier2 config to turn on context forwarding:
Glacier2.Client.ForwardContext=1
Glacier2.Server.ForwardContext=1

I then create the context map and call createSession() as follows:
final Map<String, String> contextMap = new HashMap<String, String>();
contextMap.put("foo", "bar");
chatSessionPrx = ChatSessionPrxHelper.uncheckedCast(router.createSession(id, pw, contextMap));

However, when I print out the contents of the context map received by checkPermissions() in the permissions verifier, it's always empty. What am I doing wrong?

BTW, the context maps created in ChatRoom's enter() method are passed, so I know it works at least some of the time.

This post seems to be asking the same question, but there's no answer given:

Finally, speaking of context maps, are they ever mutated? That is, for the ChatRoom class, is it safe to create the map once and store it as a class member rather than creating a new one with every call to enter()?

Thanks!

Comments

  • Which version of Ice for Java are you using? Note that, prior to 3.0.1, there were bugs with respect to contexts in the Java and C# implementations. If you are still using 3.0 or earlier, can you please upgrade to 3.0.1 and let us know whether that fixes it?

    When you pass a context map to the Ice run time, it keeps a copy of that map, so if you change the context map after passing it to the session, that will not affect the session.

    Cheers,

    Michi.
  • No contexts are forwarded to the permission verifier when sessions are established. This will be changed in the next Ice 3.1 release.
  • bartley wrote:
    Finally, speaking of context maps, are they ever mutated? That is, for the ChatRoom class, is it safe to create the map once and store it as a class member rather than creating a new one with every call to enter()?

    Ice doesn't modify the contexts that you pass. You can store them somewhere and reuse them. Alternatively, you can simply set the context as default context on the proxy, then you don't have to pass it explicitly at all.
  • mes
    mes California
    marc wrote:
    No contexts are forwarded to the permission verifier when sessions are established. This will be changed in the next Ice 3.1 release.
    Sorry Chris, I was looking at the Ice 3.1 source tree when I claimed that the router would pass along the context to the permission verifier.

    If you can't distinguish between humans and robots using the username, I think your best alternative is to use two router instances.

    Take care,
    - Mark
  • mes
    mes California
    Of course, you could also modify the Glacier2 sources yourself. The changes are trivial. :)

    - Mark
  • Wow, thanks for all the helpful replies--you guys are great. :)

    I'll probably just go with two routers. Any timeframe on when Ice 3.1 will be released?
    Ice doesn't modify the contexts that you pass. You can store them somewhere and reuse them.

    Good, thanks, that's what I had hoped.
    Alternatively, you can simply set the context as default context on the proxy, then you don't have to pass it explicitly at all.

    Oooo, even better, thanks!