Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Get Session related data
Get Session related data [message #539622] Fri, 11 June 2010 14:16 Go to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

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?


hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: Get Session related data [message #539675 is a reply to message #539622] Fri, 11 June 2010 20:04 Go to previous messageGo to next message
Austin Riddle is currently offline Austin RiddleFriend
Messages: 128
Registered: July 2009
Senior Member
Hi Martijn,

Could you describe your tracker a little bit more?

RAP has no problems with OSGi Declarative Services ...if that is what you meant.

In general, if your user tracker is a single OSGi service, it will be shared by all users of the RAP application. However, if you allow user information to be stored using a session id key, then it should work just fine...and it would work for your RCP case since there would just be one user's information stored.

It is also possible to have one user tracker registered per user...but then to obtain the correct one you would have to iterate through them and see if the session id matches the current one.

Hope this helps!

[Updated on: Fri, 11 June 2010 20:09]

Report message to a moderator

Re: Get Session related data [message #539867 is a reply to message #539675] Mon, 14 June 2010 07:27 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

Austin Riddle wrote on Fri, 11 June 2010 22:04
Hi Martijn,

Could you describe your tracker a little bit more?


The tracker is just to help the Eclipse GUI components to have access to the OSGi Service it just binds and unbinds it when nessesery. At the moment I have only on OSGi DS service but there will be more and its one of the few functions thats used in all plugins so for now ill put the user data in there.

Austin Riddle wrote on Fri, 11 June 2010 22:04
RAP has no problems with OSGi Declarative Services ...if that is what you meant.

In general, if your user tracker is a single OSGi service, it will be shared by all users of the RAP application. However, if you allow user information to be stored using a session id key, then it should work just fine...and it would work for your RCP case since there would just be one user's information stored.

It is also possible to have one user tracker registered per user...but then to obtain the correct one you would have to iterate through them and see if the session id matches the current one.

Hope this helps!


Yeah you got me thinking the right track. I am trying not to have a lot of code that's to tied to RCP or RAP so that maintaining this will be easy. (still need to figure out how to solve my Upload widget problem but that a another problem for later).

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. 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.



hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.

[Updated on: Mon, 14 June 2010 08:39]

Report message to a moderator

Re: Get Session related data [message #540017 is a reply to message #539867] Mon, 14 June 2010 15:24 Go to previous messageGo to next message
Austin Riddle is currently offline Austin RiddleFriend
Messages: 128
Registered: July 2009
Senior Member
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 #540240 is a reply to message #540017] Tue, 15 June 2010 13:09 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

I ended up creating a SessionManger plug-in with to different plug-ins (eg one for RAP and one for RCP).

I did this because this is the neatest and best solution. The session Manger in RAP environment both are the same name and functions. The biggest difference is that the RAP version extends the SessionSingletonBase and checks against the HTTPsession ID.

The SessionManager looks something like this:
public class SesionManager extends SessionSingletonBase {
	private static UserObject user;

	public static SesionManager getInstance() {
		return (SesionManager) getInstance(SesionManager.class);
	}

	/**
	 * @return the user
	 */
	public static UserObject getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public static void setUser(UserObject user) {
		SesionManager.user = user;
	}

	public static void unregisterUser() {
		SesionManager.user = null;
	}

}


I tested this and it actualy keeps track of the users and only real problem I run in to is cleanupcode. But thats a difrent story.


hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.

[Updated on: Tue, 15 June 2010 14:29]

Report message to a moderator

Re: Get Session related data [message #540979 is a reply to message #540240] Thu, 17 June 2010 20:45 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Martijn,

just want to point out that without synchronization, the concurrent
access to the static ArrayLists can't work reliably.

Ralf

Martijn Cremer wrote:
> I ended up creating a SessionManger plug-in with to different plug-ins
> (eg one for RAP and one for RCP).
>
> I did this because this is the neatest and best solution. The session
> Manger in RAP environment both are the same name and functions. The
> biggest difference is that the RAP version extends the
> SessionSingletonBase and checks against the HTTPsession ID.
>
> The SessionManager looks something like this:
>
> public class SesionManager extends SessionSingletonBase {
> private static ArrayList<OMXCustomerContact> users = new
> ArrayList<OMXCustomerContact>();
>
> private static ArrayList<String> httpSesions = new ArrayList<String>();
>
> /**
> * @return the user
> */
> public static Object getUser() {
> int i = 0;
> for (String httpSesion : httpSesions) {
> if (httpSesion.equals(RWT.getSessionStore().getId())){
> System.out.println("Session found: " +
> RWT.getSessionStore().getId());
> System.out.println(users.size());
> return users.get(i);
> }
> i++;
> }
> return null;
> }
>
> /**
> * @param user
> * the user to set
> */
> public static void registerUser(Object user2) {
> SesionManager.users.add(user2);
> SesionManager.httpSesions.add(RWT.getSessionStore().getId()) ;
> }
>
> public static void unregisterUser() {
> int i = 0;
> for (String httpSesion : httpSesions) {
> if (httpSesion.equals(RWT.getSessionStore().getId())){
> users.remove(i);
> httpSesions.remove(i);
> }
> i++;
> }
> }
>
>
> I tested this and it actualy keeps track of the users and only real
> problem I run in to is cleanupcode. But thats a difrent story.
>
Re: Get Session related data [message #541054 is a reply to message #540979] Fri, 18 June 2010 08:02 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

Hi Ralf,

Thanks for pointing out any suggestions how can create a way to implement synchronization? I did not see any thing on that in the documentation (I did not really look for it yet).

Ralf Sternberg wrote on Thu, 17 June 2010 22:45
Hi Martijn,

just want to point out that without synchronization, the concurrent
access to the static ArrayLists can't work reliably.

Ralf

Martijn Cremer wrote:
> I ended up creating a SessionManger plug-in with to different plug-ins
> (eg one for RAP and one for RCP).
>
> I did this because this is the neatest and best solution. The session
> Manger in RAP environment both are the same name and functions. The
> biggest difference is that the RAP version extends the
> SessionSingletonBase and checks against the HTTPsession ID.
>
> The SessionManager looks something like this:
>
> public class SesionManager extends SessionSingletonBase {
> private static ArrayList<OMXCustomerContact> users = new
> ArrayList<OMXCustomerContact>();
>
> private static ArrayList<String> httpSesions = new ArrayList<String>();
>
> /**
> * @return the user
> */
> public static Object getUser() {
> int i = 0;
> for (String httpSesion : httpSesions) {
> if (httpSesion.equals(RWT.getSessionStore().getId())){
> System.out.println("Session found: " +
> RWT.getSessionStore().getId());
> System.out.println(users.size());
> return users.get(i);
> }
> i++;
> }
> return null;
> }
>
> /**
> * @param user
> * the user to set
> */
> public static void registerUser(Object user2) {
> SesionManager.users.add(user2);
> SesionManager.httpSesions.add(RWT.getSessionStore().getId()) ;
> }
>
> public static void unregisterUser() {
> int i = 0;
> for (String httpSesion : httpSesions) {
> if (httpSesion.equals(RWT.getSessionStore().getId())){
> users.remove(i);
> httpSesions.remove(i);
> }
> i++;
> }
> }
>
>
> I tested this and it actualy keeps track of the users and only real
> problem I run in to is cleanupcode. But thats a difrent story.
>



hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: Get Session related data [message #541116 is a reply to message #541054] Fri, 18 June 2010 12:03 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

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

Martijn Cremer wrote:
> Hi Ralf,
> Thanks for pointing out any suggestions how can create a way to
> implement synchronization? I did not see any thing on that in the
> documentation (I did not really look for it yet).
>
> Ralf Sternberg wrote on Thu, 17 June 2010 22:45
>> Hi Martijn,
>>
>> just want to point out that without synchronization, the concurrent
>> access to the static ArrayLists can't work reliably.
>>
>> Ralf
>>
>> Martijn Cremer wrote:
>> > I ended up creating a SessionManger plug-in with to different plug-ins
>> > (eg one for RAP and one for RCP).
>> > > I did this because this is the neatest and best solution. The session
>> > Manger in RAP environment both are the same name and functions. The
>> > biggest difference is that the RAP version extends the
>> > SessionSingletonBase and checks against the HTTPsession ID.
>> > > The SessionManager looks something like this:
>> > > public class SesionManager extends SessionSingletonBase {
>> > private static ArrayList<OMXCustomerContact> users = new
>> > ArrayList<OMXCustomerContact>();
>> > > private static ArrayList<String> httpSesions = new
>> ArrayList<String>();
>> > > /**
>> > * @return the user
>> > */
>> > public static Object getUser() {
>> > int i = 0;
>> > for (String httpSesion : httpSesions) {
>> > if (httpSesion.equals(RWT.getSessionStore().getId())){
>> > System.out.println("Session found: " +
>> > RWT.getSessionStore().getId());
>> > System.out.println(users.size());
>> > return users.get(i);
>> > }
>> > i++;
>> > }
>> > return null;
>> > }
>> > > /**
>> > * @param user
>> > * the user to set
>> > */
>> > public static void registerUser(Object user2) {
>> > SesionManager.users.add(user2);
>> >
>> SesionManager.httpSesions.add(RWT.getSessionStore().getId()) ;
>> > }
>> > > public static void unregisterUser() {
>> > int i = 0;
>> > for (String httpSesion : httpSesions) {
>> > if (httpSesion.equals(RWT.getSessionStore().getId())){
>> > users.remove(i);
>> > httpSesions.remove(i);
>> > } > i++;
>> > }
>> > }
>> > > > I tested this and it actualy keeps track of the users and only real
>> > problem I run in to is cleanupcode. But thats a difrent story.
>> >
>
>
Re: Get Session related data [message #541142 is a reply to message #541116] Fri, 18 June 2010 13:11 Go to previous message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

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





hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Previous Topic:RAP Eclipse Help System
Next Topic:[Design] Custom Look and Feel with default stack presentation
Goto Forum:
  


Current Time: Fri Dec 06 01:27:29 GMT 2024

Powered by FUDForum. Page generated in 0.06519 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top