@Test public void requestsWithSubPathsInParentContext() throws Exception { BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping(); hm.setDetectHandlersInAncestorContexts(true); hm.setApplicationContext(new StaticApplicationContext(wac)); doTestRequestsWithSubPaths(hm); }
@Test public void requestsWithFullPaths() throws Exception { BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping(); hm.setAlwaysUseFullPath(true); hm.setApplicationContext(wac); Object bean = wac.getBean("godCtrl"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html"); HandlerExecutionChain hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html"); req.setContextPath("/myapp"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/mypath/welcome.html"); req.setContextPath(""); req.setServletPath("/mypath"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/Myapp/mypath/welcome.html"); req.setContextPath("/myapp"); req.setServletPath("/mypath"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); }
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); } } }
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); } } }