Commit Graph

2371 Commits

Author SHA1 Message Date
Sebastien Deleuze b09fad13a1 Catch errors when adding SourceHttpMessageConverter
This commit ignores errors like TransformerFactoryConfigurationError
that can be thrown when instantiating SourceHttpMessageConverter on
platforms where no TransformerFactory implementation is available,
like when compiling/running as GraalVM native images.

Issue: SPR-17007
2018-07-23 10:39:26 +02:00
Brian Clozel 390bb871d8 Switch order of multipart Content-Type directives
Since SPR-15205, the `FormHttpMessageConverter` is adding a `charset`
directive to the `Content-Type` request header in order to help servers
understand which charset is being used to encode headers of each part.

As reported in SPR-17030 and others, some servers are not parsing
properly such header values and assume that `boundary` is the last
directive in the `Content-Type` header.

This commit reorders the charset information right before the boundary
declaration to get around those issues.

Issue: SPR-17030
2018-07-20 18:11:05 +02:00
Juergen Hoeller 9a43d2ec20 Revised log levels: less WARN and INFO, fine-tuned DEBUG vs TRACE
Issue: SPR-16946
2018-07-20 15:05:16 +02:00
Rossen Stoyanchev 93b7a4838e UriComponentsBuilder method to configure URI variables
See Javadoc on UriComponentsBuilder#uriVariables for details.

This helps to prepare for SPR-17027 where the MvcUriComponentsBuilder
already does a partial expand but was forced to build UriComonents
and then create a new UriComponentsBuilder from it to continue. This
change makes it possible to stay with the same builder instance.

Issue: SPR-17027
2018-07-19 19:07:42 -04:00
Rossen Stoyanchev 28cd6978b5 Minor fixes: UriComponentsBuilder, UriComponents, docs
After the latest changes, two small fixes in the clone method to copy
the encode flag, and in the encodeUriTemplate method to account for
possible null query params.

Improvements in the URI encoding section.

Issue: SPR-17039, SPR-17027
2018-07-19 19:07:42 -04:00
Juergen Hoeller 51c7ceb95d Polishing 2018-07-20 00:17:37 +02:00
Juergen Hoeller 867b3d233d Upgrade to OkHttp 3.11, Apache HttpClient 4.5.6, Hibernate Validator 6.0.11 2018-07-19 17:52:08 +02:00
Juergen Hoeller 1f5d0faf1f HandlerMethod caches interface parameter annotations
Issue: SPR-11055
2018-07-19 11:38:10 +02:00
Vedran Pavic b1e28a554a Polish WebSession javadoc
Issue: SPR-17051

Closes gh-1888
2018-07-19 11:26:49 +02:00
Rossen Stoyanchev 9498da5910 Clarify behavior of WebSession#save()
+ minor update to the InMemoryWebSession to match the defined behavior.

Issue: SPR-17051
2018-07-18 22:14:02 -04:00
Juergen Hoeller 9c08a482d1 Prefer ArrayList/ArrayDeque over LinkedList for multi-element holders
LinkedList remains in place where a List is likely to remain empty or single-element (in order to avoid unused capacity).

Issue: SPR-17037
2018-07-18 22:17:42 +02:00
Rossen Stoyanchev 4d6f2df3cb Add LogUtils and HttpLogging
SPR-17012
2018-07-18 15:32:50 -04:00
Juergen Hoeller c77dbbb1e6 Specific exception for missing request header, cookie, matrix variable
Issue: SPR-14818
2018-07-18 18:56:51 +02:00
Juergen Hoeller 790d515f8c HandlerMethod exposes interface parameter annotations as well
The HandlerMethodParameter arrangement uses an approach similar to ModelAttributeMethodProcessor's FieldAwareConstructorParameter, merging the local parameter annotations with interface-declared annotations.

Issue: SPR-11055
2018-07-18 17:13:55 +02:00
sdeleuze a87764f1fd Add support for Jetty Reactive Streams HTTP client
Leverage https://github.com/jetty-project/jetty-reactive-httpclient
to add support for Jetty in WebClient via JettyClientHttpConnector.

Implemented with buffer copy instead of optimized buffer wrapping
because the latter hangs since Callback#succeeded doesn't allow
releasing the buffer and requesting more data at different times
(required for Mono<DataBuffer> for example).
See https://github.com/eclipse/jetty.project/issues/2429.

