JettyHTTPServerEngine.removeServant fails when isSessionSupport is true

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JettyHTTPServerEngine.removeServant fails when isSessionSupport is true

andrew dwyer
Hi,



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
follows:



1) Create a jetty engine with session support enabled:



    <httpj:engine-factory bus="cxf" id="kc-cxf-endpoint">

        <httpj:engine port="8686">

            <httpj:sessionSupport>true</httpj:sessionSupport>

        </httpj:engine>

    </httpj:engine-factory>



2) Then create two JAXRS servers to use that engine:



        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

        sf.setAddress("http://0.0.0.0:8686/test/test1");

        sf.setServiceClass(Service.class);

        Server server1 = sf.create();



        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

        sf.setAddress("http://0.0.0.0:8686/test/test2");

        sf.setServiceClass(Service.class);

        Server server2 = sf.create();



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.



        Server2.stop();

        Server2.destroy();



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.



Thanks

Andrew
Loading...