Bug? [BANanoServer] Project does not run in web browser

LJG

Member
I'm not sure if this is a bug or other issue.

In regard to the new B4J version (9.8.0), I applied the BANanoServer fix to the BANanoServer.b4xlib file as per https://www.b4x.com/android/forum/threads/banano-server-cannot-compile.141934/.

With that fix, I am now able to fully compile my BANanoServer project in B4J 9.8.0. But ... when I open my web browser to see my running BANanoServer project app, I get the following errors that do not allow me to load my BANanoServer project on to the web browser:

On the client web browser console side:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at s.onmessage (bananocore.js:19:2968)

On the server B4J console side:
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (HttpSession).
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:204)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: Object should first be initialized (HttpSession).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4j.object.HttpSessionWrapper.SetAttribute(HttpSessionWrapper.java:78)
at com.ab.banano.BANano.UpdateFromCacheDebug(Unknown Source)
at com.ab.banano.BANano.B4JUpdateFromCache(Unknown Source)
at b4j.example.bananoserver._updatefromcache(bananoserver.java:1583)
at b4j.example.serverindex._websocket_connected(serverindex.java:878)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
... 7 more

When I run the same BANanoServer project in the previous version of B4J, all works well.

Thank you for your help.
 

alwaysbusy

Expert
Licensed User
Longtime User
I've noticed that jetty 11 (jServer 4) does stuff differently than it did in jetty 9 (jServer 3). Previously for example I never got similar errors when running session.isNew. However, if the session is invalid now, the .isNew will throw a similar error.

In critical cases, I've added this snippet to check if the session is still valid:
B4X:
Dim joServer As JavaObject = Main.srvr
If joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethod("isValid", Array(session)) = False Then
        If page.ws.Open Then ' websocket is still open, hower the session was invalidated without closing it
            page.ws.Close ' closing the websocket
        End If
        Return
End If

Sometimes the session is invalid within 15 minutes, others keep a valid session for over 72 hours. In both cases, the WebSocket seems fine and I can still communicate between the browser and server. I'm still in the progress of running tests on how or why this is happening, so this may be a temporary solution.

Alwaysbusy
 
Top