B4J Question [ABMaterial] HTTP ERROR 403 Problem accessing page Reason Forbidden

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

HTTP ERROR 403
Problem accessing /Test/HomePage/. Reason:

Forbidden
Powered by Jetty:// 9.4.z-SNAPSHOT

I am getting the above error. It is saying that it is Forbidden

Any idea what could be the reason for this error.

I have given ABMShared.NeedsAuthorization = True, so the login Modalsheet is appearing and validating, but it is not going to the initial page ie HomePage, instead it is giving the HTTP Error 403, Forbidden

I am able to login to the page, but after successful login I get the above error message.

The www folder is there with all the required sub folders. Here is the screen snap shot




Any help will be appreciated
 

Anser

Well-Known Member
Licensed User
Longtime User
Is it a must to have ABMPageTemplate.bas in the project ?.
I renamed ABMPageTemplate.bas as HomePage.bas

Could that be a reason for the error ?
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Could that be a reason for the error ?
Could be.
Have you also changed the name in the HomePage class?

B4X:
Public Name As String = "HomePage"  '<-------------------------------------------------------- IMPORTANT

And in ABMApplication:
B4X:
Private InitialPage As String = "HomePage/"  '<-------- First page to load

And what is the url you use?

Should be something like this:
B4X:
http://localhost:yourport/yourappname ' (appname is set in ABMApplication: ABMShared.AppName = "yourappname"  '<--------------- IMPORTANT)
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
This part is correct

And in ABMApplication:
B4X:
Private InitialPage As String = "HomePage/"  '<-------- First page to load

And what is the url you use?
In my code, there was no / after the "HomePage" ie Private InitialPage As String = "HomePage"
I did not find that forward slash in the Template project too.

Anyway after seeing your above post, I added the forward slash ie
Private InitialPage As String = "HomePage/"
and then I tested it once again, unfortunately, I am getting the same error message

I use the URL http://localhost:51042/Test


My App name is Test, so I use the following URL http://localhost:51042/Test

The app is loading and the initial login page is also displayed and validated, after the validation, it is not going to the home page, it is failing at that point and giving the error message 403 forbidden.

I examined the folder structure under the www folder and the HomePage it is there exactly as expected. I am puzzled, where my mistake is
ie
www\Test\HomePage

I am just trying to evaluate and learn ABMaterial. This is a very simple project which has a HomePage with 2 menu's
1. View Customers (This page would list data from a Sqlite Table)
2. Add Customer ( This page would provide a data entry screen for eg Firstname, Lastname and then save the data to the SQlite table)

I thought a restart of my PC would solve, tried that too.

Here is the code in my Main
B4X:
Sub AppStart (Args() As String)
    ' the user needs to login
    ABMShared.NeedsAuthorization = True
 
    'Reading the required port on which the app should run
 
    ' Build the Theme
    ABMShared.BuildTheme("mytheme") 
 
    'DBM.InitializeSQLite("E:\testdata", "testsqlite.db", True)
 
    ' create the app
    Dim myApp As ABMApplication
    myApp.Initialize
     
    ' create the pages
    Dim myPage As HomePage
    myPage.Initialize 
 
    Dim myViewCustPage As ViewCustomers
    myViewCustPage.Initialize
 
    Dim myAddCustomerPage As AddCustomer
    myAddCustomerPage.Initialize
     
    ' add the pages to the app
    myApp.AddPage(myPage.Page)
    myApp.AddPage(myViewCustPage.page)
    myApp.AddPage(myAddCustomerPage.page)
     
    ' start the server
    myApp.StartServer(srvr, "srvr", 51042) 
         
    ABMShared.RedirectOutput(File.DirApp, "logs.txt")
         
    StartMessageLoop
End Sub

Here is the relevant part from ABMApplication Code. I haven't made any changes other than changing the values of InitialPage and ABMShared.AppName
B4X:
'Main application
Sub Class_Globals
    ' change to match you app
    Private InitialPage As String = "HomePage"  '<-------- First page to load
 
    ' NOTE: Once you've set the above parameters, run the App once.  That way, the complete folder structure for your app will be created
    ' /appname/
    ' /appname/images/
    ' /appname/uploads/
    '
    ' You can then put the images you need in the pages into the /appname/images/ folder and start using them.
 
    ' other variables needed
    Private AppPage As ABMPage
    Private theme As ABMTheme
    Private ws As WebSocket 'ignore
    Private ABM As ABMaterial 'ignore 
    Private Pages As List 
    Private PageNeedsUpload As List
 
    Private ABMPageId As String = ""