Issue: SPR-15092
2018-07-18 14:49:49 +02:00
Sebastien Deleuze 3c9049d530 Leverage Jetty BOM
Issue: SPR-17058
2018-07-18 14:49:49 +02:00
Juergen Hoeller 5fcfe0fa8e Polishing 2018-07-18 14:27:16 +02:00
Rossen Stoyanchev 6c4289e238 Polish 2018-07-17 17:39:16 -04:00
Juergen Hoeller ef9027e1c1 Polishing 2018-07-17 17:59:16 +02:00
Juergen Hoeller 955665b419 Consistent processing of binding/validation failures for data classes
Includes an extension of SmartValidator for candidate value validation, as well as nullability refinements in Validator and BindingResult.

Issue: SPR-16840
Issue: SPR-16841
Issue: SPR-16854
2018-07-17 17:01:34 +02:00
Rossen Stoyanchev a41a1edd93 Switch to TEMPLATE_AND_VALUES as the default mode
DefaultUriBuilderFactory now uses EncodingMode.TEMPLATE_AND_VALUES by
default. However the RestTemplate explicitly sets it to the previous
setting EncodingMode.URI_COMPONENTS, so this affects mainly the
WebClient and any direct use of DefaultUriBuilderFactory to configure
either the RestTemplate or the WebClient.

Issue: SPR-17039
2018-07-16 21:21:37 -04:00
Rossen Stoyanchev 2a0eac47f9 Add TEMPLATE_AND_VALUES mode to DefaultUriBuilderFactory
Issue: SPR-17039
2018-07-16 21:21:37 -04:00
Rossen Stoyanchev 75e45103b5 Polish DefaultUriBuilderFactory 2018-07-16 21:21:34 -04:00
Rossen Stoyanchev 5fb4982026 Support for encode() in UriComponentsBuilder
The ability to request to encode before `build()`, and more importantly
before expanding, allows stricter encoding to be applied to URI vars
and consequently to neutralize the effect of characters with reserved
meaning in a URI.

Issue: SPR-17039
2018-07-16 09:16:11 -04:00
Rossen Stoyanchev 24a30baa2a Typos in InMemoryWebSessionStore 2018-07-13 17:51:23 -04:00
Rossen Stoyanchev 43fbd63254 Add maxSessions, getSessions, removeExpiredSessions
This commit removes the session threshold check added recently which
is not effective since maxIdleTime is usually much longer than the
frequency of checks. The lazy triggering of expiration checks during
create or retreive are simple and the most effective

This commit also adds a maxSessions limit on the total number of
sessions that can be created at any one time, a getSessions method
for management purposes, and a removeExpiredSessions public API
for manual triggering of expiration checks.

Issue: SPR-17020, SPR-16713
2018-07-12 16:12:19 -04:00
Rossen Stoyanchev 32b75221b3 Improve expired session check algorithm
1. Add session count threshold as am extra pre-condition.
2. Check pre-conditions for expiration checks on every request.

Effectively an upper bound on how many sessions can be created before
expiration checks are performed.

Issue: SPR-17020
2018-07-11 15:59:18 -04:00
Rossen Stoyanchev e9ed45ee3b Fix code completion typo 2018-07-11 11:13:57 -04:00
Rossen Stoyanchev 7b3a72f483 Warn when SimpleAsyncTaskExecutor is used
Issue: SPR-16203
2018-07-11 11:10:03 -04:00
Rossen Stoyanchev 1b1bc7f5b5 Switch defaults and model for logging sensitive data
Issue: SPR-17029
2018-07-11 11:10:03 -04:00
Brian Clozel d00f6f09a5 Polish ContentCachingRequestWrapper
Issue: SPR-15762
2018-07-09 19:15:29 +02:00
zilong6 4d0800f392 Improve ContentCachingRequestWrapper performance
This commit improves the performance of `read` method variants
to write to the cache in an optimized way.

Issue: SPR-15762
2018-07-09 19:15:21 +02:00
Arjen Poutsma 2ac6a15f6f Add setBearerAuth method
Issue: SPR-16997
2018-07-09 17:06:55 +02:00
Arjen Poutsma a663454fad Changed Basic Authentication consumer to setBasicAuth method
This commit changes the Basic Authentication Consumer<HttpHeaders> to
a basic setBasicAuth(String, String) method.

Issue: SPR-16913
2018-07-09 16:41:51 +02:00
Rossen Stoyanchev 4bd22eeb13 Fallback logger for logging in http and codec packages
Issue: SPR-17012
2018-07-07 10:54:03 -04:00
Rossen Stoyanchev bca9f51092 Polish hint for suppressing logging at Encoder/Decoder 2018-07-06 20:32:08 -04:00
Rossen Stoyanchev 2874dd75ca Fine-tune WebFlux logging at HTTP/WebSocket level
1. Use special category prefix "spring-web.reactivestreams" for logging
of reactive streams signals in spring-web, since those are quite
verbose would fill the logs at TRACE.

