Hi all,

I write a simple app to get session id by calling getThreadLocalRequest
().getSession().getId(). Unfortunately, for first time of calling, I
usually get different return strings.

The code is bellow. I try to get session ids three times but app
returns three different strings of session id when the system (server
and client) has just started. Those strings are unique only when I
refresh browser.

Can you help me to point out what I am missing and/or the solution?

Thanks a lot for any help.

Code:

package com.mysite.testsession.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class GetSession implements EntryPoint {
        private final GetSessionServiceAsync myService = GWT.create
(GetSessionService.class);

        public void onModuleLoad() {
                final Label sessionLabel1 = new Label("Session1: ");
                final Label sessionLabel2 = new Label("Session2: ");
                final Label sessionLabel3 = new Label("Session3: ");

                VerticalPanel vPanel = new VerticalPanel();
                vPanel.add(sessionLabel1);
                vPanel.add(sessionLabel2);
                vPanel.add(sessionLabel3);

                RootPanel.get().add(vPanel);

                myService.getSessionId(new AsyncCallback<String>() {
                        @Override
                        public void onFailure(Throwable caught) { }

                        @Override
                        public void onSuccess(String result) {
                                sessionLabel1.setText("Session1: " + result);
                        }

                });

                myService.getSessionId(new AsyncCallback<String>() {
                        @Override
                        public void onFailure(Throwable caught) { }

                        @Override
                        public void onSuccess(String result) {
                                sessionLabel2.setText("Session2: " + result);
                        }
                });
                myService.getSessionId(new AsyncCallback<String>() {
                        @Override
                        public void onFailure(Throwable caught) { }

                        @Override
                        public void onSuccess(String result) {
                                sessionLabel3.setText("Session3: " + result);
                        }
                });
        }


}
--------------------------
package com.mysite.testsession.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("mysession")
public interface GetSessionService extends RemoteService {
        String getSessionId();
}
-----------------------------
package com.mysite.testsession.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface GetSessionServiceAsync {
        void getSessionId(AsyncCallback<String> callback);
}
----------------------------
package com.mysite.testsession.server;

import com.mysite.testsession.client.GetSessionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class GetSessionServiceImpl extends RemoteServiceServlet
implements GetSessionService {

        @Override
        public String getSessionId() {
                return getThreadLocalRequest().getSession().getId();
        }
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to