End Sub

Public Sub Initialize
    Pages.Initialize 
    PageNeedsUpload.Initialize
    ABM.AppVersion = ABMShared.AppVersion
    ABM.AppPublishedStartURL = ABMShared.AppPublishedStartURL
    ABMShared.AppName = "Test"   '<-------------------------------------------------------- IMPORTANT
     
    ' add your icons
    ' ABM.AddAppleTouchIcon("", "")
    ' ABM.AddMSTileIcon("", "")
    ' ABM.AddFavorityIcon("", "") 
 
    #If RELEASE
        ABM.PreloadAllJavascriptAndCSSFiles=True    ' NEW
        ABM.ActivateGZip("DONATORKEY", 1000) ' NEW
        'ABM.AppDefaultPageCSSInline=True ' Im not so sure anymore this is the fastest solution. After all, the browser can not cache the 'page' CSS anymore.
        'ABM.AppDefaultPageJSInline=True ' Im not so sure anymore this is the fastest solution. After all, the browser can not cache the 'page' JS anymore.
 
        Dim folders As List ' NEW
        folders.Initialize
        folders.Add(File.DirApp & "/www/" & ABMShared.AppName & "/images") 
        ABM.ActivatePNGOptimize("DONATORKEY", folders, False , 9, False, True )
    #End If
 
    ' build the local structure IMPORTANT!
    BuildPage
End Sub

'Haven't made any changes
Sub msbtn1_Clicked(Target As String)
   Dim mymodal As ABMModalSheet = AppPage.ModalSheet("login")
   Dim inp1 As ABMInput = mymodal.Content.Component("inp1")
   Dim inp2 As ABMInput = mymodal.Content.Component("inp2")
   ' here check the login a page against your login database
   If inp1.Text <> "demo" Or inp2.Text <> "demo" Then
     AppPage.ShowModalSheet("wronginput")
     Return
   End If
   ws.Session.SetAttribute("IsAuthorized", "true")
   ABMShared.NavigateToPage(ws, "", "./" & InitialPage)
End Sub

Here is the HomePage Code. I renamed ABMPageTemplate.bas as HomePage.bas
B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore 
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "HomePage"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables 
 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ' build the local structure IMPORTANT!
    BuildPage     
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    '----------------------MODIFICATION------------------------------- 
    Log("Connected")
     
    ws = WebSocket1         
 
    ABMPageId = ABM.GetPageID(page, Name,ws)
 
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds) 
 
    If ABMShared.NeedsAuthorization Then
        If session.GetAttribute2("IsAuthorized", "") = "" Then
            ABMShared.NavigateToPage(ws, ABMPageId, "../")
            Return
        End If
    End If     
    ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)     
    If page.ComesFromPageCache Then
        ' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
        Log("Comes from cache")     
        page.Refresh     
        page.FinishedLoading     
    Else
        If page.WebsocketReconnected Then
            Log("Websocket reconnected")
            ' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
            ' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
            ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
        Else
            ' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
            Log("Websocket first connection")
            page.Prepare
            ConnectPage         
        End If
    End If
    Log(ABMPageId)     
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Page_ParseEvent(Params As Map)
    Dim eventName As String = Params.Get("eventname")
    Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
    If eventName = "beforeunload" Then
        Log("preparing for url refresh")
        ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
        Return
    End If
    Dim caller As Object = page.GetEventHandler(Me, eventName)
    If caller = Me Then
        If SubExists(Me, eventName) Then
            Params.Remove("eventname")
            Params.Remove("eventparams")
            ' BEGIN NEW DRAGDROP
            If eventName = "page_dropped" Then
                page.ProcessDroppedEvent(Params)
            End If
            ' END NEW DRAGDROP
            Select Case Params.Size
                Case 0
                    CallSub(Me, eventName)
                Case 1
                    CallSub2(Me, eventName, Params.Get(eventParams(0)))
                Case 2
                    If Params.get(eventParams(0)) = "abmistable" Then
                        Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
                        CallSub2(Me, eventName, PassedTables)
                    Else
                        CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
                    End If
                Case Else
                    ' cannot be called directly, to many param
                    CallSub2(Me, eventName, Params)
            End Select
        End If
    Else
        CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
    End If
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme) 

