B4J Question WebSocket in B4J 5.80

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,
I have just updated my B4J IDE to the latest (v5.80).
When I used B4J version 5.51 (the version before I updated) the WebSockets was working fine.
Now with version 5.80 I am seeing an error.
I have created a small demo project to do some testing and the same thing is happening with that.
Here is the code:
Main Module:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region
Sub Process_Globals
    Private srvr As Server
End Sub
Sub AppStart (Args() As String)
    srvr.Initialize("srvr")
    srvr.Port = 8888
    srvr.AddWebSocket("/ws", "OnlineSocket")
    srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
    srvr.Start
    StartMessageLoop
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
OnlineSocket Module:
B4X:
'WebSocket class
Sub Class_Globals
    Private ws As WebSocket
End Sub
Public Sub Initialize
 
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
End Sub
Private Sub WebSocket_Disconnected
End Sub
The error I get in the IDE is:
Using jServer 2.80.
Am I doing something wrong or has something changed that I am not aware of or is this a bug ?
 
Last edited:

aaronk

Well-Known Member
Licensed User
Longtime User
On my local D:\
I have the project in a folder.

Didn't have any issues until I updated my B4J to version 5.80

FYI.. Should of said, running it on a Virtual Machine on a Mac. Running it under Windows 10.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Try to reinstall B4J.
Just uninstalled B4J, deleted the lib folder from C:\Program Files (x86)\Anywhere Software\B4J\Libraries

Re-installed B4J.

Now my demo project it working.

However my main project is still failing but with a different error. (I can't upload this project to the forum)

Below is what I am getting in my main project..

Error I am getting is:
Waiting for debugger to connect...
Program started.
log4j:WARN No appenders could be found for logger (org.eclipse.jetty.util.log).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Failed toString() invocation on an object of type [org.eclipse.jetty.websocket.server.WebSocketServerFactory]
java.lang.NullPointerException
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.toString(WebSocketServerFactory.java:641)
at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:304)
at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:276)
at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:230)
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.debug(JettyAwareLogger.java:206)
at org.eclipse.jetty.util.log.Slf4jLog.debug(Slf4jLog.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:322)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:226)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:149)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:126)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:121)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.eclipse.jetty.websocket.servlet.WebSocketServletFactory$Loader.load(WebSocketServletFactory.java:49)
at org.eclipse.jetty.websocket.servlet.WebSocketServlet.init(WebSocketServlet.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:637)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:421)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:760)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:211)
at b4j.example.main._webserverinitialize(main.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
SLF4J: Failed toString() invocation on an object of type [org.eclipse.jetty.websocket.server.WebSocketServerFactory]
java.lang.NullPointerException
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.toString(WebSocketServerFactory.java:641)
at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:304)
at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:276)
at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:230)
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.debug(JettyAwareLogger.java:206)
at org.eclipse.jetty.util.log.Slf4jLog.debug(Slf4jLog.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:322)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:229)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:150)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:126)
at org.eclipse.jetty.websocket.server.WebSocketServerFactory.<init>(WebSocketServerFactory.java:121)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.eclipse.jetty.websocket.servlet.WebSocketServletFactory$Loader.load(WebSocketServletFactory.java:49)
at org.eclipse.jetty.websocket.servlet.WebSocketServlet.init(WebSocketServlet.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:637)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:421)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:760)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:211)
at b4j.example.main._webserverinitialize(main.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
Emulated network latency: 100ms

B4X:
Dim srvr As Server
    srvr.Initialize("srvr")
    srvr.Port = 8888
    srvr.AddWebSocket("/ws", "OnlineSocket")
   
    srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
    srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")

    Dim err As Map
        err.Initialize
        err.Put(403, "/403.html")
        err.Put(404, "/404.html") 'page not found
        err.Put(405, "/405.html")
        err.Put(500, "/500.html") 'server error
    srvr.SetCustomErrorPages(err)
   
   
    srvr.Start

If I remove the line:
srvr.AddWebSocket("/ws", "OnlineSocket")

then the error doesn't occur.

Also check Objects\src and see whether onlinesocket.java was created.
Yes this is created.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I worked it out.

Even though I had no lines of code that referenced the jMqttbroker, it still failed. I then in-ticked it from the library list and now it works.

I would of thought if I didn't have any lines of code then it wouldn't include that lib in my project when I compile the app. Looks like it does.

Looks like that lib was causing this issue.

In B4J version 5.51 I was able to have both in the same project. Looks like this has now changed in the new version.
 
Upvote 0
Top