?Thanks Erel, maybe in the moment of slowdown of the work I will try to add it. But more for a challenge with oneself than for a real need.
Many thanks @Erel, I hope to be ableSee how it is implemented in jServer: https://github.com/AnywhereSoftware/B4J/tree/master/Libs_Server/src/anywheresoftware/b4j/object
@Erel forgive that I return to this topic and if it is the case to open a new thread tell me.No need to purchase anything. HttpServer is a simplified version of jServer (which does support SSL).
Use the Reflection library instead of JavaObject when trying to access private variablesServer is a private variable
I tried but without success. But I'm not sure I used it correctlyUse the Reflection library instead of JavaObject when trying to access private variables
server.Initialize("Server")
server.Start(port)
Dim r As Reflector
r.Target = server
r.Target = r.GetField("server") 'Get private server object
Log($"toString output: ${r.RunMethod("toString")}"$) 'Just to show we got the private server object
Log("Stopping server via private server object")
r.RunMethod("stop") 'Stop server
'Maybe now can set up SSL
Log("Starting server via private server object")
r.RunMethod("start") 'Restart server after setting up SSL
Already tried. In this way it says the field does not exist.Maybe try this (I used the code below with the HttpServer example):
Leaving SSL to someone elseB4X:server.Initialize("Server") server.Start(port) Dim r As Reflector r.Target = server r.Target = r.GetField("server") 'Get private server object Log($"toString output: ${r.RunMethod("toString")}"$) 'Just to show we got the private server object Log("Stopping server via private server object") r.RunMethod("stop") 'Stop server 'Maybe now can set up SSL Log("Starting server via private server object") r.RunMethod("start") 'Restart server after setting up SSL
Public Sub SetupSSL
Dim r As Reflector
r.Target = server
Dim O As Object = r.GetField("server") 'Get private server object
Dim J As JavaObject = Me
j.RunMethod("active_ssl", Array(o))
End Sub
#If Java
import org.eclipse.jetty.http.ssl.SslContextFactory;
import org.eclipse.jetty.server.ssl.*;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.util.resource.Resource;
public void active_ssl(Server jserver){
//jserver = new Server();
Resource keystore = Resource.newClassPathResource("/server.jks");
if (keystore != null && keystore.exists()) {
//connector.setConfidentialPort(8443);
SslContextFactory factory = new SslContextFactory();
factory.setKeyStoreResource(keystore);
factory.setKeyStorePassword("xxxxx");
factory.setTrustStore(keystore);
factory.setKeyManagerPassword("xxxxx");
SslSocketConnector sslConnector = new SslSocketConnector(factory);
sslConnector.setMaxIdleTime(5000);
sslConnector.setPort(8443);
sslConnector.setAcceptors(4);
jserver.addConnector(sslConnector);
System.out.println("SSL access to the quickstart has been enabled on port 8443");
System.out.println("You can access the application using SSL on https://localhost:8443");
System.out.println();
//jserver.start();
}
}
#End If