Recognize wildcards in media types with a suffix
The "includes" and "isCompatibleWith" methods of MediaType take into account media types with suffices (e.g. application/soap+xml) including wildcards with suffices (e.g. application/*+xml). However before this change, the isWildcardSubtype() method returned true only for subtype "*". Now a media type such as application/*+xml is also recognized as having a wildcard subtype. Issue: SPR-9841
This commit is contained in:
@@ -279,6 +279,28 @@ public class RequestResponseBodyMethodProcessorMockTests {
|
||||
processor.handleReturnValue("Foo", returnTypeStringProduces, mavContainer, webRequest);
|
||||
}
|
||||
|
||||
// SPR-9841
|
||||
|
||||
@Test
|
||||
public void handleReturnValueMediaTypeSuffix() throws Exception {
|
||||
String body = "Foo";
|
||||
MediaType accepted = MediaType.APPLICATION_XHTML_XML;
|
||||
List<MediaType> supported = Collections.singletonList(MediaType.valueOf("application/*+xml"));
|
||||
|
||||
servletRequest.addHeader("Accept", accepted);
|
||||
|
||||
expect(messageConverter.canWrite(String.class, null)).andReturn(true);
|
||||
expect(messageConverter.getSupportedMediaTypes()).andReturn(supported);
|
||||
expect(messageConverter.canWrite(String.class, accepted)).andReturn(true);
|
||||
messageConverter.write(eq(body), eq(accepted), isA(HttpOutputMessage.class));
|
||||
replay(messageConverter);
|
||||
|
||||
processor.handleReturnValue(body, returnTypeStringProduces, mavContainer, webRequest);
|
||||
|
||||
assertTrue(mavContainer.isRequestHandled());
|
||||
verify(messageConverter);
|
||||
}
|
||||
|
||||
// SPR-9160
|
||||
|
||||
@Test
|
||||
@@ -308,6 +330,7 @@ public class RequestResponseBodyMethodProcessorMockTests {
|
||||
assertEquals("Foo", servletResponse.getContentAsString());
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
public String handle1(@RequestBody String s, int i) {
|
||||
return s;
|
||||
|
||||
Reference in New Issue
Block a user