B4J Question [SOLVED] - Standalonepackage - JServer

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

I am starting to create stand alone packages for our suite of server app. Some of the apps use websockets. The problem is that when a connection occures I geet the following:

B4X:
pool-1-thread-2::INFO:sosstat│NOP│WebSocket_Connected, error - (RuntimeException) java.lang.RuntimeException: Object should first be initialized (HttpSession).

The proj attribs are :

B4X:
#Region  Project Attributes 
        
    #AdditionalJar: bcprov-jdk15on-159.jar
    #if java11
        #AdditionalJar: C:\Java\jdbc\sqljdbc_12.8\enu\jars\mssql-jdbc-12.8.1.jre11.jar
    #else
        #AdditionalJar: mssql-jdbc-6.2.2.jre8.jar
    #End If
    
    #if java11        
        ' // https://www.b4x.com/android/forum/threads/jserver-v4-0-based-on-jetty-11.140437/
        #PackagerProperty: AdditionalModuleInfoString = provides org.slf4j.spi.SLF4JServiceProvider with org.eclipse.jetty.logging.JettyLoggingServiceProvider;
        #PackagerProperty: AdditionalModuleInfoString = provides org.eclipse.jetty.io.ssl.ALPNProcessor.Server with org.eclipse.jetty.alpn.java.server.JDK9ServerALPNProcessor;
        #PackagerProperty: AdditionalModuleInfoString = provides org.eclipse.jetty.http.HttpFieldPreEncoder with org.eclipse.jetty.http2.hpack.HpackFieldPreEncoder, org.eclipse.jetty.http.Http1FieldPreEncoder;
        #PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.util.security.CredentialProvider;
        #PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.io.ssl.ALPNProcessor.Server;        
        #PackagerProperty: IncludedModules = jdk.charsets, jdk.crypto.ec
    #End If

    
    
#End Region

Regards

John
 

Chris2

Active Member
Licensed User
Longtime User
I don't think this still applies to your problem (could be wrong) but as I understand it, your jServer works just fine and the problem only occurs when you try to package it?
Good point!

Looking back at what I did (although I might be wasting your time here, I've never been sure it was correct or necesary as @alwaysbusy suggested. I implemented it when trying to resolve intermittent WS connection issues that turned out to be a jetty incompatibility between client & server, and it just got left in)...

I didn't add the js file, I just created a filter to force the creation of an HTTPSession on WS connections:
B4X:
srvr.AddFilter("/ws", "SessionCreator", False)    'https://www.b4x.com/android/forum/threads/jserver-v4-0-based-on-jetty-11.140437/

SessionCreator:
'Filter class
Sub Class_Globals
End Sub

Public Sub Initialize
End Sub

'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    req.GetSession 'a new session will be created if a session doesn't exist.
    Return True
End Sub

UPDATE: I think I'm leading you astray here. I just did a quick test, removing the srvr.AddFilter("/ws", "SessionCreator", False) line from my jServer app and it still seems to run OK without it. It might still be worth a try though I guess.
 
Last edited:
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I kind of remember this was indeed needed back in the day with an older version of Jetty and Safari, but checking the code of our WebApps we currently don't seem to do it any more either.

We do get in our logs also occasionally such a message (java.lang.RuntimeException: Object should first be initialized (HttpSession).), however the WebApp recovers from it. @Jmu5667 Do you use the Reconnecting WebSocket? https://www.b4x.com/android/forum/threads/server-automatic-reconnecting-websocket.62054/#content

We use ABM and this uses the Reconnecting WebSocket so maybe that is why it recovers in our case? 🤔
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
No, all the connections ws connections so the servlet code is not relevant. This is where the error occurs.

B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    

    Try
        sql = Main.DB_SQL.GetConnection
        
        ws = WebSocket1
        ws.Session.MaxInactiveInterval = 120
        ws.RunFunction("ServerReady", Array As Object("READY"))
        ws.Flush
        tmrKill.Enabled = True
        killTimeout = DateTime.Now + (DateTime.TicksPerSecond * 10)
        eventCount = 0
        remoteIP = ws.UpgradeRequest.RemoteAddress
        
        
    Catch
        writelog("WebSocket_Connected, error - " & LastException)
        close_socket
    End Try

End Sub
 
Upvote 0
Top