'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Private srvr As Server
Private sslConfig As SslConfiguration
End Sub
Sub AppStart (Args() As String)
srvr.Initialize("")
srvr.Port = 80
ConfigureSSL(443)
srvr.Start
UpdateSSL
StartMessageLoop
End Sub
Private Sub ConfigureSSL (SslPort As Int)
'example of SSL connector configuration
Dim ssl As SslConfiguration
ssl.Initialize
ssl.SetKeyStorePath(File.DirApp, "keystore.jks") 'path to keystore file
ssl.KeyStorePassword = "UseYourOwnPassword"
'ssl.KeyManagerPassword = "UseYourOwnPasswordCouldBeOptional"
srvr.SetSslConfiguration(ssl, SslPort)
sslConfig = ssl
'add filter to redirect all traffic from http to https (optional)
'srvr.AddFilter("/*", "HttpsFilter", False)
End Sub
Private Sub UpdateSSL
Dim timestamp As Long = File.LastModified(File.DirApp, "keystore.jks")
Dim jo As JavaObject = Me
Dim sslConfigJO As JavaObject = sslConfig
Do While True
Sleep(30000)
If File.LastModified(File.DirApp, "keystore.jks") <> timestamp Then
timestamp = File.LastModified(File.DirApp, "keystore.jks")
Log("Attempting to reload keystore")
Try
jo.RunMethod("reloadSSLConfiguration", Array(sslConfigJO))
Catch
Log(LastException)
End Try
End If
Loop
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
#if Java
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.server.Server;
public static void reloadSSLConfiguration(SslContextFactory sslFactory) throws Exception {
sslFactory.reload(sfc -> {});
//sslFactory.reload(sslFactory -> {});
}
#End If