Get Session related data [message #539622] |
Fri, 11 June 2010 10:16  |
Eclipse User |
|
|
|
Good day,
I hope to get some idea's for a little problem I run in 2 with single sourcing a RCP/RAP application. Up to now it went quite well. But now I am implementing a login system and I want to keep using the same code for RCP/RAP to keep track of the user that's logged in. I think my main problem is that I am not sure how RAP works with OSGi Dynamic service. I want to set the logged in User data in a simple tracker I written. This tracker works quite good. But now I want to add the User information I am afraid that if more then one user Data is overwritten with the new Loggedin user.
What the best way to save such data in RAP so that it also works in RCP?
|
|
|
|
|
Re: Get Session related data [message #540017 is a reply to message #539867] |
Mon, 14 June 2010 11:24   |
Eclipse User |
|
|
|
Hi Martijn,
Quote: |
The question still remains tho how do I distinct sessions in RCP. In rap you could use the RWT.getSessionStore().getId() to get the HTTPSessionID however this is not available in RCP.
|
You are right. In my previous response, however, I was speaking of a session id in general (a String). So to elaborate, for the RAP application, you can use the http session id from the entrypoint.
HttpSession session = RWT.getRequest().getSession();
String id = session.getId();
<your tracker>.setUserInfo(id,userInfo);
In the RCP case, you can use whatever string you want, from the Application class:
<your tracker>.setUserInfo("staticsessionid",userInfo);
Quote: |
So that path is not realy available well yes I could use it in the Entrypoint (the only part of RAP ony code I have) but to use it in the plugins that contain the Views and rfunctionalaty I think isnt smart.
|
In this case, I would suggest that the session ID be placed in a wrapper object (e.g., UserSession) that you create.
Then (this is slightly unconventional and may be frowned upon) register it as a Workbench service using:
Workbench workbench = (Workbench)PlatformUI.getWorkbench();
workbench.registerService(UserSesssion.class, userSessionInst);
This give you a per user instance that is registered in the workbench. Then you can retrieve it anywhere in the RCP or RAP UI using:
UserSession userSessionInst = PlatformUI.getWorkbench().getService(UserSession.class);
String sessionID = userSessionInst.getSessionId();
OR if you don't want to go that route...just hide the session in the workbench preference store.
If you don't want to have this kind of code littered throughout the codebase just encapsulate it in the plugin activator(s). So the plugin members get teh user session or user id for that matter from the activator. Then the activator can get it however necessary.
Hope this helps.
|
|
|
|
|
|
|
Re: Get Session related data [message #541142 is a reply to message #541116] |
Fri, 18 June 2010 09:11  |
Eclipse User |
|
|
|
Thx,
I dint know that live and learn.
Ralf Sternberg wrote on Fri, 18 June 2010 14:03 | Hi Martijn,
synchronization is not at all RAP-specific. The point is that your
register and unregister methods are called from differnet threads
concurrently. Just search the web for Java, Threads, Synchronization.
Ralf
|
|
|
|
Powered by
FUDForum. Page generated in 0.04307 seconds