|
182 | 182 | import org.springframework.web.cors.CorsConfiguration;
|
183 | 183 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
184 | 184 | import org.springframework.web.filter.CorsFilter;
|
| 185 | +import org.springframework.web.method.HandlerMethod; |
185 | 186 | import org.springframework.web.servlet.HandlerInterceptor;
|
186 | 187 | import org.springframework.web.servlet.HandlerMapping;
|
187 | 188 | import org.springframework.web.servlet.LocaleResolver;
|
188 | 189 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
189 | 190 | import org.springframework.web.servlet.i18n.CookieLocaleResolver;
|
190 | 191 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
| 192 | +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
| 193 | +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
191 | 194 | import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
192 | 195 | import org.springframework.web.servlet.view.JstlView;
|
193 | 196 | import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
|
@@ -474,6 +477,9 @@ public abstract class AbstractStormpathWebMvcConfiguration {
|
474 | 477 | @Autowired //all view resolvers in the spring app context. key: bean name, value: resolver
|
475 | 478 | private Map<String, org.springframework.web.servlet.ViewResolver> viewResolvers;
|
476 | 479 |
|
| 480 | + @Autowired |
| 481 | + private RequestMappingHandlerMapping requestMappingHandlerMapping; |
| 482 | + |
477 | 483 | private static class AccessibleResourceHandlerRegistry extends ResourceHandlerRegistry {
|
478 | 484 | public AccessibleResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
|
479 | 485 | super(applicationContext, servletContext);
|
@@ -1322,6 +1328,7 @@ private <T extends AbstractSocialCallbackController> T configure(T c) {
|
1322 | 1328 | private <T extends AbstractController> T init(T c) {
|
1323 | 1329 | try {
|
1324 | 1330 | c.init();
|
| 1331 | + assertUniqueMethodMapping(c); |
1325 | 1332 | return c;
|
1326 | 1333 | } catch (Exception e) {
|
1327 | 1334 | String msg = "Unable to initialize controller [" + c + "]: " + e.getMessage();
|
@@ -1563,5 +1570,25 @@ public List<String> stormpathCorsAllowedHeaders() {
|
1563 | 1570 |
|
1564 | 1571 | return java.util.Collections.emptyList();
|
1565 | 1572 | }
|
| 1573 | + |
| 1574 | + /** |
| 1575 | + * Fix for https://github.com/stormpath/stormpath-sdk-java/issues/1164 |
| 1576 | + * |
| 1577 | + * @since 1.2.3 |
| 1578 | + */ |
| 1579 | + private <T extends AbstractController> void assertUniqueMethodMapping(T c) { |
| 1580 | + Set<RequestMappingInfo> requestMappingInfoSet = requestMappingHandlerMapping.getHandlerMethods().keySet(); |
| 1581 | + for(RequestMappingInfo requestMappingInfo : requestMappingInfoSet){ |
| 1582 | + Set<String> patterns = requestMappingInfo.getPatternsCondition().getPatterns(); |
| 1583 | + for(String pattern: patterns){ |
| 1584 | + if(c.getUri() != null && c.getUri().equals(pattern)){ |
| 1585 | + HandlerMethod handlerMethod = requestMappingHandlerMapping.getHandlerMethods().get(requestMappingInfo); |
| 1586 | + throw new IllegalStateException("Mapping conflict. Stormpath cannot map '" + c.getUri() + "'. " + |
| 1587 | + "There is already '" + handlerMethod.getBean() + |
| 1588 | + "' bean method\n" + handlerMethod + " mapped."); |
| 1589 | + } |
| 1590 | + } |
| 1591 | + } |
| 1592 | + } |
1566 | 1593 | }
|
1567 | 1594 |
|
0 commit comments