eclipse-rcphttp-redirecthttpsessioneclipse-rap

Handling HTTP session timeout and redirect in Eclipse RAP application


I am working on an Eclipse RAP application (RCP as web application). After the servlet container has invalidated the HttpSession (session timeout, setMaxInactiveInterval exceeded) the following exception is thrown when clicking on the application in the browser:

java.lang.NullPointerException
at org.eclipse.rap.rwt.internal.service.LifeCycleServiceHandler.service(LifeCycleServiceHandler.java:66)
at org.eclipse.rap.rwt.engine.RWTServlet.handleValidRequest(RWTServlet.java:135)
...

So I implemented a javax.servlet.Filter that detects the situation and should now redirect somewhere to display a "session timeout, please reload" message.

My preferred solution for the "session timeout" warning would be a simple HTML5 page with a link back to the application. But I don't know how to integrate HTML5 pages with a RAP application (and whether that is a good idea to start with). Also I am not clear how and where the redirect should happen.

For redirecting I tried two variations in the Filter. The first one gives me "Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data":

httpServletResponse.sendRedirect("/myapp");

And this one "java.lang.IllegalStateException: Invalid thread access at org.eclipse.rap.rwt.RWT.checkContext(RWT.java:704)"

UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
launcher.openURL("http://www.eclipse.org/");

So I am probably really going down the wrong path here...

Does anybody know of a standard way to deal with HTTP session timeout situations in an Eclipse RAP application?

Is the HTTP session the correct place to deal with this or should I be looking at org.eclipse.rap.rwt.service.UISession, or something else?

How can I redirect to the home of the application if it lives on an URL like "http://127.0.0.1:50045/myapp"?

Can I easily integrate simple HTML5 pages with a RAP application (pages in same Eclipse project, deployed in same WAR, available on same host)? Or will this be a tedious task that does not come out of the box?


Solution

  • First off, a NullPointerException should never happen during normal operations, please file a bug including the RAP version and a stacktrace.

    Just a guess, the problem may be caused by invalidating the session from within the request processing. If this is the case, it may help to use the HttpSession method setMaxInactiveInterval with a small timeout instead.

    The problem with redirects is that a RAP application sends background (a.k.a. Ajax) requests to the server and expects JSON responses in return. If your filter redirects to some other page, the RAP client receives an HTML page instead of JSON. In order to redirect the browser to another page, you should send a JSON response to the client that includes this redirect (see bug 388249):

    {"head": {"redirect": "http://www.myurl.com/"}}
    

    To integrate other HTML5 pages in your RAP application, consider the Browser widget.