2. Add and use loggers in request and websocket session implementations
separate from reactive streams bridge for regular TRACE logging.

3. Improve log messages and add where missing (e.g. for Reactor)

Issue: SPR-16898
2018-07-06 17:33:16 -04:00
Rossen Stoyanchev 7746878b50 Remove workaround for Reactor Netty #171 2018-07-06 15:44:24 -04:00
Rossen Stoyanchev bc3cf0eeb8 Expose request id at the ServerHttpRequest level
Hiding it (at AbstractServerHttpRequest) complicates matters since
requests are often mutated and decorated, plus it's also possible to
implement the interface directly (we've one, albeit corner case).

Issue: SPR-16966
2018-07-06 15:44:24 -04:00
Rossen Stoyanchev 5dc49b16ea Correlated messages at HTTP adapter + WebSocket level
Issue: SPR-16966
2018-07-06 15:44:18 -04:00
Rossen Stoyanchev bb3061d112 Polish 2018-07-05 14:08:05 -04:00
Violeta Georgieva 22f6e5b9ff Adapt ReactorHttpsServer to lates Reactor Netty changes 2018-07-05 14:00:01 -04:00
Rossen Stoyanchev 39d5874441 Use connection id in server log messages if possible
Issue: SPR-16966
2018-07-05 08:32:27 -04:00
Rossen Stoyanchev 5cdc26770e Correlated WebClient log messages
Issue: SPR-16966
2018-07-05 08:30:23 -04:00
Rossen Stoyanchev 82310660fd Correlated encoding/decoding log messages via hints
Issue: SPR-16966
2018-07-05 08:28:15 -04:00
Rossen Stoyanchev fd90b73748 Correlated WebFlux server log messages
Issue: SPR-16966
2018-07-05 08:27:13 -04:00
Juergen Hoeller 83faee67d5 HttpMessageNotReadableException provides access to HttpInputMessage
Issue: SPR-15588
2018-07-04 22:46:09 +02:00
Rossen Stoyanchev 43d6ceb6f0 Align settings for sameSite and secure flag
After this change sameSite still gets a default value of "Strict" in
CookieWebSessionIdResolver but for changes to either sameSite or secure
it is now expected to use
addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder>).

Issue: SPR-16418, SPR-16980
2018-07-03 12:44:29 -04:00
Juergen Hoeller 9efddea5e0 Upgrade to Apache Johnzon 1.1.8 and JCA 1.7.1 2018-07-03 15:53:49 +02:00
Juergen Hoeller e485abbe56 Fix checkstyle violation (plus related polishing)
Issue: SPR-16913
2018-07-02 23:56:58 +02:00
Juergen Hoeller d08b72a75a Consistent throwing of HttpMessageNotReadableException vs IOException
Includes specific fine-tuning of ProtobufHttpMessageConverter and JAXB2 based message converters, as well as revised javadoc for abstract base classes.

