Polishing

This commit is contained in:
Juergen Hoeller
2019-05-03 15:32:47 +02:00
parent 8a48c5ad86
commit 901ced7b66
19 changed files with 135 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -54,8 +54,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* will be short-circuited. The only further processing applied is the * will be short-circuited. The only further processing applied is the
* {@link #postProcessAfterInitialization} callback from the configured * {@link #postProcessAfterInitialization} callback from the configured
* {@link BeanPostProcessor BeanPostProcessors}. * {@link BeanPostProcessor BeanPostProcessors}.
* <p>This callback will only be applied to bean definitions with a bean class. * <p>This callback will be applied to bean definitions with their bean class,
* In particular, it will not be applied to beans with a factory method. * as well as to factory-method definitions in which case the returned bean type
* will be passed in here.
* <p>Post-processors may implement the extended * <p>Post-processors may implement the extended
* {@link SmartInstantiationAwareBeanPostProcessor} interface in order * {@link SmartInstantiationAwareBeanPostProcessor} interface in order
* to predict the type of the bean object that they are going to return here. * to predict the type of the bean object that they are going to return here.
@@ -66,7 +67,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* or {@code null} to proceed with default instantiation * or {@code null} to proceed with default instantiation
* @throws org.springframework.beans.BeansException in case of errors * @throws org.springframework.beans.BeansException in case of errors
* @see #postProcessAfterInstantiation * @see #postProcessAfterInstantiation
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass()
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()
*/ */
@Nullable @Nullable
default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException { default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -85,10 +85,12 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte
} }
} }
catch (IOException ex) { catch (IOException ex) {
logger.debug("Could not read super class [" + metadata.getSuperClassName() + if (logger.isDebugEnabled()) {
"] of type-filtered class [" + metadata.getClassName() + "]"); logger.debug("Could not read super class [" + metadata.getSuperClassName() +
"] of type-filtered class [" + metadata.getClassName() + "]");
}
} }
} }
} }
} }
@@ -109,8 +111,10 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte
} }
} }
catch (IOException ex) { catch (IOException ex) {
logger.debug("Could not read interface [" + ifc + "] for type-filtered class [" + if (logger.isDebugEnabled()) {
metadata.getClassName() + "]"); logger.debug("Could not read interface [" + ifc + "] for type-filtered class [" +
metadata.getClassName() + "]");
}
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -43,8 +43,7 @@ public abstract class SerializationUtils {
return null; return null;
} }
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
try { try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object); oos.writeObject(object);
oos.flush(); oos.flush();
} }
@@ -64,8 +63,7 @@ public abstract class SerializationUtils {
if (bytes == null) { if (bytes == null) {
return null; return null;
} }
try { try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
return ois.readObject(); return ois.readObject();
} }
catch (IOException ex) { catch (IOException ex) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -34,8 +34,9 @@ public class SerializationTestUtils {
public static void testSerialization(Object o) throws IOException { public static void testSerialization(Object o) throws IOException {
OutputStream baos = new ByteArrayOutputStream(); OutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o); oos.writeObject(o);
}
} }
public static boolean isSerializable(Object o) throws IOException { public static boolean isSerializable(Object o) throws IOException {
@@ -50,16 +51,17 @@ public class SerializationTestUtils {
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o); oos.writeObject(o);
oos.flush(); oos.flush();
}
baos.flush(); baos.flush();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(bytes); ByteArrayInputStream is = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(is); try (ObjectInputStream ois = new ObjectInputStream(is)) {
Object o2 = ois.readObject(); return ois.readObject();
return o2; }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -18,6 +18,7 @@ package org.springframework.jdbc.datasource.embedded;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -42,11 +43,13 @@ abstract class AbstractEmbeddedDatabaseConfigurer implements EmbeddedDatabaseCon
try { try {
con = dataSource.getConnection(); con = dataSource.getConnection();
if (con != null) { if (con != null) {
con.createStatement().execute("SHUTDOWN"); try (Statement stmt = con.createStatement()) {
stmt.execute("SHUTDOWN");
}
} }
} }
catch (SQLException ex) { catch (SQLException ex) {
logger.warn("Could not shut down embedded database", ex); logger.info("Could not shut down embedded database", ex);
} }
finally { finally {
if (con != null) { if (con != null) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 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.
@@ -66,20 +66,23 @@ public class CustomSQLExceptionTranslatorRegistry {
private CustomSQLExceptionTranslatorRegistry() { private CustomSQLExceptionTranslatorRegistry() {
} }
/** /**
* Register a new custom translator for the specified database name. * Register a new custom translator for the specified database name.
* @param dbName the database name * @param dbName the database name
* @param translator the custom translator * @param translator the custom translator
*/ */
public void registerTranslator(String dbName, SQLExceptionTranslator translator) { public void registerTranslator(String dbName, SQLExceptionTranslator translator) {
SQLExceptionTranslator replaced = translatorMap.put(dbName, translator); SQLExceptionTranslator replaced = this.translatorMap.put(dbName, translator);
if (replaced != null) { if (logger.isDebugEnabled()) {
logger.warn("Replacing custom translator [" + replaced + "] for database '" + dbName + if (replaced != null) {
"' with [" + translator + "]"); logger.debug("Replacing custom translator [" + replaced + "] for database '" + dbName +
} "' with [" + translator + "]");
else { }
logger.info("Adding custom translator of type [" + translator.getClass().getName() + else {
"] for database '" + dbName + "'"); logger.debug("Adding custom translator of type [" + translator.getClass().getName() +
"] for database '" + dbName + "'");
}
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -85,7 +85,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return adapter.getClass().getClassLoader().loadClass(specClassName); return adapter.getClass().getClassLoader().loadClass(specClassName);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
logger.debug("No default <Provider>ActivationSpec class found: " + specClassName); if (logger.isDebugEnabled()) {
logger.debug("No default <Provider>ActivationSpec class found: " + specClassName);
}
} }
} }
@@ -98,7 +100,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return adapter.getClass().getClassLoader().loadClass(specClassName); return adapter.getClass().getClassLoader().loadClass(specClassName);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
logger.debug("No default <Provider>ActivationSpecImpl class found: " + specClassName); if (logger.isDebugEnabled()) {
logger.debug("No default <Provider>ActivationSpecImpl class found: " + specClassName);
}
} }
} }
@@ -109,7 +113,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return adapter.getClass().getClassLoader().loadClass(specClassName); return adapter.getClass().getClassLoader().loadClass(specClassName);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
logger.debug("No default ActivationSpecImpl class found in provider package: " + specClassName); if (logger.isDebugEnabled()) {
logger.debug("No default ActivationSpecImpl class found in provider package: " + specClassName);
}
} }
// ActivationSpecImpl class in "inbound" subpackage (WebSphere MQ 6.0.2.1) // ActivationSpecImpl class in "inbound" subpackage (WebSphere MQ 6.0.2.1)
@@ -118,7 +124,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return adapter.getClass().getClassLoader().loadClass(specClassName); return adapter.getClass().getClassLoader().loadClass(specClassName);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
logger.debug("No default ActivationSpecImpl class found in inbound subpackage: " + specClassName); if (logger.isDebugEnabled()) {
logger.debug("No default ActivationSpecImpl class found in inbound subpackage: " + specClassName);
}
} }
throw new IllegalStateException("No ActivationSpec class defined - " + throw new IllegalStateException("No ActivationSpec class defined - " +

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2019 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.
@@ -41,7 +41,6 @@ import org.springframework.lang.Nullable;
* @since 16.05.2003 * @since 16.05.2003
* @see org.springframework.transaction.support.TransactionTemplate * @see org.springframework.transaction.support.TransactionTemplate
* @see org.springframework.transaction.interceptor.TransactionInterceptor * @see org.springframework.transaction.interceptor.TransactionInterceptor
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/ */
public interface PlatformTransactionManager { public interface PlatformTransactionManager {
@@ -56,7 +55,7 @@ public interface PlatformTransactionManager {
* <p>An exception to the above rule is the read-only flag, which should be * <p>An exception to the above rule is the read-only flag, which should be
* ignored if no explicit read-only mode is supported. Essentially, the * ignored if no explicit read-only mode is supported. Essentially, the
* read-only flag is just a hint for potential optimization. * read-only flag is just a hint for potential optimization.
* @param definition TransactionDefinition instance (can be {@code null} for defaults), * @param definition the TransactionDefinition instance (can be {@code null} for defaults),
* describing propagation behavior, isolation level, timeout etc. * describing propagation behavior, isolation level, timeout etc.
* @return transaction status object representing the new or current transaction * @return transaction status object representing the new or current transaction
* @throws TransactionException in case of lookup, creation, or system errors * @throws TransactionException in case of lookup, creation, or system errors
@@ -68,7 +67,8 @@ public interface PlatformTransactionManager {
* @see TransactionDefinition#getTimeout * @see TransactionDefinition#getTimeout
* @see TransactionDefinition#isReadOnly * @see TransactionDefinition#isReadOnly
*/ */
TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException; TransactionStatus getTransaction(@Nullable TransactionDefinition definition)
throws TransactionException;
/** /**
* Commit the given transaction, with regard to its status. If the transaction * Commit the given transaction, with regard to its status. If the transaction

View File

@@ -87,11 +87,11 @@ public enum Propagation {
/** /**
* Execute within a nested transaction if a current transaction exists, * Execute within a nested transaction if a current transaction exists,
* behave like {@code REQUIRED} else. There is no analogous feature in EJB. * behave like {@code REQUIRED} otherwise. There is no analogous feature in EJB.
* <p>Note: Actual creation of a nested transaction will only work on specific * <p>Note: Actual creation of a nested transaction will only work on specific
* transaction managers. Out of the box, this only applies to the JDBC * transaction managers. Out of the box, this only applies to the JDBC
* DataSourceTransactionManager when working on a JDBC 3.0 driver. * DataSourceTransactionManager. Some JTA providers might support nested
* Some JTA providers might support nested transactions as well. * transactions as well.
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager * @see org.springframework.jdbc.datasource.DataSourceTransactionManager
*/ */
NESTED(TransactionDefinition.PROPAGATION_NESTED); NESTED(TransactionDefinition.PROPAGATION_NESTED);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 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.
@@ -101,7 +101,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
* <p>To find out about specific transaction characteristics, consider using * <p>To find out about specific transaction characteristics, consider using
* TransactionSynchronizationManager's {@code isSynchronizationActive()} * TransactionSynchronizationManager's {@code isSynchronizationActive()}
* and/or {@code isActualTransactionActive()} methods. * and/or {@code isActualTransactionActive()} methods.
* @return TransactionInfo bound to this thread, or {@code null} if none * @return the TransactionInfo bound to this thread, or {@code null} if none
* @see TransactionInfo#hasTransaction() * @see TransactionInfo#hasTransaction()
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive() * @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive()
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive() * @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
@@ -287,7 +287,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) { if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) {
// Standard transaction demarcation with getTransaction and commit/rollback calls. // Standard transaction demarcation with getTransaction and commit/rollback calls.
TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification); TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification);
Object retVal = null;
Object retVal;
try { try {
// This is an around advice: Invoke the next interceptor in the chain. // This is an around advice: Invoke the next interceptor in the chain.
// This will normally result in a target object being invoked. // This will normally result in a target object being invoked.
@@ -507,9 +508,10 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
else { else {
// The TransactionInfo.hasTransaction() method will return false. We created it only // The TransactionInfo.hasTransaction() method will return false. We created it only
// to preserve the integrity of the ThreadLocal stack maintained in this class. // to preserve the integrity of the ThreadLocal stack maintained in this class.
if (logger.isTraceEnabled()) if (logger.isTraceEnabled()) {
logger.trace("Don't need to create transaction for [" + joinpointIdentification + logger.trace("No need to create transaction for [" + joinpointIdentification +
"]: This method isn't transactional."); "]: This method is not transactional.");
}
} }
// We always bind the TransactionInfo to the thread, even if we didn't create // We always bind the TransactionInfo to the thread, even if we didn't create
@@ -591,7 +593,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
/** /**
* Opaque object used to hold Transaction information. Subclasses * Opaque object used to hold transaction information. Subclasses
* must pass it back to methods on this class, but not see its internals. * must pass it back to methods on this class, but not see its internals.
*/ */
protected final class TransactionInfo { protected final class TransactionInfo {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -553,7 +553,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) { if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
return definition.getTimeout(); return definition.getTimeout();
} }
return this.defaultTimeout; return getDefaultTimeout();
} }
@@ -667,7 +667,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
/** /**
* Reactivate transaction synchronization for the current thread * Reactivate transaction synchronization for the current thread
* and resume all given synchronizations. * and resume all given synchronizations.
* @param suspendedSynchronizations List of TransactionSynchronization objects * @param suspendedSynchronizations a List of TransactionSynchronization objects
*/ */
private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) { private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) {
TransactionSynchronizationManager.initSynchronization(); TransactionSynchronizationManager.initSynchronization();
@@ -980,7 +980,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
* given Spring TransactionSynchronization objects. * given Spring TransactionSynchronization objects.
* <p>To be called by this abstract manager itself, or by special implementations * <p>To be called by this abstract manager itself, or by special implementations
* of the {@code registerAfterCompletionWithExistingTransaction} callback. * of the {@code registerAfterCompletionWithExistingTransaction} callback.
* @param synchronizations List of TransactionSynchronization objects * @param synchronizations a List of TransactionSynchronization objects
* @param completionStatus the completion status according to the * @param completionStatus the completion status according to the
* constants in the TransactionSynchronization interface * constants in the TransactionSynchronization interface
* @see #registerAfterCompletionWithExistingTransaction(Object, java.util.List) * @see #registerAfterCompletionWithExistingTransaction(Object, java.util.List)
@@ -1096,9 +1096,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
* there will be an active transaction: The implementation of this method has * there will be an active transaction: The implementation of this method has
* to detect this and start an appropriate nested transaction. * to detect this and start an appropriate nested transaction.
* @param transaction transaction object returned by {@code doGetTransaction} * @param transaction transaction object returned by {@code doGetTransaction}
* @param definition TransactionDefinition instance, describing propagation * @param definition a TransactionDefinition instance, describing propagation
* behavior, isolation level, read-only flag, timeout, and transaction name * behavior, isolation level, read-only flag, timeout, and transaction name
* @throws TransactionException in case of creation or system errors * @throws TransactionException in case of creation or system errors
* @throws org.springframework.transaction.NestedTransactionNotSupportedException
* if the underlying transaction does not support nesting
*/ */
protected abstract void doBegin(Object transaction, TransactionDefinition definition) protected abstract void doBegin(Object transaction, TransactionDefinition definition)
throws TransactionException; throws TransactionException;
@@ -1231,7 +1233,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
* immediately, passing in "STATUS_UNKNOWN". This is the best we can do if there's no * immediately, passing in "STATUS_UNKNOWN". This is the best we can do if there's no
* chance to determine the actual outcome of the outer transaction. * chance to determine the actual outcome of the outer transaction.
* @param transaction transaction object returned by {@code doGetTransaction} * @param transaction transaction object returned by {@code doGetTransaction}
* @param synchronizations List of TransactionSynchronization objects * @param synchronizations a List of TransactionSynchronization objects
* @throws TransactionException in case of system errors * @throws TransactionException in case of system errors
* @see #invokeAfterCompletion(java.util.List, int) * @see #invokeAfterCompletion(java.util.List, int)
* @see TransactionSynchronization#afterCompletion(int) * @see TransactionSynchronization#afterCompletion(int)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 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.
@@ -292,10 +292,11 @@ public abstract class TransactionSynchronizationManager {
throws IllegalStateException { throws IllegalStateException {
Assert.notNull(synchronization, "TransactionSynchronization must not be null"); Assert.notNull(synchronization, "TransactionSynchronization must not be null");
if (!isSynchronizationActive()) { Set<TransactionSynchronization> synchs = synchronizations.get();
if (synchs == null) {
throw new IllegalStateException("Transaction synchronization is not active"); throw new IllegalStateException("Transaction synchronization is not active");
} }
synchronizations.get().add(synchronization); synchs.add(synchronization);
} }
/** /**

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -60,8 +60,8 @@ public class MediaTypeFactory {
* @return a multi-value map, mapping media types to file extensions. * @return a multi-value map, mapping media types to file extensions.
*/ */
private static MultiValueMap<String, MediaType> parseMimeTypes() { private static MultiValueMap<String, MediaType> parseMimeTypes() {
try (InputStream is = MediaTypeFactory.class.getResourceAsStream(MIME_TYPES_FILE_NAME)) { InputStream is = MediaTypeFactory.class.getResourceAsStream(MIME_TYPES_FILE_NAME);
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.US_ASCII)); try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.US_ASCII))) {
MultiValueMap<String, MediaType> result = new LinkedMultiValueMap<>(); MultiValueMap<String, MediaType> result = new LinkedMultiValueMap<>();
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -81,7 +81,9 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
} }
catch (Exception ex) { catch (Exception ex) {
// ignore (see class-level doc) // ignore (see class-level doc)
logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); if (logger.isDebugEnabled()) {
logger.debug("Error in checking support for parameter [" + parameter + "]: " + ex.getMessage());
}
return false; return false;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -24,10 +24,10 @@ import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter;
/** /**
* Defines the strategies for invoking {@link ExchangeFunction}s. An instance of * Provides strategies for use in an {@link ExchangeFunction}.
* this class is immutable; instances are typically created through the mutable {@link Builder}: *
* either through {@link #builder()} to set up default strategies, or {@link #empty()} to start * <p>To create an instance, see the static methods {@link #withDefaults()},
* from scratch. * {@link #builder()}, and {@link #empty()}.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Arjen Poutsma * @author Arjen Poutsma
@@ -36,31 +36,32 @@ import org.springframework.http.codec.HttpMessageWriter;
public interface ExchangeStrategies { public interface ExchangeStrategies {
/** /**
* Return the {@link HttpMessageReader}s to be used for request body conversion. * Return {@link HttpMessageReader HttpMessageReaders} to read and decode the response body with.
* @return the stream of message readers * @return the message readers
*/ */
List<HttpMessageReader<?>> messageReaders(); List<HttpMessageReader<?>> messageReaders();
/** /**
* Return the {@link HttpMessageWriter}s to be used for response body conversion. * Return {@link HttpMessageWriter HttpMessageWriters} to write and encode the request body with.
* @return the stream of message writers * @return the message writers
*/ */
List<HttpMessageWriter<?>> messageWriters(); List<HttpMessageWriter<?>> messageWriters();
// Static methods // Static builder methods
/** /**
* Return a new {@code ExchangeStrategies} with default initialization. * Return a new {@code ExchangeStrategies} instance with default configuration
* @return the new {@code ExchangeStrategies} * provided by {@link ClientCodecConfigurer}.
*/ */
static ExchangeStrategies withDefaults() { static ExchangeStrategies withDefaults() {
return builder().build(); return builder().build();
} }
/** /**
* Return a mutable builder for a {@code ExchangeStrategies} with default initialization. * Return a builder pre-configured with default configuration to start.
* @return the builder * This is the same as {@link #withDefaults()} but returns a mutable builder
* for further customizations.
*/ */
static Builder builder() { static Builder builder() {
DefaultExchangeStrategiesBuilder builder = new DefaultExchangeStrategiesBuilder(); DefaultExchangeStrategiesBuilder builder = new DefaultExchangeStrategiesBuilder();
@@ -69,8 +70,7 @@ public interface ExchangeStrategies {
} }
/** /**
* Return a mutable, empty builder for a {@code ExchangeStrategies}. * Return a builder with empty configuration to start.
* @return the builder
*/ */
static Builder empty() { static Builder empty() {
return new DefaultExchangeStrategiesBuilder(); return new DefaultExchangeStrategiesBuilder();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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,10 +28,11 @@ import org.springframework.web.server.WebFilter;
import org.springframework.web.server.i18n.LocaleContextResolver; import org.springframework.web.server.i18n.LocaleContextResolver;
/** /**
* Defines the strategies to be used for processing {@link HandlerFunction}s. An instance of * Defines the strategies to be used for processing {@link HandlerFunction HandlerFunctions}.
* this class is immutable; instances are typically created through the mutable {@link Builder}: *
* either through {@link #builder()} to set up default strategies, or {@link #empty()} to start from * <p>An instance of this class is immutable. Instances are typically created through the
* scratch. * mutable {@link Builder}: either through {@link #builder()} to set up default strategies,
* or {@link #empty()} to start from scratch.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Juergen Hoeller * @author Juergen Hoeller
@@ -78,7 +79,7 @@ public interface HandlerStrategies {
LocaleContextResolver localeContextResolver(); LocaleContextResolver localeContextResolver();
// Static methods // Static builder methods
/** /**
* Return a new {@code HandlerStrategies} with default initialization. * Return a new {@code HandlerStrategies} with default initialization.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -135,11 +135,11 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
prepareResponse(ex, response); prepareResponse(ex, response);
ModelAndView result = doResolveException(request, response, handler, ex); ModelAndView result = doResolveException(request, response, handler, ex);
if (result != null) { if (result != null) {
// Print warn message when warn logger is not enabled... // Print debug message when warn logger is not enabled.
if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) { if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result)); logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
} }
// warnLogger with full stack trace (requires explicit config) // Explicitly configured warn logger in logException method.
logException(ex, request); logException(ex, request);
} }
return result; return result;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 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.
@@ -56,7 +56,7 @@ import org.springframework.web.util.WebUtils;
public class CookieLocaleResolver extends CookieGenerator implements LocaleContextResolver { public class CookieLocaleResolver extends CookieGenerator implements LocaleContextResolver {
/** /**
* The name of the request attribute that holds the Locale. * The name of the request attribute that holds the {@code Locale}.
* <p>Only used for overriding a cookie value if the locale has been * <p>Only used for overriding a cookie value if the locale has been
* changed in the course of the current request! * changed in the course of the current request!
* <p>Use {@code RequestContext(Utils).getLocale()} * <p>Use {@code RequestContext(Utils).getLocale()}
@@ -67,7 +67,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
public static final String LOCALE_REQUEST_ATTRIBUTE_NAME = CookieLocaleResolver.class.getName() + ".LOCALE"; public static final String LOCALE_REQUEST_ATTRIBUTE_NAME = CookieLocaleResolver.class.getName() + ".LOCALE";
/** /**
* The name of the request attribute that holds the TimeZone. * The name of the request attribute that holds the {@code TimeZone}.
* <p>Only used for overriding a cookie value if the locale has been * <p>Only used for overriding a cookie value if the locale has been
* changed in the course of the current request! * changed in the course of the current request!
* <p>Use {@code RequestContext(Utils).getTimeZone()} * <p>Use {@code RequestContext(Utils).getTimeZone()}
@@ -123,14 +123,14 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
} }
/** /**
* Set a fixed Locale that this resolver will return if no cookie found. * Set a fixed locale that this resolver will return if no cookie found.
*/ */
public void setDefaultLocale(@Nullable Locale defaultLocale) { public void setDefaultLocale(@Nullable Locale defaultLocale) {
this.defaultLocale = defaultLocale; this.defaultLocale = defaultLocale;
} }
/** /**
* Return the fixed Locale that this resolver will return if no cookie found, * Return the fixed locale that this resolver will return if no cookie found,
* if any. * if any.
*/ */
@Nullable @Nullable
@@ -139,7 +139,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
} }
/** /**
* Set a fixed TimeZone that this resolver will return if no cookie found. * Set a fixed time zone that this resolver will return if no cookie found.
* @since 4.0 * @since 4.0
*/ */
public void setDefaultTimeZone(@Nullable TimeZone defaultTimeZone) { public void setDefaultTimeZone(@Nullable TimeZone defaultTimeZone) {
@@ -147,7 +147,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
} }
/** /**
* Return the fixed TimeZone that this resolver will return if no cookie found, * Return the fixed time zone that this resolver will return if no cookie found,
* if any. * if any.
* @since 4.0 * @since 4.0
*/ */
@@ -284,6 +284,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
* @param locale the locale to stringify * @param locale the locale to stringify
* @return a String representation for the given locale * @return a String representation for the given locale
* @since 4.3 * @since 4.3
* @see #isLanguageTagCompliant()
*/ */
protected String toLocaleValue(Locale locale) { protected String toLocaleValue(Locale locale) {
return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString()); return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
@@ -310,7 +311,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
/** /**
* Determine the default time zone for the given request, * Determine the default time zone for the given request,
* Called if no TimeZone cookie has been found. * Called if no time zone cookie has been found.
* <p>The default implementation returns the specified default time zone, * <p>The default implementation returns the specified default time zone,
* if any, or {@code null} otherwise. * if any, or {@code null} otherwise.
* @param request the request to resolve the time zone for * @param request the request to resolve the time zone for

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 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.
@@ -149,7 +149,9 @@ public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
if (isIgnoreInvalidLocale()) { if (isIgnoreInvalidLocale()) {
logger.debug("Ignoring invalid locale value [" + newLocale + "]: " + ex.getMessage()); if (logger.isDebugEnabled()) {
logger.debug("Ignoring invalid locale value [" + newLocale + "]: " + ex.getMessage());
}
} }
else { else {
throw ex; throw ex;