views:

3172

answers:

2

I am using GWT for my client side application. However, I am not sure how I can handle session management. The GWT application resides on one page, all server calls are done via AJAX. If a session expires on the server. let's assume the user didn't close the browser, and sending some request to server using RPC, how could my server notify the application that the session has expired and that the client side portion should show the login screen again?My sample code :

ContactDataServiceAsync contactDataService = GWT
    .create(ContactDataService.class);
  ((ServiceDefTarget) contactDataService).setServiceEntryPoint(GWT
    .getModuleBaseURL()
    + "contactDatas");

  contactDataService.getContact(2,
    new AsyncCallback<ContactData>() {
     public void onFailure(Throwable caught) {
                                      //code to show error if problem in connection or redirect  to login page

     }

     public void onSuccess(ContactData result) {
      displayContact(result);
     }
    });

If session expires only it has to show login screen, otherwise it wants to show some error using Window.alert().

How to do this and what are all the codes needed in server side and client side?

+4  A: 
Silfverstrom
Thanks.Could you please provide some sample code to check whether it is Authentication exception or some other exception.Meanwhile I try to googling.
BlackPanther
Check my edit, i think thats one ok way to solve it.
Silfverstrom
+1  A: 

This does not directly apply to those using RPC, but for those of you who are not using RPC, you should send a HTTP 401 from the server. Then you can check that status code in your RequestBuilder callback.

JP