B4J Question safari session variables in b4j v4

billyrudi

Active Member
Licensed User
Longtime User
Hi
i have problems with sessions variables with safari after upgrade to version 4.
it seems that browser lose values.
Chrome and firefox works correctly.
In safari i have the accept cookies and data from all sites active.
can anyone help me?
 
Last edited:
I encountered the same problem also with iPad and iPhone.
 
Upvote 0
I've tested the following code with an iPhone:
Code: Copy
Sub Class_Globals
End Sub

Public Sub Initialize

End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
   Dim i As Int = req.GetSession.GetAttribute2("i", 0)
   req.GetSession.SetAttribute("i", i + 1)
     resp.Write(i)
End Sub

The number is incremented. Do you see a different behavior?
 
Upvote 0
hi,
in safari and firefox i have problems with session.setattribute.
i have success with
Code: Copy
WC.LocalStorage_SetItem( "TipoUtente", "paolo")
and
Code: Copy
 WC.LocalStorage_GetItem( "TipoUtente","null").Value
where functions are
Code: Copy
Sub LocalStorage_SetItem(Key As String, Value As Object)
    mWS.Eval("$.jStorage.set(arguments[0], arguments[1]);", Array As Object(Key, Value))
End Sub

Code: Copy
Sub LocalStorage_GetItem(Key As String, Default As Object) As Future
    Return mWS.EvalWithResult("return $.jStorage.get(arguments[0], arguments[1]);", Array As Object(Key, Default))
End Sub
i have a strangeness the jstorage.js must be lowercase.

i have spent two days searching this solution.
 
Upvote 0
Erel see your chat example in safari it doesn't works...
Yes, that is the one I suspected it could go wrong. I think it happens when you move to another 'page' on your website. Pre 4.0 could do this, but 4.0 has some troubles saving the session vars. Unfortunately, ABMaterial relies a lot on this technique.

Local storage was indeed also my alternative solution. Maybe it is the new jetty version that plays a role in it?
 
Upvote 0
Try the online chat now. It should work (refresh the log-in page to make sure that the cache is invalidated).

The workaround is to create the session and send the cookie before the upgrade request.

This is done by adding this filter:
Code: Copy
srvr.AddFilter("/b4j_ws.js", "SessionCreator", False)

The class code is:
Code: Copy
'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
 
Upvote 0
Works perfectly on my iPad Erel, very elegant solution!

For ABMaterial users:

In ABMApplication add in ABMApplication in both StartServer and StartServerHTTP2:

Code: Copy
' start the server
    srvr.Initialize(srvrName)
    srvr.AddFilter("/js/b4j_ws.js", "ABMSessionCreator", False) ' <----- Add this line
    srvr.AddWebSocket("/ws/" & AppName, "ABMApplication")
...

Create a new Filter class ABMSessionCreator and add:

Code: Copy
'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
 
Upvote 0
Back
Top