SPR-7353 - @ResponseBody and returned HttpEntity now respect @RequestMapping.produces()

This commit is contained in:
Arjen Poutsma
2011-05-17 09:45:57 +00:00
parent 57c757afc5
commit ad2e0d4587
12 changed files with 396 additions and 219 deletions

View File

@@ -322,7 +322,7 @@ public class MediaType implements Comparable<MediaType> {
}
/**
* Indicate whether the {@linkplain #getType() type} is the wildcard character <code>&#42;</code> or not.
* Indicates whether the {@linkplain #getType() type} is the wildcard character <code>&#42;</code> or not.
*/
public boolean isWildcardType() {
return WILDCARD_TYPE.equals(type);
@@ -336,13 +336,22 @@ public class MediaType implements Comparable<MediaType> {
}
/**
* Indicate whether the {@linkplain #getSubtype() subtype} is the wildcard character <code>&#42;</code> or not.
* Indicates whether the {@linkplain #getSubtype() subtype} is the wildcard character <code>&#42;</code> or not.
* @return whether the subtype is <code>&#42;</code>
*/
public boolean isWildcardSubtype() {
return WILDCARD_TYPE.equals(subtype);
}
/**
* Indicates whether this media type is concrete, i.e. whether neither the type or subtype is a wildcard
* character <code>&#42;</code>.
* @return whether this media type is concrete
*/
public boolean isConcrete() {
return !isWildcardType() && !isWildcardSubtype();
}
/**
* Return the character set, as indicated by a <code>charset</code> parameter, if any.
* @return the character set; or <code>null</code> if not available

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.web;
import java.util.Collection;
import javax.servlet.ServletException;
/**
@@ -49,6 +50,15 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
this(method, supportedMethods, "Request method '" + method + "' not supported");
}
/**
* Create a new HttpRequestMethodNotSupportedException.
* @param method the unsupported HTTP request method
* @param supportedMethods the actually supported HTTP methods
*/
public HttpRequestMethodNotSupportedException(String method, Collection<String> supportedMethods) {
this(method, supportedMethods.toArray(new String[supportedMethods.size()]));
}
/**
* Create a new HttpRequestMethodNotSupportedException.
* @param method the unsupported HTTP request method

View File

@@ -16,12 +16,6 @@
package org.springframework.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,9 +24,12 @@ import java.util.List;
import java.util.Random;
import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
* @author Juergen Hoeller
@@ -499,5 +496,14 @@ public class MediaTypeTests {
MediaType mediaType = MediaType.parseMediaType("application/xml");
assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
}
@Test
public void isConcrete() {
assertTrue("text/plain not concrete", MediaType.TEXT_PLAIN.isConcrete());
assertFalse("*/* concrete", MediaType.ALL.isConcrete());
assertFalse("text/* concrete", new MediaType("text", "*").isConcrete());
}
}