Commit Graph

3050 Commits

Author SHA1 Message Date
Phillip Webb 5d785390eb Add `ClientHttpRequestInitializer` support
Add `ClientHttpRequestInitializer` interface that can be used with any
`HttpAccessor` to initialize each `ClientHttpRequest` before it's used.

This provides a useful alternative to `ClientHttpRequestInterceptor`
when users need to configure things like `HttpHeaders`.

Closes gh-22002
2019-09-12 16:01:46 -07:00
Rossen Stoyanchev 7194261961 Merge branch '5.1.x' 2019-09-12 21:17:00 +01:00
Rossen Stoyanchev 23be5dfb0e Handle invalid MediaType in Jetty/Tomcat adapters
See: gh-23553
2019-09-12 20:58:47 +01:00
Rossen Stoyanchev b7eaab4c5d Handle very early completion notification
On a Servlet container a completion notification may come at any time
even in the UNSUBSCRIBED state, i.e. before the write Publisher has
called onSubscribe.

See: gh-23553
2019-09-12 14:14:11 +01:00
Rossen Stoyanchev 07b0fa132e doFilterNestedErrorDispatch delegates to filter chain
Closes: gh-23596
2019-09-12 13:42:12 +01:00
Sam Brannen 30cff46e7f Prevent improper use of testing framework APIs
Prior to this commit, a lot of work had been done to prevent improper
use of testing Framework APIs throughout the codebase; however, there
were still some loopholes.

This commit addresses these loopholes by introducing additional
Checkstyle rules (and modifying existing rules) to prevent improper use
of testing framework APIs in production code as well as in test code.

- Checkstyle rules for banned imports have been refactored into
  multiple rules specific to JUnit 3, JUnit 4, JUnit Jupiter, and
  TestNG.
- Accidental usage of org.junit.Assume has been switched to
  org.junit.jupiter.api.Assumptions.
- All test classes now reside under org.springframework packages.
- All test classes (including abstract test classes) now conform to the
  `*Tests` naming convention.
  - As an added bonus, tests in the renamed
    ScenariosForSpringSecurityExpressionTests are now included in the
    build.
- Dead JUnit 4 parameterized code has been removed from
  DefaultServerWebExchangeCheckNotModifiedTests.

Closes gh-22962
2019-09-12 11:20:56 +02:00
Sam Brannen 5d5f9aceca Avoid accidental usage of JUnit 4 assumptions
This commit also avoids starting a server if an assumption fails.
2019-09-06 16:03:36 +02:00
Sam Brannen 591995ecc8 Polish and revive disabled tests
This commit revives some previously disabled tests and converts
some usage of @Disabled to @EnabledForTestGroups(...).
2019-09-06 15:57:27 +02:00
Sam Brannen d9e3b8b9a5 Introduce default constructor in TomcatHttpServer 2019-09-05 13:45:38 +02:00
Sam Brannen 73f5d05fd9 Avoid deprecation warning in RandomHandlerIntegrationTests 2019-09-05 13:29:01 +02:00
Phillip Webb deba2ed1b3 Add blank line between java and javax imports
See gh-23539
2019-09-04 22:05:46 -07:00
Rossen Stoyanchev bc81fa520e Reject range starting above resource length
Closes: gh-23576
2019-09-04 18:05:59 +01:00
Brian Clozel 0c7359911a Re-enable StreamingSimpleClientHttpRequestFactoryTests
Since the okhttp3 3.14 downgrade, we don't need to ignore this test
anymore.
2019-09-04 16:02:43 +02:00
Brian Clozel cccd9c8bb0 Fix okhttp3 downgrade 2019-09-04 15:07:17 +02:00
Sam Brannen 00983a1141 Update @Disabled for StreamingSimpleClientHttpRequestFactoryTests.interceptor() 2019-09-04 14:37:37 +02:00
Sam Brannen 4d819128db Fix Javadoc 2019-09-04 14:33:02 +02:00
Sam Brannen 513ce7824f Disable StreamingSimpleClientHttpRequestFactoryTests.interceptor() test 2019-09-03 16:43:48 +02:00
Rossen Stoyanchev d927d31e13 Remove reflection from ContentDispositionTests
Also minor refactoring in decoding in order to tolerate the absence of
a charset and treat as US_ASCII.

