Browse Source

Polishing

pull/710/head
Juergen Hoeller 11 years ago
parent
commit
50c578c5a0
  1. 42
      build.gradle
  2. 5
      spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
  3. 2
      spring-beans/src/test/resources/org/springframework/beans/factory/xml/testUtilNamespace.xml
  4. 5
      spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java
  5. 19
      spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java
  6. 7
      spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java
  7. 6
      spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java
  8. 13
      spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
  9. 8
      spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java
  10. 11
      spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java
  11. 8
      spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java
  12. 7
      spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java
  13. 77
      spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java

42
build.gradle

@ -441,7 +441,7 @@ project("spring-tx") {
compile(project(":spring-beans")) compile(project(":spring-beans"))
compile(project(":spring-core")) compile(project(":spring-core"))
optional(project(":spring-aop")) optional(project(":spring-aop"))
optional(project(":spring-context")) // for JCA, @EnableTransactionManagement optional(project(":spring-context")) // for JCA, @EnableTransactionManagement
optional("aopalliance:aopalliance:1.0") optional("aopalliance:aopalliance:1.0")
optional("javax.transaction:javax.transaction-api:1.2") optional("javax.transaction:javax.transaction-api:1.2")
optional("javax.resource:connector-api:1.5") optional("javax.resource:connector-api:1.5")
@ -516,7 +516,7 @@ project("spring-jdbc") {
compile(project(":spring-beans")) compile(project(":spring-beans"))
compile(project(":spring-core")) compile(project(":spring-core"))
compile(project(":spring-tx")) compile(project(":spring-tx"))
optional(project(":spring-context")) // for JndiDataSourceLookup optional(project(":spring-context")) // for JndiDataSourceLookup
optional("javax.transaction:javax.transaction-api:1.2") optional("javax.transaction:javax.transaction-api:1.2")
optional("com.mchange:c3p0:0.9.2.1") optional("com.mchange:c3p0:0.9.2.1")
optional("org.hsqldb:hsqldb:${hsqldbVersion}") optional("org.hsqldb:hsqldb:${hsqldbVersion}")
@ -533,8 +533,8 @@ project("spring-context-support") {
compile(project(":spring-core")) compile(project(":spring-core"))
compile(project(":spring-beans")) compile(project(":spring-beans"))
compile(project(":spring-context")) compile(project(":spring-context"))
optional(project(":spring-jdbc")) // for Quartz support optional(project(":spring-jdbc")) // for Quartz support
optional(project(":spring-tx")) // for Quartz support optional(project(":spring-tx")) // for Quartz support
optional("javax.mail:javax.mail-api:1.4.7") optional("javax.mail:javax.mail-api:1.4.7")
optional("javax.cache:cache-api:1.0.0") optional("javax.cache:cache-api:1.0.0")
optional("com.google.guava:guava:17.0") optional("com.google.guava:guava:17.0")
@ -550,8 +550,8 @@ project("spring-context-support") {
exclude group: "xml-apis", module: "xml-apis" exclude group: "xml-apis", module: "xml-apis"
} }
testCompile("org.apache.poi:poi:3.10.1") testCompile("org.apache.poi:poi:3.10.1")
testCompile("commons-beanutils:commons-beanutils:1.8.0") // for Velocity/JasperReports testCompile("commons-beanutils:commons-beanutils:1.8.0") // for Velocity/JasperReports
testCompile("commons-digester:commons-digester:1.8.1") // for Velocity/JasperReports testCompile("commons-digester:commons-digester:1.8.1") // for Velocity/JasperReports
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.slf4j:slf4j-api:${slf4jVersion}") testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
testRuntime("com.sun.mail:javax.mail:1.4.7") testRuntime("com.sun.mail:javax.mail:1.4.7")
@ -565,12 +565,12 @@ project("spring-web") {
description = "Spring Web" description = "Spring Web"
dependencies { dependencies {
compile(project(":spring-aop")) // for JaxWsPortProxyFactoryBean compile(project(":spring-aop")) // for JaxWsPortProxyFactoryBean
compile(project(":spring-beans")) // for MultiPartFilter compile(project(":spring-beans")) // for MultipartFilter
compile(project(":spring-context")) compile(project(":spring-context"))
compile(project(":spring-core")) compile(project(":spring-core"))
provided("javax.servlet:javax.servlet-api:3.0.1") provided("javax.servlet:javax.servlet-api:3.0.1")
optional(project(":spring-oxm")) // for MarshallingHttpMessageConverter optional(project(":spring-oxm")) // for MarshallingHttpMessageConverter
optional("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1") optional("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1")
optional("javax.portlet:portlet-api:2.0") optional("javax.portlet:portlet-api:2.0")
optional("javax.el:javax.el-api:2.2.5") optional("javax.el:javax.el-api:2.2.5")
@ -578,7 +578,7 @@ project("spring-web") {
optional("aopalliance:aopalliance:1.0") optional("aopalliance:aopalliance:1.0")
optional("com.caucho:hessian:4.0.7") optional("com.caucho:hessian:4.0.7")
optional("commons-fileupload:commons-fileupload:1.3.1") optional("commons-fileupload:commons-fileupload:1.3.1")
optional("org.apache.httpcomponents:httpclient:4.3.5") optional("org.apache.httpcomponents:httpclient:4.3.6")
optional("org.apache.httpcomponents:httpasyncclient:4.0.2") optional("org.apache.httpcomponents:httpasyncclient:4.0.2")
optional("org.codehaus.jackson:jackson-mapper-asl:${jackson1Version}") optional("org.codehaus.jackson:jackson-mapper-asl:${jackson1Version}")
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}") optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
@ -711,8 +711,8 @@ project("spring-webmvc") {
compile(project(":spring-expression")) compile(project(":spring-expression"))
compile(project(":spring-web")) compile(project(":spring-web"))
provided("javax.servlet:javax.servlet-api:3.0.1") provided("javax.servlet:javax.servlet-api:3.0.1")
optional(project(":spring-context-support")) // for Velocity support optional(project(":spring-context-support")) // for Velocity support
optional(project(":spring-oxm")) // for MarshallingView optional(project(":spring-oxm")) // for MarshallingView
optional("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1") optional("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1")
optional("javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1") optional("javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1")
optional("net.sourceforge.jexcelapi:jxl:2.6.12") optional("net.sourceforge.jexcelapi:jxl:2.6.12")
@ -764,7 +764,7 @@ project("spring-webmvc") {
} }
testCompile("javax.validation:validation-api:1.0.0.GA") testCompile("javax.validation:validation-api:1.0.0.GA")
testCompile("org.hibernate:hibernate-validator:${hibVal4Version}") testCompile("org.hibernate:hibernate-validator:${hibVal4Version}")
testCompile("org.apache.httpcomponents:httpclient:4.3.5") testCompile("org.apache.httpcomponents:httpclient:4.3.6")
testCompile("commons-fileupload:commons-fileupload:1.3.1") testCompile("commons-fileupload:commons-fileupload:1.3.1")
testCompile("commons-io:commons-io:1.3") testCompile("commons-io:commons-io:1.3")
testCompile("joda-time:joda-time:${jodaVersion}") testCompile("joda-time:joda-time:${jodaVersion}")
@ -915,13 +915,13 @@ project("spring-aspects") {
rt("org.aspectj:aspectjrt:${aspectjVersion}") rt("org.aspectj:aspectjrt:${aspectjVersion}")
compile("org.aspectj:aspectjweaver:${aspectjVersion}") compile("org.aspectj:aspectjweaver:${aspectjVersion}")
provided("org.eclipse.persistence:javax.persistence:2.0.0") provided("org.eclipse.persistence:javax.persistence:2.0.0")
optional(project(":spring-aop")) // for @Async support optional(project(":spring-aop")) // for @Async support
optional(project(":spring-beans")) // for @Configurable support optional(project(":spring-beans")) // for @Configurable support
optional(project(":spring-context")) // for @Enable* support optional(project(":spring-context")) // for @Enable* support
optional(project(":spring-context-support")) // for JavaMail support optional(project(":spring-context-support")) // for JavaMail support
optional(project(":spring-orm")) // for JPA exception translation support optional(project(":spring-orm")) // for JPA exception translation support
optional(project(":spring-tx")) // for JPA, @Transactional support optional(project(":spring-tx")) // for JPA, @Transactional support
testCompile(project(":spring-core")) // for CodeStyleAspect testCompile(project(":spring-core")) // for CodeStyleAspect
testCompile(project(":spring-test")) testCompile(project(":spring-test"))
testCompile("javax.mail:javax.mail-api:1.4.7") testCompile("javax.mail:javax.mail-api:1.4.7")
} }
@ -1157,7 +1157,7 @@ configure(rootProject) {
} }
} }
// Create an distribution that contains all dependencies (required and optional). // Create a distribution that contains all dependencies (required and optional).
// Not published by default; only for use when building from source. // Not published by default; only for use when building from source.
task depsZip(type: Zip, dependsOn: distZip) { zipTask -> task depsZip(type: Zip, dependsOn: distZip) { zipTask ->
group = "Distribution" group = "Distribution"

5
spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -104,9 +104,11 @@ public class DefaultListableBeanFactoryTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class); private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testUnreferencedSingletonWasInstantiated() { public void testUnreferencedSingletonWasInstantiated() {
KnowsIfInstantiated.clearInstantiationRecord(); KnowsIfInstantiated.clearInstantiationRecord();
@ -2748,6 +2750,7 @@ public class DefaultListableBeanFactoryTests {
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class KnowsIfInstantiated { private static class KnowsIfInstantiated {

2
spring-beans/src/test/resources/org/springframework/beans/factory/xml/testUtilNamespace.xml

@ -15,7 +15,7 @@
<util:property-path id="name" path=" <util:property-path id="name" path="
configuredBean. configuredBean.
name name
"/> "/>
<bean id="testBean" class="org.springframework.tests.sample.beans.TestBean" scope="prototype"> <bean id="testBean" class="org.springframework.tests.sample.beans.TestBean" scope="prototype">
<property name="name"> <property name="name">

5
spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java

@ -27,8 +27,9 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
* Converts an Array to another Array. First adapts the source array to a List, then * Converts an array to another array. First adapts the source array to a List,
* delegates to {@link CollectionToArrayConverter} to perform the target array conversion. * then delegates to {@link CollectionToArrayConverter} to perform the target
* array conversion.
* *
* @author Keith Donald * @author Keith Donald
* @author Phillip Webb * @author Phillip Webb

19
spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -27,23 +27,27 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.core.convert.converter.ConditionalGenericConverter;
/** /**
* Converts an Array to a Collection. * Converts an array to a Collection.
* *
* <p>First, creates a new Collection of the requested targetType. * <p>First, creates a new Collection of the requested target type.
* Then adds each array element to the target collection. * Then adds each array element to the target collection.
* Will perform an element conversion from the source component type to the collection's parameterized type if necessary. * Will perform an element conversion from the source component type
* to the collection's parameterized type if necessary.
* *
* @author Keith Donald * @author Keith Donald
* @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
final class ArrayToCollectionConverter implements ConditionalGenericConverter { final class ArrayToCollectionConverter implements ConditionalGenericConverter {
private final ConversionService conversionService; private final ConversionService conversionService;
public ArrayToCollectionConverter(ConversionService conversionService) { public ArrayToCollectionConverter(ConversionService conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, Collection.class)); return Collections.singleton(new ConvertiblePair(Object[].class, Collection.class));
@ -60,9 +64,12 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
if (source == null) { if (source == null) {
return null; return null;
} }
int length = Array.getLength(source); int length = Array.getLength(source);
TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), length); Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), length);
if (targetType.getElementTypeDescriptor() == null) {
if (elementDesc == null) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Object sourceElement = Array.get(source, i); Object sourceElement = Array.get(source, i);
target.add(sourceElement); target.add(sourceElement);
@ -72,7 +79,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Object sourceElement = Array.get(source, i); Object sourceElement = Array.get(source, i);
Object targetElement = this.conversionService.convert(sourceElement, Object targetElement = this.conversionService.convert(sourceElement,
sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor()); sourceType.elementTypeDescriptor(sourceElement), elementDesc);
target.add(targetElement); target.add(targetElement);
} }
} }

7
spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -25,7 +25,8 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.core.convert.converter.ConditionalGenericConverter;
/** /**
* Converts an Array to an Object by returning the first array element after converting it to the desired targetType. * Converts an array to an Object by returning the first array element
* after converting it to the desired target type.
* *
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
@ -34,10 +35,12 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter {
private final ConversionService conversionService; private final ConversionService conversionService;
public ArrayToObjectConverter(ConversionService conversionService) { public ArrayToObjectConverter(ConversionService conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, Object.class)); return Collections.singleton(new ConvertiblePair(Object[].class, Object.class));

6
spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java

@ -26,9 +26,9 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
* Converts an Array to a comma-delimited String. * Converts an array to a comma-delimited String. First adapts the source array
* This implementation first adapts the source Array to a List, * to a List, then delegates to {@link CollectionToStringConverter} to perform
* then delegates to {@link CollectionToStringConverter} to perform the target String conversion. * the target String conversion.
* *
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0

13
spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java

@ -36,6 +36,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
* map's parameterized types K,V if necessary. * map's parameterized types K,V if necessary.
* *
* @author Keith Donald * @author Keith Donald
* @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
final class MapToMapConverter implements ConditionalGenericConverter { final class MapToMapConverter implements ConditionalGenericConverter {
@ -64,17 +65,22 @@ final class MapToMapConverter implements ConditionalGenericConverter {
if (source == null) { if (source == null) {
return null; return null;
} }
boolean copyRequired = !targetType.getType().isInstance(source);
Map<Object, Object> sourceMap = (Map<Object, Object>) source; Map<Object, Object> sourceMap = (Map<Object, Object>) source;
// Shortcut if possible...
boolean copyRequired = !targetType.getType().isInstance(source);
if (!copyRequired && sourceMap.isEmpty()) { if (!copyRequired && sourceMap.isEmpty()) {
return sourceMap; return sourceMap;
} }
TypeDescriptor keyDesc = targetType.getMapKeyTypeDescriptor();
TypeDescriptor valueDesc = targetType.getMapValueTypeDescriptor();
List<MapEntry> targetEntries = new ArrayList<MapEntry>(sourceMap.size()); List<MapEntry> targetEntries = new ArrayList<MapEntry>(sourceMap.size());
for (Map.Entry<Object, Object> entry : sourceMap.entrySet()) { for (Map.Entry<Object, Object> entry : sourceMap.entrySet()) {
Object sourceKey = entry.getKey(); Object sourceKey = entry.getKey();
Object sourceValue = entry.getValue(); Object sourceValue = entry.getValue();
Object targetKey = convertKey(sourceKey, sourceType, targetType.getMapKeyTypeDescriptor()); Object targetKey = convertKey(sourceKey, sourceType, keyDesc);
Object targetValue = convertValue(sourceValue, sourceType, targetType.getMapValueTypeDescriptor()); Object targetValue = convertValue(sourceValue, sourceType, valueDesc);
targetEntries.add(new MapEntry(targetKey, targetValue)); targetEntries.add(new MapEntry(targetKey, targetValue));
if (sourceKey != targetKey || sourceValue != targetValue) { if (sourceKey != targetKey || sourceValue != targetValue) {
copyRequired = true; copyRequired = true;
@ -83,6 +89,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
if (!copyRequired) { if (!copyRequired) {
return sourceMap; return sourceMap;
} }
Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size()); Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size());
for (MapEntry entry : targetEntries) { for (MapEntry entry : targetEntries) {
entry.addToMap(targetMap); entry.addToMap(targetMap);

8
spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -25,8 +25,8 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.core.convert.converter.ConditionalGenericConverter;
/** /**
* Converts an Object to a single-element Array containing the Object. * Converts an Object to a single-element array containing the Object.
* Will convert the Object to the target Array's component type if necessary. * Will convert the Object to the target array's component type if necessary.
* *
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
@ -35,10 +35,12 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
private final ConversionService conversionService; private final ConversionService conversionService;
public ObjectToArrayConverter(ConversionService conversionService) { public ObjectToArrayConverter(ConversionService conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object.class, Object[].class)); return Collections.singleton(new ConvertiblePair(Object.class, Object[].class));

11
spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -37,10 +37,12 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
private final ConversionService conversionService; private final ConversionService conversionService;
public ObjectToCollectionConverter(ConversionService conversionService) { public ObjectToCollectionConverter(ConversionService conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object.class, Collection.class)); return Collections.singleton(new ConvertiblePair(Object.class, Collection.class));
@ -56,12 +58,15 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
if (source == null) { if (source == null) {
return null; return null;
} }
TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), 1); Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), 1);
if (targetType.getElementTypeDescriptor() == null || targetType.getElementTypeDescriptor().isCollection()) {
if (elementDesc == null || elementDesc.isCollection()) {
target.add(source); target.add(source);
} }
else { else {
Object singleElement = this.conversionService.convert(source, sourceType, targetType.getElementTypeDescriptor()); Object singleElement = this.conversionService.convert(source, sourceType, elementDesc);
target.add(singleElement); target.add(singleElement);
} }
return target; return target;

8
spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java

@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
* {@code String.class} can be converted to it. * {@code String.class} can be converted to it.
* *
* @author Keith Donald * @author Keith Donald
* @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
final class StringToCollectionConverter implements ConditionalGenericConverter { final class StringToCollectionConverter implements ConditionalGenericConverter {
@ -61,16 +62,19 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
return null; return null;
} }
String string = (String) source; String string = (String) source;
String[] fields = StringUtils.commaDelimitedListToStringArray(string); String[] fields = StringUtils.commaDelimitedListToStringArray(string);
TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), fields.length); Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), fields.length);
if (targetType.getElementTypeDescriptor() == null) {
if (elementDesc == null) {
for (String field : fields) { for (String field : fields) {
target.add(field.trim()); target.add(field.trim());
} }
} }
else { else {
for (String field : fields) { for (String field : fields) {
Object targetElement = this.conversionService.convert(field.trim(), sourceType, targetType.getElementTypeDescriptor()); Object targetElement = this.conversionService.convert(field.trim(), sourceType, elementDesc);
target.add(targetElement); target.add(targetElement);
} }
} }

7
spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java

@ -20,12 +20,12 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.ConverterFactory;
/** /**
* Converts from a String to a java.lang.Enum by calling {@link Enum#valueOf(Class, String)}. * Converts from a String to a {@link java.lang.Enum} by calling {@link Enum#valueOf(Class, String)}.
* *
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({"unchecked", "rawtypes"})
final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> { final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
@Override @Override
@ -35,7 +35,8 @@ final class StringToEnumConverterFactory implements ConverterFactory<String, Enu
enumType = enumType.getSuperclass(); enumType = enumType.getSuperclass();
} }
if (enumType == null) { if (enumType == null) {
throw new IllegalArgumentException("The target type " + targetType.getName() + " does not refer to an enum"); throw new IllegalArgumentException(
"The target type " + targetType.getName() + " does not refer to an enum");
} }
return new StringToEnum(enumType); return new StringToEnum(enumType);
} }

77
spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java

@ -34,16 +34,19 @@ import org.springframework.util.StringUtils;
import org.springframework.web.util.WebUtils; import org.springframework.web.util.WebUtils;
/** /**
* Base class for {@code Filter}s that perform logging operations before and after a request is processed. * Base class for {@code Filter}s that perform logging operations before and after a request
* is processed.
* *
* <p>Subclasses should override the {@code beforeRequest(HttpServletRequest, String)} and * <p>Subclasses should override the {@code beforeRequest(HttpServletRequest, String)} and
* {@code afterRequest(HttpServletRequest, String)} methods to perform the actual logging around the request. * {@code afterRequest(HttpServletRequest, String)} methods to perform the actual logging
* around the request.
* *
* <p>Subclasses are passed the message to write to the log in the {@code beforeRequest} and * <p>Subclasses are passed the message to write to the log in the {@code beforeRequest} and
* {@code afterRequest} methods. By default, only the URI of the request is logged. However, setting the * {@code afterRequest} methods. By default, only the URI of the request is logged. However,
* {@code includeQueryString} property to {@code true} will cause the query string of the request to be * setting the {@code includeQueryString} property to {@code true} will cause the query string
* included also. The payload (body) of the request can be logged via the {@code includePayload} flag. Note that * of the request to be included also. The payload (body) of the request can be logged via the
* this will only log that which is read, which might not be the entire payload. * {@code includePayload} flag. Note that this will only log that which is read, which might
* not be the entire payload.
* *
* <p>Prefixes and suffixes for the before and after messages can be configured using the * <p>Prefixes and suffixes for the before and after messages can be configured using the
* {@code beforeMessagePrefix}, {@code afterMessagePrefix}, {@code beforeMessageSuffix} and * {@code beforeMessagePrefix}, {@code afterMessagePrefix}, {@code beforeMessageSuffix} and
@ -87,41 +90,43 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
/** /**
* Set whether or not the query string should be included in the log message. <p>Should be configured using an * Set whether the query string should be included in the log message.
* {@code &lt;init-param&gt;} for parameter name "includeQueryString" in the filter definition in * <p>Should be configured using an {@code &lt;init-param&gt;} for parameter name
* {@code web.xml}. * "includeQueryString" in the filter definition in {@code web.xml}.
*/ */
public void setIncludeQueryString(boolean includeQueryString) { public void setIncludeQueryString(boolean includeQueryString) {
this.includeQueryString = includeQueryString; this.includeQueryString = includeQueryString;
} }
/** /**
* Return whether or not the query string should be included in the log message. * Return whether the query string should be included in the log message.
*/ */
protected boolean isIncludeQueryString() { protected boolean isIncludeQueryString() {
return this.includeQueryString; return this.includeQueryString;
} }
/** /**
* Set whether or not the client address and session id should be included in the log message. <p>Should be configured * Set whether the client address and session id should be included in the
* using an {@code &lt;init-param&gt;} for parameter name "includeClientInfo" in the filter definition in * log message.
* {@code web.xml}. * <p>Should be configured using an {@code &lt;init-param&gt;} for parameter name
* "includeClientInfo" in the filter definition in {@code web.xml}.
*/ */
public void setIncludeClientInfo(boolean includeClientInfo) { public void setIncludeClientInfo(boolean includeClientInfo) {
this.includeClientInfo = includeClientInfo; this.includeClientInfo = includeClientInfo;
} }
/** /**
* Return whether or not the client address and session id should be included in the log message. * Return whether the client address and session id should be included in the
* log message.
*/ */
protected boolean isIncludeClientInfo() { protected boolean isIncludeClientInfo() {
return this.includeClientInfo; return this.includeClientInfo;
} }
/** /**
* Set whether or not the request payload (body) should be included in the log message. <p>Should be configured using * Set whether the request payload (body) should be included in the log message.
* an {@code &lt;init-param&gt;} for parameter name "includePayload" in the filter definition in * <p>Should be configured using an {@code &lt;init-param&gt;} for parameter name
* {@code web.xml}. * "includePayload" in the filter definition in {@code web.xml}.
*/ */
public void setIncludePayload(boolean includePayload) { public void setIncludePayload(boolean includePayload) {
@ -129,14 +134,15 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
} }
/** /**
* Return whether or not the request payload (body) should be included in the log message. * Return whether the request payload (body) should be included in the log message.
*/ */
protected boolean isIncludePayload() { protected boolean isIncludePayload() {
return includePayload; return this.includePayload;
} }
/** /**
* Sets the maximum length of the payload body to be included in the log message. Default is 50 characters. * Sets the maximum length of the payload body to be included in the log message.
* Default is 50 characters.
*/ */
public void setMaxPayloadLength(int maxPayloadLength) { public void setMaxPayloadLength(int maxPayloadLength) {
Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' should be larger than or equal to 0"); Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' should be larger than or equal to 0");
@ -147,32 +153,36 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
* Return the maximum length of the payload body to be included in the log message. * Return the maximum length of the payload body to be included in the log message.
*/ */
protected int getMaxPayloadLength() { protected int getMaxPayloadLength() {
return maxPayloadLength; return this.maxPayloadLength;
} }
/** /**
* Set the value that should be prepended to the log message written <i>before</i> a request is processed. * Set the value that should be prepended to the log message written
* <i>before</i> a request is processed.
*/ */
public void setBeforeMessagePrefix(String beforeMessagePrefix) { public void setBeforeMessagePrefix(String beforeMessagePrefix) {
this.beforeMessagePrefix = beforeMessagePrefix; this.beforeMessagePrefix = beforeMessagePrefix;
} }
/** /**
* Set the value that should be apppended to the log message written <i>before</i> a request is processed. * Set the value that should be appended to the log message written
* <i>before</i> a request is processed.
*/ */
public void setBeforeMessageSuffix(String beforeMessageSuffix) { public void setBeforeMessageSuffix(String beforeMessageSuffix) {
this.beforeMessageSuffix = beforeMessageSuffix; this.beforeMessageSuffix = beforeMessageSuffix;
} }
/** /**
* Set the value that should be prepended to the log message written <i>after</i> a request is processed. * Set the value that should be prepended to the log message written
* <i>after</i> a request is processed.
*/ */
public void setAfterMessagePrefix(String afterMessagePrefix) { public void setAfterMessagePrefix(String afterMessagePrefix) {
this.afterMessagePrefix = afterMessagePrefix; this.afterMessagePrefix = afterMessagePrefix;
} }
/** /**
* Set the value that should be appended to the log message written <i>after</i> a request is processed. * Set the value that should be appended to the log message written
* <i>after</i> a request is processed.
*/ */
public void setAfterMessageSuffix(String afterMessageSuffix) { public void setAfterMessageSuffix(String afterMessageSuffix) {
this.afterMessageSuffix = afterMessageSuffix; this.afterMessageSuffix = afterMessageSuffix;
@ -200,22 +210,21 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
throws ServletException, IOException { throws ServletException, IOException {
boolean isFirstRequest = !isAsyncDispatch(request); boolean isFirstRequest = !isAsyncDispatch(request);
HttpServletRequest requestToUse = request;
if (isIncludePayload()) { if (isIncludePayload() && isFirstRequest) {
if (isFirstRequest) { requestToUse = new RequestCachingRequestWrapper(request);
request = new RequestCachingRequestWrapper(request);
}
} }
if (isFirstRequest) { if (isFirstRequest) {
beforeRequest(request, getBeforeMessage(request)); beforeRequest(requestToUse, getBeforeMessage(requestToUse));
} }
try { try {
filterChain.doFilter(request, response); filterChain.doFilter(requestToUse, response);
} }
finally { finally {
if (!isAsyncStarted(request)) { if (!isAsyncStarted(requestToUse)) {
afterRequest(request, getAfterMessage(request)); afterRequest(requestToUse, getAfterMessage(requestToUse));
} }
} }
} }
@ -355,9 +364,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
} }
return ch; return ch;
} }
} }
} }
} }

Loading…
Cancel
Save