I have a Jetty WebServlet that can connect with various clients written in C# and on android. This currently works using simple HTTP, but I am interested in upgrading it to HTTPS. To try and do this I am creating the server like this:
public static void main(String[] args){
SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setKeyStorePath("keystore.jks");
contextFactory.setKeyStorePassword("********");
SslConnectionFactory connectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_2_0.toString());
Server server = new Server(8080);
ServerConnector connector = new ServerConnector(server, connectionFactory);
connector.setPort(8443);
server.addConnector(connector);
ServletContextHandler servletCH = new ServletContextHandler();
servletCH.setContextPath("/");
servletCH.addServlet(ScheduleWebSocketServlet.class, "/schedule");
server.setHandler(servletCH);
server.start();
server.join();
}
This seems to be wrong. The ScheduleWebSocketServlet class is as follows:
@WebServlet(name = "Schedule WebSocketServlet", urlPatterns = {"/schedule"})
public static class ScheduleWebSocketServlet extends WebSocketServlet{
private static final long serialVersionUID = 5838283767965540728L;
public void doGet(HttpServletRequest request, HttpServletResponse response){
try {
response.getWriter().println("<h1>Hello World</h1>");
} catch (IOException e) {
Main.LogError(e);
}
}
@Override
public void configure(WebSocketServletFactory arg0) {
arg0.register(ScheduleWebSocket.class);
}
}
So my question is what is the correct way to use the WebServlet with HTTPS?
Thanks very much for the help