在没有资源标识的情况下处理RESTful服务请求的理想方式是什么

时间:2014-10-06 12:59:11

标签: rest spring-mvc

我有一个使用Spring开发的RESTful服务。该服务尝试使用带有Request方法的标识字符串作为GET来查找资源。

请求模式为:https://api.rest.com/resource/RESOURCEID

为此定义的方法是

@RequestMapping(
            value = "/{RESOURCEID}",
            method = RequestMethod.GET,
            produces = "application/json")
public @ResponseBody String retrieve(
            @PathVariable String resourceID,
            HttpServletRequest request,
            HttpServletResponse response)
                throws AbstractBaseAppException,
                       JsonGenerationException,
                       JsonMappingException,
                       IOException

现在,当我尝试提出类似:https://api.rest.com/resource/的请求时,我会在下面遇到异常:

[6/10/14 17:48:56:942 IST] 00000018 PmiRegistry   W   CWPMI0023W: Unable to register PMI module due to duplicate name: SimpleFileServlet
[6/10/14 17:48:56:982 IST] 00000018 StatsFactoryU W   CWPMI0103W: Unable to register custom PMI module due to duplicate name under the same parent or invalid PMI tree path: SimpleFileServlet
[6/10/14 17:48:57:015 IST] 00000018 stats         E com.ibm.ws.wswebcontainer.stats.ServletPmiModule ServletPmiModule error creating stats instance 
                                 com.ibm.wsspi.pmi.factory.StatsFactoryException: CWPMI0103W: Unable to register custom PMI module due to duplicate name under the same parent or invalid PMI tree path: SimpleFileServlet
     at com.ibm.ws.pmi.factory.StatsFactoryUtil.registerModule(StatsFactoryUtil.java:92)
     at com.ibm.ws.pmi.factory.StatsInstanceImpl._register(StatsInstanceImpl.java:81)
     at com.ibm.ws.pmi.factory.StatsInstanceImpl.createGroupInstance(StatsInstanceImpl.java:126)
     at com.ibm.wsspi.pmi.factory.StatsFactory.createStatsInstance(StatsFactory.java:354)
     at com.ibm.wsspi.pmi.factory.StatsFactory.createStatsInstance(StatsFactory.java:319)
     at com.ibm.ws.wswebcontainer.stats.ServletPmiModule.<init>(ServletPmiModule.java:91)
     at com.ibm.ws.wswebcontainer.stats.WebAppModule.onServletStartInit(WebAppModule.java:241)
     at com.ibm.ws.webcontainer.WebAppPmiListener.onServletStartInit(WebAppPmiListener.java:178)
     at com.ibm.ws.webcontainer.webapp.FireOnServletStartInit.fireEvent(FireOnEventListenerVisitors.java:85)
     at com.ibm.ws.webcontainer.util.EventListeners.fireEvent(EventListeners.java:53)
     at com.ibm.ws.webcontainer.webapp.WebAppEventSource.onServletStartInit(WebAppEventSource.java:121)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:314)
     at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.init(ServletWrapperImpl.java:168)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.load(ServletWrapper.java:1267)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:970)
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1370)
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:179)
     at org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler.handleRequest(DefaultServletHttpRequestHandler.java:119)
     at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
     at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
     at com.metlife.gsp.tenancy.TenantDispatcherServlet.service(TenantDispatcherServlet.java:103)
     at com.metlife.gsp.tenancy.TenantDispatcherServletProxy.service(TenantDispatcherServletProxy.java:82)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1131)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:706)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:433)
     at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:191)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:916)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1005)
     at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:903)
     at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1593)
     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:192)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
     at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
     at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1574)

1 个答案:

答案 0 :(得分:1)

我不熟悉您正在使用的框架,但有两个问题可能导致问题。

您正在向https://api.rest.com/resource/发出请求,但该方法正在倾听&#39;要匹配我期望的匹配/{RESOURCEID}(除非还有其他更好的匹配),这意味着将使用&#34; resource&#34;作为资源ID传入。

您似乎也没有专门聆听/resource/的方法。

我不明白该错误消息如何链接回到此问题。我建议你查看你看到的那些例外是什么意思以及它们的原因。