Polishing

This commit is contained in:
Juergen Hoeller 2017-02-16 14:20:40 +01:00
parent 7ed4884eaa
commit b0ef80c3ff
30 changed files with 203 additions and 238 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2017 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.
@ -1478,8 +1478,10 @@ public class BeanDefinitionParserDelegate {
/** /**
* Get the namespace URI for the supplied node. The default implementation uses {@link Node#getNamespaceURI}. * Get the namespace URI for the supplied node.
* Subclasses may override the default implementation to provide a different namespace identification mechanism. * <p>The default implementation uses {@link Node#getNamespaceURI}.
* Subclasses may override the default implementation to provide a
* different namespace identification mechanism.
* @param node the node * @param node the node
*/ */
public String getNamespaceURI(Node node) { public String getNamespaceURI(Node node) {
@ -1487,8 +1489,10 @@ public class BeanDefinitionParserDelegate {
} }
/** /**
* Ges the local name for the supplied {@link Node}. The default implementation calls {@link Node#getLocalName}. * Get the local name for the supplied {@link Node}.
* Subclasses may override the default implementation to provide a different mechanism for getting the local name. * <p>The default implementation calls {@link Node#getLocalName}.
* Subclasses may override the default implementation to provide a
* different mechanism for getting the local name.
* @param node the {@code Node} * @param node the {@code Node}
*/ */
public String getLocalName(Node node) { public String getLocalName(Node node) {

View File

@ -197,6 +197,20 @@ class ConfigurationClassParser {
processConfigurationClass(new ConfigurationClass(metadata, beanName)); processConfigurationClass(new ConfigurationClass(metadata, beanName));
} }
/**
* Validate each {@link ConfigurationClass} object.
* @see ConfigurationClass#validate
*/
public void validate() {
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
configClass.validate(this.problemReporter);
}
}
public Set<ConfigurationClass> getConfigurationClasses() {
return this.configurationClasses.keySet();
}
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException { protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) { if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
@ -390,6 +404,7 @@ class ConfigurationClassParser {
return beanMethods; return beanMethods;
} }
/** /**
* Process the given <code>@PropertySource</code> annotation metadata. * Process the given <code>@PropertySource</code> annotation metadata.
* @param propertySource metadata for the <code>@PropertySource</code> annotation found * @param propertySource metadata for the <code>@PropertySource</code> annotation found
@ -608,30 +623,15 @@ class ConfigurationClassParser {
return false; return false;
} }
/**
* Validate each {@link ConfigurationClass} object.
* @see ConfigurationClass#validate
*/
public void validate() {
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
configClass.validate(this.problemReporter);
}
}
public Set<ConfigurationClass> getConfigurationClasses() {
return this.configurationClasses.keySet();
}
ImportRegistry getImportRegistry() { ImportRegistry getImportRegistry() {
return this.importStack; return this.importStack;
} }
/** /**
* Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}. * Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
*/ */
public SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException { private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
AnnotationMetadata metadata = configurationClass.getMetadata(); AnnotationMetadata metadata = configurationClass.getMetadata();
if (metadata instanceof StandardAnnotationMetadata) { if (metadata instanceof StandardAnnotationMetadata) {
return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass()); return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
@ -642,7 +642,7 @@ class ConfigurationClassParser {
/** /**
* Factory method to obtain a {@link SourceClass} from a {@link Class}. * Factory method to obtain a {@link SourceClass} from a {@link Class}.
*/ */
public SourceClass asSourceClass(Class<?> classType) throws IOException { SourceClass asSourceClass(Class<?> classType) throws IOException {
try { try {
// Sanity test that we can read annotations, if not fall back to ASM // Sanity test that we can read annotations, if not fall back to ASM
classType.getAnnotations(); classType.getAnnotations();
@ -657,8 +657,8 @@ class ConfigurationClassParser {
/** /**
* Factory method to obtain {@link SourceClass}s from class names. * Factory method to obtain {@link SourceClass}s from class names.
*/ */
public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException { private Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>(); List<SourceClass> annotatedClasses = new ArrayList<SourceClass>(classNames.length);
for (String className : classNames) { for (String className : classNames) {
annotatedClasses.add(asSourceClass(className)); annotatedClasses.add(asSourceClass(className));
} }
@ -668,7 +668,7 @@ class ConfigurationClassParser {
/** /**
* Factory method to obtain a {@link SourceClass} from a class name. * Factory method to obtain a {@link SourceClass} from a class name.
*/ */
public SourceClass asSourceClass(String className) throws IOException { SourceClass asSourceClass(String className) throws IOException {
if (className.startsWith("java")) { if (className.startsWith("java")) {
// Never use ASM for core java types // Never use ASM for core java types
try { try {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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,7 +37,8 @@ import org.springframework.util.ClassUtils;
*/ */
public class GlassFishLoadTimeWeaver implements LoadTimeWeaver { public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME = "org.glassfish.api.deployment.InstrumentableClassLoader"; private static final String INSTRUMENTABLE_LOADER_CLASS_NAME =
"org.glassfish.api.deployment.InstrumentableClassLoader";
private final ClassLoader classLoader; private final ClassLoader classLoader;
@ -57,16 +58,10 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
Class<?> instrumentableLoaderClass; Class<?> instrumentableLoaderClass;
try { try {
instrumentableLoaderClass = classLoader.loadClass(INSTRUMENTABLE_LOADER_CLASS_NAME); instrumentableLoaderClass = classLoader.loadClass(INSTRUMENTABLE_LOADER_CLASS_NAME);
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException(
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
}
try {
this.addTransformerMethod = instrumentableLoaderClass.getMethod("addTransformer", ClassFileTransformer.class); this.addTransformerMethod = instrumentableLoaderClass.getMethod("addTransformer", ClassFileTransformer.class);
this.copyMethod = instrumentableLoaderClass.getMethod("copy"); this.copyMethod = instrumentableLoaderClass.getMethod("copy");
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException( throw new IllegalStateException(
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex); "Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
} }
@ -97,7 +92,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause()); throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex); throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex);
} }
} }
@ -115,7 +110,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause()); throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish copy method", ex); throw new IllegalStateException("Could not invoke GlassFish copy method", ex);
} }
} }

View File

@ -78,7 +78,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
this.translatorClass = classLoader.loadClass(TRANSLATOR_NAME); this.translatorClass = classLoader.loadClass(TRANSLATOR_NAME);
this.addTranslator = this.target.getClass().getMethod("addTranslator", this.translatorClass); this.addTranslator = this.target.getClass().getMethod("addTranslator", this.translatorClass);
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException( throw new IllegalStateException(
"Could not initialize JBoss LoadTimeWeaver because the JBoss 6 API classes are not available", ex); "Could not initialize JBoss LoadTimeWeaver because the JBoss 6 API classes are not available", ex);
} }
@ -92,7 +92,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
try { try {
this.addTranslator.invoke(this.target, adapterInstance); this.addTranslator.invoke(this.target, adapterInstance);
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not add transformer on JBoss 6 ClassLoader " + this.classLoader, ex); throw new IllegalStateException("Could not add transformer on JBoss 6 ClassLoader " + this.classLoader, ex);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -78,10 +78,7 @@ class JBossMCTranslatorAdapter implements InvocationHandler {
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(getClass().getName()); return getClass().getName() + " for transformer: " + this.transformer;
builder.append(" for transformer: ");
builder.append(this.transformer);
return builder.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -43,22 +43,32 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
private final Object delegatingTransformer; private final Object delegatingTransformer;
public JBossModulesAdapter(ClassLoader loader) { public JBossModulesAdapter(ClassLoader classLoader) {
this.classLoader = loader; this.classLoader = classLoader;
try { try {
Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer"); Field transformer = ReflectionUtils.findField(classLoader.getClass(), "transformer");
if (transformer == null) {
throw new IllegalArgumentException("Could not find 'transformer' field on JBoss ClassLoader: " +
classLoader.getClass().getName());
}
transformer.setAccessible(true); transformer.setAccessible(true);
this.delegatingTransformer = transformer.get(loader); this.delegatingTransformer = transformer.get(classLoader);
if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) { if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " + throw new IllegalStateException(
"Transformer not of the expected type DelegatingClassFileTransformer: " +
this.delegatingTransformer.getClass().getName()); this.delegatingTransformer.getClass().getName());
} }
this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(), this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
"addTransformer", ClassFileTransformer.class); "addTransformer", ClassFileTransformer.class);
if (this.addTransformer == null) {
throw new IllegalArgumentException(
"Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " +
this.delegatingTransformer.getClass().getName());
}
this.addTransformer.setAccessible(true); this.addTransformer.setAccessible(true);
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex); throw new IllegalStateException("Could not initialize JBoss LoadTimeWeaver", ex);
} }
} }
@ -67,7 +77,7 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
try { try {
this.addTransformer.invoke(this.delegatingTransformer, transformer); this.addTransformer.invoke(this.delegatingTransformer, transformer);
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not add transformer on JBoss 7 ClassLoader " + this.classLoader, ex); throw new IllegalStateException("Could not add transformer on JBoss 7 ClassLoader " + this.classLoader, ex);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -76,7 +76,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
} }
this.copyMethod = copyMethod; this.copyMethod = copyMethod;
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException( throw new IllegalStateException(
"Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available", ex); "Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available", ex);
} }
@ -91,7 +91,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause()); throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex); throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex);
} }
} }
@ -109,7 +109,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause()); throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat copy method", ex); throw new IllegalStateException("Could not invoke Tomcat copy method", ex);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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,7 +28,6 @@ import java.util.List;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
*
* Reflective wrapper around a WebSphere 7+ class loader. Used to * Reflective wrapper around a WebSphere 7+ class loader. Used to
* encapsulate the classloader-specific methods (discovered and * encapsulate the classloader-specific methods (discovered and
* called through reflection) from the load-time weaver. * called through reflection) from the load-time weaver.
@ -45,6 +44,7 @@ class WebSphereClassLoaderAdapter {
private static final String PLUGINS_FIELD = "preDefinePlugins"; private static final String PLUGINS_FIELD = "preDefinePlugins";
private ClassLoader classLoader; private ClassLoader classLoader;
private Class<?> wsPreProcessorClass; private Class<?> wsPreProcessorClass;
@ -68,13 +68,13 @@ class WebSphereClassLoaderAdapter {
this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD); this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD);
this.transformerList.setAccessible(true); this.transformerList.setAccessible(true);
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException( throw new IllegalStateException(
"Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex); "Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex);
} }
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) { if (!wsCompoundClassLoaderClass.isInstance(classLoader)) {
throw new IllegalArgumentException("ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]"); throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME);
} }
this.classLoader = classLoader; this.classLoader = classLoader;
} }
@ -95,7 +95,7 @@ class WebSphereClassLoaderAdapter {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause()); throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex); throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex);
} }
} }
@ -111,7 +111,7 @@ class WebSphereClassLoaderAdapter {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause()); throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex); throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.instrument.classloading.websphere; package org.springframework.instrument.classloading.websphere;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
@ -46,7 +47,7 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
this.transformer = transformer; this.transformer = transformer;
ClassLoader classLoader = transformer.getClass().getClassLoader(); ClassLoader classLoader = transformer.getClass().getClassLoader();
// first force the full class loading of the weaver by invoking transformation on a dummy class // First force the full class loading of the weaver by invoking transformation on a dummy class
try { try {
String dummyClass = Dummy.class.getName().replace('.', '/'); String dummyClass = Dummy.class.getName().replace('.', '/');
byte[] bytes = FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream(dummyClass + ".class")); byte[] bytes = FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream(dummyClass + ".class"));
@ -81,17 +82,14 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
protected byte[] transform(String className, byte[] classfileBuffer, CodeSource codeSource, ClassLoader classLoader) protected byte[] transform(String className, byte[] classfileBuffer, CodeSource codeSource, ClassLoader classLoader)
throws Exception { throws Exception {
// NB: WebSphere passes className as "." without class while the transformer expects a VM, "/" format // NB: WebSphere passes className as "." without class while the transformer expects a VM "/" format
byte[] result = transformer.transform(classLoader, className.replace('.', '/'), null, null, classfileBuffer); byte[] result = transformer.transform(classLoader, className.replace('.', '/'), null, null, classfileBuffer);
return (result != null ? result : classfileBuffer); return (result != null ? result : classfileBuffer);
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(getClass().getName()); return getClass().getName() + " for transformer: " + this.transformer;
builder.append(" for transformer: ");
builder.append(this.transformer);
return builder.toString();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -172,7 +172,7 @@ public class AnnotatedElementUtils {
*/ */
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationName) { public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return getMetaAnnotationTypes(element, AnnotationUtils.getAnnotation(element, annotationName)); return getMetaAnnotationTypes(element, AnnotationUtils.getAnnotation(element, annotationName));
} }
@ -232,7 +232,7 @@ public class AnnotatedElementUtils {
*/ */
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationName) { public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return hasMetaAnnotationTypes(element, null, annotationName); return hasMetaAnnotationTypes(element, null, annotationName);
} }
@ -290,7 +290,7 @@ public class AnnotatedElementUtils {
*/ */
public static boolean isAnnotated(AnnotatedElement element, String annotationName) { public static boolean isAnnotated(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return Boolean.TRUE.equals(searchWithGetSemantics(element, null, annotationName, alwaysTrueAnnotationProcessor)); return Boolean.TRUE.equals(searchWithGetSemantics(element, null, annotationName, alwaysTrueAnnotationProcessor));
} }
@ -391,7 +391,7 @@ public class AnnotatedElementUtils {
public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element,
String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) {
Assert.hasLength(annotationName, "annotationName must not be null or empty"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
AnnotationAttributes attributes = searchWithGetSemantics(element, null, annotationName, AnnotationAttributes attributes = searchWithGetSemantics(element, null, annotationName,
new MergedAnnotationAttributesProcessor(classValuesAsString, nestedAnnotationsAsMap)); new MergedAnnotationAttributesProcessor(classValuesAsString, nestedAnnotationsAsMap));
AnnotationUtils.postProcessAnnotationAttributes(element, attributes, classValuesAsString, nestedAnnotationsAsMap); AnnotationUtils.postProcessAnnotationAttributes(element, attributes, classValuesAsString, nestedAnnotationsAsMap);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -233,10 +233,7 @@ public class CallableStatementCreatorFactory {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "CallableStatementCreator: sql=[" + callString + "]; parameters=" + this.inParameters;
sb.append("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=[");
sb.append(callString).append("]; parameters=").append(this.inParameters);
return sb.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 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.
@ -306,10 +306,7 @@ public class PreparedStatementCreatorFactory {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "PreparedStatementCreator: sql=[" + sql + "]; parameters=" + this.parameters;
sb.append("PreparedStatementCreatorFactory.PreparedStatementCreatorImpl: sql=[");
sb.append(sql).append("]; parameters=").append(this.parameters);
return sb.toString();
} }
} }

View File

@ -45,8 +45,8 @@ public interface CallMetaDataProvider {
* This is only called for databases that are supported. This initialization * This is only called for databases that are supported. This initialization
* can be turned off by specifying that column meta data should not be used. * can be turned off by specifying that column meta data should not be used.
* @param databaseMetaData used to retrieve database specific information * @param databaseMetaData used to retrieve database specific information
* @param catalogName name of catalog to use or null * @param catalogName name of catalog to use (or {@code null} if none)
* @param schemaName name of schema name to use or null * @param schemaName name of schema name to use (or {@code null} if none)
* @param procedureName name of the stored procedure * @param procedureName name of the stored procedure
* @throws SQLException in case of initialization failure * @throws SQLException in case of initialization failure
* @see org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess() * @see org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess()

View File

@ -79,8 +79,8 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
/** /**
* Constructor used to initialize with provided database meta data. * Constructor used to initialize with provided database metadata.
* @param databaseMetaData meta data to be used * @param databaseMetaData metadata to be used
*/ */
protected GenericTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException { protected GenericTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
this.userName = databaseMetaData.getUserName(); this.userName = databaseMetaData.getUserName();
@ -308,7 +308,7 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
} }
/** /**
* Method supporting the metedata processing for a table. * Method supporting the metadata processing for a table.
*/ */
private void locateTableAndProcessMetaData( private void locateTableAndProcessMetaData(
DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) { DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -23,8 +23,8 @@ import java.util.List;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
/** /**
* Interface specifying the API to be implemented by a class providing table metedata. This is intended for internal use * Interface specifying the API to be implemented by a class providing table metadata.
* by the Simple JDBC classes. * This is intended for internal use by the Simple JDBC classes.
* *
* @author Thomas Risberg * @author Thomas Risberg
* @since 2.5 * @since 2.5
@ -32,45 +32,37 @@ import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
public interface TableMetaDataProvider { public interface TableMetaDataProvider {
/** /**
* Initialize using the database metedata provided * Initialize using the database metadata provided.
* @param databaseMetaData * @param databaseMetaData used to retrieve database specific information
* @throws SQLException * @throws SQLException in case of initialization failure
*/ */
void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException; void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException;
/** /**
* Initialize using provided database metadata, table and column information. This initalization can be * Initialize using provided database metadata, table and column information.
* turned off by specifying that column meta data should not be used. * This initialization can be turned off by specifying that column meta data should not be used.
* @param databaseMetaData used to retrieve database specific information * @param databaseMetaData used to retrieve database specific information
* @param catalogName name of catalog to use or null * @param catalogName name of catalog to use (or {@code null} if none)
* @param schemaName name of schema name to use or null * @param schemaName name of schema name to use (or {@code null} if none)
* @param tableName name of the table * @param tableName name of the table
* @throws SQLException * @throws SQLException in case of initialization failure
*/ */
void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) void initializeWithTableColumnMetaData(
DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName)
throws SQLException; throws SQLException;
/** /**
* Get the table name formatted based on metadata information. This could include altering the case. * Get the table name formatted based on metadata information. This could include altering the case.
*
* @param tableName
* @return table name formatted
*/ */
String tableNameToUse(String tableName); String tableNameToUse(String tableName);
/** /**
* Get the catalog name formatted based on metadata information. This could include altering the case. * Get the catalog name formatted based on metadata information. This could include altering the case.
*
* @param catalogName
* @return catalog name formatted
*/ */
String catalogNameToUse(String catalogName); String catalogNameToUse(String catalogName);
/** /**
* Get the schema name formatted based on metadata information. This could include altering the case. * Get the schema name formatted based on metadata information. This could include altering the case.
*
* @param schemaName
* @return schema name formatted
*/ */
String schemaNameToUse(String schemaName); String schemaNameToUse(String schemaName);
@ -78,9 +70,6 @@ public interface TableMetaDataProvider {
* Provide any modification of the catalog name passed in to match the meta data currently used. * Provide any modification of the catalog name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used or * The returned value will be used for meta data lookups. This could include altering the case used or
* providing a base catalog if none is provided. * providing a base catalog if none is provided.
*
* @param catalogName
* @return catalog name to use
*/ */
String metaDataCatalogNameToUse(String catalogName) ; String metaDataCatalogNameToUse(String catalogName) ;
@ -88,9 +77,6 @@ public interface TableMetaDataProvider {
* Provide any modification of the schema name passed in to match the meta data currently used. * Provide any modification of the schema name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used or * The returned value will be used for meta data lookups. This could include altering the case used or
* providing a base schema if none is provided. * providing a base schema if none is provided.
*
* @param schemaName
* @return schema name to use
*/ */
String metaDataSchemaNameToUse(String schemaName) ; String metaDataSchemaNameToUse(String schemaName) ;
@ -100,15 +86,15 @@ public interface TableMetaDataProvider {
boolean isTableColumnMetaDataUsed(); boolean isTableColumnMetaDataUsed();
/** /**
* Does this database support the JDBC 3.0 feature of retreiving generated keys * Does this database support the JDBC 3.0 feature of retrieving generated keys
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()} * {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
*/ */
boolean isGetGeneratedKeysSupported(); boolean isGetGeneratedKeysSupported();
/** /**
* Does this database support a simple quey to retrieve the generated key whe the JDBC 3.0 feature * Does this database support a simple query to retrieve the generated key when
* of retreiving generated keys is not supported * the JDBC 3.0 feature of retrieving generated keys is not supported?
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()} * @see #isGetGeneratedKeysSupported()
*/ */
boolean isGetGeneratedKeysSimulated(); boolean isGetGeneratedKeysSimulated();
@ -118,7 +104,7 @@ public interface TableMetaDataProvider {
String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName);
/** /**
* Does this database support a column name String array for retreiving generated keys * Does this database support a column name String array for retrieving generated keys
* {@link java.sql.Connection#createStruct(String, Object[])} * {@link java.sql.Connection#createStruct(String, Object[])}
*/ */
boolean isGeneratedKeysColumnNameArraySupported(); boolean isGeneratedKeysColumnNameArraySupported();
@ -133,4 +119,5 @@ public interface TableMetaDataProvider {
* Set the {@link NativeJdbcExtractor} to use to retrieve the native connection if necessary * Set the {@link NativeJdbcExtractor} to use to retrieve the native connection if necessary
*/ */
void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor); void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2017 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.
@ -42,9 +42,9 @@ public class TableMetaDataProviderFactory {
/** /**
* Create a TableMetaDataProvider based on the database metedata * Create a TableMetaDataProvider based on the database metadata.
* @param dataSource used to retrieve metedata * @param dataSource used to retrieve metadata
* @param context the class that holds configuration and metedata * @param context the class that holds configuration and metadata
* @return instance of the TableMetaDataProvider implementation to be used * @return instance of the TableMetaDataProvider implementation to be used
*/ */
public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) { public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) {
@ -52,9 +52,9 @@ public class TableMetaDataProviderFactory {
} }
/** /**
* Create a TableMetaDataProvider based on the database metedata * Create a TableMetaDataProvider based on the database metadata.
* @param dataSource used to retrieve metedata * @param dataSource used to retrieve metadata
* @param context the class that holds configuration and metedata * @param context the class that holds configuration and metadata
* @param nativeJdbcExtractor the NativeJdbcExtractor to be used * @param nativeJdbcExtractor the NativeJdbcExtractor to be used
* @return instance of the TableMetaDataProvider implementation to be used * @return instance of the TableMetaDataProvider implementation to be used
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -75,9 +75,8 @@ public interface SimpleJdbcInsertOperations {
/** /**
* Include synonyms for the column meta data lookups via JDBC. * Include synonyms for the column meta data lookups via JDBC.
* Note: this is only necessary to include for Oracle since other * <p>Note: This is only necessary to include for Oracle since other databases
* databases supporting synonyms seems to include the synonyms * supporting synonyms seems to include the synonyms automatically.
* automatically.
* @return the instance of this SimpleJdbcInsert * @return the instance of this SimpleJdbcInsert
*/ */
SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData(); SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData();
@ -85,7 +84,7 @@ public interface SimpleJdbcInsertOperations {
/** /**
* Use a the provided NativeJdbcExtractor during the column meta data * Use a the provided NativeJdbcExtractor during the column meta data
* lookups via JDBC. * lookups via JDBC.
* Note: this is only necessary to include when running with a connection pool * <p>Note: This is only necessary to include when running with a connection pool
* that wraps the meta data connection and when using a database like Oracle * that wraps the meta data connection and when using a database like Oracle
* where it is necessary to access the native connection to include synonyms. * where it is necessary to access the native connection to include synonyms.
* @return the instance of this SimpleJdbcInsert * @return the instance of this SimpleJdbcInsert

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -85,7 +85,7 @@ public class JdbcBeanDefinitionReader {
/** /**
* Set the JdbcTemplate to be used by this bean factory. * Set the JdbcTemplate to be used by this bean factory.
* Contains settings for DataSource, SQLExceptionTranslator, NativeJdbcExtractor, etc. * Contains settings for DataSource, SQLExceptionTranslator, etc.
*/ */
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null"); Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -26,7 +26,8 @@ import java.sql.Connection;
* native JDBC Connection such as Oracle's OracleConnection. Spring's * native JDBC Connection such as Oracle's OracleConnection. Spring's
* {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter} * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter}
* automatically detects such proxies before delegating to the actual * automatically detects such proxies before delegating to the actual
* unwrapping for a specific connection pool. * unwrapping for a specific connection pool. Alternatively, all such
* connections also support JDBC 4.0's {@link Connection#unwrap}.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.1 * @since 1.1

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -54,7 +54,7 @@ import org.springframework.core.Constants;
* without paying a performance penalty if no actual data access happens. * without paying a performance penalty if no actual data access happens.
* *
* <p>This DataSource proxy gives you behavior analogous to JTA and a * <p>This DataSource proxy gives you behavior analogous to JTA and a
* transactional JNDI DataSource (as provided by the J2EE server), even * transactional JNDI DataSource (as provided by the Java EE server), even
* with a local transaction strategy like DataSourceTransactionManager or * with a local transaction strategy like DataSourceTransactionManager or
* HibernateTransactionManager. It does not add value with Spring's * HibernateTransactionManager. It does not add value with Spring's
* JtaTransactionManager as transaction strategy. * JtaTransactionManager as transaction strategy.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -39,9 +39,6 @@ import org.springframework.util.ObjectUtils;
* <p>If client code will call {@code close()} in the assumption of a pooled * <p>If client code will call {@code close()} in the assumption of a pooled
* Connection, like when using persistence tools, set "suppressClose" to "true". * Connection, like when using persistence tools, set "suppressClose" to "true".
* This will return a close-suppressing proxy instead of the physical Connection. * This will return a close-suppressing proxy instead of the physical Connection.
* Be aware that you will not be able to cast this to a native
* {@code OracleConnection} or the like anymore; you need to use a
* {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor} then.
* *
* <p>This is primarily intended for testing. For example, it enables easy testing * <p>This is primarily intended for testing. For example, it enables easy testing
* outside an application server, for code that expects to work on a DataSource. * outside an application server, for code that expects to work on a DataSource.
@ -53,10 +50,8 @@ import org.springframework.util.ObjectUtils;
* @see #getConnection() * @see #getConnection()
* @see java.sql.Connection#close() * @see java.sql.Connection#close()
* @see DataSourceUtils#releaseConnection * @see DataSourceUtils#releaseConnection
* @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
*/ */
public class SingleConnectionDataSource extends DriverManagerDataSource public class SingleConnectionDataSource extends DriverManagerDataSource implements SmartDataSource, DisposableBean {
implements SmartDataSource, DisposableBean {
/** Create a close-suppressing proxy? */ /** Create a close-suppressing proxy? */
private boolean suppressClose; private boolean suppressClose;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 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.
@ -31,7 +31,7 @@ import org.springframework.util.Assert;
/** /**
* Proxy for a target JDBC {@link javax.sql.DataSource}, adding awareness of * Proxy for a target JDBC {@link javax.sql.DataSource}, adding awareness of
* Spring-managed transactions. Similar to a transactional JNDI DataSource * Spring-managed transactions. Similar to a transactional JNDI DataSource
* as provided by a J2EE server. * as provided by a Java EE server.
* *
* <p>Data access code that should remain unaware of Spring's data access support * <p>Data access code that should remain unaware of Spring's data access support
* can work with this proxy to seamlessly participate in Spring-managed transactions. * can work with this proxy to seamlessly participate in Spring-managed transactions.
@ -51,7 +51,7 @@ import org.springframework.util.Assert;
* Connection. If not within a transaction, normal DataSource behavior applies. * Connection. If not within a transaction, normal DataSource behavior applies.
* *
* <p>This proxy allows data access code to work with the plain JDBC API and still * <p>This proxy allows data access code to work with the plain JDBC API and still
* participate in Spring-managed transactions, similar to JDBC code in a J2EE/JTA * participate in Spring-managed transactions, similar to JDBC code in a Java EE/JTA
* environment. However, if possible, use Spring's DataSourceUtils, JdbcTemplate or * environment. However, if possible, use Spring's DataSourceUtils, JdbcTemplate or
* JDBC operation objects to get transaction participation even without a proxy for * JDBC operation objects to get transaction participation even without a proxy for
* the target DataSource, avoiding the need to define such a proxy in the first place. * the target DataSource, avoiding the need to define such a proxy in the first place.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -95,12 +95,12 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
Class<?> wsrraFactoryClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSRRAFactory"); Class<?> wsrraFactoryClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSRRAFactory");
this.newJdbcConnSpecMethod = wsrraFactoryClass.getMethod("createJDBCConnectionSpec", (Class<?>[]) null); this.newJdbcConnSpecMethod = wsrraFactoryClass.getMethod("createJDBCConnectionSpec", (Class<?>[]) null);
this.wsDataSourceGetConnectionMethod = this.wsDataSourceGetConnectionMethod =
this.wsDataSourceClass.getMethod("getConnection", new Class<?>[] {jdbcConnSpecClass}); this.wsDataSourceClass.getMethod("getConnection", jdbcConnSpecClass);
this.setTransactionIsolationMethod = this.setTransactionIsolationMethod =
jdbcConnSpecClass.getMethod("setTransactionIsolation", new Class<?>[] {int.class}); jdbcConnSpecClass.getMethod("setTransactionIsolation", int.class);
this.setReadOnlyMethod = jdbcConnSpecClass.getMethod("setReadOnly", new Class<?>[] {Boolean.class}); this.setReadOnlyMethod = jdbcConnSpecClass.getMethod("setReadOnly", Boolean.class);
this.setUserNameMethod = jdbcConnSpecClass.getMethod("setUserName", new Class<?>[] {String.class}); this.setUserNameMethod = jdbcConnSpecClass.getMethod("setUserName", String.class);
this.setPasswordMethod = jdbcConnSpecClass.getMethod("setPassword", new Class<?>[] {String.class}); this.setPasswordMethod = jdbcConnSpecClass.getMethod("setPassword", String.class);
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException( throw new IllegalStateException(
@ -144,7 +144,7 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
} }
/** /**
* Create a WebSphere {@code JDBCConnectionSpec} object for the given charateristics. * Create a WebSphere {@code JDBCConnectionSpec} object for the given characteristics.
* <p>The default implementation uses reflection to apply the given settings. * <p>The default implementation uses reflection to apply the given settings.
* Can be overridden in subclasses to customize the JDBCConnectionSpec object * Can be overridden in subclasses to customize the JDBCConnectionSpec object
* (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>; * (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>;

View File

@ -422,7 +422,7 @@ public abstract class JdbcUtils {
/** /**
* Extract a common name for the database in use even if various drivers/platforms provide varying names. * Extract a common name for the database in use even if various drivers/platforms provide varying names.
* @param source the name as provided in database metedata * @param source the name as provided in database metadata
* @return the common name to be used * @return the common name to be used
*/ */
public static String commonDatabaseName(String source) { public static String commonDatabaseName(String source) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 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.
@ -143,10 +143,9 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithStaticSql() throws Exception { public void testStringsWithStaticSql() throws Exception {
doTestStrings(false, null, null, null, null, new JdbcTemplateCallback() { doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, rch); template.query(sql, rch);
} }
}); });
@ -154,10 +153,9 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception { public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception {
doTestStrings(false, 10, 20, 30, null, new JdbcTemplateCallback() { doTestStrings(10, 20, 30, null, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, rch); template.query(sql, rch);
} }
}); });
@ -165,10 +163,9 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithEmptyPreparedStatementSetter() throws Exception { public void testStringsWithEmptyPreparedStatementSetter() throws Exception {
doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() { doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, (PreparedStatementSetter) null, rch); template.query(sql, (PreparedStatementSetter) null, rch);
} }
}); });
@ -177,10 +174,9 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithPreparedStatementSetter() throws Exception { public void testStringsWithPreparedStatementSetter() throws Exception {
final Integer argument = 99; final Integer argument = 99;
doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() { doTestStrings(null, null, null, argument, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, new PreparedStatementSetter() { template.query(sql, new PreparedStatementSetter() {
@Override @Override
public void setValues(PreparedStatement ps) throws SQLException { public void setValues(PreparedStatement ps) throws SQLException {
@ -193,10 +189,9 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithEmptyPreparedStatementArgs() throws Exception { public void testStringsWithEmptyPreparedStatementArgs() throws Exception {
doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() { doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, (Object[]) null, rch); template.query(sql, (Object[]) null, rch);
} }
}); });
@ -205,26 +200,22 @@ public class JdbcTemplateTests {
@Test @Test
public void testStringsWithPreparedStatementArgs() throws Exception { public void testStringsWithPreparedStatementArgs() throws Exception {
final Integer argument = 99; final Integer argument = 99;
doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() { doTestStrings(null, null, null, argument, new JdbcTemplateCallback() {
@Override @Override
public void doInJdbcTemplate(JdbcTemplate template, String sql, public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
RowCallbackHandler rch) {
template.query(sql, new Object[] { argument }, rch); template.query(sql, new Object[] { argument }, rch);
} }
}); });
} }
private void doTestStrings( private void doTestStrings(Integer fetchSize, Integer maxRows, Integer queryTimeout,
boolean usePreparedStatement, Object argument, JdbcTemplateCallback jdbcTemplateCallback) throws Exception {
Integer fetchSize, Integer maxRows, Integer queryTimeout, Object argument,
JdbcTemplateCallback jdbcTemplateCallback)
throws Exception {
String sql = "SELECT FORENAME FROM CUSTMR"; String sql = "SELECT FORENAME FROM CUSTMR";
String[] results = { "rod", "gary", " portia" }; String[] results = { "rod", "gary", " portia" };
class StringHandler implements RowCallbackHandler { class StringHandler implements RowCallbackHandler {
private List<String> list = new LinkedList<String>(); private List<String> list = new LinkedList<>();
@Override @Override
public void processRow(ResultSet rs) throws SQLException { public void processRow(ResultSet rs) throws SQLException {
this.list.add(rs.getString(1)); this.list.add(rs.getString(1));
@ -740,9 +731,8 @@ public class JdbcTemplateTests {
@Test @Test
public void testBatchUpdateWithListOfObjectArrays() throws Exception { public void testBatchUpdateWithListOfObjectArrays() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
final List<Object[]> ids = new ArrayList<Object[]>(); final List<Object[]> ids = new ArrayList<>();
ids.add(new Object[] {100}); ids.add(new Object[] {100});
ids.add(new Object[] {200}); ids.add(new Object[] {200});
final int[] rowsAffected = new int[] { 1, 2 }; final int[] rowsAffected = new int[] { 1, 2 };
@ -768,7 +758,7 @@ public class JdbcTemplateTests {
@Test @Test
public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception { public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
final List<Object[]> ids = new ArrayList<Object[]>(); final List<Object[]> ids = new ArrayList<>();
ids.add(new Object[] {100}); ids.add(new Object[] {100});
ids.add(new Object[] {200}); ids.add(new Object[] {200});
final int[] sqlTypes = new int[] {Types.NUMERIC}; final int[] sqlTypes = new int[] {Types.NUMERIC};
@ -851,13 +841,15 @@ public class JdbcTemplateTests {
@Test @Test
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty()
throws Exception { throws SQLException {
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(true); doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(true);
} }
@Test @Test
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet()
throws Exception { throws SQLException {
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(false); doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(false);
} }
@ -867,6 +859,7 @@ public class JdbcTemplateTests {
*/ */
private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty) private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty)
throws SQLException { throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx"); SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class); this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException); given(this.dataSource.getConnection()).willThrow(sqlException);
@ -1098,7 +1091,6 @@ public class JdbcTemplateTests {
@Test @Test
public void testNativeJdbcExtractorInvoked() throws Exception { public void testNativeJdbcExtractorInvoked() throws Exception {
final Statement statement2 = mock(Statement.class); final Statement statement2 = mock(Statement.class);
given(statement2.executeQuery(anyString())).willReturn(this.resultSet); given(statement2.executeQuery(anyString())).willReturn(this.resultSet);
@ -1246,7 +1238,7 @@ public class JdbcTemplateTests {
given(this.callableStatement.execute()).willReturn(true); given(this.callableStatement.execute()).willReturn(true);
given(this.callableStatement.getUpdateCount()).willReturn(-1); given(this.callableStatement.getUpdateCount()).willReturn(-1);
List<SqlParameter> params = new ArrayList<SqlParameter>(); List<SqlParameter> params = new ArrayList<>();
params.add(new SqlReturnResultSet("", new RowCallbackHandler() { params.add(new SqlReturnResultSet("", new RowCallbackHandler() {
@Override @Override
public void processRow(ResultSet rs) { public void processRow(ResultSet rs) {
@ -1286,7 +1278,7 @@ public class JdbcTemplateTests {
assertTrue("now it should have been set to case insensitive", assertTrue("now it should have been set to case insensitive",
this.template.isResultsMapCaseInsensitive()); this.template.isResultsMapCaseInsensitive());
List<SqlParameter> params = new ArrayList<SqlParameter>(); List<SqlParameter> params = new ArrayList<>();
params.add(new SqlOutParameter("a", 12)); params.add(new SqlOutParameter("a", 12));
Map<String, Object> out = this.template.call(new CallableStatementCreator() { Map<String, Object> out = this.template.call(new CallableStatementCreator() {
@ -1311,6 +1303,7 @@ public class JdbcTemplateTests {
given(this.connection.getMetaData()).willReturn(databaseMetaData); given(this.connection.getMetaData()).willReturn(databaseMetaData);
} }
private static class PlainNativeJdbcExtractor extends NativeJdbcExtractorAdapter { private static class PlainNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
@Override @Override
@ -1320,7 +1313,7 @@ public class JdbcTemplateTests {
} }
private static interface JdbcTemplateCallback { private interface JdbcTemplateCallback {
void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch); void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch);
} }
@ -1329,6 +1322,7 @@ public class JdbcTemplateTests {
private static class Dispatcher implements PreparedStatementCreator, SqlProvider { private static class Dispatcher implements PreparedStatementCreator, SqlProvider {
private int id; private int id;
private String sql; private String sql;
public Dispatcher(int id, String sql) { public Dispatcher(int id, String sql) {
@ -1348,4 +1342,5 @@ public class JdbcTemplateTests {
return this.sql; return this.sql;
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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,7 @@ import org.springframework.util.Assert;
* @see org.springframework.aop.framework.AopProxyUtils * @see org.springframework.aop.framework.AopProxyUtils
* @see ReflectionTestUtils * @see ReflectionTestUtils
*/ */
public class AopTestUtils { public abstract class AopTestUtils {
/** /**
* Get the <em>target</em> object of the supplied {@code candidate} object. * Get the <em>target</em> object of the supplied {@code candidate} object.
@ -42,22 +42,22 @@ public class AopTestUtils {
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will * {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
* be returned; otherwise, the {@code candidate} will be returned * be returned; otherwise, the {@code candidate} will be returned
* <em>as is</em>. * <em>as is</em>.
* @param candidate the instance to check (potentially a Spring AOP proxy); * @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null} * never {@code null})
* @return the target object or the {@code candidate}; never {@code null} * @return the target object or the {@code candidate} (never {@code null})
* @throws IllegalStateException if an error occurs while unwrapping a proxy * @throws IllegalStateException if an error occurs while unwrapping a proxy
* @see Advised#getTargetSource() * @see Advised#getTargetSource()
* @see #getUltimateTargetObject * @see #getUltimateTargetObject
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getTargetObject(Object candidate) { public static <T> T getTargetObject(Object candidate) {
Assert.notNull(candidate, "candidate must not be null"); Assert.notNull(candidate, "Candidate must not be null");
try { try {
if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) ((Advised) candidate).getTargetSource().getTarget(); return (T) ((Advised) candidate).getTargetSource().getTarget();
} }
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Failed to unwrap proxied object", ex); throw new IllegalStateException("Failed to unwrap proxied object", ex);
} }
return (T) candidate; return (T) candidate;
@ -71,23 +71,22 @@ public class AopTestUtils {
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all * {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
* nested proxies will be returned; otherwise, the {@code candidate} * nested proxies will be returned; otherwise, the {@code candidate}
* will be returned <em>as is</em>. * will be returned <em>as is</em>.
* @param candidate the instance to check (potentially a Spring AOP proxy); * @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null} * never {@code null})
* @return the ultimate target object or the {@code candidate}; never * @return the target object or the {@code candidate} (never {@code null})
* {@code null}
* @throws IllegalStateException if an error occurs while unwrapping a proxy * @throws IllegalStateException if an error occurs while unwrapping a proxy
* @see Advised#getTargetSource() * @see Advised#getTargetSource()
* @see org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass * @see org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getUltimateTargetObject(Object candidate) { public static <T> T getUltimateTargetObject(Object candidate) {
Assert.notNull(candidate, "candidate must not be null"); Assert.notNull(candidate, "Candidate must not be null");
try { try {
if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget()); return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
} }
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Failed to unwrap proxied object", ex); throw new IllegalStateException("Failed to unwrap proxied object", ex);
} }
return (T) candidate; return (T) candidate;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -50,9 +50,9 @@ import org.springframework.http.HttpStatus;
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Sam Brannen * @author Sam Brannen
* @since 3.0
* @see org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver * @see org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
* @see javax.servlet.http.HttpServletResponse#sendError(int, String) * @see javax.servlet.http.HttpServletResponse#sendError(int, String)
* @since 3.0
*/ */
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -47,10 +47,10 @@ import org.springframework.web.servlet.support.RequestContextUtils;
* <li>{@link Principal} * <li>{@link Principal}
* <li>{@link InputStream} * <li>{@link InputStream}
* <li>{@link Reader} * <li>{@link Reader}
* <li>{@link HttpMethod} (as of Spring 4.0)</li> * <li>{@link HttpMethod} (as of Spring 4.0)
* <li>{@link Locale} * <li>{@link Locale}
* <li>{@link TimeZone} (as of Spring 4.0) * <li>{@link TimeZone} (as of Spring 4.0)
* <li>{@link java.time.ZoneId} (as of Spring 4.0 and Java 8)</li> * <li>{@link java.time.ZoneId} (as of Spring 4.0 and Java 8)
* </ul> * </ul>
* *
* @author Arjen Poutsma * @author Arjen Poutsma

View File

@ -75,11 +75,9 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void servletRequest() throws Exception { public void servletRequest() throws Exception {
MethodParameter servletRequestParameter = new MethodParameter(method, 0); MethodParameter servletRequestParameter = new MethodParameter(method, 0);
assertTrue("ServletRequest not supported", resolver.supportsParameter(servletRequestParameter));
boolean isSupported = resolver.supportsParameter(servletRequestParameter);
Object result = resolver.resolveArgument(servletRequestParameter, mavContainer, webRequest, null); Object result = resolver.resolveArgument(servletRequestParameter, mavContainer, webRequest, null);
assertTrue("ServletRequest not supported", isSupported);
assertSame("Invalid result", servletRequest, result); assertSame("Invalid result", servletRequest, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled()); assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
} }
@ -88,12 +86,11 @@ public class ServletRequestMethodArgumentResolverTests {
public void session() throws Exception { public void session() throws Exception {
MockHttpSession session = new MockHttpSession(); MockHttpSession session = new MockHttpSession();
servletRequest.setSession(session); servletRequest.setSession(session);
MethodParameter sessionParameter = new MethodParameter(method, 2); MethodParameter sessionParameter = new MethodParameter(method, 2);
assertTrue("Session not supported", resolver.supportsParameter(sessionParameter));
boolean isSupported = resolver.supportsParameter(sessionParameter);
Object result = resolver.resolveArgument(sessionParameter, mavContainer, webRequest, null); Object result = resolver.resolveArgument(sessionParameter, mavContainer, webRequest, null);
assertTrue("Session not supported", isSupported);
assertSame("Invalid result", session, result); assertSame("Invalid result", session, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled()); assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
} }
@ -107,8 +104,8 @@ public class ServletRequestMethodArgumentResolverTests {
} }
}; };
servletRequest.setUserPrincipal(principal); servletRequest.setUserPrincipal(principal);
MethodParameter principalParameter = new MethodParameter(method, 3);
MethodParameter principalParameter = new MethodParameter(method, 3);
assertTrue("Principal not supported", resolver.supportsParameter(principalParameter)); assertTrue("Principal not supported", resolver.supportsParameter(principalParameter));
Object result = resolver.resolveArgument(principalParameter, null, webRequest, null); Object result = resolver.resolveArgument(principalParameter, null, webRequest, null);
@ -119,8 +116,8 @@ public class ServletRequestMethodArgumentResolverTests {
public void locale() throws Exception { public void locale() throws Exception {
Locale locale = Locale.ENGLISH; Locale locale = Locale.ENGLISH;
servletRequest.addPreferredLocale(locale); servletRequest.addPreferredLocale(locale);
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter)); assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null); Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@ -132,8 +129,8 @@ public class ServletRequestMethodArgumentResolverTests {
Locale locale = Locale.ENGLISH; Locale locale = Locale.ENGLISH;
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(locale)); new FixedLocaleResolver(locale));
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter)); assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null); Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@ -143,7 +140,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void timeZone() throws Exception { public void timeZone() throws Exception {
MethodParameter timeZoneParameter = new MethodParameter(method, 8); MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter)); assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null); Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@ -155,8 +151,8 @@ public class ServletRequestMethodArgumentResolverTests {
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles"); TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(Locale.US, timeZone)); new FixedLocaleResolver(Locale.US, timeZone));
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter)); assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null); Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@ -166,7 +162,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void zoneId() throws Exception { public void zoneId() throws Exception {
MethodParameter zoneIdParameter = new MethodParameter(method, 9); MethodParameter zoneIdParameter = new MethodParameter(method, 9);
assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter)); assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter));
Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null); Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null);
@ -189,7 +184,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void inputStream() throws Exception { public void inputStream() throws Exception {
MethodParameter inputStreamParameter = new MethodParameter(method, 5); MethodParameter inputStreamParameter = new MethodParameter(method, 5);
assertTrue("InputStream not supported", resolver.supportsParameter(inputStreamParameter)); assertTrue("InputStream not supported", resolver.supportsParameter(inputStreamParameter));
Object result = resolver.resolveArgument(inputStreamParameter, null, webRequest, null); Object result = resolver.resolveArgument(inputStreamParameter, null, webRequest, null);
@ -199,7 +193,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void reader() throws Exception { public void reader() throws Exception {
MethodParameter readerParameter = new MethodParameter(method, 6); MethodParameter readerParameter = new MethodParameter(method, 6);
assertTrue("Reader not supported", resolver.supportsParameter(readerParameter)); assertTrue("Reader not supported", resolver.supportsParameter(readerParameter));
Object result = resolver.resolveArgument(readerParameter, null, webRequest, null); Object result = resolver.resolveArgument(readerParameter, null, webRequest, null);
@ -209,7 +202,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void webRequest() throws Exception { public void webRequest() throws Exception {
MethodParameter webRequestParameter = new MethodParameter(method, 7); MethodParameter webRequestParameter = new MethodParameter(method, 7);
assertTrue("WebRequest not supported", resolver.supportsParameter(webRequestParameter)); assertTrue("WebRequest not supported", resolver.supportsParameter(webRequestParameter));
Object result = resolver.resolveArgument(webRequestParameter, null, webRequest, null); Object result = resolver.resolveArgument(webRequestParameter, null, webRequest, null);
@ -219,7 +211,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test @Test
public void httpMethod() throws Exception { public void httpMethod() throws Exception {
MethodParameter httpMethodParameter = new MethodParameter(method, 10); MethodParameter httpMethodParameter = new MethodParameter(method, 10);
assertTrue("HttpMethod not supported", resolver.supportsParameter(httpMethodParameter)); assertTrue("HttpMethod not supported", resolver.supportsParameter(httpMethodParameter));
Object result = resolver.resolveArgument(httpMethodParameter, null, webRequest, null); Object result = resolver.resolveArgument(httpMethodParameter, null, webRequest, null);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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,7 +33,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* Test fixture with {@link org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver}. * Test fixture with {@link ServletResponseMethodArgumentResolver}.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
*/ */
@ -49,6 +49,7 @@ public class ServletResponseMethodArgumentResolverTests {
private MockHttpServletResponse servletResponse; private MockHttpServletResponse servletResponse;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
resolver = new ServletResponseMethodArgumentResolver(); resolver = new ServletResponseMethodArgumentResolver();
@ -58,10 +59,10 @@ public class ServletResponseMethodArgumentResolverTests {
webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse); webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse);
} }
@Test @Test
public void servletResponse() throws Exception { public void servletResponse() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0); MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter)); assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null); Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null);
@ -69,8 +70,7 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled()); assertTrue(mavContainer.isRequestHandled());
} }
// SPR-8983 @Test // SPR-8983
public void servletResponseNoMavContainer() throws Exception { public void servletResponseNoMavContainer() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0); MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter)); assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
@ -82,7 +82,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test @Test
public void outputStream() throws Exception { public void outputStream() throws Exception {
MethodParameter outputStreamParameter = new MethodParameter(method, 1); MethodParameter outputStreamParameter = new MethodParameter(method, 1);
assertTrue("OutputStream not supported", resolver.supportsParameter(outputStreamParameter)); assertTrue("OutputStream not supported", resolver.supportsParameter(outputStreamParameter));
Object result = resolver.resolveArgument(outputStreamParameter, mavContainer, webRequest, null); Object result = resolver.resolveArgument(outputStreamParameter, mavContainer, webRequest, null);
@ -93,7 +92,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test @Test
public void writer() throws Exception { public void writer() throws Exception {
MethodParameter writerParameter = new MethodParameter(method, 2); MethodParameter writerParameter = new MethodParameter(method, 2);
assertTrue("Writer not supported", resolver.supportsParameter(writerParameter)); assertTrue("Writer not supported", resolver.supportsParameter(writerParameter));
Object result = resolver.resolveArgument(writerParameter, mavContainer, webRequest, null); Object result = resolver.resolveArgument(writerParameter, mavContainer, webRequest, null);
@ -101,7 +99,9 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled()); assertTrue(mavContainer.isRequestHandled());
} }
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
@SuppressWarnings("unused")
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
} }
} }