@ -28,15 +28,19 @@ import javax.servlet.ServletException;
@@ -28,15 +28,19 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest ;
import org.springframework.http.MediaType ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.MultiValueMap ;
import org.springframework.util.StringUtils ;
import org.springframework.web.HttpMediaTypeNotAcceptableException ;
import org.springframework.web.HttpMediaTypeNotSupportedException ;
import org.springframework.web.HttpRequestMethodNotSupportedException ;
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.method.HandlerMethod ;
import org.springframework.web.servlet.HandlerMapping ;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping ;
import org.springframework.web.servlet.mvc.condition.NameValueExpression ;
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition ;
import org.springframework.web.util.WebUtils ;
/ * *
@ -185,14 +189,17 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@@ -185,14 +189,17 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
Set < MediaType > consumableMediaTypes ;
Set < MediaType > producibleMediaTypes ;
Set < String > paramConditions ;
if ( patternAndMethodMatches . isEmpty ( ) ) {
consumableMediaTypes = getConsumableMediaTypes ( request , patternMatches ) ;
producibleMediaTypes = getProdicubleMediaTypes ( request , patternMatches ) ;
paramConditions = getRequestParams ( request , patternMatches ) ;
}
else {
consumableMediaTypes = getConsumableMediaTypes ( request , patternAndMethodMatches ) ;
producibleMediaTypes = getProdicubleMediaTypes ( request , patternAndMethodMatches ) ;
paramConditions = getRequestParams ( request , patternAndMethodMatches ) ;
}
if ( ! consumableMediaTypes . isEmpty ( ) ) {
@ -205,6 +212,10 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@@ -205,6 +212,10 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
else if ( ! producibleMediaTypes . isEmpty ( ) ) {
throw new HttpMediaTypeNotAcceptableException ( new ArrayList < MediaType > ( producibleMediaTypes ) ) ;
}
else if ( ! CollectionUtils . isEmpty ( paramConditions ) ) {
String [ ] params = paramConditions . toArray ( new String [ paramConditions . size ( ) ] ) ;
throw new UnsatisfiedServletRequestParameterException ( params , request . getParameterMap ( ) ) ;
}
else {
return null ;
}
@ -230,4 +241,18 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@@ -230,4 +241,18 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
return result ;
}
private Set < String > getRequestParams ( HttpServletRequest request , Set < RequestMappingInfo > partialMatches ) {
for ( RequestMappingInfo partialMatch : partialMatches ) {
ParamsRequestCondition condition = partialMatch . getParamsCondition ( ) ;
if ( ! CollectionUtils . isEmpty ( condition . getExpressions ( ) ) & & ( condition . getMatchingCondition ( request ) = = null ) ) {
Set < String > expressions = new HashSet < String > ( ) ;
for ( NameValueExpression expr : condition . getExpressions ( ) ) {
expressions . add ( expr . toString ( ) ) ;
}
return expressions ;
}
}
return null ;
}
}