See gh-23485
2019-09-03 12:31:13 +01:00
Rossen Stoyanchev c97580035e Polish ContentDispositionTests
Closes gh-23485
2019-09-03 12:31:13 +01:00
Jonathan Bluett-Duncan f084b63286 Fix "array index out of bounds" problem reported by LGTM.com 2019-09-03 12:31:13 +01:00
Sam Brannen 5fd81d2a26 Avoid deprecation warning in AbstractMockWebServerTests
MockResponse.setHeaders(Headers) is now deprecated.
2019-09-03 12:13:09 +02:00
Brian Clozel d4089747b8 Use dependency management in Framework build
Prior to this commit, the Spring Framework build would partially use the
dependency management plugin to import and enforce BOMs.

This commit applies the dependency management plugin to all Java
projects and regroups all version management declaration in the root
`build.gradle` file (versions and exclusions).

Some versions are overridden in specific modules for
backwards-compatibility reasons or extended support.

This commit also adds the Gradle versions plugin that checks for
dependency upgrades in artifact repositories and produces a report; you
can use the following:

    ./gradlew dependencyUpdates
2019-09-02 18:01:09 +02:00
Sebastien Deleuze ca02cc1194 Migrate to AssertJ in Kotlin tests
Closes gh-23475
2019-09-02 15:59:26 +02:00
康智冬 a6f4862f13 Fix typos related to indefinite articles
Closes gh-23555
2019-09-01 15:45:49 +02:00
Sam Brannen 0103fec5de Convert assertions to AssertJ
See gh-23551
2019-08-31 13:13:44 +02:00
Sam Brannen 5a22eafcb4 Merge branch '5.1.x' 2019-08-31 13:10:58 +02:00
Sam Brannen 9729b460f1 Retain entry set order in read-only HttpHeaders
Prior to this commit, the entry set of read-only HttpHeaders lost the
original headers' ordering.

The changes in commit ce7278aaf4 introduced a regression in the read-only
HttpHeaders support. Specifically, the implementation of entrySet() in
the internal ReadOnlyHttpHeaders class converted the original entry set
to an immutable, non-ordered set of immutable entries.

This commit fixes this issue by converting the original entry set to an
immutable, ordered set of immutable entries.

Closes gh-23551
2019-08-31 13:10:07 +02:00
Sam Brannen a496353770 Delete dead code 2019-08-31 11:44:04 +02:00
Arjen Poutsma 67d48ed821 Merge branch '5.1.x' 2019-08-29 17:18:22 +02:00
Arjen Poutsma d709a69ff1 Remove buffering of encoded parts in MultipartHttpMessageWriter
Closes gh-23518
2019-08-29 16:34:36 +02:00
Rossen Stoyanchev 117119a88d Merge branch '5.1.x' 2019-08-29 15:13:36 +03:00
Rossen Stoyanchev 88e9dcef0c Consistently apply onCompletion/onError handling
Follow-up change in addition to dd22b8fd.

See gh-23096
2019-08-29 09:20:50 +03:00
Sebastien Deleuze f65cc9a438 Remove explicit disabling of buffer recycling in Jackson codec
Since now https://github.com/FasterXML/jackson-core/issues/476
and https://github.com/FasterXML/jackson-core/issues/479 are fixed.

This commit also raises the minimum version of Jackson to 2.9.7.

Closes gh-23522
2019-08-28 18:47:21 +02:00
Sam Brannen c004ef888c Configure index in @ParameterizedTest display names
This commit prepends "[{index}] " to all custom display names
configured via @ParameterizedTest.

This provides better diagnostics between the "technical names" reported
on the CI server vs. the "display names" reported within a developer's
IDE.

See gh-23451
2019-08-28 17:06:23 +02:00
Rossen Stoyanchev 4e39450dbe Merge branch '5.1.x' 2019-08-27 21:49:51 +03:00
Rossen Stoyanchev dd22b8fd39 Fix race condition with onCompletion/onError
Closes gh-23096
2019-08-27 21:43:33 +03:00
Сергей Цыпанов 6ef75d76cd Simplify String concatenation
Closes gh-23470
2019-08-27 18:22:44 +02:00
Sam Brannen b2ad16aaa7 Merge branch '5.1.x' 2019-08-27 17:37:25 +02:00
Sam Brannen 8189c90741 Allow Set-Cookie header to be overwritten in MockHttpServletResponse
Prior to this commit, there was no way to replace the Set-Cookie header
via MockHttpServletResponse. Specifically, an invocation of setHeader()
for the Set-Cookie header resulted in an additional Set-Cookie header
instead of replacing the existing one, which is in violation of the
contract for javax.servlet.http.HttpServletResponse.setHeader(...).

