JettyHTTPServerEngine.removeServant fails when isSessionSupport is true
I’ve discovered an issue with the JettyHTTPServerEngine class when sessions
are enabled. I’ve set up tests to verify the issue and can prove that the
issue is only present when sessions are enabled. The test case I use is as
1) Create a jetty engine with session support enabled:
3) Once you try to stop one of the JAXRS servers, JettyHTTPServerEngine
will fail to remove the servant. Which means that you can no longer
recreate another JAXRS server on that URL because JettyHTTPServerEngine
will still have a reference to the context and handler. Therefore you have
to restart the entire engine, which is not great in an OSGi environment
where I’m defining the engine somewhere else.
I’ve discovered the reason for this issue is that in the
JettyHTTPServerEngine.removeServant method the code attempts to check if
the child handler is an instance of JettyHTTPHandler, if not it will just
skip over it. This will never be the case because in the addServant method
the code wraps the handler in a SessionHandler if isSessionSupport is true.
Hopefully this makes sense. I am going to attempt to build a fix for the
cxf-rt-transports-http-jetty module but I would appreciate if someone else
could take a look and confirm my understanding.
Note that I previously posted the message “NullPointerException after JAXRS
server stopped using shared Jetty engine” which I believe is also caused by
this issue. I thought now that I have narrowed down the issue I should
create a new post.