Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
Expand Down Expand Up @@ -474,6 +477,9 @@ public abstract class AbstractStormpathWebMvcConfiguration {
@Autowired //all view resolvers in the spring app context. key: bean name, value: resolver
private Map<String, org.springframework.web.servlet.ViewResolver> viewResolvers;

@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;

private static class AccessibleResourceHandlerRegistry extends ResourceHandlerRegistry {
public AccessibleResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
super(applicationContext, servletContext);
Expand Down Expand Up @@ -1322,6 +1328,7 @@ private <T extends AbstractSocialCallbackController> T configure(T c) {
private <T extends AbstractController> T init(T c) {
try {
c.init();
assertUniqueMethodMapping(c);
return c;
} catch (Exception e) {
String msg = "Unable to initialize controller [" + c + "]: " + e.getMessage();
Expand Down Expand Up @@ -1563,5 +1570,25 @@ public List<String> stormpathCorsAllowedHeaders() {

return java.util.Collections.emptyList();
}

/**
* Fix for https://github.com/stormpath/stormpath-sdk-java/issues/1164
*
* @since 1.2.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change this to 1.3.0?

*/
private <T extends AbstractController> void assertUniqueMethodMapping(T c) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reformat with IntelliJ's default settings (e.g. space after for, space after if, before brace, etc). Thanks!

Set<RequestMappingInfo> requestMappingInfoSet = requestMappingHandlerMapping.getHandlerMethods().keySet();
for(RequestMappingInfo requestMappingInfo : requestMappingInfoSet){
Set<String> patterns = requestMappingInfo.getPatternsCondition().getPatterns();
for(String pattern: patterns){
if(c.getUri() != null && c.getUri().equals(pattern)){
HandlerMethod handlerMethod = requestMappingHandlerMapping.getHandlerMethods().get(requestMappingInfo);
throw new IllegalStateException("Mapping conflict. Stormpath cannot map '" + c.getUri() + "'. " +
"There is already '" + handlerMethod.getBean() +
"' bean method\n" + handlerMethod + " mapped.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to read: `Mapping confict: Stormpath cannot map '" + c.getUri() + "'. " + handlerMethod.getBean() + "#" + handlerMethod + " is already mapped to this URI."

}
}
}
}