This commit refactors the internals of MockHttpServletResponse to ensure
that an existing Set-Cookie header is overwritten when set via an
invocation of setHeader(). This commit also verifies the expected
behavior for addHeader() and addCookie() with regard to multiple cookies.

Closes gh-23512
2019-08-27 17:20:38 +02:00
Sam Brannen ad6231ad29 Add missing @Override annotations 2019-08-23 13:50:58 +02:00
Sam Brannen 3e2b977d5d Re-enable shadowed, overridden @Test and lifecycle methods
Due to a bug (or "unintentional feature") in JUnit 4, overridden test
and lifecycle methods not annotated with @Test, @Before, @After, etc.
are still executed as test methods and lifecycle methods; however,
JUnit Jupiter does not support that. Thus, prior to this commit, some
overridden test and lifecycle methods were no longer executed after the
migration from JUnit 4 to JUnit Jupiter.

This commit addresses this issue for such known use cases, but there
are likely other such use cases within Spring's test suite.

See gh-23451
2019-08-23 13:50:57 +02:00
Arjen Poutsma 8e4f2c89ff Add headers(Consumer<HttpHeaders>) to RequestEntity and ResponseEntity
Closes gh-23404
2019-08-23 11:23:26 +02:00
Rossen Stoyanchev 274eab7c5d Merge branch '5.1.x' 2019-08-21 13:36:11 +03:00
Rossen Stoyanchev a7bb5ca473 Remove unnecessary iteration over headers
The use of LinkedCaseInsensitiveMap, going back to 3.0, makes it
unnecessary to iterate over keys which can cause
ConcurrentModificationException.

