我在基于OSG的应用程序中提供RESTful服务。我正在使用的类具有以下代码段中显示的以下路径:
@Path("shoes")
public class ShoeService extends ShoeMakerImpl
{
.
.
.
@Override
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("{shoename}")
public String getFunctionalURL(@PathParam("shoename") String shoeName)
{
.
// do some shoe stuff
.
}
}
不幸的是,当我加载并激活包含此类的包时,我收到以下消息:
[WARNING] Failed to register servlet for /shoes
org.osgi.service.http.NamespaceException: Alias /shoes is already in use.
at org.apache.felix.http.base.internal.service.SharedHttpServiceImpl.registerServlet(SharedHttpServiceImpl.java:74)
at org.apache.felix.http.base.internal.service.PerBundleHttpServiceImpl.registerServlet(PerBundleHttpServiceImpl.java:217)
at org.apache.felix.http.whiteboard.internal.manager.ServletMapping.register(ServletMapping.java:43)
at org.apache.felix.http.whiteboard.internal.manager.ExtenderManager.registerAll(ExtenderManager.java:243)
at org.apache.felix.http.whiteboard.internal.manager.ExtenderManager.setHttpService(ExtenderManager.java:203)
at org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker.added(HttpServiceTracker.java:37)
at org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker.added(HttpServiceTracker.java:24)
at org.apache.felix.http.whiteboard.internal.tracker.AbstractTracker.addingService(AbstractTracker.java:42)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:987)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:838)
at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:545)
at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4560)
at org.apache.felix.framework.Felix.registerService(Felix.java:3542)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)
at org.apache.felix.http.base.internal.service.HttpServiceFactory.start(HttpServiceFactory.java:113)
at org.apache.felix.http.base.internal.HttpServiceController.register(HttpServiceController.java:116)
at org.apache.felix.http.base.internal.DispatcherServlet.init(DispatcherServlet.java:47)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:612)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:395)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:163)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.apache.felix.http.jetty.internal.JettyService.initializeJetty(JettyService.java:269)
at org.apache.felix.http.jetty.internal.JettyService.startJetty(JettyService.java:201)
at org.apache.felix.http.jetty.internal.JettyService.start(JettyService.java:134)
at org.apache.felix.http.jetty.internal.JettyActivator.doStart(JettyActivator.java:60)
at org.apache.felix.http.base.internal.AbstractActivator.start(AbstractActivator.java:41)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2138)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:977)
at aQute.launcher.Launcher.update(Launcher.java:457)
at aQute.launcher.Launcher.activate(Launcher.java:354)
at aQute.launcher.Launcher.run(Launcher.java:238)
at aQute.launcher.Launcher.main(Launcher.java:87)
我还没有创建任何其他"别名"同名(我知道)。我已多次更改路径中的名称,甚至更改为" xxxgggc" (例如:@Path(" xxxgggc"))。
无论我在@Path注释中添加了什么,我都会收到相同的消息:
[WARNING] Failed to register servlet for /xxxgggc
org.osgi.service.http.NamespaceException: Alias /shoes is already in use.
at org.apache.felix.http.base.internal.service.SharedHttpServiceImpl.registerServlet(SharedHttpServiceImpl.java:74)
.
.
Don't need to repeat the stack trace
我可能不会关心这个警告,但是我无法在路径上访问该服务。当我尝试这样做时,使用正确的RESTful URL(http://localhost:8080/shoes/wingtip),我得到以下内容:
HTTP ERROR: 500
Problem accessing /shoes/wingtip. Reason:
java.lang.NullPointerException
有谁能告诉我为什么我会得到这种奇怪的行为,而且(更重要的是)如何解决我遇到的任何问题?
有人请指教......
[编辑补充:]
下面是我在运行时使用的软件包列表。
-runbundles: \
com.shoeshine.demo.gateway;version=snapshot,\
osgi.cmpn;version='[5.0.0,5.0.1)',\
org.apache.felix.http.whiteboard,\
com.fasterxml.jackson.core.jackson-annotations,\
com.fasterxml.jackson.core.jackson-core,\
com.fasterxml.jackson.core.jackson-databind,\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-base,\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider,\
org.amdatu.web.rest.jaxrs,\
org.amdatu.web.rest.wink,\
org.apache.felix.dependencymanager,\
org.apache.felix.http.api,\
org.apache.felix.http.base,\
org.apache.felix.http.jetty,\
org.apache.felix.http.servlet-api,\
com.shoeshine.demo.web;version=latest,\
org.apache.felix.gogo.command,\
org.apache.felix.gogo.runtime,\
org.apache.felix.gogo.shell