Created
December 24, 2014 14:49
-
-
Save kakawait/d42d328597846ccbfd13 to your computer and use it in GitHub Desktop.
Custom handler to support @controller & @RepositoryRestController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kakawait; | |
import org.springframework.core.Ordered; | |
import org.springframework.util.Assert; | |
import org.springframework.web.servlet.HandlerExecutionChain; | |
import org.springframework.web.servlet.HandlerMapping; | |
import javax.servlet.http.HttpServletRequest; | |
import java.util.List; | |
/** | |
* @author Thibaud Lepretre <[email protected]> | |
*/ | |
public class CustomMappingHandler implements HandlerMapping, Ordered { | |
private List<HandlerMapping> handlers; | |
public MergingMappingHandler(List<HandlerMapping> handlers) { | |
Assert.notNull(handlers); | |
this.handlers = handlers; | |
} | |
@Override | |
public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { | |
Exception firstException = null; | |
for (HandlerMapping handler : handlers) { | |
try { | |
return handler.getHandler(request); | |
} catch (Exception e) { | |
if (firstException == null) { | |
firstException = e; | |
} else { | |
throw firstException; | |
} | |
} | |
} | |
return null; | |
} | |
@Override | |
public int getOrder() { | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment