DATAREST-1387 - DelegatingHandlerMapping now handles HttpMediaTypeNotSupportedException.

This commit is contained in:
Oliver Drotbohm
2019-06-05 23:38:35 +02:00
parent 0401a5924d
commit ac72c8c91e
2 changed files with 7 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.core.Ordered;
import org.springframework.util.Assert;
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.servlet.HandlerExecutionChain;
@@ -74,7 +75,7 @@ public class DelegatingHandlerMapping implements HandlerMapping, Ordered, Matcha
return HandlerSelectionResult.from(request, delegates).resultOrException();
}
/*
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.MatchableHandlerMapping#match(javax.servlet.http.HttpServletRequest, java.lang.String)
*/
@@ -111,6 +112,8 @@ public class DelegatingHandlerMapping implements HandlerMapping, Ordered, Matcha
return HandlerSelectionResult.forResult(request, delegate, result);
}
} catch (HttpMediaTypeNotSupportedException o_O) {
ignoredException = o_O;
} catch (HttpMediaTypeNotAcceptableException o_O) {
ignoredException = o_O;
} catch (HttpRequestMethodNotSupportedException o_O) {

View File

@@ -30,6 +30,7 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
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.servlet.HandlerMapping;
@@ -48,7 +49,7 @@ public class DelegatingHandlerMappingUnitTests {
@Mock HandlerMapping first, second;
@Mock HttpServletRequest request;
@Test // DATAREST-490, DATAREST-522
@Test // DATAREST-490, DATAREST-522, DATAREST-1387
public void consultsAllHandlerMappingsAndThrowsExceptionEventually() throws Exception {
DelegatingHandlerMapping mapping = new DelegatingHandlerMapping(Arrays.asList(first, second));
@@ -56,6 +57,7 @@ public class DelegatingHandlerMappingUnitTests {
assertHandlerTriedButExceptionThrown(mapping, HttpMediaTypeNotAcceptableException.class);
assertHandlerTriedButExceptionThrown(mapping, HttpRequestMethodNotSupportedException.class);
assertHandlerTriedButExceptionThrown(mapping, UnsatisfiedServletRequestParameterException.class);
assertHandlerTriedButExceptionThrown(mapping, HttpMediaTypeNotSupportedException.class); // DATAREST-1387
}
@Test // DATAREST-1193