Merge pull request #1454 from diguage:lambda
* pr/1454: Polish "Replace relevant code with lambda" Replace relevant code with lambda
This commit is contained in:
commit
40df48fd95
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -76,12 +76,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
|
||||||
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
|
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
|
||||||
|
|
||||||
// Excludes methods implemented.
|
// Excludes methods implemented.
|
||||||
ClassFilter exclusion = new ClassFilter() {
|
ClassFilter exclusion = clazz -> !(introducedInterface.isAssignableFrom(clazz));
|
||||||
@Override
|
|
||||||
public boolean matches(Class<?> clazz) {
|
|
||||||
return !(introducedInterface.isAssignableFrom(clazz));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
|
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
|
||||||
this.advice = advice;
|
this.advice = advice;
|
||||||
|
|
|
||||||
|
|
@ -76,21 +76,12 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
Comparator<Method> adviceKindComparator = new ConvertingComparator<>(
|
Comparator<Method> adviceKindComparator = new ConvertingComparator<>(
|
||||||
new InstanceComparator<>(
|
new InstanceComparator<>(
|
||||||
Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class),
|
Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class),
|
||||||
new Converter<Method, Annotation>() {
|
(Converter<Method, Annotation>) method -> {
|
||||||
@Override
|
AspectJAnnotation<?> annotation =
|
||||||
public Annotation convert(Method method) {
|
AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
|
||||||
AspectJAnnotation<?> annotation =
|
return (annotation != null ? annotation.getAnnotation() : null);
|
||||||
AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
|
|
||||||
return (annotation != null ? annotation.getAnnotation() : null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Comparator<Method> methodNameComparator = new ConvertingComparator<>(
|
|
||||||
new Converter<Method, String>() {
|
|
||||||
@Override
|
|
||||||
public String convert(Method method) {
|
|
||||||
return method.getName();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
Comparator<Method> methodNameComparator = new ConvertingComparator<>(Method::getName);
|
||||||
METHOD_COMPARATOR = adviceKindComparator.thenComparing(methodNameComparator);
|
METHOD_COMPARATOR = adviceKindComparator.thenComparing(methodNameComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,13 +148,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
|
|
||||||
private List<Method> getAdvisorMethods(Class<?> aspectClass) {
|
private List<Method> getAdvisorMethods(Class<?> aspectClass) {
|
||||||
final List<Method> methods = new LinkedList<>();
|
final List<Method> methods = new LinkedList<>();
|
||||||
ReflectionUtils.doWithMethods(aspectClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithMethods(aspectClass, method -> {
|
||||||
@Override
|
// Exclude pointcuts
|
||||||
public void doWith(Method method) throws IllegalArgumentException {
|
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
|
||||||
// Exclude pointcuts
|
methods.add(method);
|
||||||
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
|
|
||||||
methods.add(method);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Collections.sort(methods, METHOD_COMPARATOR);
|
Collections.sort(methods, METHOD_COMPARATOR);
|
||||||
|
|
|
||||||
|
|
@ -264,15 +264,12 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
|
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
|
||||||
if (CompletableFuture.class.isAssignableFrom(returnType)) {
|
if (CompletableFuture.class.isAssignableFrom(returnType)) {
|
||||||
return CompletableFuture.supplyAsync(new Supplier<Object>() {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
@Override
|
try {
|
||||||
public Object get() {
|
return task.call();
|
||||||
try {
|
}
|
||||||
return task.call();
|
catch (Throwable ex) {
|
||||||
}
|
throw new CompletionException(ex);
|
||||||
catch (Throwable ex) {
|
|
||||||
throw new CompletionException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, executor);
|
}, executor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,23 +109,20 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
||||||
"No executor specified and no default executor set on AsyncExecutionInterceptor either");
|
"No executor specified and no default executor set on AsyncExecutionInterceptor either");
|
||||||
}
|
}
|
||||||
|
|
||||||
Callable<Object> task = new Callable<Object>() {
|
Callable<Object> task = () -> {
|
||||||
@Override
|
try {
|
||||||
public Object call() throws Exception {
|
Object result = invocation.proceed();
|
||||||
try {
|
if (result instanceof Future) {
|
||||||
Object result = invocation.proceed();
|
return ((Future<?>) result).get();
|
||||||
if (result instanceof Future) {
|
|
||||||
return ((Future<?>) result).get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (ExecutionException ex) {
|
|
||||||
handleError(ex.getCause(), userDeclaredMethod, invocation.getArguments());
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
handleError(ex, userDeclaredMethod, invocation.getArguments());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
catch (ExecutionException ex) {
|
||||||
|
handleError(ex.getCause(), userDeclaredMethod, invocation.getArguments());
|
||||||
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
handleError(ex, userDeclaredMethod, invocation.getArguments());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return doSubmit(task, executor, invocation.getMethod().getReturnType());
|
return doSubmit(task, executor, invocation.getMethod().getReturnType());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -28,7 +28,6 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -139,12 +138,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
// Sort non-void returning write methods to guard against the ill effects of
|
// Sort non-void returning write methods to guard against the ill effects of
|
||||||
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
|
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
|
||||||
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
|
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
|
||||||
Collections.sort(matches, new Comparator<Method>() {
|
matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
|
||||||
@Override
|
|
||||||
public int compare(Method m1, Method m2) {
|
|
||||||
return m2.toString().compareTo(m1.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,13 +245,10 @@ public abstract class PropertyMatches {
|
||||||
|
|
||||||
private static String[] calculateMatches(final String propertyName, Class<?> beanClass, final int maxDistance) {
|
private static String[] calculateMatches(final String propertyName, Class<?> beanClass, final int maxDistance) {
|
||||||
final List<String> candidates = new ArrayList<>();
|
final List<String> candidates = new ArrayList<>();
|
||||||
ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
|
ReflectionUtils.doWithFields(beanClass, field -> {
|
||||||
@Override
|
String possibleAlternative = field.getName();
|
||||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
if (calculateStringDistance(propertyName, possibleAlternative) <= maxDistance) {
|
||||||
String possibleAlternative = field.getName();
|
candidates.add(possibleAlternative);
|
||||||
if (calculateStringDistance(propertyName, possibleAlternative) <= maxDistance) {
|
|
||||||
candidates.add(possibleAlternative);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Collections.sort(candidates);
|
Collections.sort(candidates);
|
||||||
|
|
|
||||||
|
|
@ -239,20 +239,17 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
// Let's check for lookup methods here..
|
// Let's check for lookup methods here..
|
||||||
if (!this.lookupMethodsChecked.contains(beanName)) {
|
if (!this.lookupMethodsChecked.contains(beanName)) {
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithMethods(beanClass, method -> {
|
||||||
@Override
|
Lookup lookup = method.getAnnotation(Lookup.class);
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
if (lookup != null) {
|
||||||
Lookup lookup = method.getAnnotation(Lookup.class);
|
LookupOverride override = new LookupOverride(method, lookup.value());
|
||||||
if (lookup != null) {
|
try {
|
||||||
LookupOverride override = new LookupOverride(method, lookup.value());
|
RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName);
|
||||||
try {
|
mbd.getMethodOverrides().addOverride(override);
|
||||||
RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName);
|
}
|
||||||
mbd.getMethodOverrides().addOverride(override);
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
}
|
throw new BeanCreationException(beanName,
|
||||||
catch (NoSuchBeanDefinitionException ex) {
|
"Cannot apply @Lookup to beans without corresponding bean definition");
|
||||||
throw new BeanCreationException(beanName,
|
|
||||||
"Cannot apply @Lookup to beans without corresponding bean definition");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -414,48 +411,42 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
do {
|
do {
|
||||||
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
|
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalFields(targetClass, new ReflectionUtils.FieldCallback() {
|
ReflectionUtils.doWithLocalFields(targetClass, field -> {
|
||||||
@Override
|
AnnotationAttributes ann = findAutowiredAnnotation(field);
|
||||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
if (ann != null) {
|
||||||
AnnotationAttributes ann = findAutowiredAnnotation(field);
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
if (ann != null) {
|
if (logger.isWarnEnabled()) {
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
logger.warn("Autowired annotation is not supported on static fields: " + field);
|
||||||
if (logger.isWarnEnabled()) {
|
|
||||||
logger.warn("Autowired annotation is not supported on static fields: " + field);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
boolean required = determineRequiredStatus(ann);
|
return;
|
||||||
currElements.add(new AutowiredFieldElement(field, required));
|
|
||||||
}
|
}
|
||||||
|
boolean required = determineRequiredStatus(ann);
|
||||||
|
currElements.add(new AutowiredFieldElement(field, required));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
|
||||||
@Override
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
return;
|
||||||
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
}
|
||||||
|
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
|
||||||
|
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
|
logger.warn("Autowired annotation is not supported on static methods: " + method);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
|
if (method.getParameterCount() == 0) {
|
||||||
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
if (logger.isWarnEnabled()) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
logger.warn("Autowired annotation should only be used on methods with parameters: " +
|
||||||
if (logger.isWarnEnabled()) {
|
method);
|
||||||
logger.warn("Autowired annotation is not supported on static methods: " + method);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (method.getParameterCount() == 0) {
|
|
||||||
if (logger.isWarnEnabled()) {
|
|
||||||
logger.warn("Autowired annotation should only be used on methods with parameters: " +
|
|
||||||
method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean required = determineRequiredStatus(ann);
|
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
|
||||||
currElements.add(new AutowiredMethodElement(method, required, pd));
|
|
||||||
}
|
}
|
||||||
|
boolean required = determineRequiredStatus(ann);
|
||||||
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
|
currElements.add(new AutowiredMethodElement(method, required, pd));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -201,24 +201,21 @@ public class InitDestroyAnnotationBeanPostProcessor
|
||||||
final LinkedList<LifecycleElement> currInitMethods = new LinkedList<>();
|
final LinkedList<LifecycleElement> currInitMethods = new LinkedList<>();
|
||||||
final LinkedList<LifecycleElement> currDestroyMethods = new LinkedList<>();
|
final LinkedList<LifecycleElement> currDestroyMethods = new LinkedList<>();
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
|
||||||
@Override
|
if (initAnnotationType != null) {
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
if (method.getAnnotation(initAnnotationType) != null) {
|
||||||
if (initAnnotationType != null) {
|
LifecycleElement element = new LifecycleElement(method);
|
||||||
if (method.getAnnotation(initAnnotationType) != null) {
|
currInitMethods.add(element);
|
||||||
LifecycleElement element = new LifecycleElement(method);
|
if (debug) {
|
||||||
currInitMethods.add(element);
|
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
|
||||||
if (debug) {
|
|
||||||
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (destroyAnnotationType != null) {
|
}
|
||||||
if (method.getAnnotation(destroyAnnotationType) != null) {
|
if (destroyAnnotationType != null) {
|
||||||
currDestroyMethods.add(new LifecycleElement(method));
|
if (method.getAnnotation(destroyAnnotationType) != null) {
|
||||||
if (debug) {
|
currDestroyMethods.add(new LifecycleElement(method));
|
||||||
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
|
if (debug) {
|
||||||
}
|
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -877,20 +877,15 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||||
|
|
||||||
// Find the given factory method, taking into account that in the case of
|
// Find the given factory method, taking into account that in the case of
|
||||||
// @Bean methods, there may be parameters present.
|
// @Bean methods, there may be parameters present.
|
||||||
ReflectionUtils.doWithMethods(fbClass,
|
ReflectionUtils.doWithMethods(fbClass, method -> {
|
||||||
new ReflectionUtils.MethodCallback() {
|
if (method.getName().equals(factoryMethodName) &&
|
||||||
@Override
|
FactoryBean.class.isAssignableFrom(method.getReturnType())) {
|
||||||
public void doWith(Method method) {
|
Class<?> currentType = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class);
|
||||||
if (method.getName().equals(factoryMethodName) &&
|
if (currentType != null) {
|
||||||
FactoryBean.class.isAssignableFrom(method.getReturnType())) {
|
objectType.value = ClassUtils.determineCommonAncestor(currentType, objectType.value);
|
||||||
Class<?> currentType = GenericTypeResolver.resolveReturnTypeArgument(
|
}
|
||||||
method, FactoryBean.class);
|
}
|
||||||
if (currentType != null) {
|
});
|
||||||
objectType.value = ClassUtils.determineCommonAncestor(currentType, objectType.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return (objectType.value != null && Object.class != objectType.value ? objectType.value : null);
|
return (objectType.value != null && Object.class != objectType.value ? objectType.value : null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -45,15 +45,12 @@ public class JCacheInterceptor extends JCacheAspectSupport implements MethodInte
|
||||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||||
Method method = invocation.getMethod();
|
Method method = invocation.getMethod();
|
||||||
|
|
||||||
CacheOperationInvoker aopAllianceInvoker = new CacheOperationInvoker() {
|
CacheOperationInvoker aopAllianceInvoker = () -> {
|
||||||
@Override
|
try {
|
||||||
public Object invoke() {
|
return invocation.proceed();
|
||||||
try {
|
}
|
||||||
return invocation.proceed();
|
catch (Throwable ex) {
|
||||||
}
|
throw new CacheOperationInvoker.ThrowableWrapper(ex);
|
||||||
catch (Throwable ex) {
|
|
||||||
throw new ThrowableWrapper(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -107,23 +107,12 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<CacheOperation> findCacheOperations(final Class<?> clazz) {
|
protected Collection<CacheOperation> findCacheOperations(final Class<?> clazz) {
|
||||||
return determineCacheOperations(new CacheOperationProvider() {
|
return determineCacheOperations(parser -> parser.parseCacheAnnotations(clazz));
|
||||||
@Override
|
|
||||||
public Collection<CacheOperation> getCacheOperations(CacheAnnotationParser parser) {
|
|
||||||
return parser.parseCacheAnnotations(clazz);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<CacheOperation> findCacheOperations(final Method method) {
|
protected Collection<CacheOperation> findCacheOperations(final Method method) {
|
||||||
return determineCacheOperations(new CacheOperationProvider() {
|
return determineCacheOperations(parser -> parser.parseCacheAnnotations(method));
|
||||||
@Override
|
|
||||||
public Collection<CacheOperation> getCacheOperations(CacheAnnotationParser parser) {
|
|
||||||
return parser.parseCacheAnnotations(method);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -45,15 +45,12 @@ public class CacheInterceptor extends CacheAspectSupport implements MethodInterc
|
||||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||||
Method method = invocation.getMethod();
|
Method method = invocation.getMethod();
|
||||||
|
|
||||||
CacheOperationInvoker aopAllianceInvoker = new CacheOperationInvoker() {
|
CacheOperationInvoker aopAllianceInvoker = () -> {
|
||||||
@Override
|
try {
|
||||||
public Object invoke() {
|
return invocation.proceed();
|
||||||
try {
|
}
|
||||||
return invocation.proceed();
|
catch (Throwable ex) {
|
||||||
}
|
throw new CacheOperationInvoker.ThrowableWrapper(ex);
|
||||||
catch (Throwable ex) {
|
|
||||||
throw new ThrowableWrapper(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -351,72 +351,66 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
final LinkedList<InjectionMetadata.InjectedElement> currElements =
|
final LinkedList<InjectionMetadata.InjectedElement> currElements =
|
||||||
new LinkedList<>();
|
new LinkedList<>();
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalFields(targetClass, new ReflectionUtils.FieldCallback() {
|
ReflectionUtils.doWithLocalFields(targetClass, field -> {
|
||||||
@Override
|
if (webServiceRefClass != null && field.isAnnotationPresent(webServiceRefClass)) {
|
||||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
if (webServiceRefClass != null && field.isAnnotationPresent(webServiceRefClass)) {
|
throw new IllegalStateException("@WebServiceRef annotation is not supported on static fields");
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
|
||||||
throw new IllegalStateException("@WebServiceRef annotation is not supported on static fields");
|
|
||||||
}
|
|
||||||
currElements.add(new WebServiceRefElement(field, field, null));
|
|
||||||
}
|
}
|
||||||
else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
|
currElements.add(new WebServiceRefElement(field, field, null));
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
}
|
||||||
throw new IllegalStateException("@EJB annotation is not supported on static fields");
|
else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
|
||||||
}
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
currElements.add(new EjbRefElement(field, field, null));
|
throw new IllegalStateException("@EJB annotation is not supported on static fields");
|
||||||
}
|
}
|
||||||
else if (field.isAnnotationPresent(Resource.class)) {
|
currElements.add(new EjbRefElement(field, field, null));
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
}
|
||||||
throw new IllegalStateException("@Resource annotation is not supported on static fields");
|
else if (field.isAnnotationPresent(Resource.class)) {
|
||||||
}
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
if (!ignoredResourceTypes.contains(field.getType().getName())) {
|
throw new IllegalStateException("@Resource annotation is not supported on static fields");
|
||||||
currElements.add(new ResourceElement(field, field, null));
|
}
|
||||||
}
|
if (!ignoredResourceTypes.contains(field.getType().getName())) {
|
||||||
|
currElements.add(new ResourceElement(field, field, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
|
||||||
@Override
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
return;
|
||||||
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
}
|
||||||
return;
|
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
|
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
|
||||||
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
|
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
|
||||||
|
}
|
||||||
|
if (method.getParameterCount() != 1) {
|
||||||
|
throw new IllegalStateException("@WebServiceRef annotation requires a single-arg method: " + method);
|
||||||
|
}
|
||||||
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
|
currElements.add(new WebServiceRefElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
else if (ejbRefClass != null && bridgedMethod.isAnnotationPresent(ejbRefClass)) {
|
||||||
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
throw new IllegalStateException("@EJB annotation is not supported on static methods");
|
||||||
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
|
|
||||||
}
|
|
||||||
if (method.getParameterCount() != 1) {
|
|
||||||
throw new IllegalStateException("@WebServiceRef annotation requires a single-arg method: " + method);
|
|
||||||
}
|
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
|
||||||
currElements.add(new WebServiceRefElement(method, bridgedMethod, pd));
|
|
||||||
}
|
}
|
||||||
else if (ejbRefClass != null && bridgedMethod.isAnnotationPresent(ejbRefClass)) {
|
if (method.getParameterCount() != 1) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
throw new IllegalStateException("@EJB annotation requires a single-arg method: " + method);
|
||||||
throw new IllegalStateException("@EJB annotation is not supported on static methods");
|
|
||||||
}
|
|
||||||
if (method.getParameterCount() != 1) {
|
|
||||||
throw new IllegalStateException("@EJB annotation requires a single-arg method: " + method);
|
|
||||||
}
|
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
|
||||||
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
|
|
||||||
}
|
}
|
||||||
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
|
||||||
throw new IllegalStateException("@Resource annotation is not supported on static methods");
|
}
|
||||||
}
|
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
|
||||||
Class<?>[] paramTypes = method.getParameterTypes();
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
if (paramTypes.length != 1) {
|
throw new IllegalStateException("@Resource annotation is not supported on static methods");
|
||||||
throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method);
|
}
|
||||||
}
|
Class<?>[] paramTypes = method.getParameterTypes();
|
||||||
if (!ignoredResourceTypes.contains(paramTypes[0].getName())) {
|
if (paramTypes.length != 1) {
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method);
|
||||||
currElements.add(new ResourceElement(method, bridgedMethod, pd));
|
}
|
||||||
}
|
if (!ignoredResourceTypes.contains(paramTypes[0].getName())) {
|
||||||
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
|
currElements.add(new ResourceElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ package org.springframework.context.annotation;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
@ -280,13 +278,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by previously determined @Order value, if applicable
|
// Sort by previously determined @Order value, if applicable
|
||||||
Collections.sort(configCandidates, new Comparator<BeanDefinitionHolder>() {
|
configCandidates.sort((bd1, bd2) -> {
|
||||||
@Override
|
int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition());
|
||||||
public int compare(BeanDefinitionHolder bd1, BeanDefinitionHolder bd2) {
|
int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition());
|
||||||
int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition());
|
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
|
||||||
int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition());
|
|
||||||
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Detect any custom bean name generation strategy supplied through the enclosing application context
|
// Detect any custom bean name generation strategy supplied through the enclosing application context
|
||||||
|
|
|
||||||
|
|
@ -226,14 +226,11 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||||
logger.debug("Asking bean '" + beanName + "' of type [" + bean.getClass() + "] to stop");
|
logger.debug("Asking bean '" + beanName + "' of type [" + bean.getClass() + "] to stop");
|
||||||
}
|
}
|
||||||
countDownBeanNames.add(beanName);
|
countDownBeanNames.add(beanName);
|
||||||
((SmartLifecycle) bean).stop(new Runnable() {
|
((SmartLifecycle) bean).stop(() -> {
|
||||||
@Override
|
latch.countDown();
|
||||||
public void run() {
|
countDownBeanNames.remove(beanName);
|
||||||
latch.countDown();
|
if (logger.isDebugEnabled()) {
|
||||||
countDownBeanNames.remove(beanName);
|
logger.debug("Bean '" + beanName + "' completed its stop procedure");
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Bean '" + beanName + "' completed its stop procedure");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -872,12 +872,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||||
* certain internal classes from being registered automatically.
|
* certain internal classes from being registered automatically.
|
||||||
*/
|
*/
|
||||||
private void autodetectBeans(final AutodetectCapableMBeanInfoAssembler assembler) {
|
private void autodetectBeans(final AutodetectCapableMBeanInfoAssembler assembler) {
|
||||||
autodetect(new AutodetectCallback() {
|
autodetect((beanClass, beanName) -> assembler.includeBean(beanClass, beanName));
|
||||||
@Override
|
|
||||||
public boolean include(Class<?> beanClass, String beanName) {
|
|
||||||
return assembler.includeBean(beanClass, beanName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -885,12 +880,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||||
* valid MBeans and registers them automatically with the {@code MBeanServer}.
|
* valid MBeans and registers them automatically with the {@code MBeanServer}.
|
||||||
*/
|
*/
|
||||||
private void autodetectMBeans() {
|
private void autodetectMBeans() {
|
||||||
autodetect(new AutodetectCallback() {
|
autodetect((beanClass, beanName) -> isMBean(beanClass));
|
||||||
@Override
|
|
||||||
public boolean include(Class<?> beanClass, String beanName) {
|
|
||||||
return isMBean(beanClass);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,7 @@ public class ConvertingComparator<S, T> implements Comparator<S> {
|
||||||
* @return a new {@link ConvertingComparator} instance
|
* @return a new {@link ConvertingComparator} instance
|
||||||
*/
|
*/
|
||||||
public static <K, V> ConvertingComparator<Map.Entry<K, V>, K> mapEntryKeys(Comparator<K> comparator) {
|
public static <K, V> ConvertingComparator<Map.Entry<K, V>, K> mapEntryKeys(Comparator<K> comparator) {
|
||||||
return new ConvertingComparator<>(comparator, new Converter<Map.Entry<K, V>, K>() {
|
return new ConvertingComparator<>(comparator, source -> source.getKey());
|
||||||
@Override
|
|
||||||
public K convert(Map.Entry<K, V> source) {
|
|
||||||
return source.getKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -102,12 +97,7 @@ public class ConvertingComparator<S, T> implements Comparator<S> {
|
||||||
* @return a new {@link ConvertingComparator} instance
|
* @return a new {@link ConvertingComparator} instance
|
||||||
*/
|
*/
|
||||||
public static <K, V> ConvertingComparator<Map.Entry<K, V>, V> mapEntryValues(Comparator<V> comparator) {
|
public static <K, V> ConvertingComparator<Map.Entry<K, V>, V> mapEntryValues(Comparator<V> comparator) {
|
||||||
return new ConvertingComparator<>(comparator, new Converter<Map.Entry<K, V>, V>() {
|
return new ConvertingComparator<>(comparator, source -> source.getValue());
|
||||||
@Override
|
|
||||||
public V convert(Map.Entry<K, V> source) {
|
|
||||||
return source.getValue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,12 +226,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
|
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
|
||||||
return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
|
return helper.replacePlaceholders(text, placeholderName -> getPropertyAsRawString(placeholderName));
|
||||||
@Override
|
|
||||||
public String resolvePlaceholder(String placeholderName) {
|
|
||||||
return getPropertyAsRawString(placeholderName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -108,12 +108,7 @@ public class PropertyPlaceholderHelper {
|
||||||
*/
|
*/
|
||||||
public String replacePlaceholders(String value, final Properties properties) {
|
public String replacePlaceholders(String value, final Properties properties) {
|
||||||
Assert.notNull(properties, "'properties' must not be null");
|
Assert.notNull(properties, "'properties' must not be null");
|
||||||
return replacePlaceholders(value, new PlaceholderResolver() {
|
return replacePlaceholders(value, placeholderName -> properties.getProperty(placeholderName));
|
||||||
@Override
|
|
||||||
public String resolvePlaceholder(String placeholderName) {
|
|
||||||
return properties.getProperty(placeholderName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -848,13 +848,8 @@ public abstract class ReflectionUtils {
|
||||||
/**
|
/**
|
||||||
* Pre-built FieldFilter that matches all non-static, non-final fields.
|
* Pre-built FieldFilter that matches all non-static, non-final fields.
|
||||||
*/
|
*/
|
||||||
public static final FieldFilter COPYABLE_FIELDS = new FieldFilter() {
|
public static final FieldFilter COPYABLE_FIELDS =
|
||||||
|
field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
|
||||||
@Override
|
|
||||||
public boolean matches(Field field) {
|
|
||||||
return !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@ import java.util.concurrent.CompletionStage;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a
|
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a
|
||||||
|
|
@ -53,18 +50,14 @@ public class CompletableToListenableFutureAdapter<T> implements ListenableFuture
|
||||||
*/
|
*/
|
||||||
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
||||||
this.completableFuture = completableFuture;
|
this.completableFuture = completableFuture;
|
||||||
this.completableFuture.handle(new BiFunction<T, Throwable, Object>() {
|
this.completableFuture.handle((result, ex) -> {
|
||||||
@Override
|
if (ex != null) {
|
||||||
@Nullable
|
callbacks.failure(ex);
|
||||||
public Object apply(T result, @Nullable Throwable ex) {
|
|
||||||
if (ex != null) {
|
|
||||||
callbacks.failure(ex);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
callbacks.success(result);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
callbacks.success(result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,8 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public class SettableListenableFuture<T> implements ListenableFuture<T> {
|
public class SettableListenableFuture<T> implements ListenableFuture<T> {
|
||||||
|
|
||||||
private static final Callable<Object> DUMMY_CALLABLE = new Callable<Object>() {
|
private static final Callable<Object> DUMMY_CALLABLE = () -> {
|
||||||
@Override
|
throw new IllegalStateException("Should never be called");
|
||||||
public Object call() throws Exception {
|
|
||||||
throw new IllegalStateException("Should never be called");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.asm.ClassWriter;
|
|
||||||
import org.springframework.asm.MethodVisitor;
|
import org.springframework.asm.MethodVisitor;
|
||||||
import org.springframework.expression.EvaluationException;
|
import org.springframework.expression.EvaluationException;
|
||||||
import org.springframework.expression.TypedValue;
|
import org.springframework.expression.TypedValue;
|
||||||
|
|
@ -137,17 +136,11 @@ public class InlineList extends SpelNodeImpl {
|
||||||
final String constantFieldName = "inlineList$" + codeflow.nextFieldId();
|
final String constantFieldName = "inlineList$" + codeflow.nextFieldId();
|
||||||
final String className = codeflow.getClassName();
|
final String className = codeflow.getClassName();
|
||||||
|
|
||||||
codeflow.registerNewField(new CodeFlow.FieldAdder() {
|
codeflow.registerNewField((cw, cflow) ->
|
||||||
public void generateField(ClassWriter cw, CodeFlow codeflow) {
|
cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null));
|
||||||
cw.visitField(ACC_PRIVATE|ACC_STATIC|ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
codeflow.registerNewClinit(new CodeFlow.ClinitAdder() {
|
codeflow.registerNewClinit((mVisitor, cflow) ->
|
||||||
public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
|
generateClinitCode(className, constantFieldName, mVisitor, cflow, false));
|
||||||
generateClinitCode(className, constantFieldName, mv, codeflow, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;");
|
mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;");
|
||||||
codeflow.pushDescriptor("Ljava/util/List");
|
codeflow.pushDescriptor("Ljava/util/List");
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -121,25 +119,22 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||||
|
|
||||||
// Sort methods into a sensible order
|
// Sort methods into a sensible order
|
||||||
if (methods.size() > 1) {
|
if (methods.size() > 1) {
|
||||||
Collections.sort(methods, new Comparator<Method>() {
|
methods.sort((m1, m2) -> {
|
||||||
@Override
|
int m1pl = m1.getParameterCount();
|
||||||
public int compare(Method m1, Method m2) {
|
int m2pl = m2.getParameterCount();
|
||||||
int m1pl = m1.getParameterCount();
|
// varargs methods go last
|
||||||
int m2pl = m2.getParameterCount();
|
if (m1pl == m2pl) {
|
||||||
// varargs methods go last
|
if (!m1.isVarArgs() && m2.isVarArgs()) {
|
||||||
if (m1pl == m2pl) {
|
return -1;
|
||||||
if (!m1.isVarArgs() && m2.isVarArgs()) {
|
}
|
||||||
return -1;
|
else if (m1.isVarArgs() && !m2.isVarArgs()) {
|
||||||
}
|
return 1;
|
||||||
else if (m1.isVarArgs() && !m2.isVarArgs()) {
|
}
|
||||||
return 1;
|
else {
|
||||||
}
|
return 0;
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (m1pl < m2pl ? -1 : (m1pl > m2pl ? 1 : 0));
|
|
||||||
}
|
}
|
||||||
|
return (m1pl < m2pl ? -1 : (m1pl > m2pl ? 1 : 0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -391,12 +391,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||||
*/
|
*/
|
||||||
private Method[] getSortedClassMethods(Class<?> clazz) {
|
private Method[] getSortedClassMethods(Class<?> clazz) {
|
||||||
Method[] methods = clazz.getMethods();
|
Method[] methods = clazz.getMethods();
|
||||||
Arrays.sort(methods, new Comparator<Method>() {
|
Arrays.sort(methods, (o1, o2) -> (o1.isBridge() == o2.isBridge()) ? 0 : (o1.isBridge() ? 1 : -1));
|
||||||
@Override
|
|
||||||
public int compare(Method o1, Method o2) {
|
|
||||||
return (o1.isBridge() == o2.isBridge()) ? 0 : (o1.isBridge() ? 1 : -1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
@ -77,15 +76,12 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]>
|
||||||
for (String location : this.locations) {
|
for (String location : this.locations) {
|
||||||
List<Resource> resources = new ArrayList<>(
|
List<Resource> resources = new ArrayList<>(
|
||||||
Arrays.asList(this.resourcePatternResolver.getResources(location)));
|
Arrays.asList(this.resourcePatternResolver.getResources(location)));
|
||||||
Collections.sort(resources, new Comparator<Resource>() {
|
Collections.sort(resources, (r1, r2) -> {
|
||||||
@Override
|
try {
|
||||||
public int compare(Resource r1, Resource r2) {
|
return r1.getURL().toString().compareTo(r2.getURL().toString());
|
||||||
try {
|
}
|
||||||
return r1.getURL().toString().compareTo(r2.getURL().toString());
|
catch (IOException ex) {
|
||||||
}
|
return 0;
|
||||||
catch (IOException ex) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (Resource resource : resources) {
|
for (Resource resource : resources) {
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.jdbc.core.support;
|
package org.springframework.jdbc.core.support;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,15 +102,12 @@ public class JdbcBeanDefinitionReader {
|
||||||
public void loadBeanDefinitions(String sql) {
|
public void loadBeanDefinitions(String sql) {
|
||||||
Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate");
|
Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate");
|
||||||
final Properties props = new Properties();
|
final Properties props = new Properties();
|
||||||
this.jdbcTemplate.query(sql, new RowCallbackHandler() {
|
this.jdbcTemplate.query(sql, rs -> {
|
||||||
@Override
|
String beanName = rs.getString(1);
|
||||||
public void processRow(ResultSet rs) throws SQLException {
|
String property = rs.getString(2);
|
||||||
String beanName = rs.getString(1);
|
String value = rs.getString(3);
|
||||||
String property = rs.getString(2);
|
// Make a properties entry by combining bean name and property.
|
||||||
String value = rs.getString(3);
|
props.setProperty(beanName + '.' + property, value);
|
||||||
// Make a properties entry by combining bean name and property.
|
|
||||||
props.setProperty(beanName + '.' + property, value);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.propReader.registerBeanDefinitions(props);
|
this.propReader.registerBeanDefinitions(props);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -462,12 +462,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Comparator<SimpMessageMappingInfo> getMappingComparator(final Message<?> message) {
|
protected Comparator<SimpMessageMappingInfo> getMappingComparator(final Message<?> message) {
|
||||||
return new Comparator<SimpMessageMappingInfo>() {
|
return (info1, info2) -> info1.compareTo(info2, message);
|
||||||
@Override
|
|
||||||
public int compare(SimpMessageMappingInfo info1, SimpMessageMappingInfo info2) {
|
|
||||||
return info1.compareTo(info2, message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -535,12 +535,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||||
Assert.notNull(getTaskScheduler(), "To track receipts, a TaskScheduler must be configured");
|
Assert.notNull(getTaskScheduler(), "To track receipts, a TaskScheduler must be configured");
|
||||||
DefaultStompSession.this.receiptHandlers.put(this.receiptId, this);
|
DefaultStompSession.this.receiptHandlers.put(this.receiptId, this);
|
||||||
Date startTime = new Date(System.currentTimeMillis() + getReceiptTimeLimit());
|
Date startTime = new Date(System.currentTimeMillis() + getReceiptTimeLimit());
|
||||||
this.future = getTaskScheduler().schedule(new Runnable() {
|
this.future = getTaskScheduler().schedule(this::handleReceiptNotReceived, startTime);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handleReceiptNotReceived();
|
|
||||||
}
|
|
||||||
}, startTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -585,13 +585,10 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||||
logger.debug("TCP connection opened in session=" + getSessionId());
|
logger.debug("TCP connection opened in session=" + getSessionId());
|
||||||
}
|
}
|
||||||
this.tcpConnection = connection;
|
this.tcpConnection = connection;
|
||||||
this.tcpConnection.onReadInactivity(new Runnable() {
|
this.tcpConnection.onReadInactivity(() -> {
|
||||||
@Override
|
if (this.tcpConnection != null && !this.isStompConnected) {
|
||||||
public void run() {
|
handleTcpConnectionFailure("No CONNECTED frame received in " +
|
||||||
if (tcpConnection != null && !isStompConnected) {
|
MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
|
||||||
handleTcpConnectionFailure("No CONNECTED frame received in " +
|
|
||||||
MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, MAX_TIME_TO_CONNECTED_FRAME);
|
}, MAX_TIME_TO_CONNECTED_FRAME);
|
||||||
connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders()));
|
connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders()));
|
||||||
|
|
@ -700,33 +697,26 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||||
long serverReceiveInterval = connectedHeaders.getHeartbeat()[1];
|
long serverReceiveInterval = connectedHeaders.getHeartbeat()[1];
|
||||||
|
|
||||||
if (clientSendInterval > 0 && serverReceiveInterval > 0) {
|
if (clientSendInterval > 0 && serverReceiveInterval > 0) {
|
||||||
long interval = Math.max(clientSendInterval, serverReceiveInterval);
|
long interval = Math.max(clientSendInterval, serverReceiveInterval);
|
||||||
this.tcpConnection.onWriteInactivity(new Runnable() {
|
this.tcpConnection.onWriteInactivity(() -> {
|
||||||
@Override
|
TcpConnection<byte[]> conn = this.tcpConnection;
|
||||||
public void run() {
|
if (conn != null) {
|
||||||
TcpConnection<byte[]> conn = tcpConnection;
|
conn.send(HEARTBEAT_MESSAGE).addCallback(
|
||||||
if (conn != null) {
|
new ListenableFutureCallback<Void>() {
|
||||||
conn.send(HEARTBEAT_MESSAGE).addCallback(
|
public void onSuccess(Void result) {
|
||||||
new ListenableFutureCallback<Void>() {
|
}
|
||||||
public void onSuccess(Void result) {
|
|
||||||
}
|
public void onFailure(Throwable ex) {
|
||||||
public void onFailure(Throwable ex) {
|
handleTcpConnectionFailure("Failed to forward heartbeat: " + ex.getMessage(), ex);
|
||||||
handleTcpConnectionFailure(
|
}
|
||||||
"Failed to forward heartbeat: " + ex.getMessage(), ex);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, interval);
|
}, interval);
|
||||||
}
|
}
|
||||||
if (clientReceiveInterval > 0 && serverSendInterval > 0) {
|
if (clientReceiveInterval > 0 && serverSendInterval > 0) {
|
||||||
final long interval = Math.max(clientReceiveInterval, serverSendInterval) * HEARTBEAT_MULTIPLIER;
|
final long interval = Math.max(clientReceiveInterval, serverSendInterval) * HEARTBEAT_MULTIPLIER;
|
||||||
this.tcpConnection.onReadInactivity(new Runnable() {
|
this.tcpConnection.onReadInactivity(()
|
||||||
@Override
|
-> handleTcpConnectionFailure("No messages received in " + interval + " ms.", null), interval);
|
||||||
public void run() {
|
|
||||||
handleTcpConnectionFailure("No messages received in " + interval + " ms.", null);
|
|
||||||
}
|
|
||||||
}, interval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -384,12 +384,8 @@ public class LocalSessionFactoryBuilder extends Configuration {
|
||||||
private final Future<SessionFactory> sessionFactoryFuture;
|
private final Future<SessionFactory> sessionFactoryFuture;
|
||||||
|
|
||||||
public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) {
|
public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) {
|
||||||
this.sessionFactoryFuture = bootstrapExecutor.submit(new Callable<SessionFactory>() {
|
this.sessionFactoryFuture = bootstrapExecutor.submit(
|
||||||
@Override
|
(Callable<SessionFactory>) LocalSessionFactoryBuilder.this::buildSessionFactory);
|
||||||
public SessionFactory call() throws Exception {
|
|
||||||
return buildSessionFactory();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
@ -350,12 +349,8 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.bootstrapExecutor != null) {
|
if (this.bootstrapExecutor != null) {
|
||||||
this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit(new Callable<EntityManagerFactory>() {
|
this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit(
|
||||||
@Override
|
this::buildNativeEntityManagerFactory);
|
||||||
public EntityManagerFactory call() {
|
|
||||||
return buildNativeEntityManagerFactory();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.nativeEntityManagerFactory = buildNativeEntityManagerFactory();
|
this.nativeEntityManagerFactory = buildNativeEntityManagerFactory();
|
||||||
|
|
|
||||||
|
|
@ -404,38 +404,32 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||||
final LinkedList<InjectionMetadata.InjectedElement> currElements =
|
final LinkedList<InjectionMetadata.InjectedElement> currElements =
|
||||||
new LinkedList<>();
|
new LinkedList<>();
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalFields(targetClass, new ReflectionUtils.FieldCallback() {
|
ReflectionUtils.doWithLocalFields(targetClass, field -> {
|
||||||
@Override
|
if (field.isAnnotationPresent(PersistenceContext.class) ||
|
||||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
field.isAnnotationPresent(PersistenceUnit.class)) {
|
||||||
if (field.isAnnotationPresent(PersistenceContext.class) ||
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
field.isAnnotationPresent(PersistenceUnit.class)) {
|
throw new IllegalStateException("Persistence annotations are not supported on static fields");
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
|
||||||
throw new IllegalStateException("Persistence annotations are not supported on static fields");
|
|
||||||
}
|
|
||||||
currElements.add(new PersistenceElement(field, field, null));
|
|
||||||
}
|
}
|
||||||
|
currElements.add(new PersistenceElement(field, field, null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ReflectionUtils.doWithLocalMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
|
||||||
@Override
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
return;
|
||||||
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
}
|
||||||
return;
|
if ((bridgedMethod.isAnnotationPresent(PersistenceContext.class) ||
|
||||||
|
bridgedMethod.isAnnotationPresent(PersistenceUnit.class)) &&
|
||||||
|
method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
|
throw new IllegalStateException("Persistence annotations are not supported on static methods");
|
||||||
}
|
}
|
||||||
if ((bridgedMethod.isAnnotationPresent(PersistenceContext.class) ||
|
if (method.getParameterCount() != 1) {
|
||||||
bridgedMethod.isAnnotationPresent(PersistenceUnit.class)) &&
|
throw new IllegalStateException("Persistence annotation requires a single-arg method: " + method);
|
||||||
method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
|
||||||
throw new IllegalStateException("Persistence annotations are not supported on static methods");
|
|
||||||
}
|
|
||||||
if (method.getParameterCount() != 1) {
|
|
||||||
throw new IllegalStateException("Persistence annotation requires a single-arg method: " + method);
|
|
||||||
}
|
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
|
||||||
currElements.add(new PersistenceElement(method, bridgedMethod, pd));
|
|
||||||
}
|
}
|
||||||
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
|
currElements.add(new PersistenceElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,13 +70,10 @@ public class ContentRequestMatchers {
|
||||||
* Assert the request content type as a {@link MediaType}.
|
* Assert the request content type as a {@link MediaType}.
|
||||||
*/
|
*/
|
||||||
public RequestMatcher contentType(final MediaType expectedContentType) {
|
public RequestMatcher contentType(final MediaType expectedContentType) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MediaType actualContentType = request.getHeaders().getContentType();
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
assertTrue("Content type not set", actualContentType != null);
|
||||||
MediaType actualContentType = request.getHeaders().getContentType();
|
assertEquals("Content type", expectedContentType, actualContentType);
|
||||||
assertTrue("Content type not set", actualContentType != null);
|
|
||||||
assertEquals("Content type", expectedContentType, actualContentType);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,15 +90,12 @@ public class ContentRequestMatchers {
|
||||||
* content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
|
* content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
|
||||||
*/
|
*/
|
||||||
public RequestMatcher contentTypeCompatibleWith(final MediaType contentType) {
|
public RequestMatcher contentTypeCompatibleWith(final MediaType contentType) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MediaType actualContentType = request.getHeaders().getContentType();
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
assertTrue("Content type not set", actualContentType != null);
|
||||||
MediaType actualContentType = request.getHeaders().getContentType();
|
if (actualContentType != null) {
|
||||||
assertTrue("Content type not set", actualContentType != null);
|
assertTrue("Content type [" + actualContentType + "] is not compatible with [" + contentType + "]",
|
||||||
if (actualContentType != null) {
|
actualContentType.isCompatibleWith(contentType));
|
||||||
assertTrue("Content type [" + actualContentType + "] is not compatible with [" + contentType + "]",
|
|
||||||
actualContentType.isCompatibleWith(contentType));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -110,12 +104,9 @@ public class ContentRequestMatchers {
|
||||||
* Get the body of the request as a UTF-8 string and appply the given {@link Matcher}.
|
* Get the body of the request as a UTF-8 string and appply the given {@link Matcher}.
|
||||||
*/
|
*/
|
||||||
public RequestMatcher string(final Matcher<? super String> matcher) {
|
public RequestMatcher string(final Matcher<? super String> matcher) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
assertThat("Request content", mockRequest.getBodyAsString(), matcher);
|
||||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
|
||||||
assertThat("Request content", mockRequest.getBodyAsString(), matcher);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,12 +114,9 @@ public class ContentRequestMatchers {
|
||||||
* Get the body of the request as a UTF-8 string and compare it to the given String.
|
* Get the body of the request as a UTF-8 string and compare it to the given String.
|
||||||
*/
|
*/
|
||||||
public RequestMatcher string(final String expectedContent) {
|
public RequestMatcher string(final String expectedContent) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
assertEquals("Request content", expectedContent, mockRequest.getBodyAsString());
|
||||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
|
||||||
assertEquals("Request content", expectedContent, mockRequest.getBodyAsString());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,12 +124,9 @@ public class ContentRequestMatchers {
|
||||||
* Compare the body of the request to the given byte array.
|
* Compare the body of the request to the given byte array.
|
||||||
*/
|
*/
|
||||||
public RequestMatcher bytes(final byte[] expectedContent) {
|
public RequestMatcher bytes(final byte[] expectedContent) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
assertEquals("Request content", expectedContent, mockRequest.getBodyAsBytes());
|
||||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
|
||||||
assertEquals("Request content", expectedContent, mockRequest.getBodyAsBytes());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,23 +135,20 @@ public class ContentRequestMatchers {
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public RequestMatcher formData(final MultiValueMap<String, String> expectedContent) {
|
public RequestMatcher formData(final MultiValueMap<String, String> expectedContent) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
HttpInputMessage inputMessage = new HttpInputMessage() {
|
||||||
public void match(final ClientHttpRequest request) throws IOException, AssertionError {
|
@Override
|
||||||
HttpInputMessage inputMessage = new HttpInputMessage() {
|
public InputStream getBody() throws IOException {
|
||||||
@Override
|
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||||
public InputStream getBody() throws IOException {
|
return new ByteArrayInputStream(mockRequest.getBodyAsBytes());
|
||||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
}
|
||||||
return new ByteArrayInputStream(mockRequest.getBodyAsBytes());
|
@Override
|
||||||
}
|
public HttpHeaders getHeaders() {
|
||||||
@Override
|
return request.getHeaders();
|
||||||
public HttpHeaders getHeaders() {
|
}
|
||||||
return request.getHeaders();
|
};
|
||||||
}
|
FormHttpMessageConverter converter = new FormHttpMessageConverter();
|
||||||
};
|
assertEquals("Request content", expectedContent, converter.read(null, inputMessage));
|
||||||
FormHttpMessageConverter converter = new FormHttpMessageConverter();
|
|
||||||
assertEquals("Request content", expectedContent, converter.read(null, inputMessage));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.web.client.match;
|
package org.springframework.test.web.client.match;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -26,7 +25,6 @@ import org.hamcrest.Matcher;
|
||||||
|
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.client.ClientHttpRequest;
|
import org.springframework.http.client.ClientHttpRequest;
|
||||||
import org.springframework.test.util.AssertionErrors;
|
|
||||||
import org.springframework.test.web.client.MockRestServiceServer;
|
import org.springframework.test.web.client.MockRestServiceServer;
|
||||||
import org.springframework.test.web.client.RequestMatcher;
|
import org.springframework.test.web.client.RequestMatcher;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
@ -55,11 +53,7 @@ public abstract class MockRestRequestMatchers {
|
||||||
* Match to any request.
|
* Match to any request.
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher anything() {
|
public static RequestMatcher anything() {
|
||||||
return new RequestMatcher() {
|
return request -> {};
|
||||||
@Override
|
|
||||||
public void match(ClientHttpRequest request) throws AssertionError {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,12 +63,7 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher method(final HttpMethod method) {
|
public static RequestMatcher method(final HttpMethod method) {
|
||||||
Assert.notNull(method, "'method' must not be null");
|
Assert.notNull(method, "'method' must not be null");
|
||||||
return new RequestMatcher() {
|
return request -> assertEquals("Unexpected HttpMethod", method, request.getMethod());
|
||||||
@Override
|
|
||||||
public void match(ClientHttpRequest request) throws AssertionError {
|
|
||||||
AssertionErrors.assertEquals("Unexpected HttpMethod", method, request.getMethod());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,12 +73,7 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher requestTo(final Matcher<String> matcher) {
|
public static RequestMatcher requestTo(final Matcher<String> matcher) {
|
||||||
Assert.notNull(matcher, "'matcher' must not be null");
|
Assert.notNull(matcher, "'matcher' must not be null");
|
||||||
return new RequestMatcher() {
|
return request -> assertThat("Request URI", request.getURI().toString(), matcher);
|
||||||
@Override
|
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
|
||||||
assertThat("Request URI", request.getURI().toString(), matcher);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -99,12 +83,7 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher requestTo(final String expectedUri) {
|
public static RequestMatcher requestTo(final String expectedUri) {
|
||||||
Assert.notNull(expectedUri, "'uri' must not be null");
|
Assert.notNull(expectedUri, "'uri' must not be null");
|
||||||
return new RequestMatcher() {
|
return request -> assertEquals("Request URI", expectedUri, request.getURI().toString());
|
||||||
@Override
|
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
|
||||||
assertEquals("Request URI", expectedUri, request.getURI().toString());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,12 +93,7 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher requestTo(final URI uri) {
|
public static RequestMatcher requestTo(final URI uri) {
|
||||||
Assert.notNull(uri, "'uri' must not be null");
|
Assert.notNull(uri, "'uri' must not be null");
|
||||||
return new RequestMatcher() {
|
return request -> assertEquals("Unexpected request", uri, request.getURI());
|
||||||
@Override
|
|
||||||
public void match(ClientHttpRequest request) throws IOException, AssertionError {
|
|
||||||
AssertionErrors.assertEquals("Unexpected request", uri, request.getURI());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,14 +101,11 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static RequestMatcher queryParam(final String name, final Matcher<? super String>... matchers) {
|
public static RequestMatcher queryParam(final String name, final Matcher<? super String>... matchers) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MultiValueMap<String, String> params = getQueryParams(request);
|
||||||
public void match(ClientHttpRequest request) {
|
assertValueCount("query param", name, params, matchers.length);
|
||||||
MultiValueMap<String, String> params = getQueryParams(request);
|
for (int i = 0 ; i < matchers.length; i++) {
|
||||||
assertValueCount("query param", name, params, matchers.length);
|
assertThat("Query param", params.get(name).get(i), matchers[i]);
|
||||||
for (int i = 0 ; i < matchers.length; i++) {
|
|
||||||
assertThat("Query param", params.get(name).get(i), matchers[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -143,14 +114,11 @@ public abstract class MockRestRequestMatchers {
|
||||||
* Assert request query parameter values.
|
* Assert request query parameter values.
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher queryParam(final String name, final String... expectedValues) {
|
public static RequestMatcher queryParam(final String name, final String... expectedValues) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
MultiValueMap<String, String> params = getQueryParams(request);
|
||||||
public void match(ClientHttpRequest request) {
|
assertValueCount("query param", name, params, expectedValues.length);
|
||||||
MultiValueMap<String, String> params = getQueryParams(request);
|
for (int i = 0 ; i < expectedValues.length; i++) {
|
||||||
assertValueCount("query param", name, params, expectedValues.length);
|
assertEquals("Query param + [" + name + "]", expectedValues[i], params.get(name).get(i));
|
||||||
for (int i = 0 ; i < expectedValues.length; i++) {
|
|
||||||
assertEquals("Query param + [" + name + "]", expectedValues[i], params.get(name).get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -176,15 +144,13 @@ public abstract class MockRestRequestMatchers {
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static RequestMatcher header(final String name, final Matcher<? super String>... matchers) {
|
public static RequestMatcher header(final String name, final Matcher<? super String>... matchers) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
assertValueCount("header", name, request.getHeaders(), matchers.length);
|
||||||
public void match(ClientHttpRequest request) {
|
List<String> headerValues = request.getHeaders().get(name);
|
||||||
assertValueCount("header", name, request.getHeaders(), matchers.length);
|
Assert.state(headerValues != null, "No header values");
|
||||||
List<String> headerValues = request.getHeaders().get(name);
|
for (int i = 0; i < matchers.length; i++) {
|
||||||
Assert.state(headerValues != null, "No header values");
|
assertThat("Request header[" + name + "]", headerValues.get(i), matchers[i]);
|
||||||
for (int i = 0; i < matchers.length; i++) {
|
|
||||||
assertThat("Request header [" + name + "]", headerValues.get(i), matchers[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -193,15 +159,14 @@ public abstract class MockRestRequestMatchers {
|
||||||
* Assert request header values.
|
* Assert request header values.
|
||||||
*/
|
*/
|
||||||
public static RequestMatcher header(final String name, final String... expectedValues) {
|
public static RequestMatcher header(final String name, final String... expectedValues) {
|
||||||
return new RequestMatcher() {
|
return request -> {
|
||||||
@Override
|
assertValueCount("header", name, request.getHeaders(), expectedValues.length);
|
||||||
public void match(ClientHttpRequest request) {
|
List<String> headerValues = request.getHeaders().get(name);
|
||||||
assertValueCount("header", name, request.getHeaders(), expectedValues.length);
|
Assert.state(headerValues != null, "No header values");
|
||||||
List<String> headerValues = request.getHeaders().get(name);
|
for (int i = 0; i < expectedValues.length; i++) {
|
||||||
Assert.state(headerValues != null, "No header values");
|
assertEquals("Request header [" + name + "]",
|
||||||
for (int i = 0 ; i < expectedValues.length; i++) {
|
expectedValues[i], headerValues.get(i));
|
||||||
assertEquals("Request header [" + name + "]", expectedValues[i], headerValues.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,17 +222,13 @@ public class CciTemplate implements CciOperations {
|
||||||
@Override
|
@Override
|
||||||
public <T> T execute(final InteractionCallback<T> action) throws DataAccessException {
|
public <T> T execute(final InteractionCallback<T> action) throws DataAccessException {
|
||||||
Assert.notNull(action, "Callback object must not be null");
|
Assert.notNull(action, "Callback object must not be null");
|
||||||
return execute(new ConnectionCallback<T>() {
|
return execute((ConnectionCallback<T>) (connection, connectionFactory) -> {
|
||||||
@Override
|
Interaction interaction = connection.createInteraction();
|
||||||
public T doInConnection(Connection connection, ConnectionFactory connectionFactory)
|
try {
|
||||||
throws ResourceException, SQLException, DataAccessException {
|
return action.doInInteraction(interaction, connectionFactory);
|
||||||
Interaction interaction = connection.createInteraction();
|
}
|
||||||
try {
|
finally {
|
||||||
return action.doInInteraction(interaction, connectionFactory);
|
closeInteraction(interaction);
|
||||||
}
|
|
||||||
finally {
|
|
||||||
closeInteraction(interaction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -59,12 +59,8 @@ public class ResourceAdapterApplicationContext extends GenericApplicationContext
|
||||||
beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);
|
beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);
|
||||||
|
|
||||||
// JCA WorkManager resolved lazily - may not be available.
|
// JCA WorkManager resolved lazily - may not be available.
|
||||||
beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory<WorkManager>() {
|
beanFactory.registerResolvableDependency(WorkManager.class,
|
||||||
@Override
|
(ObjectFactory<WorkManager>) this.bootstrapContext::getWorkManager);
|
||||||
public WorkManager getObject() {
|
|
||||||
return bootstrapContext.getWorkManager();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.TransactionSystemException;
|
import org.springframework.transaction.TransactionSystemException;
|
||||||
import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
|
import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||||
|
|
@ -303,34 +302,30 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
else {
|
else {
|
||||||
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
|
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
|
||||||
try {
|
try {
|
||||||
Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr,
|
Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr, status -> {
|
||||||
new TransactionCallback<Object>() {
|
TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);
|
||||||
@Override
|
try {
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return invocation.proceedWithInvocation();
|
||||||
TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);
|
}
|
||||||
try {
|
catch (Throwable ex) {
|
||||||
return invocation.proceedWithInvocation();
|
if (txAttr.rollbackOn(ex)) {
|
||||||
}
|
// A RuntimeException: will lead to a rollback.
|
||||||
catch (Throwable ex) {
|
if (ex instanceof RuntimeException) {
|
||||||
if (txAttr.rollbackOn(ex)) {
|
throw (RuntimeException) ex;
|
||||||
// A RuntimeException: will lead to a rollback.
|
|
||||||
if (ex instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) ex;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new ThrowableHolderException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// A normal return value: will lead to a commit.
|
|
||||||
return new ThrowableHolder(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
cleanupTransactionInfo(txInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
throw new ThrowableHolderException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// A normal return value: will lead to a commit.
|
||||||
|
return new ThrowableHolder(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
cleanupTransactionInfo(txInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Check result: It might indicate a Throwable to rethrow.
|
// Check result: It might indicate a Throwable to rethrow.
|
||||||
if (result instanceof ThrowableHolder) {
|
if (result instanceof ThrowableHolder) {
|
||||||
|
|
|
||||||
|
|
@ -653,40 +653,36 @@ public class MediaType extends MimeType implements Serializable {
|
||||||
/**
|
/**
|
||||||
* Comparator used by {@link #sortByQualityValue(List)}.
|
* Comparator used by {@link #sortByQualityValue(List)}.
|
||||||
*/
|
*/
|
||||||
public static final Comparator<MediaType> QUALITY_VALUE_COMPARATOR = new Comparator<MediaType>() {
|
public static final Comparator<MediaType> QUALITY_VALUE_COMPARATOR = (mediaType1, mediaType2) -> {
|
||||||
|
double quality1 = mediaType1.getQualityValue();
|
||||||
@Override
|
double quality2 = mediaType2.getQualityValue();
|
||||||
public int compare(MediaType mediaType1, MediaType mediaType2) {
|
int qualityComparison = Double.compare(quality2, quality1);
|
||||||
double quality1 = mediaType1.getQualityValue();
|
if (qualityComparison != 0) {
|
||||||
double quality2 = mediaType2.getQualityValue();
|
return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3
|
||||||
int qualityComparison = Double.compare(quality2, quality1);
|
}
|
||||||
if (qualityComparison != 0) {
|
else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/*
|
||||||
return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3
|
return 1;
|
||||||
}
|
}
|
||||||
else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/*
|
else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */*
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else { // mediaType1.getType().equals(mediaType2.getType())
|
||||||
|
if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */*
|
else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/*
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html
|
else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else { // mediaType1.getType().equals(mediaType2.getType())
|
else {
|
||||||
if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic
|
int paramsSize1 = mediaType1.getParameters().size();
|
||||||
return 1;
|
int paramsSize2 = mediaType2.getParameters().size();
|
||||||
}
|
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
||||||
else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/*
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int paramsSize1 = mediaType1.getParameters().size();
|
|
||||||
int paramsSize2 = mediaType2.getParameters().size();
|
|
||||||
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,8 @@ public final class WebAsyncManager {
|
||||||
public void setAsyncWebRequest(final AsyncWebRequest asyncWebRequest) {
|
public void setAsyncWebRequest(final AsyncWebRequest asyncWebRequest) {
|
||||||
Assert.notNull(asyncWebRequest, "AsyncWebRequest must not be null");
|
Assert.notNull(asyncWebRequest, "AsyncWebRequest must not be null");
|
||||||
this.asyncWebRequest = asyncWebRequest;
|
this.asyncWebRequest = asyncWebRequest;
|
||||||
this.asyncWebRequest.addCompletionHandler(new Runnable() {
|
this.asyncWebRequest.addCompletionHandler(() -> asyncWebRequest.removeAttribute(
|
||||||
@Override
|
WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST));
|
||||||
public void run() {
|
|
||||||
asyncWebRequest.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -289,43 +285,33 @@ public final class WebAsyncManager {
|
||||||
final Callable<?> callable = webAsyncTask.getCallable();
|
final Callable<?> callable = webAsyncTask.getCallable();
|
||||||
final CallableInterceptorChain interceptorChain = new CallableInterceptorChain(interceptors);
|
final CallableInterceptorChain interceptorChain = new CallableInterceptorChain(interceptors);
|
||||||
|
|
||||||
this.asyncWebRequest.addTimeoutHandler(new Runnable() {
|
this.asyncWebRequest.addTimeoutHandler(() -> {
|
||||||
@Override
|
logger.debug("Processing timeout");
|
||||||
public void run() {
|
Object result = interceptorChain.triggerAfterTimeout(this.asyncWebRequest, callable);
|
||||||
logger.debug("Processing timeout");
|
if (result != CallableProcessingInterceptor.RESULT_NONE) {
|
||||||
Object result = interceptorChain.triggerAfterTimeout(asyncWebRequest, callable);
|
setConcurrentResultAndDispatch(result);
|
||||||
if (result != CallableProcessingInterceptor.RESULT_NONE) {
|
|
||||||
setConcurrentResultAndDispatch(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.asyncWebRequest.addCompletionHandler(new Runnable() {
|
this.asyncWebRequest.addCompletionHandler(() ->
|
||||||
@Override
|
interceptorChain.triggerAfterCompletion(this.asyncWebRequest, callable));
|
||||||
public void run() {
|
|
||||||
interceptorChain.triggerAfterCompletion(asyncWebRequest, callable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, callable);
|
interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, callable);
|
||||||
startAsyncProcessing(processingContext);
|
startAsyncProcessing(processingContext);
|
||||||
try {
|
try {
|
||||||
this.taskExecutor.submit(new Runnable() {
|
this.taskExecutor.submit(() -> {
|
||||||
@Override
|
Object result = null;
|
||||||
public void run() {
|
try {
|
||||||
Object result = null;
|
interceptorChain.applyPreProcess(this.asyncWebRequest, callable);
|
||||||
try {
|
result = callable.call();
|
||||||
interceptorChain.applyPreProcess(asyncWebRequest, callable);
|
|
||||||
result = callable.call();
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
result = ex;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
result = interceptorChain.applyPostProcess(asyncWebRequest, callable, result);
|
|
||||||
}
|
|
||||||
setConcurrentResultAndDispatch(result);
|
|
||||||
}
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
result = ex;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
result = interceptorChain.applyPostProcess(this.asyncWebRequest, callable, result);
|
||||||
|
}
|
||||||
|
setConcurrentResultAndDispatch(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (RejectedExecutionException ex) {
|
catch (RejectedExecutionException ex) {
|
||||||
|
|
@ -388,36 +374,26 @@ public final class WebAsyncManager {
|
||||||
|
|
||||||
final DeferredResultInterceptorChain interceptorChain = new DeferredResultInterceptorChain(interceptors);
|
final DeferredResultInterceptorChain interceptorChain = new DeferredResultInterceptorChain(interceptors);
|
||||||
|
|
||||||
this.asyncWebRequest.addTimeoutHandler(new Runnable() {
|
this.asyncWebRequest.addTimeoutHandler(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
interceptorChain.triggerAfterTimeout(this.asyncWebRequest, deferredResult);
|
||||||
try {
|
}
|
||||||
interceptorChain.triggerAfterTimeout(asyncWebRequest, deferredResult);
|
catch (Throwable ex) {
|
||||||
}
|
setConcurrentResultAndDispatch(ex);
|
||||||
catch (Throwable ex) {
|
|
||||||
setConcurrentResultAndDispatch(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.asyncWebRequest.addCompletionHandler(new Runnable() {
|
this.asyncWebRequest.addCompletionHandler(()
|
||||||
@Override
|
-> interceptorChain.triggerAfterCompletion(this.asyncWebRequest, deferredResult));
|
||||||
public void run() {
|
|
||||||
interceptorChain.triggerAfterCompletion(asyncWebRequest, deferredResult);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, deferredResult);
|
interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, deferredResult);
|
||||||
startAsyncProcessing(processingContext);
|
startAsyncProcessing(processingContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
interceptorChain.applyPreProcess(this.asyncWebRequest, deferredResult);
|
interceptorChain.applyPreProcess(this.asyncWebRequest, deferredResult);
|
||||||
deferredResult.setResultHandler(new DeferredResultHandler() {
|
deferredResult.setResultHandler(result -> {
|
||||||
@Override
|
result = interceptorChain.applyPostProcess(this.asyncWebRequest, deferredResult, result);
|
||||||
public void handleResult(Object result) {
|
setConcurrentResultAndDispatch(result);
|
||||||
result = interceptorChain.applyPostProcess(asyncWebRequest, deferredResult, result);
|
|
||||||
setConcurrentResultAndDispatch(result);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,8 @@ public class ExceptionHandlerMethodResolver {
|
||||||
/**
|
/**
|
||||||
* A filter for selecting {@code @ExceptionHandler} methods.
|
* A filter for selecting {@code @ExceptionHandler} methods.
|
||||||
*/
|
*/
|
||||||
public static final MethodFilter EXCEPTION_HANDLER_METHODS = new MethodFilter() {
|
public static final MethodFilter EXCEPTION_HANDLER_METHODS = method ->
|
||||||
@Override
|
(AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null);
|
||||||
public boolean matches(Method method) {
|
|
||||||
return (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arbitrary {@link Method} reference, indicating no method found in the cache.
|
* Arbitrary {@link Method} reference, indicating no method found in the cache.
|
||||||
|
|
|
||||||
|
|
@ -470,13 +470,10 @@ public class MvcUriComponentsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
|
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
|
||||||
MethodFilter selector = new MethodFilter() {
|
MethodFilter selector = method -> {
|
||||||
@Override
|
String name = method.getName();
|
||||||
public boolean matches(Method method) {
|
int argLength = method.getParameterCount();
|
||||||
String name = method.getName();
|
return (name.equals(methodName) && argLength == args.length);
|
||||||
int argLength = method.getParameterCount();
|
|
||||||
return (name.equals(methodName) && argLength == args.length);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
|
Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
|
||||||
if (methods.size() == 1) {
|
if (methods.size() == 1) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
@ -985,22 +984,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||||
/**
|
/**
|
||||||
* MethodFilter that matches {@link InitBinder @InitBinder} methods.
|
* MethodFilter that matches {@link InitBinder @InitBinder} methods.
|
||||||
*/
|
*/
|
||||||
public static final MethodFilter INIT_BINDER_METHODS = new MethodFilter() {
|
public static final MethodFilter INIT_BINDER_METHODS = method ->
|
||||||
@Override
|
AnnotationUtils.findAnnotation(method, InitBinder.class) != null;
|
||||||
public boolean matches(Method method) {
|
|
||||||
return AnnotationUtils.findAnnotation(method, InitBinder.class) != null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods.
|
* MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods.
|
||||||
*/
|
*/
|
||||||
public static final MethodFilter MODEL_ATTRIBUTE_METHODS = new MethodFilter() {
|
public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method ->
|
||||||
@Override
|
((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
|
||||||
public boolean matches(Method method) {
|
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
|
||||||
return ((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
|
|
||||||
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -170,13 +170,10 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
|
||||||
final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
|
final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
|
||||||
final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);
|
final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);
|
||||||
|
|
||||||
Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
|
Callable<WebSocketSession> connectTask = () -> {
|
||||||
@Override
|
Future<Session> future = client.connect(listener, uri, request);
|
||||||
public WebSocketSession call() throws Exception {
|
future.get();
|
||||||
Future<Session> future = client.connect(listener, uri, request);
|
return wsSession;
|
||||||
future.get();
|
|
||||||
return wsSession;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.taskExecutor != null) {
|
if (this.taskExecutor != null) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -99,20 +99,17 @@ public class AnnotatedEndpointConnectionManager extends ConnectionManagerSupport
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void openConnection() {
|
protected void openConnection() {
|
||||||
this.taskExecutor.execute(new Runnable() {
|
this.taskExecutor.execute(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
if (logger.isInfoEnabled()) {
|
||||||
try {
|
logger.info("Connecting to WebSocket at " + getUri());
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("Connecting to WebSocket at " + getUri());
|
|
||||||
}
|
|
||||||
Object endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
|
|
||||||
session = webSocketContainer.connectToServer(endpointToUse, getUri());
|
|
||||||
logger.info("Successfully connected to WebSocket");
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
logger.error("Failed to connect to WebSocket", ex);
|
|
||||||
}
|
}
|
||||||
|
Object endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
|
||||||
|
session = webSocketContainer.connectToServer(endpointToUse, getUri());
|
||||||
|
logger.info("Successfully connected to WebSocket");
|
||||||
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
logger.error("Failed to connect to WebSocket", ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -130,21 +130,18 @@ public class EndpointConnectionManager extends ConnectionManagerSupport implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void openConnection() {
|
protected void openConnection() {
|
||||||
this.taskExecutor.execute(new Runnable() {
|
this.taskExecutor.execute(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
if (logger.isInfoEnabled()) {
|
||||||
try {
|
logger.info("Connecting to WebSocket at " + getUri());
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("Connecting to WebSocket at " + getUri());
|
|
||||||
}
|
|
||||||
Endpoint endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
|
|
||||||
ClientEndpointConfig endpointConfig = configBuilder.build();
|
|
||||||
session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri());
|
|
||||||
logger.info("Successfully connected to WebSocket");
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
logger.error("Failed to connect to WebSocket", ex);
|
|
||||||
}
|
}
|
||||||
|
Endpoint endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
|
||||||
|
ClientEndpointConfig endpointConfig = configBuilder.build();
|
||||||
|
session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri());
|
||||||
|
logger.info("Successfully connected to WebSocket");
|
||||||
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
logger.error("Failed to connect to WebSocket", ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,12 +144,9 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
|
||||||
|
|
||||||
final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session);
|
final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session);
|
||||||
|
|
||||||
Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
|
Callable<WebSocketSession> connectTask = () -> {
|
||||||
@Override
|
webSocketContainer.connectToServer(endpoint, endpointConfig, uri);
|
||||||
public WebSocketSession call() throws Exception {
|
return session;
|
||||||
webSocketContainer.connectToServer(endpoint, endpointConfig, uri);
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.taskExecutor != null) {
|
if (this.taskExecutor != null) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -110,12 +110,9 @@ public class WebSocketMessageBrokerStats {
|
||||||
@Nullable
|
@Nullable
|
||||||
private ScheduledFuture<?> initLoggingTask(long initialDelay) {
|
private ScheduledFuture<?> initLoggingTask(long initialDelay) {
|
||||||
if (logger.isInfoEnabled() && this.loggingPeriod > 0) {
|
if (logger.isInfoEnabled() && this.loggingPeriod > 0) {
|
||||||
return this.sockJsTaskScheduler.scheduleAtFixedRate(new Runnable() {
|
return this.sockJsTaskScheduler.scheduleAtFixedRate(() ->
|
||||||
@Override
|
logger.info(WebSocketMessageBrokerStats.this.toString()),
|
||||||
public void run() {
|
initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS);
|
||||||
logger.info(WebSocketMessageBrokerStats.this.toString());
|
|
||||||
}
|
|
||||||
}, initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -401,17 +401,14 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||||
public void onReadInactivity(final Runnable runnable, final long duration) {
|
public void onReadInactivity(final Runnable runnable, final long duration) {
|
||||||
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
|
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
|
||||||
this.lastReadTime = System.currentTimeMillis();
|
this.lastReadTime = System.currentTimeMillis();
|
||||||
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(new Runnable() {
|
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
|
||||||
@Override
|
if (System.currentTimeMillis() - lastReadTime > duration) {
|
||||||
public void run() {
|
try {
|
||||||
if (System.currentTimeMillis() - lastReadTime > duration) {
|
runnable.run();
|
||||||
try {
|
}
|
||||||
runnable.run();
|
catch (Throwable ex) {
|
||||||
}
|
if (logger.isDebugEnabled()) {
|
||||||
catch (Throwable ex) {
|
logger.debug("ReadInactivityTask failure", ex);
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("ReadInactivityTask failure", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,12 +116,7 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
|
||||||
* request.
|
* request.
|
||||||
*/
|
*/
|
||||||
Runnable getTimeoutTask() {
|
Runnable getTimeoutTask() {
|
||||||
return new Runnable() {
|
return () -> closeInternal(new CloseStatus(2007, "Transport timed out"));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
closeInternal(new CloseStatus(2007, "Transport timed out"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -99,35 +99,32 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
|
||||||
final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session,
|
final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session,
|
||||||
final SettableListenableFuture<WebSocketSession> connectFuture) {
|
final SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||||
|
|
||||||
getTaskExecutor().execute(new Runnable() {
|
getTaskExecutor().execute(() -> {
|
||||||
@Override
|
HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
|
||||||
public void run() {
|
XhrRequestCallback requestCallback = new XhrRequestCallback(handshakeHeaders);
|
||||||
HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
|
XhrRequestCallback requestCallbackAfterHandshake = new XhrRequestCallback(httpHeaders);
|
||||||
XhrRequestCallback requestCallback = new XhrRequestCallback(handshakeHeaders);
|
XhrReceiveExtractor responseExtractor = new XhrReceiveExtractor(session);
|
||||||
XhrRequestCallback requestCallbackAfterHandshake = new XhrRequestCallback(httpHeaders);
|
while (true) {
|
||||||
XhrReceiveExtractor responseExtractor = new XhrReceiveExtractor(session);
|
if (session.isDisconnected()) {
|
||||||
while (true) {
|
session.afterTransportClosed(null);
|
||||||
if (session.isDisconnected()) {
|
break;
|
||||||
session.afterTransportClosed(null);
|
}
|
||||||
break;
|
try {
|
||||||
|
if (logger.isTraceEnabled()) {
|
||||||
|
logger.trace("Starting XHR receive request, url=" + receiveUrl);
|
||||||
}
|
}
|
||||||
try {
|
getRestTemplate().execute(receiveUrl, HttpMethod.POST, requestCallback, responseExtractor);
|
||||||
if (logger.isTraceEnabled()) {
|
requestCallback = requestCallbackAfterHandshake;
|
||||||
logger.trace("Starting XHR receive request, url=" + receiveUrl);
|
}
|
||||||
}
|
catch (Throwable ex) {
|
||||||
getRestTemplate().execute(receiveUrl, HttpMethod.POST, requestCallback, responseExtractor);
|
if (!connectFuture.isDone()) {
|
||||||
requestCallback = requestCallbackAfterHandshake;
|
connectFuture.setException(ex);
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
else {
|
||||||
if (!connectFuture.isDone()) {
|
session.handleTransportError(ex);
|
||||||
connectFuture.setException(ex);
|
session.afterTransportClosed(new CloseStatus(1006, ex.getMessage()));
|
||||||
}
|
|
||||||
else {
|
|
||||||
session.handleTransportError(ex);
|
|
||||||
session.afterTransportClosed(new CloseStatus(1006, ex.getMessage()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -368,27 +368,24 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
||||||
if (this.sessionCleanupTask != null) {
|
if (this.sessionCleanupTask != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sessionCleanupTask = getTaskScheduler().scheduleAtFixedRate(new Runnable() {
|
this.sessionCleanupTask = getTaskScheduler().scheduleAtFixedRate(() -> {
|
||||||
@Override
|
List<String> removedIds = new ArrayList<>();
|
||||||
public void run() {
|
for (SockJsSession session : sessions.values()) {
|
||||||
List<String> removedIds = new ArrayList<>();
|
try {
|
||||||
for (SockJsSession session : sessions.values()) {
|
if (session.getTimeSinceLastActive() > getDisconnectDelay()) {
|
||||||
try {
|
sessions.remove(session.getId());
|
||||||
if (session.getTimeSinceLastActive() > getDisconnectDelay()) {
|
removedIds.add(session.getId());
|
||||||
sessions.remove(session.getId());
|
session.close();
|
||||||
removedIds.add(session.getId());
|
|
||||||
session.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
// Could be part of normal workflow (e.g. browser tab closed)
|
|
||||||
logger.debug("Failed to close " + session, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled() && !removedIds.isEmpty()) {
|
catch (Throwable ex) {
|
||||||
logger.debug("Closed " + removedIds.size() + " sessions: " + removedIds);
|
// Could be part of normal workflow (e.g. browser tab closed)
|
||||||
|
logger.debug("Failed to close " + session, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (logger.isDebugEnabled() && !removedIds.isEmpty()) {
|
||||||
|
logger.debug("Closed " + removedIds.size() + " sessions: " + removedIds);
|
||||||
|
}
|
||||||
}, getDisconnectDelay());
|
}, getDisconnectDelay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue