NastyDiaper
NastyDiaper

Reputation: 2558

Jetty WebSockets over HTTPS configured through the WebSocketServlet

I have seen many examples on how to configure Jetty for HTTPS SSL for Jetty but they all seem to utilize a separate Server class containing a main method for execution. I want to execute my WebServlet as a standard servlet configured via the web.xml file. I currently have:

@WebServlet
public class MonitoringServlet extends WebSocketServlet {

    @Override
    public void configure(WebSocketServletFactory factory) {
        factory.register(MonitoringSocket.class);
    }
}

Where would I place my SSL Servlet configuration code? In the configure method of this Servlet? In the init method?

I do understand that in this case there is no need for instantiating a Server object and using .start() and .join

Upvotes: 0

Views: 99

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49555

Servlets are just a means of producing a response to a request.

Typically a request can be from HTTP/0.9, HTTP/1.0, HTTP/1.1, or HTTP/2.

Using SSL/TLS for the secure part of the protocol.

Technically speaking, HTTP isn't even required for Servlets to function.

The protocol used to submit the request is outside of the control of the Servlet you are implementing to provide a response.

In Jetty, you'll want:

  • a Server instance
  • at least 1 Connector configured for SSL/TLS
  • at least 1 handler assigned to the Server
    • Using servlets without all of the baggage of a "web application" (a "web application" typically has a WEB-INF/web.xml, WEB-INF/classes, and WEB-INF/lib/*.jar) this would be a ServletContextHandler
    • Using servlets with a "web application" this would be a WebAppContext

This setup can come from a configured ${jetty.base} in the jetty-distribution or via use of Java to build up the server, its connectors, and its handlers.

Upvotes: 1

Related Questions