Browse Source

Merge branch '5.1.x'

pull/22883/head
Juergen Hoeller 6 years ago
parent
commit
ec8689d1fc
  1. 11
      spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java
  2. 9
      spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java
  3. 4
      spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java
  4. 20
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
  5. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java
  6. 13
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerStrategies.java

11
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private String remoteHost = DEFAULT_REMOTE_HOST;
/** List of locales in descending order. */
private final List<Locale> locales = new LinkedList<>();
private final LinkedList<Locale> locales = new LinkedList<>();
private boolean secure = false;
@ -779,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -779,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public void addPreferredLocale(Locale locale) {
Assert.notNull(locale, "Locale must not be null");
this.locales.add(0, locale);
this.locales.addFirst(locale);
updateAcceptLanguageHeader();
}
@ -817,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -817,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
@Override
public Locale getLocale() {
return this.locales.get(0);
return this.locales.getFirst();
}
/**
@ -1015,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -1015,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
List<Locale> locales = headers.getAcceptLanguageAsLocales();
this.locales.clear();
this.locales.addAll(locales);
if (this.locales.isEmpty()) {
this.locales.add(Locale.ENGLISH);
}
}
catch (IllegalArgumentException ex) {
// Invalid Accept-Language format -> just store plain header

9
spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -351,6 +351,13 @@ public class MockHttpServletRequestTests { @@ -351,6 +351,13 @@ public class MockHttpServletRequestTests {
assertEquals("en_US", request.getHeader("Accept-Language"));
}
@Test
public void emptyAcceptLanguageHeader() {
request.addHeader("Accept-Language", "");
assertEquals(Locale.ENGLISH, request.getLocale());
assertEquals("", request.getHeader("Accept-Language"));
}
@Test
public void getServerNameWithDefaultName() {
assertEquals("localhost", request.getServerName());

4
spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java

@ -41,7 +41,6 @@ import org.springframework.lang.Nullable; @@ -41,7 +41,6 @@ import org.springframework.lang.Nullable;
* @since 16.05.2003
* @see org.springframework.transaction.support.TransactionTemplate
* @see org.springframework.transaction.interceptor.TransactionInterceptor
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
public interface PlatformTransactionManager extends TransactionManager {
@ -68,7 +67,8 @@ public interface PlatformTransactionManager extends TransactionManager { @@ -68,7 +67,8 @@ public interface PlatformTransactionManager extends TransactionManager {
* @see TransactionDefinition#getTimeout
* @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

20
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private String remoteHost = DEFAULT_REMOTE_HOST;
/** List of locales in descending order. */
private final List<Locale> locales = new LinkedList<>();
private final LinkedList<Locale> locales = new LinkedList<>();
private boolean secure = false;
@ -403,12 +403,11 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -403,12 +403,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
private void updateContentTypeHeader() {
if (StringUtils.hasLength(this.contentType)) {
StringBuilder sb = new StringBuilder(this.contentType);
if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) &&
StringUtils.hasLength(this.characterEncoding)) {
sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding);
String value = this.contentType;
if (StringUtils.hasLength(this.characterEncoding) && !this.contentType.toLowerCase().contains(CHARSET_PREFIX)) {
value += ';' + CHARSET_PREFIX + this.characterEncoding;
}
doAddHeaderValue(HttpHeaders.CONTENT_TYPE, sb.toString(), true);
doAddHeaderValue(HttpHeaders.CONTENT_TYPE, value, true);
}
}
@ -780,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -780,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public void addPreferredLocale(Locale locale) {
Assert.notNull(locale, "Locale must not be null");
this.locales.add(0, locale);
this.locales.addFirst(locale);
updateAcceptLanguageHeader();
}
@ -818,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -818,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
@Override
public Locale getLocale() {
return this.locales.get(0);
return this.locales.getFirst();
}
/**
@ -1016,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -1016,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
List<Locale> locales = headers.getAcceptLanguageAsLocales();
this.locales.clear();
this.locales.addAll(locales);
if (this.locales.isEmpty()) {
this.locales.add(Locale.ENGLISH);
}
}
catch (IllegalArgumentException ex) {
// Invalid Accept-Language format -> just store plain header

8
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -37,18 +37,18 @@ public interface ExchangeStrategies { @@ -37,18 +37,18 @@ public interface ExchangeStrategies {
/**
* 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();
/**
* 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();
// Static methods
// Static builder methods
/**
* Return a new {@code ExchangeStrategies} with default configuration

13
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerStrategies.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -28,10 +28,11 @@ import org.springframework.web.server.WebFilter; @@ -28,10 +28,11 @@ import org.springframework.web.server.WebFilter;
import org.springframework.web.server.i18n.LocaleContextResolver;
/**
* Defines the strategies to be used for processing {@link HandlerFunction HandlerFunctions}. An instance of
* 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
* scratch.
* Defines the strategies to be used for processing {@link HandlerFunction HandlerFunctions}.
*
* <p>An instance of 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 scratch.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
@ -78,7 +79,7 @@ public interface HandlerStrategies { @@ -78,7 +79,7 @@ public interface HandlerStrategies {
LocaleContextResolver localeContextResolver();
// Static methods
// Static builder methods
/**
* Return a new {@code HandlerStrategies} with default initialization.

Loading…
Cancel
Save