Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Offline Mode throwing exception when coming back online

Diego Marcia
6 years ago Sep 09, 2015 2:54pm

Hello, everybody
I am trying to implement the Offline Mode in my TouchKit application and I managed to get a custom offline Widget to get displayed when the device loses network connection.

However, when connection comes back an Exception is thrown:

sept. 09, 2015 12:22:37 PM org.atmosphere.cpr.DefaultBroadcaster addAtmosphereResource
WARNING: Duplicate resource 3f27dc93-bd11-4b9a-ad32-b0d21f385167. Could be caused by a dead connection not detected by your server. Replacing the old one with the fresh one
sept. 09, 2015 12:22:37 PM org.atmosphere.container.JSR356Endpoint onError
SEVERE:
java.io.IOException: An existing connection was forcibly closed by the remote host
      at sun.nio.ch.SocketDispatcher.read0(Native Method)
      at sun.nio.ch.SocketDispatcher.read(Unknown Source)
      at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
      at sun.nio.ch.IOUtil.read(Unknown Source)
      at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
      at org.apache.tomcat.util.net.NioChannel.read(NioChannel.java:140)
      at org.apache.coyote.http11.upgrade.NioServletInputStream.fillReadBuffer(NioServletInputStream.java:136)
      at org.apache.coyote.http11.upgrade.NioServletInputStream.doRead(NioServletInputStream.java:80)
      at org.apache.coyote.http11.upgrade.AbstractServletInputStream.read(AbstractServletInputStream.java:124)
      at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:51)
      at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
      at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
      at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)

The device comes back to the previously shown view, but interaction gets stuck.
Here is my widgetset descriptor:

<module>
      <inherits name="com.vaadin.DefaultWidgetSet" />
 
      <inherits name="com.vaadin.addon.touchkit.gwt.TouchKitWidgetSet" />
 
      <inherits name="org.vaadin.addon.leaflet.Widgetset" />
   
      <set-configuration-property
            name='touchkit.manifestlinker.additionalCacheRoot'
            value='src/main/webapp/VAADIN/themes/MyTheme:../../../VAADIN/themes/MyTheme' />
 
      <replace-with
            class="com.example.demo.frontend.widgetset.client.offlinepage.OfflinePageWidget">
            <when-type-is class="com.vaadin.addon.touchkit.gwt.client.offlinemode.OfflineMode" />
      </replace-with>
</module>

Where OfflinePageWidget is the class implementing the custom widget client side, extends VOverlay and implements the interface OfflineMode. Its server side does nothing, simply sets the size in the constructor and specializes the getState() method. The same goes for their connector, which simply specializes the methods required by interface AbstractComponentConnector. The widget doesn't implement any rpc or shared state operation.
Regarding the custom Servlet, the only setting is setCacheManifestEnabled(true), while for the OfflineMode settings I have setPersistentSessionCookie(true) and offlineMode.setOfflineModeTimeout(15).
 
It seems to me that I implemented all necessary operations, but I of course may be wrong, so I'm asking you if you believe I forgot something.
Thank you!

Diego Marcia
6 years ago Sep 10, 2015 7:49am

Some additional information I can give you is that my UI enables Push operations from a background thread

@Push(PushMode.MANUAL)

Indeed, if I comment this annotation as well as thread creation and launching, the exception seems to not be thrown.
So I now wonder if there's a way to "reconcile" PushMode and OfflineMode...