Browse Source

Polishing

(cherry picked from commit b541fc9)
pull/761/head
Juergen Hoeller 11 years ago
parent
commit
7ed7f981c9
  1. 5
      spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
  2. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java
  3. 18
      spring-context/src/main/java/org/springframework/context/annotation/Role.java
  4. 6
      spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java
  5. 2
      spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java
  6. 16
      spring-core/src/main/java/org/springframework/util/CollectionUtils.java
  7. 13
      spring-core/src/test/java/org/springframework/core/convert/support/ByteBufferConverterTests.java
  8. 5
      spring-core/src/test/java/org/springframework/tests/TestGroup.java
  9. 2
      spring-jms/src/main/java/org/springframework/jms/annotation/JmsBootstrapConfiguration.java
  10. 62
      spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java
  11. 12
      spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java
  12. 5
      spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java
  13. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java
  14. 26
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java

5
spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -219,8 +219,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
throws BeansException { throws BeansException {
StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(props); StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(props);
doProcessProperties(beanFactoryToProcess, valueResolver);
this.doProcessProperties(beanFactoryToProcess, valueResolver);
} }
/** /**

4
spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -279,7 +279,7 @@ public class BeanDefinitionBuilder {
*/ */
public BeanDefinitionBuilder addDependsOn(String beanName) { public BeanDefinitionBuilder addDependsOn(String beanName) {
if (this.beanDefinition.getDependsOn() == null) { if (this.beanDefinition.getDependsOn() == null) {
this.beanDefinition.setDependsOn(new String[] {beanName}); this.beanDefinition.setDependsOn(beanName);
} }
else { else {
String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName); String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);

18
spring-context/src/main/java/org/springframework/context/annotation/Role.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,16 +28,16 @@ import org.springframework.beans.factory.config.BeanDefinition;
* Indicates the 'role' hint for a given bean. * Indicates the 'role' hint for a given bean.
* *
* <p>May be used on any class directly or indirectly annotated with * <p>May be used on any class directly or indirectly annotated with
* {@link org.springframework.stereotype.Component} or on methods annotated with * {@link org.springframework.stereotype.Component} or on methods
* {@link Bean}. * annotated with {@link Bean}.
* *
* <p>If this annotation is not present on a Component or Bean definition, the * <p>If this annotation is not present on a Component or Bean definition,
* default value of {@link BeanDefinition#ROLE_APPLICATION} will apply. * the default value of {@link BeanDefinition#ROLE_APPLICATION} will apply.
* *
* <p>If Role is present on a {@link Configuration @Configuration} class, this * <p>If Role is present on a {@link Configuration @Configuration} class,
* indicates the role of the configuration class bean definition and does not * this indicates the role of the configuration class bean definition and
* cascade to all @{@code Bean} methods defined within. This behavior is * does not cascade to all @{@code Bean} methods defined within. This behavior
* different than that of the @{@link Lazy} annotation, for example. * is different than that of the @{@link Lazy} annotation, for example.
* *
* @author Chris Beams * @author Chris Beams
* @since 3.1 * @since 3.1

6
spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java

@ -152,7 +152,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* Set the default charset to use for parsing resource bundle files. * Set the default charset to use for parsing resource bundle files.
* <p>Default is none, using the {@code java.util.ResourceBundle} * <p>Default is none, using the {@code java.util.ResourceBundle}
* default encoding: ISO-8859-1. * default encoding: ISO-8859-1.
* and more flexibility in setting of an encoding per file. * @since 3.1.3
*/ */
public void setDefaultEncoding(String defaultEncoding) { public void setDefaultEncoding(String defaultEncoding) {
this.defaultEncoding = defaultEncoding; this.defaultEncoding = defaultEncoding;
@ -167,6 +167,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* {@code java.util.ResourceBundle}. However, this is often not desirable * {@code java.util.ResourceBundle}. However, this is often not desirable
* in an application server environment, where the system Locale is not relevant * in an application server environment, where the system Locale is not relevant
* to the application at all: Set this flag to "false" in such a scenario. * to the application at all: Set this flag to "false" in such a scenario.
* @since 3.1.3
*/ */
public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) { public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) {
this.fallbackToSystemLocale = fallbackToSystemLocale; this.fallbackToSystemLocale = fallbackToSystemLocale;
@ -188,6 +189,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* Consider {@link ReloadableResourceBundleMessageSource} in combination * Consider {@link ReloadableResourceBundleMessageSource} in combination
* with resource bundle files in a non-classpath location. * with resource bundle files in a non-classpath location.
* </ul> * </ul>
* @since 3.1.3
*/ */
public void setCacheSeconds(int cacheSeconds) { public void setCacheSeconds(int cacheSeconds) {
this.cacheMillis = (cacheSeconds * 1000); this.cacheMillis = (cacheSeconds * 1000);
@ -304,7 +306,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* @param locale the Locale to look for * @param locale the Locale to look for
* @return the corresponding ResourceBundle * @return the corresponding ResourceBundle
* @throws MissingResourceException if no matching bundle could be found * @throws MissingResourceException if no matching bundle could be found
* @see java.util.ResourceBundle#getBundle(String, java.util.Locale, ClassLoader) * @see java.util.ResourceBundle#getBundle(String, Locale, ClassLoader)
* @see #getBundleClassLoader() * @see #getBundleClassLoader()
*/ */
protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException { protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException {

2
spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java

@ -44,7 +44,7 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
public AsyncAnnotationBeanPostProcessor asyncAdvisor() { public AsyncAnnotationBeanPostProcessor asyncAdvisor() {
Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected"); Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected");
AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor(); AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
Class<? extends Annotation> customAsyncAnnotation = enableAsync.getClass("annotation"); Class<? extends Annotation> customAsyncAnnotation = this.enableAsync.getClass("annotation");
if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) { if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
bpp.setAsyncAnnotationType(customAsyncAnnotation); bpp.setAsyncAnnotationType(customAsyncAnnotation);
} }

16
spring-core/src/main/java/org/springframework/util/CollectionUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -335,9 +335,10 @@ public abstract class CollectionUtils {
} }
/** /**
* Adapt a {@code Map<K, List<V>>} to an {@code MultiValueMap<K,V>}. * Adapt a {@code Map<K, List<V>>} to an {@code MultiValueMap<K, V>}.
* @param map the map * @param map the original map
* @return the multi-value map * @return the multi-value map
* @since 3.1
*/ */
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) { public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) {
return new MultiValueMapAdapter<K, V>(map); return new MultiValueMapAdapter<K, V>(map);
@ -348,8 +349,9 @@ public abstract class CollectionUtils {
* Return an unmodifiable view of the specified multi-value map. * Return an unmodifiable view of the specified multi-value map.
* @param map the map for which an unmodifiable view is to be returned. * @param map the map for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified multi-value map. * @return an unmodifiable view of the specified multi-value map.
* @since 3.1
*/ */
public static <K,V> MultiValueMap<K,V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) { public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) {
Assert.notNull(map, "'map' must not be null"); Assert.notNull(map, "'map' must not be null");
Map<K, List<V>> result = new LinkedHashMap<K, List<V>>(map.size()); Map<K, List<V>> result = new LinkedHashMap<K, List<V>>(map.size());
for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) { for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) {
@ -366,7 +368,7 @@ public abstract class CollectionUtils {
*/ */
private static class EnumerationIterator<E> implements Iterator<E> { private static class EnumerationIterator<E> implements Iterator<E> {
private Enumeration<E> enumeration; private final Enumeration<E> enumeration;
public EnumerationIterator(Enumeration<E> enumeration) { public EnumerationIterator(Enumeration<E> enumeration) {
this.enumeration = enumeration; this.enumeration = enumeration;
@ -476,8 +478,8 @@ public abstract class CollectionUtils {
} }
@Override @Override
public void putAll(Map<? extends K, ? extends List<V>> m) { public void putAll(Map<? extends K, ? extends List<V>> map) {
this.map.putAll(m); this.map.putAll(map);
} }
@Override @Override

13
spring-core/src/test/java/org/springframework/core/convert/support/ByteBufferConverterTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,6 +35,7 @@ public class ByteBufferConverterTests {
private GenericConversionService conversionService; private GenericConversionService conversionService;
@Before @Before
public void setup() { public void setup() {
this.conversionService = new GenericConversionService(); this.conversionService = new GenericConversionService();
@ -43,6 +44,7 @@ public class ByteBufferConverterTests {
this.conversionService.addConverter(new OtherTypeToByteArrayConverter()); this.conversionService.addConverter(new OtherTypeToByteArrayConverter());
} }
@Test @Test
public void byteArrayToByteBuffer() throws Exception { public void byteArrayToByteBuffer() throws Exception {
byte[] bytes = new byte[] { 1, 2, 3 }; byte[] bytes = new byte[] { 1, 2, 3 };
@ -78,6 +80,7 @@ public class ByteBufferConverterTests {
assertThat(bytes, equalTo(convert.array())); assertThat(bytes, equalTo(convert.array()));
} }
private static class OtherType { private static class OtherType {
private byte[] bytes; private byte[] bytes;
@ -88,8 +91,8 @@ public class ByteBufferConverterTests {
} }
private static class ByteArrayToOtherTypeConverter implements
Converter<byte[], OtherType> { private static class ByteArrayToOtherTypeConverter implements Converter<byte[], OtherType> {
@Override @Override
public OtherType convert(byte[] source) { public OtherType convert(byte[] source) {
@ -97,8 +100,8 @@ public class ByteBufferConverterTests {
} }
} }
private static class OtherTypeToByteArrayConverter implements
Converter<OtherType, byte[]> { private static class OtherTypeToByteArrayConverter implements Converter<OtherType, byte[]> {
@Override @Override
public byte[] convert(OtherType source) { public byte[] convert(OtherType source) {

5
spring-core/src/test/java/org/springframework/tests/TestGroup.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,6 @@ import static java.lang.String.*;
*/ */
public enum TestGroup { public enum TestGroup {
/** /**
* Tests that take a considerable amount of time to run. Any test lasting longer than * Tests that take a considerable amount of time to run. Any test lasting longer than
* 500ms should be considered a candidate in order to avoid making the overall test * 500ms should be considered a candidate in order to avoid making the overall test
@ -68,6 +67,7 @@ public enum TestGroup {
*/ */
CUSTOM_COMPILATION; CUSTOM_COMPILATION;
/** /**
* Parse the specified comma separated string of groups. * Parse the specified comma separated string of groups.
* @param value the comma separated string of groups * @param value the comma separated string of groups
@ -102,4 +102,5 @@ public enum TestGroup {
} }
return groups; return groups;
} }
} }

2
spring-jms/src/main/java/org/springframework/jms/annotation/JmsBootstrapConfiguration.java

@ -29,7 +29,7 @@ import org.springframework.jms.config.JmsListenerEndpointRegistry;
* a default {@link JmsListenerEndpointRegistry}. * a default {@link JmsListenerEndpointRegistry}.
* *
* <p>This configuration class is automatically imported when using the @{@link EnableJms} * <p>This configuration class is automatically imported when using the @{@link EnableJms}
* annotation. See {@link EnableJms} Javadoc for complete usage. * annotation. See the {@link EnableJms} javadocs for complete usage details.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 4.1 * @since 4.1

62
spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,55 +55,56 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
/** /**
* Represents the expected result that doesn't contain the xml declaration. * Represents the expected result that doesn't contain the xml declaration.
*/ */
private static final String DOCUMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String DOCUMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
+ "<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>"; "<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
/** /**
* Represents the expected result that doesn't contain the xml namespaces. * Represents the expected result that doesn't contain the xml namespaces.
*/ */
private static final String SUPPRESSED_NAMESPACE_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flights><flight><number>42</number></flight></flights>"; private static final String SUPPRESSED_NAMESPACE_EXPECTED_STRING =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><flights><flight><number>42</number></flight></flights>";
/** /**
* Represents the expected result with modified root element name. * Represents the expected result with modified root element name.
*/ */
private static final String ROOT_ELEMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String ROOT_ELEMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<tns:canceledFlights xmlns:tns=\"http://samples.springframework.org/flight\">" "<tns:canceledFlights xmlns:tns=\"http://samples.springframework.org/flight\">" +
+ "<tns:flight><tns:number>42</tns:number></tns:flight></tns:canceledFlights>"; "<tns:flight><tns:number>42</tns:number></tns:flight></tns:canceledFlights>";
/** /**
* Represents the expected result with 'xsi:type' attribute. * Represents the expected result with 'xsi:type' attribute.
*/ */
private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+ " xmlns:java=\"http://java.sun.com\"" " xmlns:java=\"http://java.sun.com\"" +
+ " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
+ "<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";
/** /**
* Represents the expected result with suppressed 'xsi:type' attribute. * Represents the expected result with suppressed 'xsi:type' attribute.
*/ */
private static final String SUPPRESSED_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String SUPPRESSED_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<objects><castor-object><name>test</name><value>8</value></castor-object></objects>"; "<objects><castor-object><name>test</name><value>8</value></castor-object></objects>";
/** /**
* Represents the expected result with 'xsi:type' attribute for root element. * Represents the expected result with 'xsi:type' attribute for root element.
*/ */
private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" "<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+ " xmlns:java=\"http://java.sun.com\"" " xmlns:java=\"http://java.sun.com\"" +
+ " xsi:type=\"java:java.util.Arrays$ArrayList\">" " xsi:type=\"java:java.util.Arrays$ArrayList\">" +
+ "<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" "<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
+ "<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";
/** /**
* Represents the expected result without 'xsi:type' attribute for root element. * Represents the expected result without 'xsi:type' attribute for root element.
*/ */
private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+ " xmlns:java=\"http://java.sun.com\"" " xmlns:java=\"http://java.sun.com\"" +
+ " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
+ "<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";
@Override @Override
@ -277,9 +278,9 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
} }
/** /**
* Asserts the values of xpath expression evaluation is exactly the same as expected value. </p> The xpath may contain * Asserts the values of xpath expression evaluation is exactly the same as expected value.
* the xml namespace prefixes, since namespaces from flight example are being registered. * <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example
* * are being registered.
* @param msg the error message that will be used in case of test failure * @param msg the error message that will be used in case of test failure
* @param expected the expected value * @param expected the expected value
* @param xpath the xpath to evaluate * @param xpath the xpath to evaluate
@ -302,8 +303,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
/** /**
* Creates a instance of {@link CastorObject} for testing. * Creates a instance of {@link CastorObject} for testing.
*
* @return a instance of {@link CastorObject}
*/ */
private CastorObject createCastorObject() { private CastorObject createCastorObject() {
CastorObject castorObject = new CastorObject(); CastorObject castorObject = new CastorObject();
@ -311,4 +310,5 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
castorObject.setValue(8); castorObject.setValue(8);
return castorObject; return castorObject;
} }
} }

12
spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,15 +47,16 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests {
*/ */
protected static final String EXTRA_ATTRIBUTES_STRING = protected static final String EXTRA_ATTRIBUTES_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" + "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight status=\"canceled\"><tns:number>42</tns:number></tns:flight></tns:flights>"; "<tns:flight status=\"canceled\"><tns:number>42</tns:number></tns:flight></tns:flights>";
/** /**
* Represents the xml with additional element that is not mapped in Castor config. * Represents the xml with additional element that is not mapped in Castor config.
*/ */
protected static final String EXTRA_ELEMENTS_STRING = protected static final String EXTRA_ELEMENTS_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" + "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number><tns:date>2011-06-14</tns:date>" + "<tns:flight><tns:number>42</tns:number><tns:date>2011-06-14</tns:date>" +
"</tns:flight></tns:flights>"; "</tns:flight></tns:flights>";
@Override @Override
protected void testFlights(Object o) { protected void testFlights(Object o) {
@ -237,7 +238,6 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests {
@Test @Test
public void unmarshalSaxSourceExternalEntities() throws Exception { public void unmarshalSaxSourceExternalEntities() throws Exception {
final AtomicReference<XMLReader> result = new AtomicReference<XMLReader>(); final AtomicReference<XMLReader> result = new AtomicReference<XMLReader>();
CastorMarshaller marshaller = new CastorMarshaller() { CastorMarshaller marshaller = new CastorMarshaller() {
@Override @Override
@ -248,13 +248,11 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests {
}; };
// 1. external-general-entities disabled (default) // 1. external-general-entities disabled (default)
marshaller.unmarshal(new SAXSource(new InputSource("1"))); marshaller.unmarshal(new SAXSource(new InputSource("1")));
assertNotNull(result.get()); assertNotNull(result.get());
assertEquals(false, result.get().getFeature("http://xml.org/sax/features/external-general-entities")); assertEquals(false, result.get().getFeature("http://xml.org/sax/features/external-general-entities"));
// 2. external-general-entities disabled (default) // 2. external-general-entities disabled (default)
result.set(null); result.set(null);
marshaller.setProcessExternalEntities(true); marshaller.setProcessExternalEntities(true);
marshaller.unmarshal(new SAXSource(new InputSource("1"))); marshaller.unmarshal(new SAXSource(new InputSource("1")));

5
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,11 +33,11 @@ import org.springframework.http.converter.HttpMessageConverter;
* <p>Supported for annotated handler methods in Servlet environments. * <p>Supported for annotated handler methods in Servlet environments.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0
* @see RequestHeader * @see RequestHeader
* @see ResponseBody * @see ResponseBody
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
* @since 3.0
*/ */
@Target(ElementType.PARAMETER) @Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ -49,6 +49,7 @@ public @interface RequestBody {
* <p>Default is {@code true}, leading to an exception thrown in case * <p>Default is {@code true}, leading to an exception thrown in case
* there is no body content. Switch this to {@code false} if you prefer * there is no body content. Switch this to {@code false} if you prefer
* {@code null} to be passed when the body content is {@code null}. * {@code null} to be passed when the body content is {@code null}.
* @since 3.2
*/ */
boolean required() default true; boolean required() default true;

8
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java

@ -50,8 +50,8 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
* *
* <p>An {@code @RequestBody} method argument is also validated if it is annotated * <p>An {@code @RequestBody} method argument is also validated if it is annotated
* with {@code @javax.validation.Valid}. In case of validation failure, * with {@code @javax.validation.Valid}. In case of validation failure,
* {@link MethodArgumentNotValidException} is raised and results in a 400 response * {@link MethodArgumentNotValidException} is raised and results in an HTTP 400
* status code if {@link DefaultHandlerExceptionResolver} is configured. * response status code if {@link DefaultHandlerExceptionResolver} is configured.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -114,7 +114,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam, protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam,
Type paramType) throws IOException, HttpMediaTypeNotSupportedException { Type paramType) throws IOException, HttpMediaTypeNotSupportedException {
final HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest); HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest);
InputStream inputStream = inputMessage.getBody(); InputStream inputStream = inputMessage.getBody();
@ -139,7 +139,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
} }
inputMessage = new ServletServerHttpRequest(servletRequest) { inputMessage = new ServletServerHttpRequest(servletRequest) {
@Override @Override
public InputStream getBody() throws IOException { public InputStream getBody() {
// Form POST should not get here // Form POST should not get here
return pushbackInputStream; return pushbackInputStream;
} }

26
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,8 +59,8 @@ import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* Test fixture for a {@link RequestResponseBodyMethodProcessor} with actual delegation * Test fixture for a {@link RequestResponseBodyMethodProcessor} with
* to HttpMessageConverter instances. * actual delegation to {@link HttpMessageConverter} instances.
* *
* <p>Also see {@link RequestResponseBodyMethodProcessorMockTests}. * <p>Also see {@link RequestResponseBodyMethodProcessorMockTests}.
* *
@ -177,9 +177,7 @@ public class RequestResponseBodyMethodProcessorTests {
assertEquals("foobarbaz", result); assertEquals("foobarbaz", result);
} }
// SPR-9942 @Test(expected = HttpMessageNotReadableException.class) // SPR-9942
@Test(expected = HttpMessageNotReadableException.class)
public void resolveArgumentRequiredNoContent() throws Exception { public void resolveArgumentRequiredNoContent() throws Exception {
this.servletRequest.setContent(new byte[0]); this.servletRequest.setContent(new byte[0]);
this.servletRequest.setContentType("text/plain"); this.servletRequest.setContentType("text/plain");
@ -189,9 +187,7 @@ public class RequestResponseBodyMethodProcessorTests {
processor.resolveArgument(paramString, mavContainer, webRequest, binderFactory); processor.resolveArgument(paramString, mavContainer, webRequest, binderFactory);
} }
// SPR-9964 @Test // SPR-9964
@Test
public void resolveArgumentTypeVariable() throws Exception { public void resolveArgumentTypeVariable() throws Exception {
Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class); Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method); HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
@ -211,9 +207,7 @@ public class RequestResponseBodyMethodProcessorTests {
assertEquals("Jad", result.getName()); assertEquals("Jad", result.getName());
} }
// SPR-11225 @Test // SPR-11225
@Test
public void resolveArgumentTypeVariableWithNonGenericConverter() throws Exception { public void resolveArgumentTypeVariableWithNonGenericConverter() throws Exception {
Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class); Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method); HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
@ -235,9 +229,7 @@ public class RequestResponseBodyMethodProcessorTests {
assertEquals("Jad", result.getName()); assertEquals("Jad", result.getName());
} }
// SPR-9160 @Test // SPR-9160
@Test
public void handleReturnValueSortByQuality() throws Exception { public void handleReturnValueSortByQuality() throws Exception {
this.servletRequest.addHeader("Accept", "text/plain; q=0.5, application/json"); this.servletRequest.addHeader("Accept", "text/plain; q=0.5, application/json");
@ -346,9 +338,7 @@ public class RequestResponseBodyMethodProcessorTests {
assertFalse(content.contains("\"withoutView\":\"without\"")); assertFalse(content.contains("\"withoutView\":\"without\""));
} }
// SPR-12149 @Test // SPR-12149
@Test
public void jacksonJsonViewWithResponseBodyAndXmlMessageConverter() throws Exception { public void jacksonJsonViewWithResponseBodyAndXmlMessageConverter() throws Exception {
Method method = JacksonViewController.class.getMethod("handleResponseBody"); Method method = JacksonViewController.class.getMethod("handleResponseBody");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonViewController(), method); HandlerMethod handlerMethod = new HandlerMethod(new JacksonViewController(), method);

Loading…
Cancel
Save