I've updated the "main", "startHttpServer" and "startHttpsServer" methods in order to make the code work:
public static void main(String[] args) throws Exception {
Engine.setLogLevel(java.util.logging.Level.INFO);
Component component = new Component();
component.getLogService().setLoggerName("net.asdf.WebComponent.www");
component.getDefaultHost().attach(new TestPatrick());
// Attach the server connectors descriptors to the component
component.getServers().add(startHttpsServer(component, 443));
component.getServers().add(startHttpServer(component, 8182));
// Start the component, which will lead to start, at the end, the real connectors.
component.start();
}
private static Server startHttpServer(Component component, Integer port) throws Exception {
return new Server(Protocol.HTTP, port, component);
}
private static Server startHttpsServer(Component component, Integer port) throws Exception {
// create embedding https jetty server
Server server = new Server(new Context(), Protocol.HTTPS, port, component);
Series<Parameter> parameters = server.getContext().getParameters();
parameters.add("keystore", "jks/keystore.jks");
parameters.add("keyStorePath", "jks/keystore.jks");
parameters.add("keyStorePassword", "xxx");
parameters.add("keyManagerPassword", "xxx");
parameters.add("keyPassword", "xxx");
parameters.add("password", "xxx");
parameters.add("keyStoreType", KeyStore.getDefaultType());
parameters.add("tracing", "true");
parameters.add("truststore", "jks/keystore.jks");
parameters.add("trustStorePath", "jks/keystore.jks");
parameters.add("trustStorePassword", "xxx");
parameters.add("trustPassword", "xxx");
parameters.add("trustStoreType", KeyStore.getDefaultType());
parameters.add("allowRenegotiate", "true");
parameters.add("type", "1");
return server;
}
Here are some explanations. The Component is a container for applications, it aims at providing some services to these applications. For example, it provides server connectors, that help applications to be reached via client requests using several protocols. The Restlet framework furnishes several implementations of server connectors; one is internal, the others are based on a specific framework such as Jetty. As we do not want your code to be dependent on a specific extension, the philosophy it to let the Component declare its required server connectors using the Server class, which acts as a descriptor. Then, the Engine discovers the implementations located in the classpath, and transparently creates the real server helpers.
I hope my explanations are clear. If not, please feel free to ask for more.