Avoid defensive checks against Java 8 API (java.util.Optional etc)
This commit also fixes broken javadoc links and code references. Issue: SPR-13188
This commit is contained in:
parent
adb935db79
commit
51252ebbca
|
|
@ -190,14 +190,13 @@ configure(allprojects) { project ->
|
|||
"http://docs.jboss.org/jbossas/javadoc/4.0.5/connector/",
|
||||
"http://docs.jboss.org/jbossas/javadoc/7.1.2.Final/",
|
||||
"http://commons.apache.org/proper/commons-lang/javadocs/api-2.5/",
|
||||
"http://commons.apache.org/proper/commons-codec/apidocs/",
|
||||
"http://commons.apache.org/proper/commons-dbcp/apidocs/",
|
||||
"http://tiles.apache.org/tiles-request/apidocs/",
|
||||
"http://tiles.apache.org/framework/apidocs/",
|
||||
"http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/",
|
||||
"http://ehcache.org/apidocs/${ehcacheVersion}",
|
||||
"http://ehcache.org/apidocs/${ehcache3Version}",
|
||||
"http://quartz-scheduler.org/api/2.2.0/",
|
||||
"http://quartz-scheduler.org/api/2.2.1/",
|
||||
"http://fasterxml.github.io/jackson-core/javadoc/2.7/",
|
||||
"http://fasterxml.github.io/jackson-databind/javadoc/2.7/",
|
||||
"http://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.7/",
|
||||
|
|
@ -347,7 +346,6 @@ project("spring-core") {
|
|||
compile(files(cglibRepackJar))
|
||||
compile(files(objenesisRepackJar))
|
||||
compile("commons-logging:commons-logging:1.2")
|
||||
optional("commons-codec:commons-codec:1.10")
|
||||
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||
optional("net.sf.jopt-simple:jopt-simple:5.0.2")
|
||||
optional("log4j:log4j:${log4jVersion}")
|
||||
|
|
@ -1116,6 +1114,8 @@ configure(rootProject) {
|
|||
|
||||
doFirst {
|
||||
classpath = files(
|
||||
// ensure Servlet 3.x has precedence on the javadoc classpath
|
||||
project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" },
|
||||
// ensure the javadoc process can resolve types compiled from .aj sources
|
||||
project(":spring-aspects").sourceSets.main.output
|
||||
)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public interface MethodInterceptor extends Interceptor {
|
|||
* after the invocation. Polite implementations would certainly
|
||||
* like to invoke {@link Joinpoint#proceed()}.
|
||||
* @param invocation the method invocation joinpoint
|
||||
* @return the result of the call to {@link Joinpoint#proceed();
|
||||
* @return the result of the call to {@link Joinpoint#proceed()};
|
||||
* might be intercepted by the interceptor
|
||||
* @throws Throwable if the interceptors or the target object
|
||||
* throws an exception
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ import org.springframework.core.task.AsyncListenableTaskExecutor;
|
|||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.core.task.support.TaskExecutorAdapter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
|
@ -70,11 +68,6 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME = "taskExecutor";
|
||||
|
||||
|
||||
// Java 8's CompletableFuture type present?
|
||||
private static final boolean completableFuturePresent = ClassUtils.isPresent(
|
||||
"java.util.concurrent.CompletableFuture", AsyncExecutionInterceptor.class.getClassLoader());
|
||||
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final Map<Method, AsyncTaskExecutor> executors = new ConcurrentHashMap<Method, AsyncTaskExecutor>(16);
|
||||
|
|
@ -257,13 +250,20 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
* @return the execution result (potentially a corresponding {@link Future} handle)
|
||||
*/
|
||||
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
|
||||
if (completableFuturePresent) {
|
||||
Future<Object> result = CompletableFutureDelegate.processCompletableFuture(returnType, task, executor);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
if (CompletableFuture.class.isAssignableFrom(returnType)) {
|
||||
return CompletableFuture.supplyAsync(new Supplier<Object>() {
|
||||
@Override
|
||||
public Object get() {
|
||||
try {
|
||||
return task.call();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
if (ListenableFuture.class.isAssignableFrom(returnType)) {
|
||||
else if (ListenableFuture.class.isAssignableFrom(returnType)) {
|
||||
return ((AsyncListenableTaskExecutor) executor).submitListenable(task);
|
||||
}
|
||||
else if (Future.class.isAssignableFrom(returnType)) {
|
||||
|
|
@ -303,29 +303,4 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Java 8.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class CompletableFutureDelegate {
|
||||
|
||||
public static <T> Future<T> processCompletableFuture(Class<?> returnType, final Callable<T> task, Executor executor) {
|
||||
if (!CompletableFuture.class.isAssignableFrom(returnType)) {
|
||||
return null;
|
||||
}
|
||||
return CompletableFuture.supplyAsync(new Supplier<T>() {
|
||||
@Override
|
||||
public T get() {
|
||||
try {
|
||||
return task.call();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,7 @@ import org.springframework.core.ResolvableType;
|
|||
import org.springframework.core.convert.ConversionException;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
|
@ -75,19 +73,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
*/
|
||||
private static final Log logger = LogFactory.getLog(AbstractNestablePropertyAccessor.class);
|
||||
|
||||
private static Class<?> javaUtilOptionalClass = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
javaUtilOptionalClass =
|
||||
ClassUtils.forName("java.util.Optional", AbstractNestablePropertyAccessor.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Java 8 not available - Optional references simply not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int autoGrowCollectionLimit = Integer.MAX_VALUE;
|
||||
|
||||
Object wrappedObject;
|
||||
|
|
@ -202,13 +187,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
* @param rootObject the root object at the top of the path
|
||||
*/
|
||||
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
|
||||
Assert.notNull(object, "Target object must not be null");
|
||||
if (object.getClass() == javaUtilOptionalClass) {
|
||||
this.wrappedObject = OptionalUnwrapper.unwrap(object);
|
||||
}
|
||||
else {
|
||||
this.wrappedObject = object;
|
||||
}
|
||||
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
||||
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||
this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.wrappedObject);
|
||||
this.nestedPropertyAccessors = null;
|
||||
|
|
@ -834,7 +814,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
PropertyTokenHolder tokens = getPropertyNameTokens(nestedProperty);
|
||||
String canonicalName = tokens.canonicalName;
|
||||
Object value = getPropertyValue(tokens);
|
||||
if (value == null || (value.getClass() == javaUtilOptionalClass && OptionalUnwrapper.isEmpty(value))) {
|
||||
if (value == null || (value instanceof Optional && !((Optional) value).isPresent())) {
|
||||
if (isAutoGrowNestedPaths()) {
|
||||
value = setDefaultValue(tokens);
|
||||
}
|
||||
|
|
@ -845,8 +825,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
|
||||
// Lookup cached sub-PropertyAccessor, create new one if not found.
|
||||
AbstractNestablePropertyAccessor nestedPa = this.nestedPropertyAccessors.get(canonicalName);
|
||||
if (nestedPa == null || nestedPa.getWrappedInstance() !=
|
||||
(value.getClass() == javaUtilOptionalClass ? OptionalUnwrapper.unwrap(value) : value)) {
|
||||
if (nestedPa == null || nestedPa.getWrappedInstance() != ObjectUtils.unwrapOptional(value)) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Creating new nested " + getClass().getSimpleName() + " for property '" + canonicalName + "'");
|
||||
}
|
||||
|
|
@ -1037,24 +1016,4 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
public String[] keys;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Java 8.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class OptionalUnwrapper {
|
||||
|
||||
public static Object unwrap(Object optionalObject) {
|
||||
Optional<?> optional = (Optional<?>) optionalObject;
|
||||
Assert.isTrue(optional.isPresent(), "Optional value must be present");
|
||||
Object result = optional.get();
|
||||
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(Object optionalObject) {
|
||||
return !((Optional<?>) optionalObject).isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.lang.reflect.Modifier;
|
|||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
|
@ -54,20 +55,6 @@ class TypeConverterDelegate {
|
|||
|
||||
private static final Log logger = LogFactory.getLog(TypeConverterDelegate.class);
|
||||
|
||||
/** Java 8's java.util.Optional.empty() instance */
|
||||
private static Object javaUtilOptionalEmpty = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> clazz = ClassUtils.forName("java.util.Optional", TypeConverterDelegate.class.getClassLoader());
|
||||
javaUtilOptionalEmpty = ClassUtils.getMethod(clazz, "empty").invoke(null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Java 8 not available - conversion to Optional not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final PropertyEditorRegistrySupport propertyEditorRegistry;
|
||||
|
||||
private final Object targetObject;
|
||||
|
|
@ -269,8 +256,8 @@ class TypeConverterDelegate {
|
|||
}
|
||||
else {
|
||||
// convertedValue == null
|
||||
if (javaUtilOptionalEmpty != null && requiredType.equals(javaUtilOptionalEmpty.getClass())) {
|
||||
convertedValue = javaUtilOptionalEmpty;
|
||||
if (requiredType == Optional.class) {
|
||||
convertedValue = Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ import org.springframework.beans.factory.config.DependencyDescriptor;
|
|||
import org.springframework.core.OrderComparator;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CompositeIterator;
|
||||
|
|
@ -114,18 +113,9 @@ import org.springframework.util.StringUtils;
|
|||
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
|
||||
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
|
||||
|
||||
private static Class<?> javaUtilOptionalClass = null;
|
||||
|
||||
private static Class<?> javaxInjectProviderClass = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
javaUtilOptionalClass =
|
||||
ClassUtils.forName("java.util.Optional", DefaultListableBeanFactory.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Java 8 not available - Optional references simply not supported then.
|
||||
}
|
||||
try {
|
||||
javaxInjectProviderClass =
|
||||
ClassUtils.forName("javax.inject.Provider", DefaultListableBeanFactory.class.getClassLoader());
|
||||
|
|
@ -1002,8 +992,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
|
||||
|
||||
descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
|
||||
if (descriptor.getDependencyType().equals(javaUtilOptionalClass)) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(descriptor, beanName);
|
||||
if (descriptor.getDependencyType() == Optional.class) {
|
||||
return createOptionalDependency(descriptor, beanName);
|
||||
}
|
||||
else if (ObjectFactory.class == descriptor.getDependencyType() ||
|
||||
ObjectProvider.class == descriptor.getDependencyType()) {
|
||||
|
|
@ -1403,6 +1393,23 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
"Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations()));
|
||||
}
|
||||
|
||||
private Optional<?> createOptionalDependency(DependencyDescriptor descriptor, String beanName, final Object... args) {
|
||||
DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
|
||||
@Override
|
||||
public boolean isRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveCandidate(String beanName, BeanFactory beanFactory) {
|
||||
return (!ObjectUtils.isEmpty(args) ? beanFactory.getBean(beanName, args) :
|
||||
super.resolveCandidate(beanName, beanFactory));
|
||||
}
|
||||
};
|
||||
descriptorToUse.increaseNestingLevel();
|
||||
return Optional.ofNullable(doResolveDependency(descriptorToUse, beanName, null, null));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
@ -1466,30 +1473,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Separate inner class for avoiding a hard dependency on the {@code javax.inject} API.
|
||||
*/
|
||||
@UsesJava8
|
||||
private class OptionalDependencyFactory {
|
||||
|
||||
public Object createOptionalDependency(DependencyDescriptor descriptor, String beanName, final Object... args) {
|
||||
DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
|
||||
@Override
|
||||
public boolean isRequired() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public Object resolveCandidate(String beanName, BeanFactory beanFactory) {
|
||||
return (!ObjectUtils.isEmpty(args) ? beanFactory.getBean(beanName, args) :
|
||||
super.resolveCandidate(beanName, beanFactory));
|
||||
}
|
||||
};
|
||||
descriptorToUse.increaseNestingLevel();
|
||||
return Optional.ofNullable(doResolveDependency(descriptorToUse, beanName, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializable ObjectFactory/ObjectProvider for lazy resolution of a dependency.
|
||||
*/
|
||||
|
|
@ -1504,14 +1487,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
public DependencyObjectProvider(DependencyDescriptor descriptor, String beanName) {
|
||||
this.descriptor = new DependencyDescriptor(descriptor);
|
||||
this.descriptor.increaseNestingLevel();
|
||||
this.optional = this.descriptor.getDependencyType().equals(javaUtilOptionalClass);
|
||||
this.optional = (this.descriptor.getDependencyType() == Optional.class);
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() throws BeansException {
|
||||
if (this.optional) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName);
|
||||
return createOptionalDependency(this.descriptor, this.beanName);
|
||||
}
|
||||
else {
|
||||
return doResolveDependency(this.descriptor, this.beanName, null, null);
|
||||
|
|
@ -1521,7 +1504,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
@Override
|
||||
public Object getObject(final Object... args) throws BeansException {
|
||||
if (this.optional) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName, args);
|
||||
return createOptionalDependency(this.descriptor, this.beanName, args);
|
||||
}
|
||||
else {
|
||||
DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
|
||||
|
|
@ -1537,7 +1520,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
@Override
|
||||
public Object getIfAvailable() throws BeansException {
|
||||
if (this.optional) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName);
|
||||
return createOptionalDependency(this.descriptor, this.beanName);
|
||||
}
|
||||
else {
|
||||
DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
|
||||
|
|
@ -1563,7 +1546,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
}
|
||||
};
|
||||
if (this.optional) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(descriptorToUse, this.beanName);
|
||||
return createOptionalDependency(descriptorToUse, this.beanName);
|
||||
}
|
||||
else {
|
||||
return doResolveDependency(descriptorToUse, this.beanName, null, null);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,8 +19,6 @@ package org.springframework.beans.propertyeditors;
|
|||
import java.beans.PropertyEditorSupport;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Editor for {@code java.time.ZoneId}, translating zone ID Strings into {@code ZoneId}
|
||||
* objects. Exposes the {@code TimeZone} ID as a text representation.
|
||||
|
|
@ -30,7 +28,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @see java.time.ZoneId
|
||||
* @see TimeZoneEditor
|
||||
*/
|
||||
@UsesJava8
|
||||
public class ZoneIdEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.util.function.Function;
|
|||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
import org.springframework.cache.support.AbstractValueAdaptingCache;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +35,6 @@ import org.springframework.util.Assert;
|
|||
* @author Stephane Nicoll
|
||||
* @since 4.3
|
||||
*/
|
||||
@UsesJava8
|
||||
public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||
|
||||
private final String name;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@
|
|||
* <p>Note: EhCache 3.x lives in a different package namespace
|
||||
* and is not covered by the traditional support classes here.
|
||||
* Instead, consider using it through JCache (JSR-107), with
|
||||
* Spring's support in {@link org.springframework.cache.jcache}.
|
||||
* Spring's support in {@code org.springframework.cache.jcache}.
|
||||
*/
|
||||
package org.springframework.cache.ehcache;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -52,7 +52,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
|
|||
private static final boolean jsr107Present = ClassUtils.isPresent(
|
||||
"javax.cache.Cache", CachingConfigurationSelector.class.getClassLoader());
|
||||
|
||||
private static final boolean jCacheImplPresent = ClassUtils.isPresent(
|
||||
private static final boolean jcacheImplPresent = ClassUtils.isPresent(
|
||||
PROXY_JCACHE_CONFIGURATION_CLASS, CachingConfigurationSelector.class.getClassLoader());
|
||||
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
|
|||
List<String> result = new ArrayList<String>();
|
||||
result.add(AutoProxyRegistrar.class.getName());
|
||||
result.add(ProxyCachingConfiguration.class.getName());
|
||||
if (jsr107Present && jCacheImplPresent) {
|
||||
if (jsr107Present && jcacheImplPresent) {
|
||||
result.add(PROXY_JCACHE_CONFIGURATION_CLASS);
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
|
|
@ -94,7 +94,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
|
|||
private String[] getAspectJImports() {
|
||||
List<String> result = new ArrayList<String>();
|
||||
result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME);
|
||||
if (jsr107Present && jCacheImplPresent) {
|
||||
if (jsr107Present && jcacheImplPresent) {
|
||||
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -60,11 +60,10 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
|||
private static final String JCACHE_ASPECT_CLASS_NAME =
|
||||
"org.springframework.cache.aspectj.JCacheCacheAspect";
|
||||
|
||||
|
||||
private static final boolean jsr107Present = ClassUtils.isPresent(
|
||||
"javax.cache.Cache", AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader());
|
||||
|
||||
private static final boolean jCacheImplPresent = ClassUtils.isPresent(
|
||||
private static final boolean jcacheImplPresent = ClassUtils.isPresent(
|
||||
"org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource",
|
||||
AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader());
|
||||
|
||||
|
|
@ -91,7 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
|||
|
||||
private void registerCacheAspect(Element element, ParserContext parserContext) {
|
||||
SpringCachingConfigurer.registerCacheAspect(element, parserContext);
|
||||
if (jsr107Present && jCacheImplPresent) { // Register JCache aspect
|
||||
if (jsr107Present && jcacheImplPresent) {
|
||||
JCacheCachingConfigurer.registerCacheAspect(element, parserContext);
|
||||
}
|
||||
}
|
||||
|
|
@ -99,7 +98,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
|||
private void registerCacheAdvisor(Element element, ParserContext parserContext) {
|
||||
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
|
||||
SpringCachingConfigurer.registerCacheAdvisor(element, parserContext);
|
||||
if (jsr107Present && jCacheImplPresent) { // Register JCache advisor
|
||||
if (jsr107Present && jcacheImplPresent) {
|
||||
JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import org.springframework.cache.CacheManager;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.expression.AnnotatedElementKey;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
|
@ -81,18 +80,6 @@ import org.springframework.util.StringUtils;
|
|||
public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
implements BeanFactoryAware, InitializingBean, SmartInitializingSingleton {
|
||||
|
||||
private static Class<?> javaUtilOptionalClass = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
javaUtilOptionalClass =
|
||||
ClassUtils.forName("java.util.Optional", CacheAspectSupport.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Java 8 not available - Optional references simply not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final Map<CacheOperationCacheKey, CacheOperationMetadata> metadataCache =
|
||||
|
|
@ -401,9 +388,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
if (cacheHit != null && cachePutRequests.isEmpty() && !hasCachePut(contexts)) {
|
||||
// If there are no put requests, just use the cache hit
|
||||
cacheValue = cacheHit.get();
|
||||
if (method.getReturnType() == javaUtilOptionalClass &&
|
||||
(cacheValue == null || cacheValue.getClass() != javaUtilOptionalClass)) {
|
||||
returnValue = OptionalUnwrapper.wrap(cacheValue);
|
||||
if (method.getReturnType() == Optional.class &&
|
||||
(cacheValue == null || cacheValue.getClass() != Optional.class)) {
|
||||
returnValue = Optional.ofNullable(cacheValue);
|
||||
}
|
||||
else {
|
||||
returnValue = cacheValue;
|
||||
|
|
@ -412,12 +399,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
else {
|
||||
// Invoke the method if we don't have a cache hit
|
||||
returnValue = invokeOperation(invoker);
|
||||
if (returnValue != null && returnValue.getClass() == javaUtilOptionalClass) {
|
||||
cacheValue = OptionalUnwrapper.unwrap(returnValue);
|
||||
}
|
||||
else {
|
||||
cacheValue = returnValue;
|
||||
}
|
||||
cacheValue = ObjectUtils.unwrapOptional(returnValue);
|
||||
}
|
||||
|
||||
// Collect any explicit @CachePuts
|
||||
|
|
@ -828,26 +810,4 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Java 8.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class OptionalUnwrapper {
|
||||
|
||||
public static Object unwrap(Object optionalObject) {
|
||||
Optional<?> optional = (Optional<?>) optionalObject;
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
Object result = optional.get();
|
||||
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Object wrap(Object value) {
|
||||
return Optional.ofNullable(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import org.springframework.core.DecoratingClassLoader;
|
||||
import org.springframework.core.OverridingClassLoader;
|
||||
import org.springframework.core.SmartClassLoader;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -37,13 +36,10 @@ import org.springframework.util.ReflectionUtils;
|
|||
* @see AbstractApplicationContext
|
||||
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setTempClassLoader
|
||||
*/
|
||||
@UsesJava7
|
||||
class ContextTypeMatchClassLoader extends DecoratingClassLoader implements SmartClassLoader {
|
||||
|
||||
static {
|
||||
if (parallelCapableClassLoaderAvailable) {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,7 +24,6 @@ import java.util.TimeZone;
|
|||
import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* A context that holds user-specific <code>java.time</code> (JSR-310) settings
|
||||
|
|
@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.0
|
||||
* @see DateTimeContextHolder
|
||||
*/
|
||||
@UsesJava8
|
||||
public class DateTimeContext {
|
||||
|
||||
private Chronology chronology;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,7 +20,6 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* A holder for a thread-local user {@link DateTimeContext}.
|
||||
|
|
@ -28,7 +27,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @author Juergen Hoeller
|
||||
* @since 4.0
|
||||
*/
|
||||
@UsesJava8
|
||||
public final class DateTimeContextHolder {
|
||||
|
||||
private static final ThreadLocal<DateTimeContext> dateTimeContextHolder =
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -29,7 +29,6 @@ import java.util.GregorianCalendar;
|
|||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterRegistry;
|
||||
import org.springframework.format.datetime.DateFormatterRegistrar;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Installs lower-level type converters required to integrate
|
||||
|
|
@ -43,7 +42,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @author Juergen Hoeller
|
||||
* @since 4.0.1
|
||||
*/
|
||||
@UsesJava8
|
||||
final class DateTimeConverters {
|
||||
|
||||
/**
|
||||
|
|
@ -86,7 +84,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class LocalDateTimeToLocalDateConverter implements Converter<LocalDateTime, LocalDate> {
|
||||
|
||||
@Override
|
||||
|
|
@ -96,7 +93,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class LocalDateTimeToLocalTimeConverter implements Converter<LocalDateTime, LocalTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -106,7 +102,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class ZonedDateTimeToLocalDateConverter implements Converter<ZonedDateTime, LocalDate> {
|
||||
|
||||
@Override
|
||||
|
|
@ -116,7 +111,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class ZonedDateTimeToLocalTimeConverter implements Converter<ZonedDateTime, LocalTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -126,7 +120,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class ZonedDateTimeToLocalDateTimeConverter implements Converter<ZonedDateTime, LocalDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -135,7 +128,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
}
|
||||
|
||||
@UsesJava8
|
||||
private static class ZonedDateTimeToOffsetDateTimeConverter implements Converter<ZonedDateTime, OffsetDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -145,7 +137,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class ZonedDateTimeToInstantConverter implements Converter<ZonedDateTime, Instant> {
|
||||
|
||||
@Override
|
||||
|
|
@ -156,7 +147,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class OffsetDateTimeToLocalDateConverter implements Converter<OffsetDateTime, LocalDate> {
|
||||
|
||||
@Override
|
||||
|
|
@ -166,7 +156,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class OffsetDateTimeToLocalTimeConverter implements Converter<OffsetDateTime, LocalTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -176,7 +165,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class OffsetDateTimeToLocalDateTimeConverter implements Converter<OffsetDateTime, LocalDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -186,7 +174,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class OffsetDateTimeToZonedDateTimeConverter implements Converter<OffsetDateTime, ZonedDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -196,7 +183,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class OffsetDateTimeToInstantConverter implements Converter<OffsetDateTime, Instant> {
|
||||
|
||||
@Override
|
||||
|
|
@ -206,7 +192,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToZonedDateTimeConverter implements Converter<Calendar, ZonedDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -216,7 +201,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToOffsetDateTimeConverter implements Converter<Calendar, OffsetDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -226,7 +210,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToLocalDateConverter implements Converter<Calendar, LocalDate> {
|
||||
|
||||
@Override
|
||||
|
|
@ -236,7 +219,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToLocalTimeConverter implements Converter<Calendar, LocalTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -246,7 +228,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToLocalDateTimeConverter implements Converter<Calendar, LocalDateTime> {
|
||||
|
||||
@Override
|
||||
|
|
@ -256,7 +237,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class CalendarToInstantConverter implements Converter<Calendar, Instant> {
|
||||
|
||||
@Override
|
||||
|
|
@ -267,7 +247,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class LongToInstantConverter implements Converter<Long, Instant> {
|
||||
|
||||
@Override
|
||||
|
|
@ -277,7 +256,6 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
private static class InstantToLongConverter implements Converter<Instant, Long> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.time.format.ResolverStyle;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
|
@ -44,7 +43,6 @@ import org.springframework.util.StringUtils;
|
|||
* @see #setDateTimeStyle
|
||||
* @see DateTimeFormatterFactoryBean
|
||||
*/
|
||||
@UsesJava8
|
||||
public class DateTimeFormatterFactory {
|
||||
|
||||
private String pattern;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -35,7 +35,6 @@ import java.util.Map;
|
|||
import org.springframework.format.FormatterRegistrar;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Configures the JSR-310 <code>java.time</code> formatting system for use with Spring.
|
||||
|
|
@ -51,7 +50,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @see org.springframework.format.datetime.DateFormatterRegistrar
|
||||
* @see org.springframework.format.datetime.joda.DateTimeFormatterFactoryBean
|
||||
*/
|
||||
@UsesJava8
|
||||
public class DateTimeFormatterRegistrar implements FormatterRegistrar {
|
||||
|
||||
private enum Type {DATE, TIME, DATE_TIME}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.time.Duration;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Formatter} implementation for a JSR-310 {@link Duration},
|
||||
|
|
@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.2.4
|
||||
* @see Duration#parse
|
||||
*/
|
||||
@UsesJava8
|
||||
class DurationFormatter implements Formatter<Duration> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Formatter} implementation for a JSR-310 {@link java.time.Instant},
|
||||
|
|
@ -37,7 +36,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @see java.time.format.DateTimeFormatter#ISO_INSTANT
|
||||
* @see java.time.format.DateTimeFormatter#RFC_1123_DATE_TIME
|
||||
*/
|
||||
@UsesJava8
|
||||
public class InstantFormatter implements Formatter<Instant> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.time.MonthDay;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Formatter} implementation for a JSR-310 {@link MonthDay},
|
||||
|
|
@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.2.4
|
||||
* @see MonthDay#parse
|
||||
*/
|
||||
@UsesJava8
|
||||
class MonthDayFormatter implements Formatter<MonthDay> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.time.Period;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Formatter} implementation for a JSR-310 {@link Period},
|
||||
|
|
@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.2.4
|
||||
* @see Period#parse
|
||||
*/
|
||||
@UsesJava8
|
||||
class PeriodFormatter implements Formatter<Period> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,7 +28,6 @@ import java.time.temporal.TemporalAccessor;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Parser;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Parser} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor},
|
||||
|
|
@ -44,7 +43,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @see java.time.OffsetDateTime#parse(CharSequence, java.time.format.DateTimeFormatter)
|
||||
* @see java.time.OffsetTime#parse(CharSequence, java.time.format.DateTimeFormatter)
|
||||
*/
|
||||
@UsesJava8
|
||||
public final class TemporalAccessorParser implements Parser<TemporalAccessor> {
|
||||
|
||||
private final Class<? extends TemporalAccessor> temporalAccessorType;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.time.temporal.TemporalAccessor;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Printer;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Printer} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor},
|
||||
|
|
@ -32,7 +31,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @see DateTimeContextHolder#getFormatter
|
||||
* @see java.time.format.DateTimeFormatter#format(java.time.temporal.TemporalAccessor)
|
||||
*/
|
||||
@UsesJava8
|
||||
public final class TemporalAccessorPrinter implements Printer<TemporalAccessor> {
|
||||
|
||||
private final DateTimeFormatter formatter;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.time.YearMonth;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link Formatter} implementation for a JSR-310 {@link YearMonth},
|
||||
|
|
@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.2.4
|
||||
* @see YearMonth#parse
|
||||
*/
|
||||
@UsesJava8
|
||||
class YearMonthFormatter implements Formatter<YearMonth> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -52,9 +52,8 @@ import org.springframework.util.ReflectionUtils;
|
|||
* web application). There is no direct API dependency between this LoadTimeWeaver
|
||||
* adapter and the underlying ClassLoader, just a 'loose' method contract.
|
||||
*
|
||||
* <p>This is the LoadTimeWeaver to use in combination with Spring's
|
||||
* {@link org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader}
|
||||
* for Tomcat 5.0+ as well as with the Resin application server version 3.1+.
|
||||
* <p>This is the LoadTimeWeaver to use e.g. with the Resin application server
|
||||
* version 3.1+.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -62,7 +61,6 @@ import org.springframework.util.ReflectionUtils;
|
|||
* @see #addTransformer(java.lang.instrument.ClassFileTransformer)
|
||||
* @see #getThrowawayClassLoader()
|
||||
* @see SimpleThrowawayClassLoader
|
||||
* @see org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
|
||||
*/
|
||||
public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.instrument.classloading;
|
|||
import java.lang.instrument.ClassFileTransformer;
|
||||
|
||||
import org.springframework.core.OverridingClassLoader;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* Simplistic implementation of an instrumentable {@code ClassLoader}.
|
||||
|
|
@ -30,13 +29,10 @@ import org.springframework.lang.UsesJava7;
|
|||
* @author Costin Leau
|
||||
* @since 2.0
|
||||
*/
|
||||
@UsesJava7
|
||||
public class SimpleInstrumentableClassLoader extends OverridingClassLoader {
|
||||
|
||||
static {
|
||||
if (parallelCapableClassLoaderAvailable) {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.instrument.classloading;
|
||||
|
||||
import org.springframework.core.OverridingClassLoader;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* ClassLoader that can be used to load classes without bringing them
|
||||
|
|
@ -27,13 +26,10 @@ import org.springframework.lang.UsesJava7;
|
|||
* @author Rod Johnson
|
||||
* @since 2.0
|
||||
*/
|
||||
@UsesJava7
|
||||
public class SimpleThrowawayClassLoader extends OverridingClassLoader {
|
||||
|
||||
static {
|
||||
if (parallelCapableClassLoaderAvailable) {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation for Tomcat's
|
||||
* new {@link org.apache.tomcat.InstrumentableClassLoader InstrumentableClassLoader}.
|
||||
* {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation
|
||||
* for Tomcat's new {@code org.apache.tomcat.InstrumentableClassLoader}.
|
||||
* Also capable of handling Spring's TomcatInstrumentableClassLoader when encountered.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -22,12 +22,9 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}.
|
||||
* May be used on Java 7 and 8 as well as on Java 6 with {@code jsr166.jar} on the classpath
|
||||
* (ideally on the VM bootstrap classpath).
|
||||
*
|
||||
* <p>For details on the ForkJoinPool API and its use with RecursiveActions, see the
|
||||
* <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
|
||||
|
|
@ -38,7 +35,6 @@ import org.springframework.lang.UsesJava7;
|
|||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
@UsesJava7
|
||||
public class ForkJoinPoolFactoryBean implements FactoryBean<ForkJoinPool>, InitializingBean, DisposableBean {
|
||||
|
||||
private boolean commonPool = false;
|
||||
|
|
|
|||
|
|
@ -24,11 +24,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable;
|
||||
import org.springframework.scheduling.support.TaskUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -75,11 +73,6 @@ import org.springframework.util.ObjectUtils;
|
|||
public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
|
||||
implements FactoryBean<ScheduledExecutorService> {
|
||||
|
||||
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
|
||||
private static final boolean setRemoveOnCancelPolicyAvailable =
|
||||
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
|
||||
|
||||
|
||||
private int poolSize = 1;
|
||||
|
||||
private ScheduledExecutorTask[] scheduledExecutorTasks;
|
||||
|
|
@ -150,7 +143,6 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
|
|||
|
||||
|
||||
@Override
|
||||
@UsesJava7
|
||||
protected ExecutorService initializeExecutor(
|
||||
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
|
||||
|
||||
|
|
@ -158,7 +150,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
|
|||
createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
|
||||
|
||||
if (this.removeOnCancelPolicy) {
|
||||
if (setRemoveOnCancelPolicyAvailable && executor instanceof ScheduledThreadPoolExecutor) {
|
||||
if (executor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -31,13 +31,11 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.core.task.TaskRejectedException;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.scheduling.SchedulingTaskExecutor;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.support.TaskUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
|
|
@ -58,11 +56,6 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
|||
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {
|
||||
|
||||
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
|
||||
private static final boolean setRemoveOnCancelPolicyAvailable =
|
||||
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
|
||||
|
||||
|
||||
private volatile int poolSize = 1;
|
||||
|
||||
private volatile boolean removeOnCancelPolicy = false;
|
||||
|
|
@ -91,10 +84,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
|
||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||
*/
|
||||
@UsesJava7
|
||||
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
|
||||
this.removeOnCancelPolicy = removeOnCancelPolicy;
|
||||
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
|
||||
}
|
||||
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
|
||||
|
|
@ -110,7 +102,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
}
|
||||
|
||||
|
||||
@UsesJava7
|
||||
@Override
|
||||
protected ExecutorService initializeExecutor(
|
||||
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
|
||||
|
|
@ -118,7 +109,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
|
||||
|
||||
if (this.removeOnCancelPolicy) {
|
||||
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
else {
|
||||
|
|
@ -187,11 +178,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
* Return the current setting for the remove-on-cancel mode.
|
||||
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
|
||||
*/
|
||||
@UsesJava7
|
||||
public boolean isRemoveOnCancelPolicy() {
|
||||
if (!setRemoveOnCancelPolicyAvailable) {
|
||||
return false;
|
||||
}
|
||||
if (this.scheduledExecutor == null) {
|
||||
// Not initialized yet: return our setting for the time being.
|
||||
return this.removeOnCancelPolicy;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
|
@ -44,9 +43,7 @@ import org.springframework.core.MethodParameter;
|
|||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.format.support.FormatterPropertyEditorAdapter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
|
@ -124,19 +121,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
|||
*/
|
||||
protected static final Log logger = LogFactory.getLog(DataBinder.class);
|
||||
|
||||
private static Class<?> javaUtilOptionalClass = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
javaUtilOptionalClass =
|
||||
ClassUtils.forName("java.util.Optional", DataBinder.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Java 8 not available - Optional references simply not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final Object target;
|
||||
|
||||
private final String objectName;
|
||||
|
|
@ -183,12 +167,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
|||
* @param objectName the name of the target object
|
||||
*/
|
||||
public DataBinder(Object target, String objectName) {
|
||||
if (target != null && target.getClass() == javaUtilOptionalClass) {
|
||||
this.target = OptionalUnwrapper.unwrap(target);
|
||||
}
|
||||
else {
|
||||
this.target = target;
|
||||
}
|
||||
this.target = ObjectUtils.unwrapOptional(target);
|
||||
this.objectName = objectName;
|
||||
}
|
||||
|
||||
|
|
@ -884,22 +863,4 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
|||
return getBindingResult().getModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Java 8.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class OptionalUnwrapper {
|
||||
|
||||
public static Object unwrap(Object optionalObject) {
|
||||
Optional<?> optional = (Optional<?>) optionalObject;
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
Object result = optional.get();
|
||||
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ import java.util.Collections;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Base class for decorating ClassLoaders such as {@link OverridingClassLoader}
|
||||
|
|
@ -33,20 +31,10 @@ import org.springframework.util.ClassUtils;
|
|||
* @author Rod Johnson
|
||||
* @since 2.5.2
|
||||
*/
|
||||
@UsesJava7
|
||||
public abstract class DecoratingClassLoader extends ClassLoader {
|
||||
|
||||
/**
|
||||
* Java 7+ {@code ClassLoader.registerAsParallelCapable()} available?
|
||||
* @since 4.1.2
|
||||
*/
|
||||
protected static final boolean parallelCapableClassLoaderAvailable =
|
||||
ClassUtils.hasMethod(ClassLoader.class, "registerAsParallelCapable");
|
||||
|
||||
static {
|
||||
if (parallelCapableClassLoaderAvailable) {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.springframework.core;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link ParameterNameDiscoverer} strategy interface,
|
||||
* using the Java 8 standard reflection mechanism (if available), and falling back
|
||||
|
|
@ -33,14 +31,8 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
|
||||
|
||||
private static final boolean standardReflectionAvailable = ClassUtils.isPresent(
|
||||
"java.lang.reflect.Executable", DefaultParameterNameDiscoverer.class.getClassLoader());
|
||||
|
||||
|
||||
public DefaultParameterNameDiscoverer() {
|
||||
if (standardReflectionAvailable) {
|
||||
addDiscoverer(new StandardReflectionParameterNameDiscoverer());
|
||||
}
|
||||
addDiscoverer(new StandardReflectionParameterNameDiscoverer());
|
||||
addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,10 +85,9 @@ public abstract class MethodIntrospector {
|
|||
|
||||
/**
|
||||
* Select methods on the given target type based on a filter.
|
||||
* <p>Callers define methods of interest through the
|
||||
* {@link ReflectionUtils.MethodFilter} parameter.
|
||||
* <p>Callers define methods of interest through the {@code MethodFilter} parameter.
|
||||
* @param targetType the target type to search methods on
|
||||
* @param methodFilter a {@link ReflectionUtils.MethodFilter} to help
|
||||
* @param methodFilter a {@code MethodFilter} to help
|
||||
* recognize handler methods of interest
|
||||
* @return the selected methods, or an empty set in case of no match
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import java.lang.reflect.ParameterizedType;
|
|||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
|
||||
|
|
@ -48,21 +48,6 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public class MethodParameter {
|
||||
|
||||
private static final Class<?> javaUtilOptionalClass;
|
||||
|
||||
static {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Java 8 not available - Optional references simply not supported then.
|
||||
clazz = null;
|
||||
}
|
||||
javaUtilOptionalClass = clazz;
|
||||
}
|
||||
|
||||
|
||||
private final Method method;
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
|
@ -320,7 +305,7 @@ public class MethodParameter {
|
|||
* @since 4.3
|
||||
*/
|
||||
public boolean isOptional() {
|
||||
return (getParameterType() == javaUtilOptionalClass);
|
||||
return (getParameterType() == Optional.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.springframework.core;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -34,7 +33,6 @@ import org.springframework.util.FileCopyUtils;
|
|||
* @author Juergen Hoeller
|
||||
* @since 2.0.1
|
||||
*/
|
||||
@UsesJava7
|
||||
public class OverridingClassLoader extends DecoratingClassLoader {
|
||||
|
||||
/** Packages that are excluded by default */
|
||||
|
|
@ -44,9 +42,7 @@ public class OverridingClassLoader extends DecoratingClassLoader {
|
|||
private static final String CLASS_FILE_SUFFIX = ".class";
|
||||
|
||||
static {
|
||||
if (parallelCapableClassLoaderAvailable) {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,8 +20,6 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* {@link ParameterNameDiscoverer} implementation which uses JDK 8's reflection facilities
|
||||
* for introspecting parameter names (based on the "-parameters" compiler flag).
|
||||
|
|
@ -30,7 +28,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.0
|
||||
* @see java.lang.reflect.Parameter#getName()
|
||||
*/
|
||||
@UsesJava8
|
||||
public class StandardReflectionParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.util.stream.Stream;
|
|||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
|
@ -49,9 +48,6 @@ public class TypeDescriptor implements Serializable {
|
|||
|
||||
static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
||||
|
||||
private static final boolean streamAvailable = ClassUtils.isPresent(
|
||||
"java.util.stream.Stream", TypeDescriptor.class.getClassLoader());
|
||||
|
||||
private static final Map<Class<?>, TypeDescriptor> commonTypesCache = new HashMap<Class<?>, TypeDescriptor>(18);
|
||||
|
||||
private static final Class<?>[] CACHED_COMMON_TYPES = {
|
||||
|
|
@ -340,10 +336,10 @@ public class TypeDescriptor implements Serializable {
|
|||
if (this.resolvableType.isArray()) {
|
||||
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
|
||||
}
|
||||
if (streamAvailable && StreamDelegate.isStream(this.type)) {
|
||||
return StreamDelegate.getStreamElementType(this);
|
||||
if (Stream.class.isAssignableFrom(this.type)) {
|
||||
return getRelatedIfResolvable(this, this.resolvableType.as(Stream.class).getGeneric(0));
|
||||
}
|
||||
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
|
||||
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric(0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -694,20 +690,4 @@ public class TypeDescriptor implements Serializable {
|
|||
return new TypeDescriptor(type, null, source.annotations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Java 8.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class StreamDelegate {
|
||||
|
||||
public static boolean isStream(Class<?> type) {
|
||||
return Stream.class.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
public static TypeDescriptor getStreamElementType(TypeDescriptor source) {
|
||||
return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,19 +40,10 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public class DefaultConversionService extends GenericConversionService {
|
||||
|
||||
/** Java 8's java.util.Optional class available? */
|
||||
private static final boolean javaUtilOptionalClassAvailable =
|
||||
ClassUtils.isPresent("java.util.Optional", DefaultConversionService.class.getClassLoader());
|
||||
|
||||
/** Java 8's java.time package available? */
|
||||
private static final boolean jsr310Available =
|
||||
ClassUtils.isPresent("java.time.ZoneId", DefaultConversionService.class.getClassLoader());
|
||||
|
||||
/** Java 8's java.util.stream.Stream class available? */
|
||||
private static final boolean streamAvailable = ClassUtils.isPresent(
|
||||
"java.util.stream.Stream", DefaultConversionService.class.getClassLoader());
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code DefaultConversionService} with the set of
|
||||
|
|
@ -83,9 +74,7 @@ public class DefaultConversionService extends GenericConversionService {
|
|||
converterRegistry.addConverter(new ObjectToObjectConverter());
|
||||
converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
|
||||
converterRegistry.addConverter(new FallbackObjectToStringConverter());
|
||||
if (javaUtilOptionalClassAvailable) {
|
||||
converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
|
||||
}
|
||||
converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -117,9 +106,7 @@ public class DefaultConversionService extends GenericConversionService {
|
|||
converterRegistry.addConverter(new CollectionToObjectConverter(conversionService));
|
||||
converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService));
|
||||
|
||||
if (streamAvailable) {
|
||||
converterRegistry.addConverter(new StreamConverter(conversionService));
|
||||
}
|
||||
converterRegistry.addConverter(new StreamConverter(conversionService));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
|
@ -72,20 +73,6 @@ public class GenericConversionService implements ConfigurableConversionService {
|
|||
private static final GenericConverter NO_MATCH = new NoOpConverter("NO_MATCH");
|
||||
|
||||
|
||||
/** Java 8's java.util.Optional.empty() */
|
||||
private static Object javaUtilOptionalEmpty = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> clazz = ClassUtils.forName("java.util.Optional", GenericConversionService.class.getClassLoader());
|
||||
javaUtilOptionalEmpty = ClassUtils.getMethod(clazz, "empty").invoke(null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Java 8 not available - conversion to Optional not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final Converters converters = new Converters();
|
||||
|
||||
private final Map<ConverterCacheKey, GenericConverter> converterCache =
|
||||
|
|
@ -231,8 +218,8 @@ public class GenericConversionService implements ConfigurableConversionService {
|
|||
* @return the converted null object
|
||||
*/
|
||||
protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (javaUtilOptionalEmpty != null && targetType.getObjectType() == javaUtilOptionalEmpty.getClass()) {
|
||||
return javaUtilOptionalEmpty;
|
||||
if (targetType.getObjectType() == Optional.class) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,7 +23,6 @@ import java.util.Set;
|
|||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Convert an Object to {@code java.util.Optional<T>} if necessary using the
|
||||
|
|
@ -34,7 +33,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @author Juergen Hoeller
|
||||
* @since 4.1
|
||||
*/
|
||||
@UsesJava8
|
||||
final class ObjectToOptionalConverter implements ConditionalGenericConverter {
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -26,7 +26,6 @@ import java.util.stream.Stream;
|
|||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Converts a {@link Stream} to and from a collection or array, converting the
|
||||
|
|
@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @author Stephane Nicoll
|
||||
* @since 4.2
|
||||
*/
|
||||
@UsesJava8
|
||||
class StreamConverter implements ConditionalGenericConverter {
|
||||
|
||||
private static final TypeDescriptor STREAM_TYPE = TypeDescriptor.valueOf(Stream.class);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.core.convert.support;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +27,6 @@ import org.springframework.util.StringUtils;
|
|||
* @author Stephane Nicoll
|
||||
* @since 4.2
|
||||
*/
|
||||
@UsesJava8
|
||||
class StringToTimeZoneConverter implements Converter<String, TimeZone> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,7 +20,6 @@ import java.time.ZoneId;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Simple converter from Java 8's {@link java.time.ZoneId} to {@link java.util.TimeZone}.
|
||||
|
|
@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.0
|
||||
* @see TimeZone#getTimeZone(java.time.ZoneId)
|
||||
*/
|
||||
@UsesJava8
|
||||
final class ZoneIdToTimeZoneConverter implements Converter<ZoneId, TimeZone> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,7 +21,6 @@ import java.util.Calendar;
|
|||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Simple converter from Java 8's {@link java.time.ZonedDateTime} to {@link java.util.Calendar}.
|
||||
|
|
@ -36,7 +35,6 @@ import org.springframework.lang.UsesJava8;
|
|||
* @since 4.0.1
|
||||
* @see java.util.GregorianCalendar#from(java.time.ZonedDateTime)
|
||||
*/
|
||||
@UsesJava8
|
||||
final class ZonedDateTimeToCalendarConverter implements Converter<ZonedDateTime, Calendar> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,7 +28,6 @@ import java.nio.file.OpenOption;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -41,7 +40,6 @@ import org.springframework.util.Assert;
|
|||
* @since 4.0
|
||||
* @see java.nio.file.Path
|
||||
*/
|
||||
@UsesJava7
|
||||
public class PathResource extends AbstractResource implements WritableResource {
|
||||
|
||||
private final Path path;
|
||||
|
|
|
|||
|
|
@ -32,5 +32,6 @@ import java.lang.annotation.Target;
|
|||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface UsesJava7 {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,5 +32,6 @@ import java.lang.annotation.Target;
|
|||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface UsesJava8 {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,62 +18,22 @@ package org.springframework.util;
|
|||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Base64;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* A simple utility class for Base64 encoding and decoding.
|
||||
*
|
||||
* <p>Adapts to either Java 8's {@link java.util.Base64} class or Apache Commons Codec's
|
||||
* {@link org.apache.commons.codec.binary.Base64} class. With neither Java 8 nor Commons
|
||||
* Codec present, {@link #encode}/{@link #decode} calls will throw an IllegalStateException.
|
||||
* However, as of Spring 4.2, {@link #encodeToString} and {@link #decodeFromString} will
|
||||
* nevertheless work since they can delegate to the JAXB DatatypeConverter as a fallback.
|
||||
* However, this does not apply when using the ...UrlSafe... methods for RFC 4648 "URL and
|
||||
* Filename Safe Alphabet"; a delegate is required.
|
||||
* <p>
|
||||
* <em>Note:</em> Apache Commons Codec does not add padding ({@code =}) when encoding with
|
||||
* the URL and Filename Safe Alphabet.
|
||||
* <p>Adapts to Java 8's {@link java.util.Base64} in a convenience fashion.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Gary Russell
|
||||
* @since 4.1
|
||||
* @see java.util.Base64
|
||||
* @see org.apache.commons.codec.binary.Base64
|
||||
* @see javax.xml.bind.DatatypeConverter#printBase64Binary
|
||||
* @see javax.xml.bind.DatatypeConverter#parseBase64Binary
|
||||
*/
|
||||
public abstract class Base64Utils {
|
||||
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
|
||||
private static final Base64Delegate delegate;
|
||||
|
||||
static {
|
||||
Base64Delegate delegateToUse = null;
|
||||
// JDK 8's java.util.Base64 class present?
|
||||
if (ClassUtils.isPresent("java.util.Base64", Base64Utils.class.getClassLoader())) {
|
||||
delegateToUse = new JdkBase64Delegate();
|
||||
}
|
||||
// Apache Commons Codec present on the classpath?
|
||||
else if (ClassUtils.isPresent("org.apache.commons.codec.binary.Base64", Base64Utils.class.getClassLoader())) {
|
||||
delegateToUse = new CommonsCodecBase64Delegate();
|
||||
}
|
||||
delegate = delegateToUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that Byte64 encoding between byte arrays is actually supported.
|
||||
* @throws IllegalStateException if neither Java 8 nor Apache Commons Codec is present
|
||||
*/
|
||||
private static void assertDelegateAvailable() {
|
||||
Assert.state(delegate != null,
|
||||
"Neither Java 8 nor Apache Commons Codec found - Base64 encoding between byte arrays not supported");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base64-encode the given byte array.
|
||||
* @param src the original byte array (may be {@code null})
|
||||
|
|
@ -82,8 +42,10 @@ public abstract class Base64Utils {
|
|||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
*/
|
||||
public static byte[] encode(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
return delegate.encode(src);
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getEncoder().encode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,8 +56,10 @@ public abstract class Base64Utils {
|
|||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
*/
|
||||
public static byte[] decode(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
return delegate.decode(src);
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getDecoder().decode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,8 +72,10 @@ public abstract class Base64Utils {
|
|||
* @since 4.2.4
|
||||
*/
|
||||
public static byte[] encodeUrlSafe(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
return delegate.encodeUrlSafe(src);
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlEncoder().encode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,8 +88,10 @@ public abstract class Base64Utils {
|
|||
* @since 4.2.4
|
||||
*/
|
||||
public static byte[] decodeUrlSafe(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
return delegate.decodeUrlSafe(src);
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlDecoder().decode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -139,15 +107,7 @@ public abstract class Base64Utils {
|
|||
if (src.length == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (delegate != null) {
|
||||
// Full encoder available
|
||||
return new String(delegate.encode(src), DEFAULT_CHARSET);
|
||||
}
|
||||
else {
|
||||
// JAXB fallback for String case
|
||||
return DatatypeConverter.printBase64Binary(src);
|
||||
}
|
||||
return new String(encode(src), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -162,15 +122,7 @@ public abstract class Base64Utils {
|
|||
if (src.length() == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
if (delegate != null) {
|
||||
// Full encoder available
|
||||
return delegate.decode(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
else {
|
||||
// JAXB fallback for String case
|
||||
return DatatypeConverter.parseBase64Binary(src);
|
||||
}
|
||||
return decode(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,8 +135,7 @@ public abstract class Base64Utils {
|
|||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
*/
|
||||
public static String encodeToUrlSafeString(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
return new String(delegate.encodeUrlSafe(src), DEFAULT_CHARSET);
|
||||
return new String(encodeUrlSafe(src), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -196,89 +147,7 @@ public abstract class Base64Utils {
|
|||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
*/
|
||||
public static byte[] decodeFromUrlSafeString(String src) {
|
||||
assertDelegateAvailable();
|
||||
return delegate.decodeUrlSafe(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
|
||||
interface Base64Delegate {
|
||||
|
||||
byte[] encode(byte[] src);
|
||||
|
||||
byte[] decode(byte[] src);
|
||||
|
||||
byte[] encodeUrlSafe(byte[] src);
|
||||
|
||||
byte[] decodeUrlSafe(byte[] src);
|
||||
}
|
||||
|
||||
|
||||
@UsesJava8
|
||||
static class JdkBase64Delegate implements Base64Delegate {
|
||||
|
||||
@Override
|
||||
public byte[] encode(byte[] src) {
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getEncoder().encode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(byte[] src) {
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getDecoder().decode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeUrlSafe(byte[] src) {
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlEncoder().encode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decodeUrlSafe(byte[] src) {
|
||||
if (src == null || src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlDecoder().decode(src);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CommonsCodecBase64Delegate implements Base64Delegate {
|
||||
|
||||
private final org.apache.commons.codec.binary.Base64 base64 =
|
||||
new org.apache.commons.codec.binary.Base64();
|
||||
|
||||
private final org.apache.commons.codec.binary.Base64 base64UrlSafe =
|
||||
new org.apache.commons.codec.binary.Base64(0, null, true);
|
||||
|
||||
@Override
|
||||
public byte[] encode(byte[] src) {
|
||||
return this.base64.encode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(byte[] src) {
|
||||
return this.base64.decode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeUrlSafe(byte[] src) {
|
||||
return this.base64UrlSafe.encode(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decodeUrlSafe(byte[] src) {
|
||||
return this.base64UrlSafe.decode(src);
|
||||
}
|
||||
|
||||
return decodeUrlSafe(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,12 @@ import java.security.NoSuchAlgorithmException;
|
|||
/**
|
||||
* Miscellaneous methods for calculating digests.
|
||||
* <p>Mainly for internal use within the framework; consider
|
||||
* <a href="http://commons.apache.org/codec/">Apache Commons Codec</a> for a
|
||||
* more comprehensive suite of digest utilities.
|
||||
* <a href="http://commons.apache.org/codec/">Apache Commons Codec</a>
|
||||
* for a more comprehensive suite of digest utilities.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Craig Andrews
|
||||
* @since 3.0
|
||||
* @see org.apache.commons.codec.digest.DigestUtils
|
||||
*/
|
||||
public abstract class DigestUtils {
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.lang.reflect.Array;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Miscellaneous object utility methods.
|
||||
|
|
@ -109,6 +110,7 @@ public abstract class ObjectUtils {
|
|||
* Determine whether the given object is empty.
|
||||
* <p>This method supports the following object types.
|
||||
* <ul>
|
||||
* <li>{@code Optional}: considered empty if {@link Optional#empty()}</li>
|
||||
* <li>{@code Array}: considered empty if its length is zero</li>
|
||||
* <li>{@link CharSequence}: considered empty if its length is zero</li>
|
||||
* <li>{@link Collection}: delegates to {@link Collection#isEmpty()}</li>
|
||||
|
|
@ -119,6 +121,7 @@ public abstract class ObjectUtils {
|
|||
* @param obj the object to check
|
||||
* @return {@code true} if the object is {@code null} or <em>empty</em>
|
||||
* @since 4.2
|
||||
* @see Optional#isPresent()
|
||||
* @see ObjectUtils#isEmpty(Object[])
|
||||
* @see StringUtils#hasLength(CharSequence)
|
||||
* @see StringUtils#isEmpty(Object)
|
||||
|
|
@ -131,6 +134,9 @@ public abstract class ObjectUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (obj instanceof Optional) {
|
||||
return !((Optional) obj).isPresent();
|
||||
}
|
||||
if (obj.getClass().isArray()) {
|
||||
return Array.getLength(obj) == 0;
|
||||
}
|
||||
|
|
@ -148,6 +154,26 @@ public abstract class ObjectUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwrap the given object which is potentially a {@link java.util.Optional}.
|
||||
* @param obj the candidate object
|
||||
* @return either the value held within the {@code Optional}, {@code null}
|
||||
* if the {@code Optional} is empty, or simply the given object as-is
|
||||
* @since 5.0
|
||||
*/
|
||||
public static Object unwrapOptional(Object obj) {
|
||||
if (obj instanceof Optional) {
|
||||
Optional<?> optional = (Optional<?>) obj;
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
Object result = optional.get();
|
||||
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
|
||||
return result;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given array contains the given element.
|
||||
* @param array the array to check (may be {@code null},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -22,22 +22,19 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
|
||||
/**
|
||||
* Adapts a {@link CompletableFuture} into a {@link ListenableFuture}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2
|
||||
*/
|
||||
@UsesJava8
|
||||
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
|
||||
private final CompletableFuture<T> completableFuture;
|
||||
|
||||
private final ListenableFutureCallbackRegistry<T> callbacks = new ListenableFutureCallbackRegistry<T>();
|
||||
|
||||
|
||||
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
||||
this.completableFuture = completableFuture;
|
||||
this.completableFuture.handle(new BiFunction<T, Throwable, Object>() {
|
||||
|
|
@ -54,6 +51,7 @@ public class CompletableToListenableFutureAdapter<T> implements ListenableFuture
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
||||
this.callbacks.addCallback(callback);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -31,41 +30,26 @@ import static org.junit.Assert.*;
|
|||
public class Base64UtilsTests {
|
||||
|
||||
@Test
|
||||
public void encodeWithJdk8VsCommonsCodec() throws UnsupportedEncodingException {
|
||||
Base64Utils.Base64Delegate jdkDelegate = new Base64Utils.JdkBase64Delegate();
|
||||
Base64Utils.Base64Delegate commonsDelegate = new Base64Utils.CommonsCodecBase64Delegate();
|
||||
|
||||
public void encode() throws UnsupportedEncodingException {
|
||||
byte[] bytes = new byte[]
|
||||
{-0x4f, 0xa, -0x73, -0x4f, 0x64, -0x20, 0x75, 0x41, 0x5, -0x49, -0x57, -0x65, -0x19, 0x2e, 0x3f, -0x1b};
|
||||
assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes));
|
||||
assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes)));
|
||||
|
||||
bytes = "Hello World".getBytes("UTF-8");
|
||||
assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes));
|
||||
assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes)));
|
||||
|
||||
bytes = "Hello World\r\nSecond Line".getBytes("UTF-8");
|
||||
assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes));
|
||||
assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes)));
|
||||
|
||||
bytes = "Hello World\r\nSecond Line\r\n".getBytes("UTF-8");
|
||||
assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes));
|
||||
assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes)));
|
||||
|
||||
bytes = new byte[] { (byte) 0xfb, (byte) 0xf0 };
|
||||
assertArrayEquals("+/A=".getBytes(), jdkDelegate.encode(bytes));
|
||||
assertArrayEquals("+/A=".getBytes(), commonsDelegate.encode(bytes));
|
||||
assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes)));
|
||||
assertArrayEquals("+/A=".getBytes(), Base64Utils.encode(bytes));
|
||||
assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes)));
|
||||
|
||||
assertArrayEquals("-_A=".getBytes(), jdkDelegate.encodeUrlSafe(bytes));
|
||||
assertArrayEquals("-_A".getBytes(), commonsDelegate.encodeUrlSafe(bytes)); // no padding with commons and URL safe
|
||||
assertArrayEquals(bytes, jdkDelegate.decodeUrlSafe(jdkDelegate.encodeUrlSafe(bytes)));
|
||||
assertArrayEquals(bytes, commonsDelegate.decodeUrlSafe(commonsDelegate.encodeUrlSafe(bytes)));
|
||||
assertArrayEquals("-_A=".getBytes(), Base64Utils.encodeUrlSafe(bytes));
|
||||
assertArrayEquals(bytes, Base64Utils.decodeUrlSafe(Base64Utils.encodeUrlSafe(bytes)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,17 +24,12 @@ import javax.sql.rowset.RowSetProvider;
|
|||
|
||||
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link ResultSetExtractor} implementation that returns a Spring {@link SqlRowSet}
|
||||
* representation for each given {@link ResultSet}.
|
||||
*
|
||||
* <p>The default implementation uses a standard JDBC CachedRowSet underneath.
|
||||
* This means that JDBC RowSet support needs to be available at runtime:
|
||||
* by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 6,
|
||||
* or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7+ / JDBC 4.1+.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2
|
||||
|
|
@ -45,17 +40,14 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet> {
|
||||
|
||||
private static final CachedRowSetFactory cachedRowSetFactory;
|
||||
private static final RowSetFactory rowSetFactory;
|
||||
|
||||
static {
|
||||
if (ClassUtils.isPresent("javax.sql.rowset.RowSetProvider",
|
||||
SqlRowSetResultSetExtractor.class.getClassLoader())) {
|
||||
// using JDBC 4.1 RowSetProvider, available on JDK 7+
|
||||
cachedRowSetFactory = new StandardCachedRowSetFactory();
|
||||
try {
|
||||
rowSetFactory = RowSetProvider.newFactory();
|
||||
}
|
||||
else {
|
||||
// JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl on JDK 6
|
||||
cachedRowSetFactory = new SunCachedRowSetFactory();
|
||||
catch (SQLException ex) {
|
||||
throw new IllegalStateException("Cannot create RowSetFactory through RowSetProvider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,69 +86,7 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
|
|||
* @see #createSqlRowSet
|
||||
*/
|
||||
protected CachedRowSet newCachedRowSet() throws SQLException {
|
||||
return cachedRowSetFactory.createCachedRowSet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal strategy interface for the creation of CachedRowSet instances.
|
||||
*/
|
||||
private interface CachedRowSetFactory {
|
||||
|
||||
CachedRowSet createCachedRowSet() throws SQLException;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on JDBC 4.1 RowSetProvider class.
|
||||
*/
|
||||
@UsesJava7
|
||||
private static class StandardCachedRowSetFactory implements CachedRowSetFactory {
|
||||
|
||||
private final RowSetFactory rowSetFactory;
|
||||
|
||||
public StandardCachedRowSetFactory() {
|
||||
try {
|
||||
this.rowSetFactory = RowSetProvider.newFactory();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
throw new IllegalStateException("Cannot create RowSetFactory through RowSetProvider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRowSet createCachedRowSet() throws SQLException {
|
||||
return this.rowSetFactory.createCachedRowSet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Sun's CachedRowSetImpl class.
|
||||
*/
|
||||
private static class SunCachedRowSetFactory implements CachedRowSetFactory {
|
||||
|
||||
private static final Class<?> implementationClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
implementationClass = ClassUtils.forName("com.sun.rowset.CachedRowSetImpl",
|
||||
SqlRowSetResultSetExtractor.class.getClassLoader());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRowSet createCachedRowSet() throws SQLException {
|
||||
try {
|
||||
return (CachedRowSet) implementationClass.newInstance();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
return rowSetFactory.createCachedRowSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -36,8 +36,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Generic utility methods for working with JDBC. Mainly for internal use
|
||||
|
|
@ -54,11 +52,6 @@ public abstract class JdbcUtils {
|
|||
*/
|
||||
public static final int TYPE_UNKNOWN = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
// Check for JDBC 4.1 getObject(int, Class) method - available on JDK 7 and higher
|
||||
private static final boolean getObjectWithTypeAvailable =
|
||||
ClassUtils.hasMethod(ResultSet.class, "getObject", int.class, Class.class);
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JdbcUtils.class);
|
||||
|
||||
|
||||
|
|
@ -135,7 +128,6 @@ public abstract class JdbcUtils {
|
|||
* @return the value object
|
||||
* @throws SQLException if thrown by the JDBC API
|
||||
*/
|
||||
@UsesJava7 // guard optional use of JDBC 4.1 (safe with 1.6 due to getObjectWithTypeAvailable check)
|
||||
public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException {
|
||||
if (requiredType == null) {
|
||||
return getResultSetValue(rs, index);
|
||||
|
|
@ -192,19 +184,17 @@ public abstract class JdbcUtils {
|
|||
}
|
||||
else {
|
||||
// Some unknown type desired -> rely on getObject.
|
||||
if (getObjectWithTypeAvailable) {
|
||||
try {
|
||||
return rs.getObject(index, requiredType);
|
||||
}
|
||||
catch (AbstractMethodError err) {
|
||||
logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
|
||||
}
|
||||
catch (SQLFeatureNotSupportedException ex) {
|
||||
logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
try {
|
||||
return rs.getObject(index, requiredType);
|
||||
}
|
||||
catch (AbstractMethodError err) {
|
||||
logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
|
||||
}
|
||||
catch (SQLFeatureNotSupportedException ex) {
|
||||
logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
// Fall back to getObject without type specification...
|
||||
return getResultSetValue(rs, index);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -29,7 +29,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
|
||||
|
|
@ -412,7 +411,6 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
|
|||
/**
|
||||
* @see java.sql.ResultSet#getObject(int, Class)
|
||||
*/
|
||||
@UsesJava7
|
||||
@Override
|
||||
public <T> T getObject(int columnIndex, Class<T> type) throws InvalidResultSetAccessException {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import org.springframework.util.MimeType;
|
|||
* {@link Marshaller} and {@link Unmarshaller} abstractions.
|
||||
*
|
||||
* <p>This converter requires a {@code Marshaller} and {@code Unmarshaller} before it can
|
||||
* be used. These can be injected by the {@linkplain MarshallingMessageConverter(Marshaller)
|
||||
* be used. These can be injected by the {@linkplain #MarshallingMessageConverter(Marshaller)
|
||||
* constructor} or {@linkplain #setMarshaller(Marshaller) bean properties}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.handler;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.util.ReflectionUtils.MethodFilter;
|
||||
|
||||
/**
|
||||
* Defines the algorithm for searching handler methods exhaustively including interfaces and parent
|
||||
* classes while also dealing with parameterized methods as well as interface and class-based proxies.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
* @deprecated as of Spring 4.2.3, in favor of the generalized and refined {@link MethodIntrospector}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class HandlerMethodSelector {
|
||||
|
||||
/**
|
||||
* Select handler methods for the given handler type.
|
||||
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
|
||||
* @param handlerType the handler type to search handler methods on
|
||||
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
|
||||
* @return the selected methods, or an empty set
|
||||
* @see MethodIntrospector#selectMethods(Class, MethodFilter)
|
||||
*/
|
||||
public static Set<Method> selectMethods(Class<?> handlerType, MethodFilter handlerMethodFilter) {
|
||||
return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.messaging.handler.invocation;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
|
|
@ -29,7 +28,6 @@ import org.springframework.util.concurrent.ListenableFuture;
|
|||
* @author Sebastien Deleuze
|
||||
* @since 4.2
|
||||
*/
|
||||
@UsesJava8
|
||||
public class CompletableFutureReturnValueHandler extends AbstractAsyncReturnValueHandler {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ import org.springframework.messaging.support.MessageHeaderInitializer;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
|
@ -87,10 +86,6 @@ import org.springframework.validation.Validator;
|
|||
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
||||
implements EmbeddedValueResolverAware, SmartLifecycle {
|
||||
|
||||
private static final boolean completableFuturePresent = ClassUtils.isPresent(
|
||||
"java.util.concurrent.CompletableFuture", SimpAnnotationMethodMessageHandler.class.getClassLoader());
|
||||
|
||||
|
||||
private final SubscribableChannel clientInboundChannel;
|
||||
|
||||
private final SimpMessageSendingOperations clientMessagingTemplate;
|
||||
|
|
@ -331,9 +326,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
|||
|
||||
// Single-purpose return value types
|
||||
handlers.add(new ListenableFutureReturnValueHandler());
|
||||
if (completableFuturePresent) {
|
||||
handlers.add(new CompletableFutureReturnValueHandler());
|
||||
}
|
||||
handlers.add(new CompletableFutureReturnValueHandler());
|
||||
|
||||
// Annotation-based return value types
|
||||
SendToMethodReturnValueHandler sendToHandler =
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
|||
|
||||
private static final String MVC_VALIDATOR_NAME = "mvcValidator";
|
||||
|
||||
private static final boolean jackson2Present= ClassUtils.isPresent(
|
||||
private static final boolean jackson2Present = ClassUtils.isPresent(
|
||||
"com.fasterxml.jackson.databind.ObjectMapper", AbstractMessageBrokerConfiguration.class.getClassLoader());
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -279,7 +279,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
|||
* InstrumentationLoadTimeWeaver, which requires a Spring-specific (but very general)
|
||||
* VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts
|
||||
* with an underlying ClassLoader based on specific extended methods being available
|
||||
* on it (for example, interacting with Spring's TomcatInstrumentableClassLoader).
|
||||
* on it.
|
||||
* <p><b>NOTE:</b> As of Spring 2.5, the context's default LoadTimeWeaver (defined
|
||||
* as bean with name "loadTimeWeaver") will be picked up automatically, if available,
|
||||
* removing the need for LoadTimeWeaver configuration on each affected target bean.</b>
|
||||
|
|
@ -290,7 +290,6 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
|||
* is responsible for the weaving configuration.
|
||||
* @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
|
||||
* @see org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver
|
||||
* @see org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
|
||||
*/
|
||||
@Override
|
||||
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
|
|||
return new SessionTransactionData(session, previousFlushMode, null, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
|
||||
FlushMode flushMode = (FlushMode) ReflectionUtils.invokeMethod(getFlushMode, session);
|
||||
if (readOnly) {
|
||||
|
|
@ -330,6 +331,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
|
|||
this.previousIsolationLevel = previousIsolationLevel;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void resetSessionState() {
|
||||
if (this.previousFlushMode != null) {
|
||||
this.session.setFlushMode(this.previousFlushMode);
|
||||
|
|
|
|||
|
|
@ -24,16 +24,12 @@ import javax.persistence.spi.PersistenceProvider;
|
|||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.DerbyDialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.InformixDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.dialect.Oracle9iDialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.jpa.HibernateEntityManager;
|
||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate
|
||||
|
|
@ -64,12 +60,11 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
|||
private final Class<? extends EntityManager> entityManagerInterface;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("deprecation")
|
||||
public HibernateJpaVendorAdapter() {
|
||||
ClassLoader cl = HibernateJpaVendorAdapter.class.getClassLoader();
|
||||
this.persistenceProvider = new SpringHibernateJpaPersistenceProvider();
|
||||
this.entityManagerFactoryInterface = HibernateEntityManagerFactory.class;
|
||||
this.entityManagerInterface = HibernateEntityManager.class;
|
||||
this.entityManagerFactoryInterface = org.hibernate.jpa.HibernateEntityManagerFactory.class;
|
||||
this.entityManagerInterface = org.hibernate.jpa.HibernateEntityManager.class;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -142,13 +137,13 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
|||
protected Class<?> determineDatabaseDialectClass(Database database) {
|
||||
switch (database) {
|
||||
case DB2: return DB2Dialect.class;
|
||||
case DERBY: return DerbyDialect.class;
|
||||
case DERBY: return org.hibernate.dialect.DerbyDialect.class;
|
||||
case H2: return H2Dialect.class;
|
||||
case HSQL: return HSQLDialect.class;
|
||||
case INFORMIX: return InformixDialect.class;
|
||||
case MYSQL: return MySQLDialect.class;
|
||||
case ORACLE: return Oracle9iDialect.class;
|
||||
case POSTGRESQL: return PostgreSQLDialect.class;
|
||||
case POSTGRESQL: return org.hibernate.dialect.PostgreSQLDialect.class;
|
||||
case SQL_SERVER: return SQLServerDialect.class;
|
||||
case SYBASE: return org.hibernate.dialect.SybaseDialect.class;
|
||||
default: return null;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public abstract class TestPropertySourceUtils {
|
|||
/**
|
||||
* The name of the {@link MapPropertySource} created from <em>inlined properties</em>.
|
||||
* @since 4.1.5
|
||||
* @see {@link #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])}
|
||||
* @see #addInlinedPropertiesToEnvironment
|
||||
*/
|
||||
public static final String INLINED_PROPERTIES_PROPERTY_SOURCE_NAME = "Inlined Test Properties";
|
||||
|
||||
|
|
@ -224,8 +224,7 @@ public abstract class TestPropertySourceUtils {
|
|||
* @see TestPropertySource#properties
|
||||
* @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
|
||||
*/
|
||||
public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context,
|
||||
String... inlinedProperties) {
|
||||
public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties) {
|
||||
Assert.notNull(context, "context must not be null");
|
||||
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
|
||||
addInlinedPropertiesToEnvironment(context.getEnvironment(), inlinedProperties);
|
||||
|
|
@ -252,13 +251,11 @@ public abstract class TestPropertySourceUtils {
|
|||
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
|
||||
if (!ObjectUtils.isEmpty(inlinedProperties)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Adding inlined properties to environment: "
|
||||
+ ObjectUtils.nullSafeToString(inlinedProperties));
|
||||
logger.debug("Adding inlined properties to environment: " + ObjectUtils.nullSafeToString(inlinedProperties));
|
||||
}
|
||||
MapPropertySource ps = (MapPropertySource) environment.getPropertySources().get(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||
if (ps == null) {
|
||||
ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME,
|
||||
new LinkedHashMap<String, Object>());
|
||||
ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME, new LinkedHashMap<String, Object>());
|
||||
environment.getPropertySources().addFirst(ps);
|
||||
}
|
||||
ps.getSource().putAll(convertInlinedPropertiesToMap(inlinedProperties));
|
||||
|
|
@ -285,21 +282,19 @@ public abstract class TestPropertySourceUtils {
|
|||
public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) {
|
||||
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
Properties props = new Properties();
|
||||
|
||||
for (String pair : inlinedProperties) {
|
||||
if (!StringUtils.hasText(pair)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
props.load(new StringReader(pair));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to load test environment property from [" + pair + "].", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex);
|
||||
}
|
||||
Assert.state(props.size() == 1, "Failed to load exactly one test environment property from [" + pair + "].");
|
||||
|
||||
Assert.state(props.size() == 1, "Failed to load exactly one test environment property from [" + pair + "]");
|
||||
for (String name : props.stringPropertyNames()) {
|
||||
map.put(name, props.getProperty(name));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -719,28 +719,22 @@ public class Jackson2ObjectMapperBuilder {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) {
|
||||
// Java 7 java.nio.file.Path class present?
|
||||
if (ClassUtils.isPresent("java.nio.file.Path", this.moduleClassLoader)) {
|
||||
try {
|
||||
Class<? extends Module> jdk7Module = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk7.Jdk7Module", this.moduleClassLoader);
|
||||
objectMapper.registerModule(BeanUtils.instantiate(jdk7Module));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk7 not available
|
||||
}
|
||||
try {
|
||||
Class<? extends Module> jdk7Module = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk7.Jdk7Module", this.moduleClassLoader);
|
||||
objectMapper.registerModule(BeanUtils.instantiate(jdk7Module));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk7 not available
|
||||
}
|
||||
|
||||
// Java 8 java.util.Optional class present?
|
||||
if (ClassUtils.isPresent("java.util.Optional", this.moduleClassLoader)) {
|
||||
try {
|
||||
Class<? extends Module> jdk8Module = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk8.Jdk8Module", this.moduleClassLoader);
|
||||
objectMapper.registerModule(BeanUtils.instantiate(jdk8Module));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk8 not available
|
||||
}
|
||||
try {
|
||||
Class<? extends Module> jdk8Module = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk8.Jdk8Module", this.moduleClassLoader);
|
||||
objectMapper.registerModule(BeanUtils.instantiate(jdk8Module));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk8 not available
|
||||
}
|
||||
|
||||
// Java 8 java.time package present?
|
||||
|
|
@ -812,7 +806,7 @@ public class Jackson2ObjectMapperBuilder {
|
|||
return new XmlMapper(new XmlFactory(xmlInputFactory()), module);
|
||||
}
|
||||
|
||||
private static final XMLInputFactory xmlInputFactory() {
|
||||
private static XMLInputFactory xmlInputFactory() {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -34,7 +34,6 @@ import org.springframework.beans.factory.DisposableBean;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
|
@ -190,7 +189,6 @@ public abstract class AbstractJaxWsServiceExporter implements BeanFactoryAware,
|
|||
* @see Endpoint#create(Object)
|
||||
* @see Endpoint#create(String, Object)
|
||||
*/
|
||||
@UsesJava7 // optional use of Endpoint#create with WebServiceFeature[]
|
||||
protected Endpoint createEndpoint(Object bean) {
|
||||
if (this.endpointFeatures != null || this.webServiceFeatures != null) {
|
||||
WebServiceFeature[] endpointFeaturesToUse = this.endpointFeatures;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -25,7 +25,6 @@ import javax.xml.ws.WebServiceFeature;
|
|||
import javax.xml.ws.handler.HandlerResolver;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -147,7 +146,6 @@ public class LocalJaxWsServiceFactory {
|
|||
* @see #setServiceName
|
||||
* @see #setWsdlDocumentUrl
|
||||
*/
|
||||
@UsesJava7 // optional use of Service#create with WebServiceFeature[]
|
||||
public Service createJaxWsService() {
|
||||
Assert.notNull(this.serviceName, "No service name specified");
|
||||
Service service;
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@ import org.springframework.core.annotation.AliasFor;
|
|||
* {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the
|
||||
* {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter}
|
||||
* pair which are the default in the MVC Java config and the MVC namespace.
|
||||
* In particular {@code @CrossOrigin} is not supported with the
|
||||
* {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter}
|
||||
* pair both of which are also deprecated.
|
||||
*
|
||||
* @author Russell Allen
|
||||
* @author Sebastien Deleuze
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import java.lang.annotation.Target;
|
|||
* @since 3.0
|
||||
* @see RequestMapping
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
|
||||
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||
* @see RequestHeader
|
||||
* @see ResponseBody
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
|
||||
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
|||
|
|
@ -235,19 +235,8 @@ import org.springframework.core.annotation.AliasFor;
|
|||
* <p><b>NOTE:</b> {@code @RequestMapping} will only be processed if an
|
||||
* an appropriate {@code HandlerMapping}-{@code HandlerAdapter} pair
|
||||
* is configured. If you are defining custom {@code HandlerMappings} or
|
||||
* {@code HandlerAdapters}, then you need to add
|
||||
* {@code DefaultAnnotationHandlerMapping} and
|
||||
* {@code AnnotationMethodHandlerAdapter} to your configuration.</code>.
|
||||
*
|
||||
* <p><b>NOTE:</b> Spring 3.1 introduced a new set of support classes for
|
||||
* {@code @RequestMapping} methods in Servlet environments called
|
||||
* {@code RequestMappingHandlerMapping} and
|
||||
* {@code RequestMappingHandlerAdapter}. They are recommended for use and
|
||||
* even required to take advantage of new features in Spring MVC 3.1 (search
|
||||
* {@literal "@MVC 3.1-only"} in this source file) and going forward.
|
||||
* The new support classes are enabled by default from the MVC namespace and
|
||||
* with use of the MVC Java config ({@code @EnableWebMvc}) but must be
|
||||
* configured explicitly if using neither.
|
||||
* {@code HandlerAdapters}, then you need to add {@code RequestMappingHandlerMapping}
|
||||
* and {@code RequestMappingHandlerAdapter} to your configuration.</code>.
|
||||
*
|
||||
* <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
|
||||
* make sure to consistently put <i>all</i> your mapping annotations - such as
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ import org.springframework.stereotype.Controller;
|
|||
* {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the
|
||||
* {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter}
|
||||
* pair which are the default in the MVC Java config and the MVC namespace.
|
||||
* In particular {@code @RestController} is not supported with the
|
||||
* {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter}
|
||||
* pair both of which are also deprecated.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@ import org.springframework.core.annotation.AliasFor;
|
|||
* {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the
|
||||
* {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter} pair
|
||||
* which are the default in the MVC Java config and the MVC namespace.
|
||||
* In particular {@code @RestControllerAdvice} is not supported with the
|
||||
* {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter}
|
||||
* pair both of which are also deprecated.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.3
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -39,7 +39,7 @@ import org.springframework.web.context.request.NativeWebRequest;
|
|||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.2
|
||||
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomArgumentResolvers
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#setCustomArgumentResolvers
|
||||
*/
|
||||
public interface WebArgumentResolver {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -79,7 +79,6 @@ public abstract class AbstractRequestAttributesScope implements Scope {
|
|||
* {@link RequestAttributes} constant
|
||||
* @see RequestAttributes#SCOPE_REQUEST
|
||||
* @see RequestAttributes#SCOPE_SESSION
|
||||
* @see RequestAttributes#SCOPE_GLOBAL_SESSION
|
||||
*/
|
||||
protected abstract int getScope();
|
||||
|
||||
|
|
|
|||
|
|
@ -64,9 +64,7 @@ public abstract class WebAsyncUtils {
|
|||
|
||||
/**
|
||||
* Create an AsyncWebRequest instance. By default, an instance of
|
||||
* {@link StandardServletAsyncWebRequest} gets created when running in
|
||||
* Servlet 3.0 (or higher) environment - as a fallback, an instance
|
||||
* of {@link NoSupportAsyncWebRequest} will be returned.
|
||||
* {@link StandardServletAsyncWebRequest} gets created.
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
* @return an AsyncWebRequest instance (never {@code null})
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.method;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.util.ReflectionUtils.MethodFilter;
|
||||
|
||||
/**
|
||||
* Defines the algorithm for searching handler methods exhaustively including interfaces and parent
|
||||
* classes while also dealing with parameterized methods as well as interface and class-based proxies.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
* @deprecated as of Spring 4.2.3, in favor of the generalized and refined {@link MethodIntrospector}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class HandlerMethodSelector {
|
||||
|
||||
/**
|
||||
* Select handler methods for the given handler type.
|
||||
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
|
||||
* @param handlerType the handler type to search handler methods on
|
||||
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
|
||||
* @return the selected methods, or an empty set
|
||||
* @see MethodIntrospector#selectMethods(Class, MethodFilter)
|
||||
*/
|
||||
public static Set<Method> selectMethods(Class<?> handlerType, MethodFilter handlerMethodFilter) {
|
||||
return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||
* constructor (and then added to the model). Once created the attribute is
|
||||
* populated via data binding to Servlet request parameters. Validation may be
|
||||
* applied if the argument is annotated with {@code @javax.validation.Valid}.
|
||||
* or {@link @Validated}.
|
||||
* or Spring's own {@code @org.springframework.validation.annotation.Validated}.
|
||||
*
|
||||
* <p>When this handler is created with {@code annotationNotRequired=true}
|
||||
* any non-simple type argument and return value is regarded as a model
|
||||
|
|
|
|||
|
|
@ -98,13 +98,13 @@ public abstract class MultipartResolutionDelegate {
|
|||
}
|
||||
}
|
||||
else if (Part.class == parameter.getNestedParameterType()) {
|
||||
return (isMultipart ? RequestPartResolver.resolvePart(request, name) : null);
|
||||
return (isMultipart ? resolvePart(request, name) : null);
|
||||
}
|
||||
else if (isPartCollection(parameter)) {
|
||||
return (isMultipart ? RequestPartResolver.resolvePartList(request, name) : null);
|
||||
return (isMultipart ? resolvePartList(request, name) : null);
|
||||
}
|
||||
else if (isPartArray(parameter)) {
|
||||
return (isMultipart ? RequestPartResolver.resolvePartArray(request, name) : null);
|
||||
return (isMultipart ? resolvePartArray(request, name) : null);
|
||||
}
|
||||
else {
|
||||
return UNRESOLVABLE;
|
||||
|
|
@ -138,37 +138,30 @@ public abstract class MultipartResolutionDelegate {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static Part resolvePart(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
return servletRequest.getPart(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class to avoid hard-coded dependency on Servlet 3.0 Part type...
|
||||
*/
|
||||
private static class RequestPartResolver {
|
||||
|
||||
public static Object resolvePart(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
return servletRequest.getPart(name);
|
||||
}
|
||||
|
||||
public static Object resolvePartList(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
Collection<Part> parts = servletRequest.getParts();
|
||||
List<Part> result = new ArrayList<Part>(parts.size());
|
||||
for (Part part : parts) {
|
||||
if (part.getName().equals(name)) {
|
||||
result.add(part);
|
||||
}
|
||||
private static List<Part> resolvePartList(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
Collection<Part> parts = servletRequest.getParts();
|
||||
List<Part> result = new ArrayList<Part>(parts.size());
|
||||
for (Part part : parts) {
|
||||
if (part.getName().equals(name)) {
|
||||
result.add(part);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Object resolvePartArray(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
Collection<Part> parts = servletRequest.getParts();
|
||||
List<Part> result = new ArrayList<Part>(parts.size());
|
||||
for (Part part : parts) {
|
||||
if (part.getName().equals(name)) {
|
||||
result.add(part);
|
||||
}
|
||||
private static Part[] resolvePartArray(HttpServletRequest servletRequest, String name) throws Exception {
|
||||
Collection<Part> parts = servletRequest.getParts();
|
||||
List<Part> result = new ArrayList<Part>(parts.size());
|
||||
for (Part part : parts) {
|
||||
if (part.getName().equals(name)) {
|
||||
result.add(part);
|
||||
}
|
||||
return result.toArray(new Part[result.size()]);
|
||||
}
|
||||
return result.toArray(new Part[result.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ import org.springframework.web.util.WebUtils;
|
|||
* <li>It can use any {@link HandlerMapping} implementation - pre-built or provided as part
|
||||
* of an application - to control the routing of requests to handler objects. Default is
|
||||
* {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping} and
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping}.
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}.
|
||||
* HandlerMapping objects can be defined as beans in the servlet's application context,
|
||||
* implementing the HandlerMapping interface, overriding the default HandlerMapping if
|
||||
* present. HandlerMappings can be given any bean name (they are tested by type).
|
||||
|
|
@ -84,7 +84,7 @@ import org.springframework.web.util.WebUtils;
|
|||
* {@link org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter}, for Spring's
|
||||
* {@link org.springframework.web.HttpRequestHandler} and
|
||||
* {@link org.springframework.web.servlet.mvc.Controller} interfaces, respectively. A default
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter}
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter}
|
||||
* will be registered as well. HandlerAdapter objects can be added as beans in the
|
||||
* application context, overriding the default HandlerAdapters. Like HandlerMappings,
|
||||
* HandlerAdapters can be given any bean name (they are tested by type).
|
||||
|
|
@ -92,7 +92,7 @@ import org.springframework.web.util.WebUtils;
|
|||
* <li>The dispatcher's exception resolution strategy can be specified via a
|
||||
* {@link HandlerExceptionResolver}, for example mapping certain exceptions to error pages.
|
||||
* Default are
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver},
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver},
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver}, and
|
||||
* {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver}.
|
||||
* These HandlerExceptionResolvers can be overridden through the application context.
|
||||
|
|
@ -131,7 +131,7 @@ import org.springframework.web.util.WebUtils;
|
|||
* {@code HandlerAdapter} (for method-level annotations) is present in the dispatcher.</b>
|
||||
* This is the case by default. However, if you are defining custom {@code HandlerMappings}
|
||||
* or {@code HandlerAdapters}, then you need to make sure that a corresponding custom
|
||||
* {@code DefaultAnnotationHandlerMapping} and/or {@code AnnotationMethodHandlerAdapter}
|
||||
* {@code RequestMappingHandlerMapping} and/or {@code RequestMappingHandlerAdapter}
|
||||
* is defined as well - provided that you intend to use {@code @RequestMapping}.
|
||||
*
|
||||
* <p><b>A web application can define any number of DispatcherServlets.</b>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
*
|
||||
* <p>This class can be implemented by application developers, although this is not
|
||||
* necessary, as {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping}
|
||||
* and {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping}
|
||||
* and {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}
|
||||
* are included in the framework. The former is the default if no
|
||||
* HandlerMapping bean is registered in the application context.
|
||||
*
|
||||
|
|
@ -49,7 +49,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
* @see org.springframework.core.Ordered
|
||||
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping
|
||||
* @see org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
|
||||
* @see org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
|
||||
*/
|
||||
public interface HandlerMapping {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,9 +28,9 @@ import org.springframework.util.StringUtils;
|
|||
*
|
||||
* <p>This is the default implementation used by the
|
||||
* {@link org.springframework.web.servlet.DispatcherServlet}, along with
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping}
|
||||
* (on Java 5 and higher). Alternatively, {@link SimpleUrlHandlerMapping} allows for
|
||||
* customizing a handler mapping declaratively.
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}.
|
||||
* Alternatively, {@link SimpleUrlHandlerMapping} allows for customizing a
|
||||
* handler mapping declaratively.
|
||||
*
|
||||
* <p>The mapping is from URL to bean name. Thus an incoming URL "/foo" would map
|
||||
* to a handler named "/foo", or to "/foo /foo2" in case of multiple mappings to
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.context.i18n.SimpleLocaleContext;
|
||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.LocaleContextResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
|
@ -242,7 +241,6 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
|
|||
* @return the corresponding {@code Locale} instance
|
||||
* @since 4.3
|
||||
*/
|
||||
@UsesJava7
|
||||
protected Locale parseLocaleValue(String locale) {
|
||||
return (isLanguageTagCompliant() ? Locale.forLanguageTag(locale) : StringUtils.parseLocaleString(locale));
|
||||
}
|
||||
|
|
@ -256,7 +254,6 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
|
|||
* @return a String representation for the given locale
|
||||
* @since 4.3
|
||||
*/
|
||||
@UsesJava7
|
||||
protected String toLocaleValue(Locale locale) {
|
||||
return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
|
@ -183,7 +182,6 @@ public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {
|
|||
* @return the corresponding {@code Locale} instance
|
||||
* @since 4.3
|
||||
*/
|
||||
@UsesJava7
|
||||
protected Locale parseLocaleValue(String locale) {
|
||||
return (isLanguageTagCompliant() ? Locale.forLanguageTag(locale) : StringUtils.parseLocaleString(locale));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
||||
import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* Handles return values of type {@link CompletionStage} (implemented by
|
||||
* {@link java.util.concurrent.CompletableFuture} for example).
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2
|
||||
*
|
||||
* @deprecated as of 4.3 {@link DeferredResultMethodReturnValueHandler} supports
|
||||
* CompletionStage return values via an adapter mechanism.
|
||||
*/
|
||||
@Deprecated
|
||||
@UsesJava8
|
||||
public class CompletionStageReturnValueHandler implements AsyncHandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return CompletionStage.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
||||
return (returnValue != null && returnValue instanceof CompletionStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final DeferredResult<Object> deferredResult = new DeferredResult<Object>();
|
||||
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
CompletionStage<Object> future = (CompletionStage<Object>) returnValue;
|
||||
future.thenAccept(new Consumer<Object>() {
|
||||
@Override
|
||||
public void accept(Object result) {
|
||||
deferredResult.setResult(result);
|
||||
}
|
||||
});
|
||||
future.exceptionally(new Function<Throwable, Object>() {
|
||||
@Override
|
||||
public Object apply(Throwable ex) {
|
||||
deferredResult.setErrorResult(ex);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,9 +22,7 @@ import java.util.concurrent.CompletionStage;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
|
@ -50,9 +48,7 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho
|
|||
this.adapterMap = new HashMap<Class<?>, DeferredResultAdapter>(5);
|
||||
this.adapterMap.put(DeferredResult.class, new SimpleDeferredResultAdapter());
|
||||
this.adapterMap.put(ListenableFuture.class, new ListenableFutureAdapter());
|
||||
if (ClassUtils.isPresent("java.util.concurrent.CompletionStage", getClass().getClassLoader())) {
|
||||
this.adapterMap.put(CompletionStage.class, new CompletionStageAdapter());
|
||||
}
|
||||
this.adapterMap.put(CompletionStage.class, new CompletionStageAdapter());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -114,6 +110,7 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapter for {@code ListenableFuture} return values.
|
||||
*/
|
||||
|
|
@ -137,10 +134,10 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapter for {@code CompletionStage} return values.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class CompletionStageAdapter implements DeferredResultAdapter {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
||||
import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* Handles return values of type
|
||||
* {@link org.springframework.util.concurrent.ListenableFuture}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
*
|
||||
* @deprecated as of 4.3 {@link DeferredResultMethodReturnValueHandler} supports
|
||||
* ListenableFuture return values via an adapter mechanism.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ListenableFutureReturnValueHandler implements AsyncHandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return ListenableFuture.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
||||
return (returnValue != null && returnValue instanceof ListenableFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final DeferredResult<Object> deferredResult = new DeferredResult<Object>();
|
||||
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer);
|
||||
|
||||
ListenableFuture<?> future = (ListenableFuture<?>) returnValue;
|
||||
future.addCallback(new ListenableFutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
deferredResult.setResult(result);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
deferredResult.setErrorResult(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -38,8 +38,8 @@ import org.springframework.cglib.proxy.Enhancer;
|
|||
import org.springframework.cglib.proxy.Factory;
|
||||
import org.springframework.cglib.proxy.MethodProxy;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
|
|
@ -778,7 +778,6 @@ public class MvcUriComponentsBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see #MethodArgumentBuilder(Class, Method)
|
||||
* @deprecated as of 4.2, this is deprecated in favor of alternative constructors
|
||||
* that accept a controllerType argument
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
|
|
@ -158,7 +157,13 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
|||
}
|
||||
}
|
||||
if (parameter.isOptional()) {
|
||||
arg = OptionalResolver.resolveValue(arg);
|
||||
if (arg == null || (arg instanceof Collection && ((Collection) arg).isEmpty()) ||
|
||||
(arg instanceof Object[] && ((Object[]) arg).length == 0)) {
|
||||
arg = Optional.empty();
|
||||
}
|
||||
else {
|
||||
arg = Optional.of(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return arg;
|
||||
|
|
@ -177,20 +182,4 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
|||
return partName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid hard-coded dependency on Java 8 Optional type...
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class OptionalResolver {
|
||||
|
||||
public static Object resolveValue(Object value) {
|
||||
if (value == null || (value instanceof Collection && ((Collection) value).isEmpty()) ||
|
||||
(value instanceof Object[] && ((Object[]) value).length == 0)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,7 +28,6 @@ import javax.servlet.http.HttpSession;
|
|||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
|
@ -131,7 +130,6 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
|||
/**
|
||||
* Inner class to avoid a hard-coded dependency on Java 8's {@link java.time.ZoneId}.
|
||||
*/
|
||||
@UsesJava8
|
||||
private static class ZoneIdResolver {
|
||||
|
||||
public static Object resolveZoneId(HttpServletRequest request) {
|
||||
|
|
|
|||
|
|
@ -142,22 +142,6 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* The origin of this test class is {@link ServletAnnotationControllerHandlerMethodTests}.
|
||||
*
|
||||
* Tests in this class run against the {@link HandlerMethod} infrastructure:
|
||||
* <ul>
|
||||
* <li>RequestMappingHandlerMapping
|
||||
* <li>RequestMappingHandlerAdapter
|
||||
* <li>ExceptionHandlerExceptionResolver
|
||||
* </ul>
|
||||
*
|
||||
* <p>Rather than against the existing infrastructure:
|
||||
* <ul>
|
||||
* <li>DefaultAnnotationHandlerMapping
|
||||
* <li>AnnotationMethodHandlerAdapter
|
||||
* <li>AnnotationMethodHandlerExceptionResolver
|
||||
* </ul>
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandlerMethodTests {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -46,7 +46,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
|
@ -54,20 +53,6 @@ import org.springframework.web.servlet.view.AbstractView;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests in this class run against the {@link HandlerMethod} infrastructure:
|
||||
* <ul>
|
||||
* <li>RequestMappingHandlerMapping
|
||||
* <li>RequestMappingHandlerAdapter
|
||||
* <li>ExceptionHandlerExceptionResolver
|
||||
* </ul>
|
||||
*
|
||||
* <p>Rather than against the existing infrastructure:
|
||||
* <ul>
|
||||
* <li>DefaultAnnotationHandlerMapping
|
||||
* <li>AnnotationMethodHandlerAdapter
|
||||
* <li>AnnotationMethodHandlerExceptionResolver
|
||||
* </ul>
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
import javax.websocket.ClientEndpointConfig.Configurator;
|
||||
import javax.websocket.ContainerProvider;
|
||||
|
|
@ -39,7 +38,6 @@ import org.springframework.core.task.AsyncListenableTaskExecutor;
|
|||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
|
|
@ -51,7 +49,6 @@ import org.springframework.web.socket.adapter.standard.StandardWebSocketSession;
|
|||
import org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter;
|
||||
import org.springframework.web.socket.client.AbstractWebSocketClient;
|
||||
|
||||
|
||||
/**
|
||||
* A WebSocketClient based on standard Java WebSocket API.
|
||||
*
|
||||
|
|
@ -172,7 +169,6 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
|
|||
return result;
|
||||
}
|
||||
|
||||
@UsesJava7 // fallback to InetAddress.getLoopbackAddress()
|
||||
private InetAddress getLocalHost() {
|
||||
try {
|
||||
return InetAddress.getLocalHost();
|
||||
|
|
|
|||
|
|
@ -1290,7 +1290,7 @@ a better feel for its functionality
|
|||
|
||||
Concrete implementations for the main media (mime) types are provided in the framework
|
||||
and are registered by default with the `RestTemplate` on the client-side and with
|
||||
`AnnotationMethodHandlerAdapter` on the server-side.
|
||||
`RequestMethodHandlerAdapter` on the server-side.
|
||||
|
||||
The implementations of ``HttpMessageConverter``s are described in the following sections.
|
||||
For all converters a default media type is used but can be overridden by setting the
|
||||
|
|
|
|||
|
|
@ -2132,7 +2132,7 @@ controller-specific tweaking of the binding rules.
|
|||
|
||||
To externalize data binding initialization, you can provide a custom implementation of
|
||||
the `WebBindingInitializer` interface, which you then enable by supplying a custom bean
|
||||
configuration for an `AnnotationMethodHandlerAdapter`, thus overriding the default
|
||||
configuration for an `RequestMappingHandlerAdapter`, thus overriding the default
|
||||
configuration.
|
||||
|
||||
The following example from the PetClinic application shows a configuration using a
|
||||
|
|
|
|||
Loading…
Reference in New Issue