hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
190 stars 98 forks source link

ANTLR NoClassDefFoundError error #176

Open jmacauley opened 7 years ago

jmacauley commented 7 years ago

Spent a couple days debugging this problem. I finally figured out what was wrong. I am using Apache Karaf (4.0.6).

Here is the error log:

2016-10-28 16:57:21,761 | WARN  | tp1812628202-171 | ServletHandler                   | 92 - org.eclipse.jetty.util - 9.2.17.v20160517 | 
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/libraries/antlr/runtime/tree/Tree
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)[7:com.eclipsesource.jaxrs.jersey-min:2.22.2]
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)[7:com.eclipsesource.jaxrs.jersey-min:2.22.2]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)[7:com.eclipsesource.jaxrs.jersey-min:2.22.2]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)[7:com.eclipsesource.jaxrs.jersey-min:2.22.2]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)[7:com.eclipsesource.jaxrs.jersey-min:2.22.2]
    at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76)[10:com.eclipsesource.jaxrs.publisher:5.3.1.201602281253]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[90:org.eclipse.jetty.servlet:9.2.17.v20160517]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[90:org.eclipse.jetty.servlet:9.2.17.v20160517]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[110:org.ops4j.pax.web.pax-web-jetty:4.2.8]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[88:org.eclipse.jetty.security:9.2.17.v20160517]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:276)[110:org.ops4j.pax.web.pax-web-jetty:4.2.8]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[90:org.eclipse.jetty.servlet:9.2.17.v20160517]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[110:org.ops4j.pax.web.pax-web-jetty:4.2.8]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.Server.handle(Server.java:499)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[89:org.eclipse.jetty.server:9.2.17.v20160517]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[81:org.eclipse.jetty.io:9.2.17.v20160517]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[92:org.eclipse.jetty.util:9.2.17.v20160517]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[92:org.eclipse.jetty.util:9.2.17.v20160517]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_40]

This log would only show up when invoking a POST operation on a JAX-RS annotated method using the jax-rs-provider-moxy feature when a @XmlRootElement annotated class was referenced as a body parameter in the method parameters. The POST would fail. GET operations were fine. It would not occur using the jax-rs-provider-gson feature, or if I took care if the processing using an InputStream for the body parameter.

Here is a code segment:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/models/{id}/deltas")
public Response propagateModelDelta(@PathParam("id") String id, DeltaRequest deltaRequest);

I determined that the EclipseLink ANTLR bundle was not loaded in my Karaf instance. If I look at the jax-rs-provider-moxy feature definition I see the EclipseLink Core is specified as a bundle dependency.

<feature name="jax-rs-provider-moxy" version="2.2">
    <bundle dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.core/2.5.2</bundle>
    <bundle dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.moxy/2.5.2</bundle>
    <bundle>mvn:com.eclipsesource.jaxrs/provider-moxy/2.2</bundle>
</feature>

When I look at the EclipseLink Core 2.5.2.v20140319-9ad6abd bundle manifest it specified ANTLR at optional:

Require-Bundle: org.eclipse.persistence.antlr; bundle-version="3.2.0"; resolution:=optional

Which is allowing the bundle to load without the ANTLR bundle. Since Karaf does not have the ANTLR bundle loaded as a dependency it fails to find the targeted class.

I added the following dependency in my feature to force it to be loaded (not sure which ANTLR version I should be using).

<bundle  dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.antlr/2.6.4</bundle>

This allowed me to clear the issue and use the jax-rs-provider-moxy feature.

I assume the solution is to specify this dependency in the jax-rs-provider-moxy feature definition like so?

<feature name="jax-rs-provider-moxy" version="2.2">
    <bundle dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.antlr/2.6.4</bundle>
    <bundle dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.core/2.5.2</bundle>
    <bundle dependency="true">mvn:org.eclipse.persistence/org.eclipse.persistence.moxy/2.5.2</bundle>
    <bundle>mvn:com.eclipsesource.jaxrs/provider-moxy/2.2</bundle>
</feature>

Thank you, John