Web App Crashing Session NilObjectException

Hi I have a web app that has a login screen. I am also using a service to login users. I am using a subclass of URLConnection to connect to the service.

Here is the code of my login button (which is inside a web container, the web container is placed in the SignInPage. The SignInConnector - URLConnection instance - is added to the SignInPage):

Try
  Var json As New JSONItem
  
  json.Value("email") =  email.Text
  json.Value("password") =  password.Text
  
  SignInPage.SignInConnector.RequestHeader("apikey") = "MyAppKey" 
  SignInPage.SignInConnector.RequestHeader("Content-Type") = "application/json" 
  
  SignInPage.SignInConnector.SetRequestContent(json.ToString, "application/json")
  
  SignInPage.SignInConnector.Send("POST","https://my.service.com/login")
Catch e As JSONException
  MessageBox("An error occurred, please try again")
End Try

and in my URLConnection ContentReceived event, i have this code

Sub ContentReceived(URL As String, HTTPStatus As Integer, content As String)
  Session.Login()
End Sub

Session has a

  • Login() method
  • LoggedIn property
  • Opening Event

In the opening event of the session i have this code: Self.LoggedIn = False. The login method only sets the session.loggedIn = true. I looked into the xojo example and try to do the same. The only difference i am using a URLConnection. Maybe the way i am doing the URLConnection is the issue?

When I run the web app, i can see the content of my service response with the correct data, it is when it is trying to execute the Session.Login code that throws a NilObjectException. I see a red x next to the Session.Login() Not sure what to do. Any help will be greatly appreciated.

I guess I am starting to think that the URLConnection is the culprit. If i do URLConnection.send or URLConnection.sendsync i get different errors, one crashes the app (session none existent) the other does not connect. I removed my login screen and the app works fine (so far).

Catch NetworkException too not only the JsonEcception!

When using URLConnection.Send, it makes an async request.
Although SignInConnector is an object of SignInPage, it does not have any information about the current session.

  1. Add a String property named sessionID in SignInPage.
  2. Change your Login button code to this:
Try
  Var json As New JSONItem
  
  json.Value("email") =  email.Text
  json.Value("password") =  password.Text
  
  SignInPage.sessionID = Session.identifier //Keeps a reference to the session.identifier
  SignInPage.SignInConnector.RequestHeader("apikey") = "MyAppKey" 
  SignInPage.SignInConnector.RequestHeader("Content-Type") = "application/json" 
  
  SignInPage.SignInConnector.SetRequestContent(json.ToString, "application/json")
  
  SignInPage.SignInConnector.Send("POST","https://my.service.com/login")
Catch e As JSONException
  MessageBox("An error occurred, please try again")
End Try

In URLConnection ContentReceived event change code to this:

Sub ContentReceived(URL As String, HTTPStatus As Integer, content As String)
  Var context As new WebSessionContext(SignInPage.sessionID) //Creates a new context for the session
  Session.Login()
End Sub
3 Likes

Hi @Jeremie_L, first thank you for your time. I made the suggested changes. It now throws an error in the place i am hosting it.

This is the page error: Connection Problem

We are having trouble communicating with the server. Please wait a moment while we attempt to reconnect.

Command Line Error : Application is ready
Runtime Error
Please report what caused this error along with the information below.
Common/ObjectGlue.cpp: 147
Failure Condition: mClassPtr
Xojo.Core.PlatformNotSupportedException
Aborted (core dumped)

This errors are only happening if my main page is the login page with a URLConnection. If i remove the login page, it seems to work fine so far.

Quite difficult to understand the source of the error.
Are you able to get the exception stack trace too?
That would help.

Can you share a sample project? That can help others test and give ideas.

Hi Alberto, literally the project is just the code above. Its one page for signin (I had one container with the textfields for email and password, and a button but I removed it and made it simpler by putting the controls on the page) the login button has the code I have shown above connecting to the service.

I also have a class named SignInConnector (super URLConnection) that only has the ContentReceived event with the code above.

Like i mentioned in my previous post, my session had a method called Login (now SignIn) and a property called LoggedIn (now AccessToken). The session no longer has a opening event. The code for that signIn method is

Session.AccessToken =  resp

Var main As New MainPage
main.Show

Lastly i have a page with just one button that does nothing that shows after successful login.

Last famous words… “it works fine in my computer” but when i load it to the host i does not work when the login screen is the default web page. If i remove the login as the default web page and i set the second page as the default, it works fine so far.

I am new to xojo, how can i get an exception stack trace if “it works fine in my computer” but not when it is loaded to the host and try to access it from the web.

Seeing a .cpp filename in an error means something went wrong inside the framwork. This can happen if your host doesn’t meet the minimum system requirements for a Xojo Web app.

Check your system and components against the list in the documentation:

https://documentation.xojo.com/resources/system_requirements_for_current_release.html#server-requirements

You won’t get one for a .cpp error, but you can log each line of the RuntimeException.Stack string array in the App.UnhandledException event.

If you’re new to hosting Xojo Web apps, but would like to do so on your own server you could check out my app, Lifeboat. It is built to simplify the whole server setup and deployment process.

When adding new features, I test it with the Linux flavors and versions on the service providers that are listed on the web page and in the documentation.

1 Like

Thank you @Tim_Parnell . I am just testing the web features in xojo. I think Lifeboat its something i can use once i am ready for prod. But for now this is a simple app that i believe it meets the requirements Ubuntu 23.10 and also i did a ldd on my app and it looks like the libraries needed are there…

ldd xojo-test
	linux-vdso.so.1 (0x00007ffea77a5000)
	XojoConsoleFramework64.so => /root/./xojo-test Libs/XojoConsoleFramework64.so (0x00007fc5bb200000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc5bae00000)
	libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fc5bd8df000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fc5bb0b9000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc5bd8da000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc5bd8d3000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc5bd8ce000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc5bad15000)
	libunwind.so.8 => /lib/x86_64-linux-gnu/libunwind.so.8 (0x00007fc5bd8b2000)
	libunwind-x86_64.so.8 => /lib/x86_64-linux-gnu/libunwind-x86_64.so.8 (0x00007fc5bd896000)
	libc++.so.1 => /root/./xojo-test Libs/libc++.so.1 (0x00007fc5ba800000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc5bd870000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc5bd947000)
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007fc5bd865000)
	libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007fc5bb01e000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fc5bd833000)

The problem, like i said earlier was the URLConnection. As you can see that is not beeing shown as a library needed in the app unless you go back to the docs (System requirements — Xojo documentation).

Once I installed the needed library for URLConnection - libsoup using the terminal: sudo apt-get -y install libsoup2.4-dev it worked fine.

Thank you all, today with your help i learn about session and context and libraries in my hosts. Again thank you for your patience and help.

Sorry this solution was possible with the docs (in the solution post) from @Tim_Parnell.