Working on SPR-5631 - Implicit /** mapping on type-level @RequestMapping

This commit is contained in:
Arjen Poutsma 2009-04-16 13:23:24 +00:00
parent 4fb901c657
commit 6121da988b
2 changed files with 29 additions and 7 deletions

View File

@ -110,11 +110,19 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler
// @RequestMapping found at type level // @RequestMapping found at type level
this.cachedMappings.put(handlerType, mapping); this.cachedMappings.put(handlerType, mapping);
Set<String> urls = new LinkedHashSet<String>(); Set<String> urls = new LinkedHashSet<String>();
String[] paths = mapping.value(); String[] typeLevelPaths = mapping.value();
if (paths.length > 0) { if (typeLevelPaths.length > 0) {
// @RequestMapping specifies paths at type level // @RequestMapping specifies paths at type level
for (String path : paths) { String[] methodLevelPaths = determineUrlsForHandlerMethods(handlerType);
addUrlsForPath(urls, path); for (String typeLevelPath : typeLevelPaths) {
if (!typeLevelPath.startsWith("/")) {
typeLevelPath = "/" + typeLevelPath;
}
for (String methodLevelPath : methodLevelPaths) {
String combinedPath = getPathMatcher().combine(typeLevelPath, methodLevelPath);
addUrlsForPath(urls, combinedPath);
}
addUrlsForPath(urls, typeLevelPath);
} }
return StringUtils.toStringArray(urls); return StringUtils.toStringArray(urls);
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.mvc.annotation; package org.springframework.web.servlet.mvc.annotation;
import java.io.IOException; import java.io.IOException;
@ -8,8 +24,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
@ -73,7 +89,6 @@ public class UriTemplateServletAnnotationControllerTests {
} }
@Test @Test
@Ignore("In progress")
public void relative() throws Exception { public void relative() throws Exception {
initServlet(RelativePathUriTemplateController.class); initServlet(RelativePathUriTemplateController.class);
@ -120,7 +135,6 @@ public class UriTemplateServletAnnotationControllerTests {
} }
@Test @Test
@Ignore("In progress")
public void implicitSubPath() throws Exception { public void implicitSubPath() throws Exception {
initServlet(ImplicitSubPathController.class); initServlet(ImplicitSubPathController.class);