End Sub

public Sub BuildPage()
    ' initialize the theme
    BuildTheme
 
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "HomePage.html"
    page.PageTitle = ""
    page.PageDescription = ""
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
     
    page.ShowConnectedIndicator = True
             
    ' adding a navigation bar
    ABMShared.BuildNavigationBar(page, "Home Page (Test) ","../images/logo.png", "", "", "")
 
    'page.DebugConsoleEnable(True,250)
                 
    ' create the page grid
    page.AddRowsM(5,True,0,20, "").AddCellsOS(1,0,0,0,12,12,12,"")     
    page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components         
End Sub

public Sub ConnectPage()         
    '    connecting the navigation bar 
    ABMShared.ConnectNavigationBar(page)
 
    ' add your own components
    ' add header
    page.Cell(1,1).AddComponent(ABMShared.BuildHeader(page, "hdr1", "Welcome to Demo Application!"))
'    ' add paragraph
    page.Cell(1,1).AddComponent(ABMShared.BuildParagraph(page, "par1", "This web application is developed by the test "))
 
    page.Cell(1,1).AddComponent(ABMShared.BuildParagraph(page, "par2", "This is a new initiative from the IT Department, as a part of their continuos efforts to simplify the work process of the organization. We believe that you will find this new wep application attractive and useful "))
 
    Dim img As ABMImage
    img.Initialize(page, "img", "../images/logo.png?" & ABMShared.AppVersion, 1)
    page.Cell(2,1).AddComponent(img)
 
    ' also add the components to the footer
    ABMShared.ConnectFooterFixed(page)
     
    ' refresh the page 
    page.Refresh     
 
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition
End Sub

Sub Page_Dropped(Params As Map)
    If Params.Get("before") = "" Then
        Log("'" & Params.Get("component") & "' moved from " & Params.Get("source") & " to " & Params.Get("target"))
    Else
        Log("'" & Params.Get("component") & "' moved from " & Params.Get("source") & " to " & Params.Get("target") & " before component " & Params.Get("before"))
    End If 
End Sub

' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String) 
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
    If Action = "LogOff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub

Sub Page_MsgboxResult(returnName As String, result As String)
 
End Sub

Sub Page_InputboxResult(returnName As String, result As String)
 
End Sub

Sub Page_DebugConsole(message As String)
    Log("---> " & message) 
End Sub

Sub Page_FileUploaded(FileName As String, success As Boolean) 
 
End Sub

Sub Page_ToastClicked(ToastId As String, Action As String)
     
End Sub

Sub Page_ToastDismissed(ToastId As String) 
 
End Sub

Sub Page_Authenticated(Params As Map)
 
End Sub

Sub Page_FirebaseAuthError(extra As String)
 
End Sub

Sub Page_FirebaseAuthStateChanged(IsLoggedIn As Boolean)
 
End Sub

Sub Page_FirebaseStorageError(jobID As String, extra As String)
 
End Sub

Sub Page_FirebaseStorageResult(jobID As String, extra As String)
 
End Sub

Sub Page_ModalSheetDismissed(ModalSheetName As String)
 
End Sub

Sub Page_NextContent(TriggerComponent As String)
 
End Sub

Sub Page_SignedOffSocialNetwork(Network As String, Extra As String)
 
End Sub

Sub page_CellClicked(Target As String, RowCell As String)
    'Log(Target)
End Sub

Sub page_RowClicked(Target As String, Row As String)
    'Log(Target)
End Sub

Sub Page_NativeResponse(jsonMessage As String)
 
End Sub

Sub Page_NavigationbarSearch(search As String)
 
End Sub

Any help will be appreciated
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I am just evaluating and trying to understand the concepts and then learn ABMaterial library. I use the latest public version ie 3.75

I have mailed the project zip to you (excluding the www folder)
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
It is because you are using custom names for the html files too. You can omit the .html file in the urls, but only if it is called index.html (web default) This should solve it if you want custom html file names (in ABMApplication)

B4X:
Private InitialPage As String = "HomePage/HomePage.html"  '<-------- First page to load
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Thank you. That resolved the problem.

If I use custom names for html files, then I understand that I need to take care of this issue only in the Initial page variable in the ABMApplication. Right ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…