Polishing

This commit is contained in:
Sam Brannen 2023-07-15 12:53:12 +02:00
parent 8629182822
commit e6d360c1c6
11 changed files with 82 additions and 62 deletions

View File

@ -742,7 +742,7 @@ reliance on it.
[[webflux-config-blocking-execution]]
== Blocking Execution
The WebFlux Java config lets you to customize blocking execution in WebFlux.
The WebFlux Java config allows you to customize blocking execution in WebFlux.
You can have blocking controller methods called on a separate thread by providing
an `Executor` such as the
@ -777,7 +777,7 @@ Kotlin::
@Override
fun configureBlockingExecution(configurer: BlockingExecutionConfigurer) {
val executor = ...
val executor = ...
configurer.setExecutor(executor)
}
}

View File

@ -33,7 +33,7 @@ import static org.mockito.BDDMockito.verify;
* @author Philippe Marschall
* @since 6.1
*/
public class SqlArrayValueTests {
class SqlArrayValueTests {
private final Connection con = mock();
@ -47,7 +47,7 @@ public class SqlArrayValueTests {
@Test
public void setValue() throws SQLException {
void setValue() throws SQLException {
given(this.ps.getConnection()).willReturn(this.con);
given(this.con.createArrayOf("smallint", elements)).willReturn(this.arr);

View File

@ -33,7 +33,8 @@ import org.springframework.util.NumberUtils;
/**
* Miscellaneous utility methods for DAO implementations.
* Useful with any data access technology.
*
* <p>Useful with any data access technology.
*
* @author Juergen Hoeller
* @since 1.0.2
@ -80,7 +81,7 @@ public abstract class DataAccessUtils {
if (resultList.size() > 1) {
throw new IncorrectResultSizeDataAccessException(1);
}
return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
return resultList.isEmpty() ? null : resultList.get(0);
}
}

View File

@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.DataAccessUtilsTests.MapPersistenceExceptionTranslator;
import org.springframework.dao.support.MapPersistenceExceptionTranslator;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.stereotype.Repository;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.dao.support.DataAccessUtilsTests.MapPersistenceExceptionTranslator;
import static org.assertj.core.api.Assertions.assertThat;
@ -28,18 +27,17 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson
* @since 2.0
*/
public class ChainedPersistenceExceptionTranslatorTests {
class ChainedPersistenceExceptionTranslatorTests {
@Test
public void empty() {
void empty() {
ChainedPersistenceExceptionTranslator pet = new ChainedPersistenceExceptionTranslator();
//MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException("in");
assertThat(DataAccessUtils.translateIfNecessary(in, pet)).isSameAs(in);
}
@Test
public void exceptionTranslationWithTranslation() {
void exceptionTranslationWithTranslation() {
MapPersistenceExceptionTranslator mpet1 = new MapPersistenceExceptionTranslator();
RuntimeException in1 = new RuntimeException("in");
InvalidDataAccessApiUsageException out1 = new InvalidDataAccessApiUsageException("out");

View File

@ -20,15 +20,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
@ -40,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller
* @since 20.10.2004
*/
public class DataAccessUtilsTests {
class DataAccessUtilsTests {
@Test
public void withEmptyCollection() {
void withEmptyCollection() {
Collection<String> col = new HashSet<>();
assertThat(DataAccessUtils.uniqueResult(col)).isNull();
@ -73,7 +70,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withTooLargeCollection() {
void withTooLargeCollection() {
Collection<String> col = new HashSet<>(2);
col.add("test1");
col.add("test2");
@ -124,7 +121,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withInteger() {
void withInteger() {
Collection<Integer> col = new HashSet<>(1);
col.add(5);
@ -143,7 +140,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withSameIntegerInstanceTwice() {
void withSameIntegerInstanceTwice() {
Integer i = 5;
Collection<Integer> col = new ArrayList<>(1);
col.add(i);
@ -158,7 +155,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withEquivalentIntegerInstanceTwice() {
void withEquivalentIntegerInstanceTwice() {
Collection<Integer> col = Arrays.asList(555, 555);
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
@ -167,7 +164,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withLong() {
void withLong() {
Collection<Long> col = new HashSet<>(1);
col.add(5L);
@ -186,7 +183,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withString() {
void withString() {
Collection<String> col = new HashSet<>(1);
col.add("test1");
@ -208,7 +205,7 @@ public class DataAccessUtilsTests {
}
@Test
public void withDate() {
void withDate() {
Date date = new Date();
Collection<Date> col = new HashSet<>(1);
col.add(date);
@ -232,14 +229,14 @@ public class DataAccessUtilsTests {
}
@Test
public void exceptionTranslationWithNoTranslation() {
void exceptionTranslationWithNoTranslation() {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException();
assertThat(DataAccessUtils.translateIfNecessary(in, mpet)).isSameAs(in);
}
@Test
public void exceptionTranslationWithTranslation() {
void exceptionTranslationWithTranslation() {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException("in");
InvalidDataAccessApiUsageException out = new InvalidDataAccessApiUsageException("out");
@ -261,20 +258,4 @@ public class DataAccessUtilsTests {
return ex -> assertThat(ex.getExpectedSize()).as("expected size").isEqualTo(expectedSize);
}
public static class MapPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
// in to out
private final Map<RuntimeException, RuntimeException> translations = new HashMap<>();
public void addTranslation(RuntimeException in, RuntimeException out) {
this.translations.put(in, out);
}
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return (DataAccessException) translations.get(ex);
}
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.dao.support;
import java.util.HashMap;
import java.util.Map;
import org.springframework.dao.DataAccessException;
public class MapPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
// in to out
private final Map<RuntimeException, RuntimeException> translations = new HashMap<>();
public void addTranslation(RuntimeException in, RuntimeException out) {
this.translations.put(in, out);
}
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return (DataAccessException) this.translations.get(ex);
}
}

View File

@ -103,7 +103,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
}
/**
* Initialize a URI from the given Servet request.
* Initialize a URI from the given Servlet request.
* @param servletRequest the request
* @return the initialized URI
* @since 6.1

View File

@ -25,21 +25,20 @@ import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
* Utility class to assist with processing "Forwarded" and "X-Forwarded-*" headers.
*
* <p><strong>Note:</strong>There are security considerations surrounding the use
* <p><strong>Note:</strong> There are security considerations surrounding the use
* of forwarded headers. Those should not be used unless the application is
* behind a trusted proxy that inserts them and also explicitly removes any such
* headers coming from an external source.
*
* <p>In most cases, should not use this class directly but rely on
* {@link org.springframework.web.filter.ForwardedHeaderFilter} for Spring MVC, or
* <p>In most cases, you should not use this class directly but rather rely on
* {@link org.springframework.web.filter.ForwardedHeaderFilter} for Spring MVC or
* {@link org.springframework.web.server.adapter.ForwardedHeaderTransformer} in
* order to extract the information from them as early as possible, and discard
* such headers. Underlying servers such as Tomcat, Jetty, Reactor Netty, also
* provides options to handle forwarded headers even earlier.
* order to extract the information from the headers as early as possible and discard
* such headers. Underlying servers such as Tomcat, Jetty, and Reactor Netty also
* provide options to handle forwarded headers even earlier.
*
* @author Rossen Stoyanchev
* @since 6.1
@ -56,10 +55,11 @@ public abstract class ForwardedHeaderUtils {
/**
* Adapt the scheme+host+port of the given {@link URI} from the "Forwarded" header,
* see <a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>, or
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded"
* is not present.
* Adapt the scheme+host+port of the given {@link URI} from the "Forwarded" header
* (see <a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>) or from the
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers if
* "Forwarded" is not present.
* @param uri the request {@code URI}
* @param headers the HTTP headers to consider
* @return a {@link UriComponentsBuilder} that reflects the request URI and
* additional updates from forwarded headers
@ -106,7 +106,7 @@ public abstract class ForwardedHeaderUtils {
catch (NumberFormatException ex) {
throw new IllegalArgumentException("Failed to parse a port from \"forwarded\"-type headers. " +
"If not behind a trusted proxy, consider using ForwardedHeaderFilter " +
"with the removeOnly=true. Request headers: " + headers);
"with removeOnly=true. Request headers: " + headers);
}
uriComponentsBuilder.resetPortIfDefaultForScheme();
@ -138,11 +138,11 @@ public abstract class ForwardedHeaderUtils {
/**
* Parse the first "Forwarded: for=..." or "X-Forwarded-For" header value to
* an {@code InetSocketAddress} representing the address of the client.
* @param uri the request URI
* @param uri the request {@code URI}
* @param headers the request headers that may contain forwarded headers
* @param remoteAddress the current remoteAddress
* @param remoteAddress the current remote address
* @return an {@code InetSocketAddress} with the extracted host and port, or
* {@code null} if the headers are not present.
* {@code null} if the headers are not present
* @see <a href="https://tools.ietf.org/html/rfc7239#section-5.2">RFC 7239, Section 5.2</a>
*/
@Nullable

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ public class BlockingExecutionConfigurer {
/**
* Configure a predicate to decide if a controller method is blocking and
* should be called on a separate thread if an executor is
* {@link #setExecutor configured}.
* {@linkplain #setExecutor configured}.
* <p>The default predicate matches controller methods whose return type is
* not recognized by the configured
* {@link org.springframework.core.ReactiveAdapterRegistry}.

View File

@ -151,7 +151,7 @@ public class RequestMappingHandlerAdapter
* Provide a predicate to decide which controller methods to invoke through
* the configured {@link #setBlockingExecutor blockingExecutor}.
* <p>If an executor is configured, the default predicate matches controller
* methods whose return type not recognized by the configured
* methods whose return type is not recognized by the configured
* {@link org.springframework.core.ReactiveAdapterRegistry}.
* @param predicate the predicate to use
* @since 6.1