Catch IAE when parsing content type

Issue: SPR-10308
master
Rossen Stoyanchev 12 years ago
parent 3abe05c65e
commit c611083415
  1. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java
  2. 13
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java

@ -205,7 +205,12 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
if (!consumableMediaTypes.isEmpty()) {
MediaType contentType = null;
if (StringUtils.hasLength(request.getContentType())) {
contentType = MediaType.parseMediaType(request.getContentType());
try {
contentType = MediaType.parseMediaType(request.getContentType());
}
catch (IllegalArgumentException ex) {
throw new HttpMediaTypeNotSupportedException(ex.getMessage());
}
}
throw new HttpMediaTypeNotSupportedException(contentType, new ArrayList<MediaType>(consumableMediaTypes));
}

@ -180,6 +180,19 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
@Test
public void testMediaTypeNotValue() throws Exception {
try {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/person/1");
request.setContentType("bogus");
this.handlerMapping.getHandler(request);
fail("HttpMediaTypeNotSupportedException expected");
}
catch (HttpMediaTypeNotSupportedException ex) {
assertEquals("Invalid media type \"bogus\": does not contain '/'", ex.getMessage());
}
}
@Test
public void mediaTypeNotAccepted() throws Exception {
testMediaTypeNotAccepted("/persons");

Loading…
Cancel
Save