NullPointerException after JAXRS server stopped using shared Jetty engine

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

NullPointerException after JAXRS server stopped using shared Jetty engine

andrew dwyer
Hi,



I’m trying to register two JAXRS servers using one shared Jetty engine and
I’m getting an exception when one of them is restarted. I’m running CXF
3.1.5 within a Karaf based OSGi environment (jboss fuse 6.3.0).



Basically my setup is 2 separate OSGi bundles each with a JAXRS server
defined via spring. In one bundle I have defined my own Jetty engine bound
to a port, in the other I refer to this port in another similar JAXRS
service definition. On the shared Jetty engine I have attached a security
constraint handler provided by Redhat Keycloak, but I don't think this is
the source of the problem. This works fine when both bundles are deployed
sequentially, but once I restart the bundle that doesn’t have the engine
defined I get a 500 error every time I attempt to hit the endpoint. This is
the exception that is logged:



2017-07-03 06:39:16,810 | WARN  | qtp846639410-220 |
HttpChannel                      | ?                                   ? |
96 - org.eclipse.jetty.util - 9.2.19.v20160908 | /cxf/b/test

java.lang.NullPointerException

        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(
AbstractHTTPDestination.java:254)[118:org.apache.cxf.cxf-
rt-transports-http:3.1.5.redhat-630187]

        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.
doService(JettyHTTPDestination.java:234)[239:org.apache.cxf.cxf-rt-
transports-http-jetty:3.1.5.redhat-630187]

        at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(
JettyHTTPHandler.java:70)[239:org.apache.cxf.cxf-rt-
transports-http-jetty:3.1.5.redhat-630187]

        at org.eclipse.jetty.server.session.SessionHandler.
doHandle(SessionHandler.java:223)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.ContextHandler.
doHandle(ContextHandler.java:1127)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.session.SessionHandler.
doScope(SessionHandler.java:187)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.ContextHandler.
doScope(ContextHandler.java:1061)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.ScopedHandler.handle(
ScopedHandler.java:141)[93:org.eclipse.jetty.server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(
ContextHandlerCollection.java:215)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.HandlerCollection.
handle(HandlerCollection.java:110)[93:org.eclipse.jetty.
server:9.2.19.v20160908]

        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
HandlerWrapper.java:97)[93:org.eclipse.jetty.server:9.2.19.v20160908]

        at org.eclipse.jetty.server.Server.handle(Server.java:499)
[93:org.eclipse.jetty.server:9.2.19.v20160908]

        at org.eclipse.jetty.server.HttpChannel.handle(
HttpChannel.java:311)[93:org.eclipse.jetty.server:9.2.19.v20160908]

        at org.eclipse.jetty.server.HttpConnection.onFillable(
HttpConnection.java:257)[93:org.eclipse.jetty.server:9.2.19.v20160908]

        at org.eclipse.jetty.io.AbstractConnection$2.run(
AbstractConnection.java:544)[86:org.eclipse.jetty.io:9.2.19.v20160908]

        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
QueuedThreadPool.java:635)[96:org.eclipse.jetty.util:9.2.19.v20160908]

        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(
QueuedThreadPool.java:555)[96:org.eclipse.jetty.util:9.2.19.v20160908]

        at java.lang.Thread.run(Thread.java:745)[:1.8.0_77]



This is the spring config I have in bundle 1 (this contains the Jetty
engine and associated constraint):



    <bean id="configResolver" class="org.keycloak.adapters.osgi.
PathBasedKeycloakConfigResolver"/>

    <bean id="keycloakAuthenticator" class="org.keycloak.adapters.jetty.
KeycloakJettyAuthenticator">

        <property name="configResolver" ref="configResolver"/>

    </bean>

    <bean id="constraint" class="org.eclipse.jetty.util.
security.Constraint">

        <property name="name" value="Services"/>

        <property name="roles">

            <list>

                <value>servicesUser</value>

            </list>

        </property>

        <property name="authenticate" value="true"/>

        <property name="dataConstraint" value="0"/>

    </bean>

    <bean id="constraintMapping" class="org.eclipse.jetty.
security.ConstraintMapping">

        <property name="constraint" ref="constraint"/>

        <property name="pathSpec" value="/*"/>

    </bean>

    <bean id="securityHandler" class="org.eclipse.jetty.security.
ConstraintSecurityHandler">

        <property name="authenticator" ref="keycloakAuthenticator" />

        <property name="constraintMappings">

            <list>

                <ref bean="constraintMapping" />

            </list>

        </property>

        <property name="authMethod" value="BASIC"/>

        <property name="realmName" value="does-not-matter"/>

    </bean>



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

        <httpj:engine port="8282">

            <httpj:tlsServerParameters>

                <!-- As described in http://cxf.apache.org/docs/
client-http-transport-including-ssl-support.html -->

            </httpj:tlsServerParameters>

            <httpj:handlers>

                <ref bean="securityHandler" />

            </httpj:handlers>

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

        </httpj:engine>

    </httpj:engine-factory>



    <jaxrs:server id="a-service" depends-on="kc-cxf-endpoint" address="
https://0.0.0.0:8282/cxf/a">

        <jaxrs:serviceBeans>

            <ref bean="somebean-a"/>

        </jaxrs:serviceBeans>

        <jaxrs:providers>

            <bean class="com.fasterxml.jackson.jaxrs.json.
JacksonJsonProvider"/>

        </jaxrs:providers>

    </jaxrs:server>



This is the spring config I have in bundle 2 (much simpler. Just reuses the
same cxf context).



    <jaxrs:server id="b-service" address="https://0.0.0.0:8282/cxf/b">

        <jaxrs:serviceBeans>

            <ref bean="somebean-b"/>

        </jaxrs:serviceBeans>

        <jaxrs:providers>

            <bean class="com.fasterxml.jackson.jaxrs.json.
JacksonJsonProvider"/>

        </jaxrs:providers>

        <jaxrs:features>

            <cxf:logging/>

        </jaxrs:features>

    </jaxrs:server>



Note that I’m using the same /cxf context in both servers but it doesn’t
make any difference - the problem still occurs even if they are totally
different root contexts.



Hopefully someone can suggest what I’m doing wrong?



Thanks



Andrew
Loading...