Clear server push session on shutdown
[lgpl/argeo-commons.git] / swt / rap / org.argeo.cms.swt.rap / src / org / argeo / cms / web / CmsWebEntryPoint.java
index b61259b7fa80d2939a827aba735c06b6d27938dc..9c94da8f34c2de11bac5ab89c34f8980ca464f14 100644 (file)
@@ -2,6 +2,8 @@ package org.argeo.cms.web;
 
 import static org.eclipse.rap.rwt.internal.service.ContextProvider.getApplicationContext;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.security.PrivilegedAction;
 import java.util.Locale;
 import java.util.UUID;
@@ -17,8 +19,8 @@ import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.CmsSession;
 import org.argeo.api.cms.ux.CmsImageManager;
 import org.argeo.api.cms.ux.CmsView;
+import org.argeo.cms.CurrentUser;
 import org.argeo.cms.LocaleUtils;
-import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.RemoteAuthCallbackHandler;
 import org.argeo.cms.servlet.ServletHttpRequest;
 import org.argeo.cms.servlet.ServletHttpResponse;
@@ -167,10 +169,10 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                                return;
                }
                display.syncExec(() -> {
-                       CmsFeedback.show("Unexpected exception in CMS", e);
-                       exception = e;
-//                     log.error("Unexpected exception in CMS", e);
-                       doRefresh();
+                       // TODO internationalise
+                       CmsFeedback.error("Unexpected exception", e);
+                       // TODO report
+//                     doRefresh();
                });
        }
 
@@ -179,19 +181,19 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                        Subject.doAs(getSubject(), new PrivilegedAction<Void>() {
                                @Override
                                public Void run() {
-                                       if (exception != null) {
-                                               // TODO internationalise
-                                               CmsFeedback.show("Unexpected exception", exception);
-                                               exception = null;
-                                               // TODO report
-                                       }
+//                                     if (exception != null) {
+//                                             // TODO internationalise
+//                                             CmsFeedback.error("Unexpected exception", exception);
+//                                             exception = null;
+//                                             // TODO report
+//                                     }
                                        cmsWebApp.getCmsApp().refreshUi(ui, state);
                                        return null;
                                }
                        });
        }
 
-       /** Sets the state of the entry point and retrieve the related JCR node. */
+       /** Sets the state of the entry point and retrieve the related content. */
        protected String setState(String newState) {
                cmsWebApp.getCmsApp().setState(ui, newState);
                state = newState;
@@ -200,7 +202,7 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
 
        @Override
        public void navigateTo(String state) {
-               exception = null;
+//             exception = null;
                String title = setState(state);
                if (title != null)
                        doRefresh();
@@ -241,6 +243,15 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                return cmsSession;
        }
 
+       @Override
+       public URI toBackendUri(String url) {
+               try {
+                       return new URI(url);
+               } catch (URISyntaxException e) {
+                       throw new IllegalArgumentException("Cannot convert " + url, e);
+               }
+       }
+
        /*
         * EntryPoint IMPLEMENTATION
         */
@@ -271,27 +282,28 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                                                        return null;
                                                }
                                        });
-                               } catch (Throwable e) {
-                                       if (e instanceof SWTError) {
-                                               SWTError swtError = (SWTError) e;
-                                               if (swtError.code == SWT.ERROR_FUNCTION_DISPOSED) {
-                                                       log.error("Unexpected SWT error in event loop, ignoring it. " + e.getMessage());
-                                                       continue eventLoop;
-                                               } else {
-                                                       log.error("Unexpected SWT error in event loop, shutting down...", e);
-                                                       break eventLoop;
-                                               }
-                                       } else if (e instanceof ThreadDeath) {
-                                               throw (ThreadDeath) e;
-                                       } else if (e instanceof Error) {
-                                               log.error("Unexpected error in event loop, shutting down...", e);
-                                               break eventLoop;
-                                       } else {
-                                               log.error("Unexpected exception in event loop, ignoring it. " + e.getMessage());
+                               } catch (SWTError e) {
+                                       SWTError swtError = (SWTError) e;
+                                       if (swtError.code == SWT.ERROR_FUNCTION_DISPOSED) {
+                                               log.error("Unexpected SWT error in event loop, ignoring it. " + e.getMessage());
                                                continue eventLoop;
+                                       } else {
+                                               log.error("Unexpected SWT error in event loop, shutting down...", e);
+                                               break eventLoop;
                                        }
+                               } catch (ThreadDeath e) {
+                                       // ThreadDeath is expected when the UI thread terminates
+                                       throw (ThreadDeath) e;
+                               } catch (Error e) {
+                                       log.error("Unexpected error in event loop, shutting down...", e);
+                                       break eventLoop;
+                               } catch (Throwable e) {
+                                       log.error("Unexpected exception in event loop, ignoring it. " + e.getMessage());
+                                       continue eventLoop;
                                }
                        }
+                       if (serverPushSession != null)
+                               serverPushSession.stop();
                        if (!display.isDisposed())
                                display.dispose();
                }