B4J Code Snippet Additional jServer (web server) Setting Snippets

Just thought it would be good to keep additional jServer/Jetty/Web Server settings in one place.

I'll go first;

Set Max Post/Form Size (setMaxFormContentSize) (link)

B4X:
Dim jo As JavaObject = webserver  
jo.GetFieldJO("context").RunMethod("setMaxFormContentSize", Array(10000000)) 'Size is in bytes, this example is 10mb
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
Set Specific Host IP (to listen on?) (link)

B4X:
Dim jo As JavaObject = webserver
jo.SetField("host", "ip.address")
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
Set SetCookieJsessionidHttpOnly (setHttpOnly) (link)

B4X:
Dim jo As JavaObject = webserver
Dim sessionmanager As JavaObject = jo.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethod("getSessionManager", Null)
sessionmanager.RunMethod("setHttpOnly", Array(True))
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
RemoveServerVersionFromResponses (link)

B4X:
Private Sub RemoveServerVersionFromResponses (Server As Server)
   Dim jo As JavaObject = Server
   jo = jo.GetField("server")
   Dim connectors() As Object = jo.RunMethod("getConnectors", Null)
   For Each co As JavaObject In connectors
     Dim connections() As Object = co.RunMethodJO("getConnectionFactories", Null).RunMethod("toArray", Null)
     For Each connection As JavaObject In connections
       If GetType(connection) = "org.eclipse.jetty.server.HttpConnectionFactory" Then
         Dim configuration As JavaObject = connection.RunMethod("getHttpConfiguration", Null)
         configuration.RunMethod("setSendServerVersion", Array(False))
       End If
     Next
   Next
End Sub
 

tchart

Well-Known Member
Licensed User
Longtime User
Stop Running Server (link)

B4X:
Dim jo As JavaObject = server
jo.GetFieldJO("server").RunMethod("stop", null)
 

tchart

Well-Known Member
Licensed User
Longtime User
Set Max Idle Time (setIdleTimeout) (link)

B4X:
srvr.Start
Dim jo As JavaObject = srvr
Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
Dim timeout As Long = 50000
For Each c As JavaObject In connectors
   c.RunMethod("setIdleTimeout", Array(timeout))
Next
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
Set Max Text Message Size (setMaxTextMessageSize) (link)

B4X:
Sub SetMaxTextMessage(size As Int)
   Dim jo As JavaObject = ws
   jo = jo.GetFieldJO("session").RunMethod("getPolicy", Null)
   jo.RunMethod("setMaxTextMessageSize", Array(size))
End Sub
 

tchart

Well-Known Member
Licensed User
Longtime User
jServer v2.80+ Enabling TLSv1.1 (setIncludeCipherSuites/setExcludeCipherSuites) (link)

B4X:
Dim jo As JavaObject = ssl
jo.RunMethod("setIncludeCipherSuites", Array(Array As String("TLS_RSA_WITH_AES_128_CBC_SHA")))
jo.RunMethod("setExcludeCipherSuites", Array(Array As String()))
 
Top