Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] How to access ServletContext from WebSocketListener?

Good morning,

In a custom WebSocketServlet I create, start and store in the ServletContext a Jetty HttpClient instance:

public class MyServlet extends WebSocketServlet {
    private final SslContextFactory mSslFactory = new SslContextFactory();
    private final HttpClient mHttpClient = new HttpClient(mSslFactory);

    @Override
    public void init() throws ServletException {
        super.init();

        try {
            mHttpClient.start();
        } catch (Exception ex) {
            throw new ServletException(ex);
        }

        ServletContext ctx = getServletContext();
        ctx.setAttribute("http_client", mHttpClient);
    }

And then in the onWebSocketText method of my custom WebSocketListener I need to retrieve the running HttpClient instance.

I have provided few more details at:
https://stackoverflow.com/questions/45074546/how-to-access-servletcontext-from-jetty-websocketlistener

How to get ahold of the ServletContext please? Should I create a custom WebSocketCreator for that?

Regards
Alex




Back to the top