Closes gh-23460
2019-08-21 13:34:17 +03:00
Rossen Stoyanchev 78abc27432 Remove statusCode state tracking
Closes gh-23490
2019-08-21 11:45:56 +03:00
Rossen Stoyanchev 0a7fdb380f Fix checkstyle error 2019-08-21 11:02:10 +03:00
Rossen Stoyanchev ff6ccd0d04 Adapt tests changed in 5.1.x to master 2019-08-21 10:24:46 +03:00
Rossen Stoyanchev 364c7c459d Merge branch '5.1.x' 2019-08-21 10:21:32 +03:00
Rossen Stoyanchev b86c11cc9b Respect existing content-length for HTTP HEAD
Closes gh-23484
2019-08-21 02:28:19 +03:00
Brian Clozel e9523161f0 Revert "Revert "Refactor Gradle tasks in Spring Framework build""
This reverts commit fb0d618751.
2019-08-20 20:26:43 +02:00
Stephane Nicoll fb0d618751 Revert "Refactor Gradle tasks in Spring Framework build"
This reverts commit 1539ba8991.
2019-08-20 20:07:11 +02:00
Brian Clozel 1539ba8991 Refactor Gradle tasks in Spring Framework build
This commit reorganizes tasks and scripts in the build to only apply
them where they're needed. We're considering here 3 "types" of projects
in our build:
* the root project, handling documentation, publishing, etc
* framework modules (a project that's published as a spring artifact)
* internal modules, such as the BOM, our coroutines support and our
integration-tests

With this change, we're strealining the project configuration for all
spring modules and only applying plugins when needed (typically our
kotlin support).

See gh-23282
2019-08-20 18:17:02 +02:00
Sam Brannen cf1bf3d98c Polish parameterized tests 2019-08-20 12:43:31 +02:00
Sam Brannen 288461a541 Introduce @EnabledForTestGroups in Spring's test suite
Closes gh-23476
2019-08-17 14:47:24 +02:00
Sam Brannen bbe33832cf Clean up warnings in Javadoc 2019-08-17 13:21:28 +02:00
Sam Brannen 979508a7f3 Remove JUnit 4 dependency from all modules except spring-test
This commit removes the JUnit 4 dependency from all modules except
spring-test which provides explicit JUnit 4 support.

This commit also includes the following.

- migration from JUnit 4 assertions to JUnit Jupiter assertions in all
  Kotlin tests
- migration from JUnit 4 assumptions in Spring's TestGroup support to
  JUnit Jupiter assumptions, based on org.opentest4j.TestAbortedException
- introduction of a new TestGroups utility class than can be used from
  existing JUnit 4 tests in the spring-test module in order to perform
  assumptions using JUnit 4's Assume class

See gh-23451
2019-08-17 11:37:21 +02:00
Sam Brannen 3f3e41923f Migrate rest of test suite from JUnit 4 to JUnit Jupiter
This commit migrates the rest of Spring's test suite to JUnit Jupiter,
except spring-test which will be migrated in a separate commit.

See gh-23451
2019-08-17 11:36:58 +02:00
Sam Brannen 3df85c783f Migrate parameterized tests in spring-core
This commit migrates parameterized tests in spring-core using the
"composed @ParameterizedTest" approach. This approach is reused in
follow-up commits for the migration of the remaining modules.

For a concrete example, see AbstractDataBufferAllocatingTests and its
subclasses (e.g., DataBufferTests).

Specifically, AbstractDataBufferAllocatingTests declares a custom
@ParameterizedDataBufferAllocatingTest annotation that is
meta-annotated with @ParameterizedTest and
@MethodSource("org.springframework.core.io.buffer.AbstractDataBufferAllocatingTests#dataBufferFactories()").

Individual methods in concrete subclasses are then annotated with
@ParameterizedDataBufferAllocatingTest instead of @ParameterizedTest or
@Test.

The approach makes the migration from JUnit 4 to JUnit Jupiter rather
straightforward; however, there is one major downside. The arguments
for a @ParameterizedTest test method can only be accessed by the test
method itself. It is not possible to access them in an @BeforeEach
method (see https://github.com/junit-team/junit5/issues/944).
Consequently, we are forced to declare the parameters in each such
method and delegate to a custom "setup" method. Although this is a bit
cumbersome, I feel it is currently the best way to achieve fine grained
parameterized tests within our test suite without implementing a custom
TestTemplateInvocationContextProvider for each specific use case.

Once https://github.com/junit-team/junit5/issues/878 is resolved, we
should consider migrating to parameterized test classes.

See gh-23451
2019-08-17 11:36:47 +02:00
Daniel Le 60ec736264 Fix */* in Javadoc
This commit changes {@code &#42;&#47;&#42;} to <code>&#42;&#47;&#42;</code>
so that "*/*" is rendered correctly.

Closes gh-23439
2019-08-09 13:32:18 +02:00
Phillip Webb 62a3e41473 Deprecate mutable methods of MethodParameter
Deprecate all mutation methods in `MethodParameter` in favor of factory
methods that return a new instance. Existing code that previously relied
on mutation has been updated to use the replacement methods.

Closes gh-23385
2019-08-01 08:05:14 +01:00
Juergen Hoeller 6eca9e7cc9 Drop logger field in HandlerMethodArgumentResolverComposite 2019-07-31 23:58:02 +02:00
Juergen Hoeller dea9ad6cb2 Merge branch '5.1.x' 2019-07-31 23:53:32 +02:00
Juergen Hoeller ea4f7d365f Deprecate logger field in HandlerMethodArgumentResolverComposite 2019-07-31 23:48:21 +02:00
Juergen Hoeller 3b235a098f Merge branch '5.1.x' 2019-07-30 22:52:20 +02:00
Juergen Hoeller 59064f0780 Upgrade to Undertow 2.0.23 and Apache Johnzon 1.1.12 2019-07-30 22:27:09 +02:00
Juergen Hoeller 960079e5f5 Retain non-null HttpStatus return value in Client(Http)Response
See gh-23366
2019-07-30 22:26:46 +02:00
Arjen Poutsma ac9a11a581 Merge branch '5.1.x' 2019-07-30 18:03:01 +02:00
Arjen Poutsma 29ef985411 Add support for non-standard status codes
Added support for status codes that do not occur in HttpStatus in
DefaultClientResponseBuilder and made ClientResponse::statusCode
ClientHttpResponse::getStatusCode @Nullable.

Closed gh-23366
2019-07-30 17:44:47 +02:00
Juergen Hoeller 8ef557df2f Merge branch '5.1.x' 2019-07-30 17:34:29 +02:00
Juergen Hoeller c4622dbebc Polishing 2019-07-30 16:59:01 +02:00
Juergen Hoeller cc57506474 Add status code 425 ("Too Early") to HttpStatus enum
Closes gh-23384
2019-07-30 16:05:00 +02:00
Rossen Stoyanchev 9648b1c2c6 Merge branch '5.1.x' 2019-07-30 12:06:39 +01:00
Rossen Stoyanchev 7b697266be PathPatternParser allows '-' in variables
The isJavaIdentifier check is not really required, but also seems
intuitive for variables to be Java identifier-like. This commit relaxes
the constraint a bit by also allowing "-".

Closes gh-23101
2019-07-30 12:04:47 +01:00
Sam Brannen 9655fc5007 Introduce ServerHttpRequest.Builder.header() variant for setting headers
Prior to this commit, the `header(String, String)` method in the
ServerHttpRequest.Builder API actually added a header value instead of
setting or overriding a header value. Since this conflicted with the
stated behavior in the Javadoc as well as the original intention of the
method, we have decided to introduce an overloaded variant
`header(String, String...)` which accepts a var-args list of header
values to set or override.

In addition, this commit deprecates the existing `header(String, String)`
method for removal in Spring Framework 5.2.

In order not to be a breaking change for custom implementations of the
builder API, this commit implements the new `header(String, String...)`
method as an interface `default` method, with the intent to remove the
default implementation in Spring Framework 5.2

closes gh-23333
2019-07-25 13:45:39 +02:00
Sam Brannen db3990d031 Merge branch '5.1.x' 2019-07-25 13:44:31 +02:00
Sam Brannen 5034d1e7b3 Introduce ServerHttpRequest.Builder.header() variant for setting headers
Prior to this commit, the `header(String, String)` method in the
ServerHttpRequest.Builder API actually added a header value instead of
setting or overriding a header value. Since this conflicted with the
stated behavior in the Javadoc as well as the original intention of the
method, we have decided to introduce an overloaded variant
`header(String, String...)` which accepts a var-args list of header
values to set or override.

In addition, this commit deprecates the existing `header(String, String)`
method for removal in Spring Framework 5.2.

In order not to be a breaking change for custom implementations of the
builder API, this commit implements the new `header(String, String...)`
method as an interface `default` method, with the intent to remove the
default implementation in Spring Framework 5.2

closes gh-23333
2019-07-25 13:02:09 +02:00
Stephane Nicoll f95372d757 Merge branch '5.1.x' 2019-07-25 08:39:31 +02:00
Johnny Lim 946fc39d42 Add Javadoc since for Jaxb2XmlDecoder(MimeType...)
See gh-23353
2019-07-25 08:38:46 +02:00
Rossen Stoyanchev acb3d1cf88 Fix typo in test from previous commit
See gh-23310
2019-07-22 14:59:52 +01:00
Rossen Stoyanchev 358a6d6f10 Improve separator support in PathContainer
To make the switching of separators complete, it is also important to
know whether the decoding of path segment values and the parsing of
path param should be done as those are applied transparently.

This commit replaces the recently added separator argument to
PathContainer.parsePath with an Options type with two predefined
constants. One for HTTP URLs with automatic decoding and parsing of
path params, and another for "." separated message routes without
decoding except for encoded sequences of the separator itself.

See gh-23310
2019-07-22 11:28:38 +01:00
Sam Brannen b0939a8af0 Suppress deprecation warnings in Gradle build 2019-07-21 13:12:02 +02:00
Juergen Hoeller 45136aabd4 Upgrade to Protobuf 3.9 (plus consistent XMLUnit declarations) 2019-07-20 19:06:54 +02:00
Juergen Hoeller cdeb1fef5f Merge branch '5.1.x' 2019-07-20 18:23:00 +02:00
Juergen Hoeller 92890232df Upgrade to OpenPDF 1.2.21, Rome 1.12.1, XStream 1.4.11.1
Includes updated javadoc links for 5.1.x branch.
2019-07-20 18:20:03 +02:00
Arjen Poutsma c8704ce473 Introduce DataBufferWrapper
This commit introduces the DataBufferWrapper, a wrapper for DataBuffers,
and uses it in applicable use cases.
2019-07-19 12:45:24 +02:00
Rossen Stoyanchev 24e96b6c79 Merge branch '5.1.x' 2019-07-19 10:52:30 +01:00
Rossen Stoyanchev 153ac82380 Polish 2019-07-19 10:44:23 +01:00
Andreas Kluth 4973e110ee An empty X-Forwarded-Prefix with a path containing escape sequences leads to exceptions. 2019-07-19 10:44:23 +01:00
Rossen Stoyanchev 2b94205ba9 Update docs on multipart with RestTemplate
Replace docs on using MultipartBodyBuilder for the RestTemplate with
examples that show MultiValueMap. Originally the idea was to make
MultipartBodyBuilder accessible to the RestTemplate too, but with
support for async parts that's no longer a good fit.

Closes gh-23295
2019-07-19 10:43:50 +01:00
Sebastien Deleuze 095fd5bcb3 Use Kotlin BOM
Close gh-23316
2019-07-19 10:43:54 +02:00
Sam Brannen 38f6d270f8 Delete dead code in tests 2019-07-18 12:20:26 +02:00
Juergen Hoeller 94e3210ae7 Fix nullability warnings and javadoc-triggered package cycles 2019-07-17 22:34:07 +02:00
Sebastien Deleuze d6e3394b81 Polishing
See gh-23219
2019-07-16 19:23:21 +02:00
Sam Brannen b2b79ae1e6 Polish contribution
See gh-23219
2019-07-16 14:57:32 +02:00
Rossen Stoyanchev 1ff29b0f6b Merge branch '5.1.x' 2019-07-15 11:34:35 +01:00
Rossen Stoyanchev 99c4a9eeba Filtering for nested ERROR dispatch
OncePerRequestFilter now has a doFilter method that allows separate
processing of nested ERROR dispatches. This is useful for filters
that wrap the request and response.

Closes gh-23196
2019-07-15 11:23:12 +01:00
Rossen Stoyanchev 2eba010c1b Merge branch '5.1.x' 2019-07-13 11:00:57 +01:00
Rossen Stoyanchev 235858e4e5 Exposes supported mime types in Jaxb2Decoder
Closes gh-23278
2019-07-13 11:00:43 +01:00
Rob Winch fde92793b5 Fix http URLs
See gh-22839
2019-07-11 18:14:20 +02:00
Stephane Nicoll 4a5063f4c0 Merge branch '5.1.x' 2019-07-11 09:55:13 +02:00
桂坤 81eb911c09 Fix typo in UrlPathHelper
See gh-23274
2019-07-11 09:54:03 +02:00
Сергей Цыпанов 1728bf17fc Avoid unnecessary boxing where primitives can be used
Closes gh-23267
2019-07-10 16:51:18 +02:00
Arjen Poutsma 2909de8829 Remove ServerWebExchange::getParts and ServerRequest::parts
Revert to state before DefaultMultipartMessageReader
2019-07-10 16:20:20 +02:00
Arjen Poutsma 77c24aac2f Remove DefaultMultipartMessageReader
The DefaultMultipartMessageReader has been removed for 5.2 and will be
part of a future release. This commit switches back to the
SynchronossPartHttpMessageReader.

gh-21659
2019-07-10 16:00:11 +02:00
Rossen Stoyanchev c199cb9054 @ConnectMapping for RSocket handling
The new annotation helps to differentiate the handling of connection
level frames (SETUP and METADATA_PUSH) from the 4 stream requests.

Closes gh-23177
2019-07-08 17:04:23 +01:00
Sebastien Deleuze 2b4d6ce354 Add body methods with Object parameter to WebFlux
The commit deprecates syncBody(Object) in favor of body(Object)
which has the same behavior in ServerResponse, WebClient and
WebTestClient. It also adds body(Object, Class) and
body(Object, ParameterizedTypeReference) methods in order to support
any reactive type that can be adapted to a Publisher via
ReactiveAdapterRegistry. Related BodyInserters#fromProducer
methods are provided as well.

Shadowed Kotlin body<T>() extensions are deprecated in favor of
bodyWithType<T>() ones, including dedicated Publisher<T> and
Flow<T> variants. Coroutines extensions are adapted as well, and
body(Object) can now be used with suspending functions.

Closes gh-23212
2019-07-07 22:27:57 +02:00
Sam Brannen 0fbc9bf461 Fix broken Javadoc links 2019-07-07 19:50:34 +02:00
Sam Brannen 575027af24 Polishing 2019-07-07 16:34:15 +02:00
Sam Brannen fae75cb238 Polish contribution
See gh-23237
2019-07-07 16:29:03 +02:00
Johnny Lim 6dcf390fa2 Rename PathPatternRouteMatcherTest to PathPatternRouteMatcherTests
Closes gh-23239
2019-07-07 16:28:09 +02:00
Сергей Цыпанов 9f81ffa5ae Use StringJoiner where possible to simplify String joining
Closes gh-23237
2019-07-07 16:19:01 +02:00
Sam Brannen 8f5b2b2231 Merge branch '5.1.x' 2019-07-07 14:49:34 +02:00
Sam Brannen efab6eb55d Ignore empty entries when parsing MediaTypes and MimeTypes
Prior to Spring Framework 5.1.3, MimeTypeUtils.parseMimeTypes() and
MediaType.parseMediaTypes() ignored empty entries, but 5.1.3 introduced
a regression in that an empty entry -- for example, due to a trailing
comma in the list of media types in an HTTP Accept header -- would result
in a "406 Not Acceptable" response status.

This commit fixes this by filtering out empty entries before parsing
them into MimeType and MediaType instances. Empty entries are therefore
effectively ignored.

Fixes gh-23241
2019-07-07 12:39:46 +02:00
Rossen Stoyanchev fbb72eff2e Polish 2019-07-05 09:02:24 +01:00
Dmytro Nosan ea10ee5265 queryParam and replaceParam with List
See gh-23114
2019-07-05 09:02:24 +01:00
Phillip Webb 932f771380 Improve performance of FormContentFilter
Improve the performance of `FormContentFilter` by checking directly if
`contentType` is empty. This saves the need for an exception to thrown
then immediately caught.

Closes gh-23216
2019-06-29 22:31:11 -07:00
Sam Brannen 896496341a Add explicit support for multipart/mixed in FormHttpMessageConverter
Commit 5008423408 added support for
multipart/* media types in FormHttpMessageConverter, but users still had
to manually register multipart/mixed as a supported media type in order
to POST multipart data with that content type.

This commit removes the need to manually register multipart/mixed as a
supported media type by registering it automatically in
FormHttpMessageConverter. In addition, this commit introduces
MULTIPART_MIXED and MULTIPART_MIXED_VALUE constants in MediaType.

Closes gh-23209
2019-06-29 11:41:15 +03:00
Sam Brannen 75d1428e24 Polishing 2019-06-29 11:41:15 +03:00
Sam Brannen 3e41f5e6b6 Cache the encoded credentials in BasicAuthenticationInterceptor
Prior to this commit, the Basic Authentication credentials were encoded
for each request.

This commit addresses this minor performance issue by caching the
encoded credentials in BasicAuthenticationInterceptor.

In addition, this commit introduces new encodeBasicAuth() and
setBasicAuth(String encodedCredentials) methods in HttpHeaders to
support this feature.

Closes gh-23204
2019-06-28 18:48:59 +03:00
Sam Brannen 5008423408 Support multipart/* MediaTypes in RestTemplate
Prior to this commit, RestTemplate posted multipart with Content-Type
"multipart/form-data" even if the FormHttpMessageConverter configured
in the RestTemplate had been configured to support additional multipart
subtypes. This made it impossible to POST form data using a content
type such as "multipart/mixed" or "multipart/related".

This commit addresses this issue by updating FormHttpMessageConverter
to support custom multipart subtypes for writing form data.

For example, the following use case is now supported.

MediaType multipartMixed = new MediaType("multipart", "mixed");

restTemplate.getMessageConverters().stream()
    .filter(FormHttpMessageConverter.class::isInstance)
    .map(FormHttpMessageConverter.class::cast)
    .findFirst()
    .orElseThrow(() ->
        new IllegalStateException("Failed to find FormHttpMessageConverter"))
    .addSupportedMediaTypes(multipartMixed);

MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("field 1", "value 1");
parts.add("file", new ClassPathResource("myFile.jpg"));

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(multipartMixed);
HttpEntity<MultiValueMap<String, Object>> requestEntity =
    new HttpEntity<>(parts, requestHeaders);

restTemplate.postForLocation("https://example.com/myFileUpload", requestEntity);

Closes gh-23159
2019-06-28 17:13:18 +03:00
Sam Brannen 7bc727c895 Convert addSupportedMediaType() to var-args in FormHttpMessageConverter
This commit changes the new addSupportedMediaType(MediaType) method
to addSupportedMediaTypes(MediaType...), in order to allow registration
of multiple supported media types simultaneously.

See gh-23203
2019-06-27 16:55:03 +03:00
Sam Brannen 1ef60f2d3b Polishing 2019-06-27 16:05:38 +03:00
Sam Brannen 91ae711a54 Fix Javadoc for MediaType 2019-06-27 16:05:38 +03:00
Sam Brannen 4e7d8a8873 Introduce addSupportedMediaType() in FormHttpMessageConverter
Closes gh-23203
2019-06-27 16:05:38 +03:00
Sam Brannen 8e1cb9a059 Improve diagnostics for all server failures in RestTemplateIntegrationTests 2019-06-27 14:16:19 +03:00
Sam Brannen d522e9835f Polish AbstractMockWebServerTestCase 2019-06-27 13:45:32 +03:00
Sam Brannen 0b6239cecc Improve diagnostics for failures in RestTemplateIntegrationTests 2019-06-26 15:16:54 +03:00
Sam Brannen 7d6be2e26e Polishing 2019-06-26 15:12:32 +03:00
Sam Brannen 0f1d16bb05 Fix Checkstyle violation 2019-06-24 17:54:04 +03:00
Sam Brannen d0231cb29a Presort beans in ControllerAdviceBean.findAnnotatedBeans()
Prior to this commit, all clients of
ControllerAdviceBean.findAnnotatedBeans() sorted the returned list
manually. In addition, clients within the core Spring Framework
unnecessarily used AnnotationAwareOrderComparator instead of
OrderComparator to sort the list.

This commit presorts the ControllerAdviceBean list using OrderComparator
directly within ControllerAdviceBean.findAnnotatedBeans().

Closes gh-23188
2019-06-24 16:26:11 +03:00
Sam Brannen d5a2bdee8d Improve Javadoc for @ControllerAdvice regarding ordering
Closes gh-23163
2019-06-24 14:36:04 +03:00
Sam Brannen 9239ab1891 Support Ordered interface for @ControllerAdvice beans
Closes gh-23163
2019-06-23 19:31:35 +03:00
Sam Brannen 978adbdae7 Avoid duplicate lookups of @ControllerAdvice annotations
See gh-23163
2019-06-23 18:31:04 +03:00
Sam Brannen 7576d0d40c Polishing
See gh-23163
2019-06-22 19:06:58 +03:00
Sam Brannen 4568edf6c4 Simplify ControllerAdviceBean constructors
See gh-23163
2019-06-22 19:02:49 +03:00
Sam Brannen 8f30639a0a Test status quo for Ordered support for @ControllerAdvice beans
See gh-23163
2019-06-22 18:18:57 +03:00
Sam Brannen 21267e56b7 Cache resolved bean instance in ControllerAdviceBean
Prior to this commit, the resolveBean() method in ControllerAdviceBean
looked up the @ControllerAdvice bean instance in the ApplicationContext
by name for every web request that involved lookups for global methods
annotated with @ExceptionHandler, @InitBinder, and @ModelAttribute.

This commit avoids the need for such repeated lookups in the
ApplicationContext by caching the resolved @ControllerAdvice bean
instance within ControllerAdviceBean once it has been resolved.
2019-06-21 18:27:33 +03:00
Sam Brannen 59901592d2 Introduce regression tests for ControllerAdviceBean
This commit introduces unit tests for the status quo in
ControllerAdviceBeanTests to serve as regression tests for future
changes to ControllerAdviceBean.
2019-06-21 17:21:50 +03:00
Sam Brannen 52f1a3aef9 Polish ControllerAdviceBean 2019-06-21 17:11:12 +03:00
Rossen Stoyanchev 030caea9cf Merge branch '5.1.x' 2019-06-21 14:15:26 +01:00
Rossen Stoyanchev 594c5806a6 Handle error in apply of writeFunction
Closes gh-23175
2019-06-21 14:15:14 +01:00
Sam Brannen 0e5a38591f Cache beanType in ControllerAdviceBean 2019-06-21 14:09:05 +03:00
Sam Brannen 2759b4b909 Avoid use of Stream API in ControllerAdviceBean 2019-06-21 13:49:49 +03:00
Sam Brannen d5554d5d8d Polish @ControllerAdvice and @RestControllerAdvice 2019-06-21 13:26:30 +03:00
Sam Brannen ad915f4a26 Document that Ordered is not supported for @ControllerAdvice beans
Closes gh-23172
2019-06-21 12:39:34 +03:00
Arjen Poutsma 11c7907a59 Add Flux<Part> ServerWebExchange.getParts()
This commit introduces ServerWebExchange.getParts(), as an alternative,
streaming way of accessing multipart data.
2019-06-21 10:59:12 +02:00
Brian Clozel cc05608ae9 PathPattern does not use custom separator
Prior to this commit, `PathPattern::extractPathWithinMapping`
would always use the default path pattern separator `/` when extracting
the path within the pattern of a matched route.

This commit ensures that `PathPattern` uses the configured separator
when extracting the path within the matched mapping.

Fixes gh-23168
2019-06-20 20:27:22 +02:00
Brian Clozel 5787fc16fb PathPatternRouteMatcher should use custom separator
Prior to this commit, the `PathPatternRouteMatcher` would always use the
default path pattern separator when parsing incoming route strings to
`RouteMatcher.Route` instances.
When the `PathPatternRouteMatcher` is configured with a
`PathPatternParser` that has a custom separator (e.g., `.`), then the
matching algorithm can't match routes against parsed patterns.

This commit ensures that the route matcher uses the configured separator
at all times.

Fixes gh-23167
2019-06-20 20:23:04 +02:00
Sam Brannen f56c54dfc8 Polishing 2019-06-20 18:09:22 +03:00
Sam Brannen d2e6d0269b Preliminary tests for multipart/related & multipart/mixed in RestTemplate
See gh-23159
2019-06-20 11:35:18 +03:00