@Override protected void addUrlsForPath(Set<String> urls, String path) { super.addUrlsForPath(urls, path); urls.add(path + "/"); }
/** * Passes the given request to a proper controller. * * @param request * @return * @throws Exception */ public MockHttpServletResponse handle(HttpServletRequest request) throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); HandlerExecutionChain handlerExecutionChain = null; for (DefaultAnnotationHandlerMapping handlerMapping : handlerMappings) { handlerExecutionChain = handlerMapping.getHandler(request); if (handlerExecutionChain != null) { break; } } Assert.assertNotNull("The request URI does not exist", handlerExecutionChain); handlerAdapter.handle(request, response, handlerExecutionChain.getHandler()); return response; }
private void findResources() { Map<String, Object> handlerMap = new HashMap<String, Object>(); DefaultAnnotationHandlerMapping annotationMapping = new DefaultAnnotationHandlerMapping(); annotationMapping.setApplicationContext(applicationContext); annotationMapping.initApplicationContext(); handlerMap.putAll(annotationMapping.getHandlerMap()); BeanNameUrlHandlerMapping beanMapping = new BeanNameUrlHandlerMapping(); beanMapping.setApplicationContext(applicationContext); beanMapping.initApplicationContext(); handlerMap.putAll(beanMapping.getHandlerMap()); this.urls = findUniqueUrls(handlerMap.keySet()); this.defaultResources = findMethods(handlerMap, this.urls); this.jsonResources = new ArrayList<ResourceInfo>(); for (Iterator<ResourceInfo> iterator = this.defaultResources.iterator(); iterator.hasNext(); ) { ResourceInfo info = (ResourceInfo) iterator.next(); if (info.getUrl().endsWith(".json")) { iterator.remove(); this.jsonResources.add(info); } } }