There are lots of ways you could do it. Here's one way:
(1) create a wrapper object around your RPC service, replicating all the
methods. This is much easier if you use the command pattern, because
your service requires only a very small number of methods.
(2) Make all RPC calls through this wrapper
(3) The wrapper makes the real RPC call. Do not check whether the
session is alive before making the call - just make the call and see if
it works.
(4) If the session has timed out, the RPC call should fail with a
checked exception that you can look for in your wrapper's onFailure
method. If the session has timed out, then the wrapper can handle that
somehow. (Perhaps by showing a login screen, sending credentials to the
server, then rerunning the original RPC request).
(5) If the RPC call fails because the server and client are different
versions, then the wrapper can display a suitable message to the user
("refresh your browser")
(6) If the RPC call fails for some other reason (that the wrapper cannot
handle) then pass the failure back to the caller's onFailure method.
Using a centralised RPC service like this has some advantages:
- your wrapper can store the user's current session ID in a static
variable, and insert it into the RPC payload. The calling code doesn't
need to know or care about this. If you do this, then the wrapper's API
is slightly different from the service API, since the service API can
have an argument for the session ID that the wrapper's API can leave out.
- you don't need to worry about session expiry everywhere because the
wrapper will handle it
- you can easily piggy-back additional data onto the server's response
because the wrapper can be responsible for unwrapping it
- you can create some network metric capture code that only goes into
the wrapper
HTH
Paul
On 13/10/10 11:40, Chan wrote:
Hi,
I have a GWT application that requires a login to gain access. The
ServiceImpl compares the input with records in a mysql database.
A HTTPSession is created if the user exists and when the user requests
information, this session is checked to ensure he is a legitimate user
and it returns a userid.
This userid is then used as parameter in the logAction rpc.
So for every action the user does, a validation RPC takes place and in
the onSuccess method a logAction rpc is implemented.
So to clarify the problem:
RPC.getInstance().isSessionAlive(new AsyncCallback<User>(){
public void onFailure(Throwable caught) {..}
public void onSuccess(User result) {
if(result != null){
RPC.getInstance().logActions(result.getUserId(), (new
Time()).getTime(), "Description", "SomeData", null);
}else{
BodyPanel.getInstance().setMainPanel(new
LoginScreen().getPanel());
}
Becuase my application is pretty large there are going to be a lot of
nested RPC`s because the returned result is needed right away.
Is there another cleaner way to check if someone is logged in and
retrieve the user id without nested RPC`s? (i.e. storing user id local
or some kind of pattern)
--
You received this message because you are subscribed to the Google Groups "Google
Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.