B4J Question [ABMaterial] set new path webserver

FabioRome

Member
Licensed User
Longtime User
my server is rooted in the public_html folder instead of www

B4X:
public Sub StartServer(srvr As Server, srvrName As String, srvrPort As Int
srvr.Initialize(srvrName)
srvr.StaticFilesFolder = File.Combine(File.DirApp, "public_html")
    ' uncomment this if you want to directly access the app in the url without having to add the app name
    ' e.g. 192.168.1.105:51042 or 192.168.1.105 if you are using port 80
    srvr.AddFilter( "/", "ABMRootFilter", False )
    
    ' NEW V3 Cache Control
    srvr.AddFilter("/*", "ABMCacheControl", False)
    ' NEW 4.00 custom error pages (optional) Needs the ABMErrorHandler class
    srvr.SetCustomErrorPages(CreateMap("org.eclipse.jetty.server.error_page.global": "/" & ABMShared.AppName & "/error")) ' OPTIONAL
    srvr.AddHandler("/" & ABMShared.AppName & "/error", "ABMErrorHandler", False) ' OPTIONAL
    
    srvr.AddWebSocket("/ws/" & ABMShared.AppName, "ABMApplication")
    For i =0 To Pages.Size - 1
        srvr.AddWebSocket("/ws/" & ABMShared.AppName & "/" & Pages.Get(i) , Pages.Get(i))
        If PageNeedsUpload.Get(i) Then           
            srvr.AddHandler("/" & ABMShared.AppName & "/" & Pages.Get(i) & "/abmuploadhandler", "ABMUploadHandler", False)
        End If
    Next   
    srvr.AddBackgroundWorker("ABMCacheScavenger")
    srvr.Port = srvrPort
        
    #If RELEASE       
        srvr.SetStaticFilesOptions(CreateMap("gzip":True,"dirAllowed":False))
    #Else       
        srvr.SetStaticFilesOptions(CreateMap("gzip":False,"dirAllowed":False))
    #End If
    
    srvr.Start       
    
    Dim joServer As JavaObject = srvr
    joServer.GetFieldJO("server").RunMethod("stop", Null)
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setMaxAge", Array(31536000)) ' 1 year   
    
    ' NEW FEATURE! Each App has its own Session Cookie
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setName", Array(ABMShared.AppName.ToUpperCase))
    joServer.GetFieldJO("server").RunMethod("start", Null)
    
    Dim secs As Long = ABMShared.CacheScavengePeriodSeconds ' must be defined as a long, else you get a 'java.lang.RuntimeException: Method: setIntervalSec not matched.' error
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionIdManager", Null).RunMethodJO("getSessionHouseKeeper", Null).RunMethod("setIntervalSec", Array As Object(secs))
            
    Dim jo As JavaObject = srvr
    Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
    Dim timeout As Long = ABMShared.SessionMaxInactiveIntervalSeconds*1000
    For Each c As JavaObject In connectors
        c.RunMethod("setIdleTimeout", Array(timeout))
    Next

    ABMShared.CachedPages = srvr.CreateThreadSafeMap

but I get error on this routine

B4X:
public Sub AddPage(Page As ABMPage)
    Pages.Add(Page.Name)   
    PageNeedsUpload.Add(ABM.WritePageToDisk(Page, File.DirApp & "/public_html/" & ABMShared.AppName & "/" & Page.Name & "/", Page.PageHTMLName, ABMShared.NeedsAuthorization)) 'public_html 'www
End Sub

below the generated error

B4X:
Error occurred on line: 134 (ABMApplication)
java.lang.NullPointerException
    at java.base/java.io.File.<init>(File.java:279)
    at com.ab.abmaterial.ABMPage.WritePageToDiskPerTheme(ABMPage.java:4739)
    at com.ab.abmaterial.ABMPage.WritePageToDisk(ABMPage.java:4433)
    at com.ab.abmaterial.ABMaterial.WritePageToDisk(ABMaterial.java:3570)
    at com.ab.template.abmapplication._addpage(abmapplication.java:101)
    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:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    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:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at com.ab.template.main.main(main.java:29)

thanks for the support
(sorry for my english I used google translate)
 

FabioRome

Member
Licensed User
Longtime User
Does the folder public_html exist? It should as it would normally already contain the css, js and font folders.

in public_html the folders exist, the error does not create the APP_NAME folder. the instruction on which it fails is:

B4X:
public Sub AddPage(Page As ABMPage)
    Pages.Add(Page.Name)
    PageNeedsUpload.Add(ABM.WritePageToDisk(Page, File.DirApp & "/public_html/" & ABMShared.AppName & "/" & Page.Name & "/", Page.PageHTMLName, ABMShared.NeedsAuthorization)) 'public_html 'www
End Sub

if I put www again then this step works. the structure on my server is:
/private/ABMATERIAL_APP_NAME
/logs/
/public_html/css
/public_html/font
/public_html/js

However, even the B4J IDE does not work the root switch, it seems that it only works if you use the WWW folder, it seems as if in some non-visible settings you only use the www


I did one more test. I downloaded the file https://gorgeousapps.com/ABMExtras4.51.zip
and compiled the CHAT example changing www to public_html and the same error is still generated

@alwaysbusy can you help me, please ? thank
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…