View Full Version : How to maintain a user-connection between two GWT-projects

30 Dec 2010, 12:27 AM

i need some help,

I have two GWT-projects: "login" and "webapp".
The user has to logon to my server with his credentials. The login-project has one servlet class with several servlet methods. At initialization of the servlet the "init" method will be called:

publicvoid init (ServletConfig config) throws ServletException {
ServletContext context = config.getServletContext();
ConnectionPool cp = new ConnectionPool();

context.setAttribute("currentConnections", cp);


The ServletContext object gets an attribute "currentConnections" to store a ConnectionPool object.
The ConnectionPool object stores the connection from the given user in a HashMap with the given SessionId:

ConnectionPool cp = new ConnectionPool();

cp = (ConnectionPool) getServletContext().getAttribute("currentConnections");

cp.putConnection(getThreadLocalRequest().getSession().getId(), new ConnectionModel(username, con));

The user will be directed to "webapp"-application...

In my "webapp"-project i try to retrieve this stored connection for the user:

ConnectionPool cp = new ConnectionPool();

cp = (ConnectionPool) getServletContext().getAttribute("currentConnections");

Connection con = null;
con = cp.takeFromPool(getThreadLocalRequest().getSession().getId());

The con is always == null !!!
I think the scope of ServletContext with his attribute is to restricted?!?
My sessionId is possibly also a different in the "login" and the "webapp"-application.

Is there a better solution to maintain a user-connection between two web-apps?

I appreciate any advice!

30 Dec 2010, 2:41 AM
Cannot you simple store it directly in a session? Why do you want to go this complicated?

9 Jan 2011, 11:27 PM
Hi Sven,

sry for delayed reply.

What is so special with this session object?
How can i realize my intention?

kind regards

10 Jan 2011, 1:44 AM
I believe this can not work. Every web app has it's own session context. Check the session ids, they will be different. You need another approach. For example: store the connection information in a database, give the key to the second app and read the login information from the database in the second app.

Another approch is, to put both apps together in one app.

10 Jan 2011, 2:21 AM
Hi gishmo,

your last advice was, what i was thinking of, too.

Your second advice:
How can i store connections in a database? Is there a certain datatype for this?

10 Jan 2011, 2:26 AM
I do not understand, why you are storing logged in users in the sessioncontext?

Why are you doing this?

10 Jan 2011, 2:43 AM
the user will do many request against a database.
So why the should be prompted every time?

10 Jan 2011, 3:42 AM
This question is not gxt related.

Are you using database access management for the user management of your web app? Does every user has it's own db connection? If so, you should think about your architecture. ;-)

The easiest way to handle logon in a web application is to store the information inside the session. Every user owns a session. So, this works fine.

10 Jan 2011, 6:51 AM
Yes, every user has his own connection. Authorization is controlled by database.

I think i will put the first project into the other...this would be the quick and dirty version. B)

Thank you