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

ClassNotFoundException when using Moxy and a service returning a List #133

Closed marcanpilami closed 8 years ago

marcanpilami commented 8 years ago

Hello,

I am using version 5.3.0.201512270850 (latest at the time of writing) of the connector (bundles publisher and provider.moxy), as well as Jersey 2.22.1 and Moxy 2.6.2 (not the 2.6.0 bundled with Jersey as there is an import issue with it).

Most JAX-RS services work fine. But those which return a List fail with exception

javax.servlet.ServletException: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jaxb/many/CollectionValue
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:88)[131:org.ops4j.pax.web.pax-web-jetty:4.2.3]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.Server.handle(Server.java:497)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)[104:org.eclipse.jetty.io:9.2.10.v20150310]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[115:org.eclipse.jetty.util:9.2.10.v20150310]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[115:org.eclipse.jetty.util:9.2.10.v20150310]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_66]
Caused by: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jaxb/many/CollectionValue
        at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:487)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76)[135:com.eclipsesource.jaxrs.publisher:5.3.0.201512270850]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)[113:org.eclipse.jetty.servlet:9.2.10.v20150310]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[113:org.eclipse.jetty.servlet:9.2.10.v20150310]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)[131:org.ops4j.pax.web.pax-web-jetty:4.2.3]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[111:org.eclipse.jetty.security:9.2.10.v20150310]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:271)[131:org.ops4j.pax.web.pax-web-jetty:4.2.3]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[113:org.eclipse.jetty.servlet:9.2.10.v20150310]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[112:org.eclipse.jetty.server:9.2.10.v20150310]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[131:org.ops4j.pax.web.pax-web-jetty:4.2.3]
        ... 8 more
Caused by: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jaxb/many/CollectionValue
        at org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:278)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:260)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:509)[184:org.glassfish.jersey.core.jersey-server:2.22.1]
        at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:334)[184:org.glassfish.jersey.core.jersey-server:2.22.1]
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)[173:org.glassfish.jersey.core.jersey-common:2.22.1]
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)[184:org.glassfish.jersey.core.jersey-server:2.22.1]
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)[184:org.glassfish.jersey.core.jersey-server:2.22.1]
        at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)[183:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.1]
        ... 26 more
Caused by: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jaxb/many/CollectionValue
        at java.lang.ClassLoader.defineClass1(Native Method)[:1.8.0_66]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760)[:1.8.0_66]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:642)[:1.8.0_66]
        at org.eclipse.persistence.internal.jaxb.JaxbClassLoader.generateClass(JaxbClassLoader.java:124)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.generateClassFromBytes(AnnotationsProcessor.java:4758)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.generateCollectionValue(AnnotationsProcessor.java:4544)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processAdditionalClasses(AnnotationsProcessor.java:1278)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processAdditionalClasses(AnnotationsProcessor.java:1188)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.postBuildTypeInfo(AnnotationsProcessor.java:771)
        at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:302)
        at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:156)
        at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1123)
        at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:192)
        at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:165)
        at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:152)
        at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:112)
        at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:102)
        at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.getJAXBContext(MOXyJsonProvider.java:325)
        at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:926)
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
        at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
        at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)
        at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
        at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
        at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711)
        at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
        at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
        at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
        ... 35 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.internal.jaxb.many.CollectionValue not found by com.eclipsesource.jaxrs.publisher [135]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)[org.apache.felix.framework-5.4.0.jar:]
        at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)[org.apache.felix.framework-5.4.0.jar:]
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_66]
        at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)
        at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
        at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)[:1.8.0_66]
        at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_66]
        at org.eclipse.persistence.internal.jaxb.JaxbClassLoader.loadClass(JaxbClassLoader.java:107)[190:org.eclipse.persistence.moxy:2.6.2.v20151217-774c696]
        ... 66 more

Sample REST service is:

package org.test;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.osgi.service.component.annotations.Component;

@Component(service = Object.class)
@Path("/marsu")
public class App
{
    // WORKS
    @GET
    public String getHouba()
    {
        return "houba";
    }

    // FAILS
    @GET
    @Path("/e")
    public List<String> getList()
    {
        List<String> res = new ArrayList<>();
        res.add("a");
        res.add("b");
        res.add("c");
        return res;
    }
}

It seems there is some weird classloader magic here: the package containing CollectionValue IS exported by the moxy bundle. But it is the publisher bundle which tries to import that class, and it has no import on it. It seems Moxy tries to load its classes from the CL that loaded its provider class (which would be the publisher).

Is there a mean to impose bundle CL? Do you thing it is a Moxy bug?

Thanks a lot!

hstaudacher commented 8 years ago

@BryanHunt do you understand what's going on here?

BryanHunt commented 8 years ago

I'm pretty sure the problem is not the publisher bundle since there are "caused by" exceptions lower in the stack trace. It seems the problem is Moxy itself. I would talk with the Moxy folks and see what they say.

hstaudacher commented 8 years ago

Closed as we can't do anything about it