From 6121da988b23a4b5c5755e555b439fadecab6773 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 16 Apr 2009 13:23:24 +0000 Subject: [PATCH] Working on SPR-5631 - Implicit /** mapping on type-level @RequestMapping --- .../DefaultAnnotationHandlerMapping.java | 16 +++++++++++---- ...plateServletAnnotationControllerTests.java | 20 ++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java index 3137d732047..46b5c62ae53 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java @@ -110,11 +110,19 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler // @RequestMapping found at type level this.cachedMappings.put(handlerType, mapping); Set urls = new LinkedHashSet(); - String[] paths = mapping.value(); - if (paths.length > 0) { + String[] typeLevelPaths = mapping.value(); + if (typeLevelPaths.length > 0) { // @RequestMapping specifies paths at type level - for (String path : paths) { - addUrlsForPath(urls, path); + String[] methodLevelPaths = determineUrlsForHandlerMethods(handlerType); + 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); } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java index 2ca85cdc1ad..d18818dfe3a 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java @@ -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; import java.io.IOException; @@ -8,8 +24,8 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import static org.junit.Assert.*; -import org.junit.Test; import org.junit.Ignore; +import org.junit.Test; import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -73,7 +89,6 @@ public class UriTemplateServletAnnotationControllerTests { } @Test - @Ignore("In progress") public void relative() throws Exception { initServlet(RelativePathUriTemplateController.class); @@ -120,7 +135,6 @@ public class UriTemplateServletAnnotationControllerTests { } @Test - @Ignore("In progress") public void implicitSubPath() throws Exception { initServlet(ImplicitSubPathController.class);