Issue: SPR-16995
2018-07-02 22:37:29 +02:00
Arjen Poutsma 6bcf6ffb06 Add Basic Authentication Consumer
Issue: SPR-16913
2018-07-02 15:16:03 +02:00
Juergen Hoeller 4ff1e3e74b Consistent abstract declaration for utility classes (plus polishing)
Issue: SPR-16968
2018-07-01 02:31:20 +02:00
Rossen Stoyanchev e72f4ec501 Fix checkstyle error 2018-06-29 21:45:43 -04:00
Rossen Stoyanchev d74e09a925 Polish MockClientHttpRequest 2018-06-29 17:37:45 -04:00
Rossen Stoyanchev 7f555785dd Add getBodyAsString() to MockClientHttpRequest
Issue: SPR-16988
2018-06-29 17:34:23 -04:00
Rossen Stoyanchev 51ec7c6b4a Add hook for customizing response cookie
Issue: SPR-16980
2018-06-29 18:15:52 -03:00
Rossen Stoyanchev 5ec8db1adc Polish CookieWebSessionIdResolver 2018-06-29 18:15:52 -03:00
Rossen Stoyanchev 907a306ee2 Fix locally failing test in FlushingIntegrationTests 2018-06-29 18:15:52 -03:00
Damiano Albani 3165b3c024 Fix typo in Java doc 2018-06-29 18:12:43 -03:00
Juergen Hoeller e22466e9d5 Polishing 2018-06-29 19:44:15 +02:00
Juergen Hoeller d34e6f7f70 Polishing 2018-06-28 18:02:07 +02:00
Juergen Hoeller 40efcc933c Polishing 2018-06-28 14:51:33 +02:00
Juergen Hoeller bac68c8d3f StandardServletMultipartResolver accepts any HTTP method for multipart
Issue: SPR-16975
2018-06-28 14:15:16 +02:00
Phillip Webb a89e716cc7 Use tabs rather than spaces in tests
Update tests to ensure that tabs are used instead of spaces. Also
consistently apply a new line at the end of each file.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 1c25cec44f Polish test code
Polish a few issue identified when adding checkstyle to the
build. Although checkstyle is not enforcing rules on tests,
these are a few minor changes that are still worth making.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 81451aa800 Organize imports
Reorganize imports to ensure consistent ordering. This commit also
expands any `.*` static imports in favor of using fully-qualified
method references.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 5cedd0d5d4 Consistently use tabs rather than spaces
Update code that has accidentally used spaces instead of tabs.
Also remove all trailing whitespace.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 9de3689f63 Never use 'this.' when accessing loggers
Ensure that `this.` is never used when accessing loggers.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 0b53c1096a Always use 'this.' when accessing fields
Ensure that `this.` is used consistently when accessing class
fields.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb eeebd51f57 Use consistent class design
Update all classes so that inner classes are always last. Also
ensure that utility classes are always final and have a private
constructor and make exceptions final whenever possible.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 0ad0f341bd Don't use single letter catch variables
Update existing catch blocks to ensure that `ex` is always used
in preference to `e` or `t` as the variable name.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 866e9d702e Use consistent block style
Update all code to use a consistent block style.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 04a8c285df Fix annotation styling issues
Update all annotations so that each is on its own line and
consistently use the short form (i.e. don't use `value=`) when
possible.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb e9d1b39aff Apply consistent copyright header
Add copyright header to `package-info.java` files and fix a few
malformed headers on existing java files.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb c3a17dfd47 Ensure all files end with a newline
Update all files to ensure that they always end with a new line.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb e0480f75ac Fix javadoc checkstyle issues
Fix checkstyle violations for javadoc.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Rossen Stoyanchev 7ccd2b024d Refine logging for async requests
Issue: SPR-16898
2018-06-25 14:42:29 -03:00
Juergen Hoeller 2a15962d7f WebHttpHandlerBuilder retains ApplicationContext in copy constructor
Issue: SPR-16972
2018-06-25 18:12:12 +02:00
Rossen Stoyanchev 900bc8a2e3 Logging improvements for WebFlux
Issue: SPR-16898
2018-06-22 22:44:24 -04:00
Juergen Hoeller eaffcbe3be Upgrade to Gradle 4.8.1
Includes Kotlin 1.2.50, RxJava 2.1.15 and Protobuf 3.6.

Issue: SPR-16475
2018-06-22 22:49:12 +02:00
Brian Clozel 4a26f93a0d WebClient writes Content-Length for Mono bodies
In SPR-16892, the `EncoderHttpMessageWriter` has been improved to write
`"Content-Length"` HTTP response headers if the response body is of type
`Mono` (i.e. the actual content length is easily accessible without
buffering a possibly large response body). That change was relying on
the fact that the server side is using a `ChannelSendOperator` to delay
the writing of the body until the first signal is received.

This strategy is not effective on the client side, since no such channel
operator is used for `WebClient`. This commit improves
`EncoderHttpMessageWriter` and delays, for `Mono` HTTP message bodies
only, the writing of the body so that we can write the
`"Content-Length"` header information once we've got the body resolved.

Issue: SPR-16949
2018-06-19 11:51:45 +02:00
Rossen Stoyanchev 28a5c3009e Improve DEBUG/TRACE logging for Spring MVC
Issue: SPR-16898
2018-06-18 18:33:11 -04:00
Juergen Hoeller 003d643adc Consistent support for new JsonMappingException wording in Jackson 2.9
Issue: SPR-16947
2018-06-17 21:42:20 +02:00
Mark Chesney e4666c17ec Support new exception message wording since Jackson 2.9
The wording changed from "Can not find" to "Cannot find" via PR #1682

Issues: SPR-16947
2018-06-17 13:27:20 +02:00
Rossen Stoyanchev ebdcc015a4 Correctly set maxAge and expires in ResponseCookie
Issue: SPR-16940
2018-06-14 13:07:17 -04:00
Brian Clozel 09d9450154 Add SameSite support in WebFlux SESSION cookies
This commit adds support for the "SameSite" attribute in response
cookies. As explained in rfc6265bis, this attribute can be used to limit
the scope of a cookie so that it can't be attached to a request unless
it is sent from the "same-site".

This feature is currently supported by Google Chrome and Firefox, other
browsers will ignore this attribute.

This feature can help prevent CSRF attacks; this is why this commit adds
this attribute by default for SESSION Cookies in WebFlux.

See: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis

Issue: SPR-16418
2018-06-14 11:39:03 +02:00
Juergen Hoeller 1e5f8cc232 FilePart and MultipartFile provide transferTo(Path) variant
Also, ZeroCopyHttpOutputMessage provides writeWith(Path, int, int), enforcing that variant as the implementation target in 5.1 (analogous to FilePart).

Issue: SPR-16925
2018-06-14 00:42:36 +02:00
Rossen Stoyanchev 0b61c748f6 Protected methods for serializing form content
Issue: SPR-16855
2018-06-13 17:14:49 -04:00
Rossen Stoyanchev 278881b8df Polish form writer and converter 2018-06-13 17:05:34 -04:00
Juergen Hoeller 0dc434b35e Polishing 2018-06-13 22:04:10 +02:00
Juergen Hoeller 3fc8ec498c MockHttpServletRequest returns a single InputStream or Reader
Issue: SPR-16505
Issue: SPR-16499
2018-06-13 22:03:16 +02:00
Juergen Hoeller 0b64bcd319 Remove outdated Servlet environment constraints from annotation javadoc
Issue: SPR-16936
2018-06-12 11:28:13 +02:00
Allon Mureinik 2573a543b2 SPR-16936 Fix PathVariable javadoc
@PathVariable's javadoc states that it supports MultiValueMap
parameters (introduced by commit df0902), but by reading through the
code, that does not seem to be the case (compare, e.g.,
PathVariableMapMethodArgumentResolver to
RequestParamMapMethodArgumentResolver).

Moreover, parsing MultipleValueMap is done according to the ";"
character, and placing such a character in a path (e.g., consider
something like "/app/{param}/show" would just break the path.

This patch fixes PathVariable's javadoc by removing the mention of
MultiValueMap.
2018-06-12 11:12:57 +02:00
Brian Clozel 05ff8b722d Fix ResourceRegion HttpMessageConverter write checks
This commit fixes the write checks for
`ResourceRegionHttpMessageConverter`, which was previously not checking
properly the parameterized type (e.g. in case of a `List<Something>`).

Issue: SPR-16932
2018-06-11 22:53:55 +02:00
Juergen Hoeller 9c36b53833 Upgrade to JAXB 2.3.0.1, Aalto XML 1.1, Rome 1.10 2018-06-11 22:01:51 +02:00
Brian Clozel a5cd01a4c8 Restrict HTTP methods on Reactive HiddenHttpMethodFilter
This commit restricts the allowed HTTP methods on HiddenHttpMethodFilter
(Reactive variant) to the following: PUT, DELETE, PATCH.

This filter is meant to be used to simulate those methods from HTML
forms sent by browsers, so no other methods are allowed.

Issue: SPR-16836
2018-06-11 18:53:23 +02:00
Brian Clozel f64fa3dea1 Restrict HTTP methods on Servlet HiddenHttpMethodFilter
This commit restricts the allowed HTTP methods on HiddenHttpMethodFilter
(Servlet variant) to the following: PUT, DELETE, PATCH.

This filter is meant to be used to simulate those methods from HTML
forms sent by browsers, so no other methods are allowed.

Issue: SPR-16836
2018-06-11 18:53:23 +02:00
Brian Clozel 417354da8a Remove dependency management noise from POMs
Prior to this commit, the generated POMs for Spring Framework modules
would contain unneeded/harmful information from the Spring Framework
build:

1. The BOM imports applied to each module by the dependency
management plugin, for example for Netty or Reactor Netty.
Spring should not export that opinion to its POMs.

2. The exclusion of "org.slf4:jcl-over-slf4j" from *all* dependencies,
which made the POMs much larger than necessary and suggested to
developers that they should exclude it as well when using all those
listed dependencies. In fact, only Apache Tiles currently brings that
transitively.

This commit removes that information from the POMs.
The dependencyManagement Gradle plugin is disabled for POM generation
and we manually resolve the dependency versions during the generation
phase.
The Gradle build is streamlined to exclude "org.slf4:jcl-over-slf4j"
only when necessary.

Issue: SPR-16893
2018-06-11 15:57:54 +02:00
Rossen Stoyanchev 86c861516d Accept Predicate instead of HandlerTypePredicate
Issue: SPR-16336
2018-06-08 15:32:07 -04:00