class OpenfireWebSocketServlet extends JettyWebSocketServlet {

    private static final long serialVersionUID = 1074354600476010708L;
    private static final Logger Log = LoggerFactory.getLogger(OpenfireWebSocketServlet.class);

    @Override
    public void destroy()
    {
        // terminate any active websocket sessions
        SessionManager sm = XMPPServer.getInstance().getSessionManager();
        for (ClientSession session : sm.getSessions()) {
            if (session instanceof LocalSession) {
                Object ws = ((LocalSession) session).getSessionData("ws");
                if (ws != null && (Boolean) ws) {
                    Log.debug( "Closing session as websocket servlet is being destroyed: {}", session );
                    session.close();
                }
            }
        }

        super.destroy();
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        // add CORS headers for all HTTP responses (errors, etc.)
        if (HttpBindManager.HTTP_BIND_CORS_ENABLED.getValue())
        {
            final HttpBindManager boshManager = HttpBindManager.getInstance();
            if (boshManager.isAllOriginsAllowed()) {
                // Set the Access-Control-Allow-Origin header to * to allow all Origin to do the CORS
                response.setHeader("Access-Control-Allow-Origin", HttpBindManager.HTTP_BIND_CORS_ALLOW_ORIGIN_ALL);
            } else {
                // Get the Origin header from the request and check if it is in the allowed Origin Map.
                // If it is allowed write it back to the Access-Control-Allow-Origin header of the respond.
                final String origin = request.getHeader("Origin");
                if (boshManager.isThisOriginAllowed(origin)) {
                    response.setHeader("Access-Control-Allow-Origin", origin);
                }
            }
            response.setHeader("Access-Control-Allow-Methods", String.join(",", HttpBindManager.HTTP_BIND_CORS_ALLOW_METHODS.getValue()));
            response.setHeader("Access-Control-Allow-Headers", String.join(",", HttpBindManager.HTTP_BIND_CORS_ALLOW_HEADERS.getValue()));
            response.setHeader("Access-Control-Max-Age", String.valueOf(HttpBindManager.HTTP_BIND_CORS_MAX_AGE.getValue().toSeconds()));
        }
        super.service(request, response);
    }

    @Override
    public void configure(JettyWebSocketServletFactory factory)
    {<FILL_FUNCTION_BODY>}
}

        if (!WebSocketClientConnectionHandler.isCompressionEnabled()) {
            factory.getAvailableExtensionNames().remove("permessage-deflate");
        }
        final int messageSize = JiveGlobals.getIntProperty("xmpp.parser.buffer.size", 1048576);
        factory.setMaxTextMessageSize(messageSize);

        // Jetty's idle policy cannot be modified - it will bluntly kill the connection. Ensure that it's longer than
        // the maximum amount of idle-time that Openfire allows for its client connections!
        final Duration propValue = ConnectionSettings.Client.IDLE_TIMEOUT_PROPERTY.getValue();
        final long maxJettyIdleMs;
        if (propValue.isNegative() || propValue.isZero()) {
            maxJettyIdleMs = Long.MAX_VALUE;
        } else {
            maxJettyIdleMs = propValue.plus(Duration.of(30, ChronoUnit.SECONDS)).toMillis();
        }
        factory.setIdleTimeout(Duration.ofMillis(maxJettyIdleMs));

        factory.setCreator((req, resp) -> {
            try {
                for (String subprotocol : req.getSubProtocols())
                {
                    if ("xmpp".equals(subprotocol))
                    {
                        resp.setAcceptedSubProtocol(subprotocol);
                        return new WebSocketClientConnectionHandler();
                    }
                }
            } catch (Exception e) {
                Log.warn("Unable to load websocket factory", e);
            }
            Log.warn("Failed to create websocket for {}:{} make a request at {}", req.getHttpServletRequest().getRemoteAddr(), req.getHttpServletRequest().getRemotePort(), req.getRequestPath() );
            return null;
        });
    
<no_super_class>