不能将Wink 1.2.1用作Eclipse产品中的JAX RS实现

时间:2017-03-13 14:41:43

标签: eclipse jax-rs osgi apache-wink classloading

我目前正在编写包含嵌入式码头的Eclipse产品。嵌入式码头封装了一个眨眼应用程序。我正在使用wink 1.2.1在eclipse产品中孵化,将库作为​​Eclipse插件包装并使用来自轨道内部版本号的JAX RS 1.1.1包:R20151221205849。

最初,当我运行Eclipse产品时,我遇到以下异常:

显示java.lang.NullPointerException     在org.apache.wink.common.internal.http.Accept.valueOf(Accept.java:139)     在org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptHeader(HttpHeadersImpl.java:152)     at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptableMediaTypes(HttpHeadersImpl.java:106)     在org.apache.wink.server.internal.registry.ResourceRegistry.filterByProduces(ResourceRegistry.java:558)     在org.apache.wink.server.internal.registry.ResourceRegistry.filterDispatchMethods(ResourceRegistry.java:482)     在org.apache.wink.server.internal.registry.ResourceRegistry.findSubResourceMethod(ResourceRegistry.java:391)     at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:168)     在org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)     在org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)     在org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)     在org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:48)     在org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207)     在org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)     在org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:119)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)     在org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)     在org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)     at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)     在org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)     在org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)     在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)     在org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)     在org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)     在org.eclipse.jetty.server.Server.handle(Server.java:366)     at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)     at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)     at org.eclipse.jetty.server.AbstractHttpConnection $ RequestHandler.headerComplete(AbstractHttpConnection.java:1033)     在org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)     在org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:231)     at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)     在org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)     在org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)     在org.eclipse.jetty.io.nio.SelectChannelEndPoint $ 1.run(SelectChannelEndPoint.java:53)     在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)     在org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:543)

这个回答:https://stackoverflow.com/a/20402681/5907194表明原因是另一个jax rs实现与wink的冲突。

实际上,在调查了JAX RS中的FactoryFinder.find(String factoryId,String fallbackClassName)之后,事实证明JAX RS回退到默认的jersey实现,因为类加载器无法从中加载JAX RS类实现的名称。 META-INF / services / javax.ws.rs.ext.runtimeDeletage文件位于我捆绑的wink common eclipse插件中。

我怀疑这是osgi类加载的问题,因为JAX RS插件的类加载器无法看到JAX RS不依赖的插件中的资源。因此,我将我的计算机上的JAX RS插件的Eclipse伙伴策略(http://www.wickedshell.net/blog/2010/01/fragments-vs-buddy-classloading/)更改为" Eclipse-BuddyPolicy:已注册"使用" Eclipse-RegisterBuddy:javax.Ws.rs注册Wink通用插件和JAX RS Require-Bundle:javax.Ws.rs"

现在可以避免异常,并且可以正确运行产品。现在我的问题如下:是否需要更改轨道上的JAX RS插件以与其他JAX RS实现(例如wink)一起使用,或者还有其他选项我不知道?

请注意我无法升级到JAX RS 2.0,也不能使用不同的JAX RS实现,因为我正在使用依赖于wink的OSLC4J。

1 个答案:

答案 0 :(得分:0)

Eclipse-BuddyPolicy的问题在于它是特定于Equinox的。另一个挑战是Java的服务查找器。默认情况下,它在OSGi环境中无法正常工作。您可以尝试使用有助于JAX-RS捆绑的片段。将Apache SPI Fly添加到堆栈可能会更幸运。但是,这需要为服务提供商和消费者提供额外的标头。我添加了Apache SPI Fly Bundles to EBR

根据您的具体要求/堆栈,听起来您可能更幸运自己创建JAX-RS捆绑包。有a look at EBR可以根据需要创建自定义捆绑包。 Eclipse Orbit中的一个是专门为使用它的Eclipse项目中的用例而创建的。它可能无法满足Wink和您的产品的特定需求。