Commit Graph

671 Commits

Author SHA1 Message Date
Rossen Stoyanchev 78f3a3cb11 Update javadoc for MultipartFile.transferTo
Issue: SPR-12650
2015-02-02 17:29:39 -05:00
Rossen Stoyanchev fd426aaa4d Update Netty4ClientHttpRequestFactory buffer size
Before this change, the maxRequestSize property was used (incorrectly)
to limit both the size of the request and response. The change:

- removes maxRequestSize and therefore no longer places limits on the
size of the request thus matching to AbstractBufferingClientHttpRequest
which is the base class for other buffering client implementations.

- adds maxResponseSize property required to create Netty's
HttpObjectAggregator for aggregating responses.

Issue: SPR-12623
2015-02-02 15:50:22 -05:00
Rossen Stoyanchev a32b5e61d0 Add support for Server-Sent Events
This commit adds ResponseBodyEmitter and SseEmitter (and also
ResponseEntity<ResponseBodyEmitter> and ResponseEntity<SseEmitter>) as
new return value types supported on @RequestMapping controller methods.

See Javadoc on respective types for more details.

Issue: SPR-12212
2015-01-29 17:55:09 -05:00
Sebastien Deleuze ccb1c13951 Use UTC timezone in Jackson builder and factory tests
Issue: SPR-12634
2015-01-26 15:59:15 +01:00
Brian Clozel cf86ecddb5 Avoid loss of body content in AbstractRequestLoggingFilter
Prior to this commit, the `ContentCachingRequestWrapper` class would
cache the response content only if the reponse would be consumed using
its InputStream. In case of a Form request, Spring MVC consumes the
response using the `getParameter*` Servlet API methods. This causes the
cached content to never be written.

This commit makes the `ContentCachingResponseWrapper` write the request
body to the cache buffer by using the `getParameter*` API, thus avoiding
those issues.

Issue: SPR-7913
2015-01-26 11:41:34 +01:00
Sebastien Deleuze 5fb6d6d89c Allow Jackson builder modules configuration to be customized
Modules (well-known or user provided) registration is now performed
first in order to allow their configuration to be customized by more
specific ones like custom serializers or deserializers.

Issue: SPR-12634
2015-01-26 11:08:08 +01:00
Juergen Hoeller d4dac250a8 AbstractRequestLoggingFilter allows for dedicated shouldLog check in CommonsRequestLoggingFilter
Issue: SPR-12609
2015-01-20 16:01:53 +01:00
Sebastien Deleuze bf7a9754d5 Avoid using Java 8 ZoneId class
Issue: SPR-12594
2015-01-20 15:24:55 +01:00
Sebastien Deleuze b89e62e5f6 Support specifying Jackson TimeZone and Locale
Issue: SPR-12594
2015-01-20 14:57:14 +01:00
Sam Brannen c50df0c420 Polish MessageBodyClientHttpResponseWrapper
Added missing copyright clause and fixed @since version.
2015-01-08 18:02:00 +01:00
Brian Clozel b6675b6167 Revisit empty body response support in HTTP client
Prior to this commit, HTTP responses without body (response status 204
or 304, Content-Length: 0) were handled properly by RestTemplates. But
some other cases were not properly managed, throwing exceptions for
valid HTTP responses.

This commit better handles HTTP responses, using a response wrapper that
can tell if a response:

* has no message body (HTTP status 1XX, 204, 304 or Content-Length:0)
* has an empty message body

This covers rfc7230 Section 3.3.3.

Issue: SPR-8016
2015-01-08 17:34:39 +01:00
Craig Andrews 213a3fd779 Performance improvements in ShallowEtagHeaderFilter
Prior to this change, the ShallowEtagHeaderFilter would use a
ResizableByteArrayOutputStream to internally write data and calculate
the ETag. While that implementation is faster than the regular
ByteArrayOutputStream (since it has a better strategy for growing the
internal buffer), a lot of buffer copying/writing still happens.

This change adds a new FastByteArrayOutputStream implementation that
internally uses a LinkedList<Byte[]> to store the content. So when
writing bytes to that OutputStream implementation, new byte[] are
added to the list when the previous ones are full. This saves most
of the instantiating/copying operations.

Note that new methods were added in DigestUtils to allow usage of
Streams instead of byte[], which is more efficient in our case.

Fixes #653

Issue: SPR-12081
2015-01-08 16:08:09 +01:00
Stephane Nicoll bce145c06e Merged HttpClient defaults with local customizations
Update HttpComponents wrapper to merge local customizations with the
default of the current HttpClient instead of overriding everything.

This is available as from HttpComponents 4.4. that exposes the default
request config from the  client via the Configurable interface. If the
client does not implement such interface, the previous behaviour is
applied

Issue: SPR-12583
2015-01-05 14:28:47 +01:00
Brian Clozel e02719e5e3 Fix path mapping issue in default servlet mode
Prior to this commit, some requests would be wrongly mapped to "/" when:

* requests ends with "//" such as "/foo/bar//"
* the DispatcherServlet is mapped as the default ("/")
* the app container sanitizes the servletPath

In those cases, the path extraction algorithm was wrongly guessing the
path of the current request.

This commit detects if the app container sanitized the servletPath for
the current request. If so, it uses a sanitized version of the
requestUri to extract the path information.

Issue: SPR-12372
2014-12-31 14:08:49 +01:00
Sam Brannen 40449e2741 Suppress warnings in tests
This commit suppresses warnings in test classes that were polluting the
Gradle build output.
2014-12-31 02:10:30 +01:00
Juergen Hoeller 9ac02b319d Remove pre-3.2 deprecated classes and methods
Issue: SPR-12578
2014-12-30 20:05:15 +01:00
Juergen Hoeller fad76336f6 Polishing 2014-12-30 15:26:43 +01:00
Juergen Hoeller 730bd02da7 Polishing 2014-12-30 15:01:51 +01:00
Juergen Hoeller 86b8112c90 Polishing 2014-12-29 15:13:40 +01:00
Stephane Nicoll 71783c5d86 Allow default settings of a custom HttpClient to apply
Previously the default settings of a custom HttpClient were always
ignored since a RequestConfig instance was always set no matter if
some customizations were applied or not.

This commit keeps an internal RequestConfig object instance that is
only initialized if the user applies a customization. If he does not, the
default settings of the HttpClient are used as it should.

Note that if the HttpComponents API exposed the default RequestConfig
of a given HttpClient, we would be able to merge our customizations with
the one specified by the client. Unfortunately, such API does not exist
and the "defaultSettingsOfHttpClientLostOnExecutorCustomization" test
illustrates that limitation.

Issue: SPR-12540
2014-12-29 09:36:54 +01:00
Rossen Stoyanchev ea05e0b1ad Improve @SessionAttributes support during redirect
Before this change attributes listed with @SessionAttributes would not
be saved in the session when there was a redirect and the controller
method declared a parameter of type RedirectAttributes.

This change ensures it's the "default" model that is always the one
checked for @SessionAttributes under all circumstances since
RedirectAttributes is really only meant to provide String values to
insert into or append to the the redirect URL.

Issue: SPR-12542
2014-12-23 14:24:44 -05:00
Rossen Stoyanchev ea2943feca Polish ModelAndViewContainer and update tests 2014-12-23 14:24:43 -05:00
Juergen Hoeller c114c08922 Preparations for Jackson 2.5
Issue: SPR-12565
2014-12-22 18:46:57 +01:00
Stephane Nicoll aafdcecf53 Customize connection request timeout
Prior to this commit it was not possible to easily customize the
connection request timeout used by the HttpClient. Both
`HttpComponentsClientHttpRequestFactory` and
`HttpComponentsClientHttpRequestFactoryTests` have been updated to
support a `connectionRequestTimeout` property.

Issue: SPR-12166
2014-12-22 16:31:07 +01:00
Stephane Nicoll 24b82746b5 Polish upgrade to HttpComponents 4.3
Polish fbe605123 to make explicit the fact that a null RequestConfig
can be used to force the defaults of the current HttpClient.

Issue: SPR-11113
2014-12-22 14:31:24 +01:00
Stephane Nicoll fbe6051233 Upgrade HttpComponentsHIRE to HttpComponents 4.3
Previously, HttpComponentsHttpInvokerRequestExecutor was not compatible
with the new API of HttpComponents 4.3. Specifically, it is not possible
to update the socket and read timeouts on the HttpClient itself anymore.

We actually already updated HttpComponentsClientHttpRequestFactory for a
similar problem in SPR-11442: if we detect an older HttpClient
implementation, we update the timeout directly on the client. If that's
not the case, we keep the value in the factory itself and use it when a
new HttpRequest needs to be created.

This commit also uses the new API to create a default HttpClient and
therefore requires HttpComponents 4.3. As mentioned above, it is still
possible to use deprecated HttpClient instances against this executor.

Issue: SPR-11113
2014-12-22 11:02:32 +01:00
Rossen Stoyanchev 0524a82c09 Update unprocessableEntity to allow body
Issue: SPR-12515
2014-12-08 16:19:52 -05:00
Juergen Hoeller 1daa5eb383 ResponseEntity provides static "unprocessableEntity()" convenience method as well
Issue: SPR-12515
2014-12-07 15:34:39 +01:00
Rossen Stoyanchev 189ec75789 Add ability to clone to UriComponentsBuilder hierarchy
Issue: SPR-12494
2014-12-05 12:16:15 -05:00
Sebastien Deleuze 2fccf3ff44 Add support for autowiring Jackson handlers
This commit introduces the SpringHandlerInstantiator
class, a Jackson HandlerInstantiator that allows to autowire
Jackson handlers (JsonSerializer, JsonDeserializer, KeyDeserializer,
TypeResolverBuilder and TypeIdResolver) if needed.

SpringHandlerInstantiator is automatically used with
@EnableWebMvc and <mvc:annotation-driven />.

Issue: SPR-10768
2014-12-05 17:37:28 +01:00
Juergen Hoeller d1f8968595 ControllerAdvice basePackages specifically refer to actual packages (avoiding accidental prefix matches with other packages)
Issue: SPR-12509
2014-12-05 13:25:48 +01:00
Brian Clozel 98870251f9 Better empty response body support in RestTemplate
Prior to this change, RestTemplate returned an empty response body if:

* HTTP return status 204 or 304
* Content-length header equals 0

This change adds a new condition for this, better supporting RFC7230
section 3.4, for connections that are closed without response body:

* No Content-length header
* No Transfer-encoding: chunked header value
* a Connection: close header value

See SPR-7911 for previous efforts in that space.

Issue: SPR-8016
2014-12-05 09:57:41 +01:00
Brian Clozel b2878a4f60 Merge pull request #704 from aantono/master
Fixed the output stream incomplete data by explicitly flushing the OutputStreamWriter
2014-12-05 09:51:55 +01:00
Alex Antonov bf8d99d7e4 Fixed the output stream incomplete data by explicitly flushing the OutputStreamWriter 2014-12-04 16:46:15 -06:00
Juergen Hoeller 4013fe03a5 Revised ControllerAdvice basePackages handling (based on package names instead of java.lang.Package)
Issue: SPR-12506
2014-12-04 17:56:01 +01:00
Alex Antonov b041cffe5d Fix for NPE when creating ProtobufHttpMessageConverter without ExtensionRegistryInitializer 2014-12-03 12:26:18 -06:00
Sebastien Deleuze fbd85925de Use Jackson improved default configuration everywhere
With this commit, Jackson builder is now used in spring-websocket
to create the ObjectMapper instance.

It is not possible to use the builder for spring-messaging
and spring-jms since these modules don't have a dependency on
spring-web, thus they now just customize the same features:
 - MapperFeature#DEFAULT_VIEW_INCLUSION is disabled
 - DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES is disabled

Issue: SPR-12293
2014-12-03 09:49:41 +01:00
Roy Clarkson 83ecf5ca1d Fix issue where FormHttpMessageConverter fails to write multipart data
FormHttpMessageConverter incorrectly determines that the media type
"multipart/form-data; charset=utf-8" is not multipart. This commit
allows the media type to contain a charset parameter.
2014-12-02 16:06:49 -05:00
Juergen Hoeller 2496d68e9f Relaxed final declarations and protected doInvoke methods
Issue: SPR-12484
2014-12-01 15:07:24 +01:00
Juergen Hoeller decc5cd1ae Extracted ContentCachingRequestWrapper and ContentCachingResponseWrapper
Issue: SPR-12477
2014-11-28 17:17:02 +01:00
Juergen Hoeller a6e7044523 Correct since declarations in Netty 4 client support 2014-11-26 11:29:58 +01:00
Juergen Hoeller 929cda6790 Allow custom @Validated annotations for handler method parameters
Issue: SPR-12406
2014-11-24 23:34:24 +01:00
Juergen Hoeller aadb93f30c Rearranged WebAsyncTask constructor interdependencies and assertions
Issue: SPR-12457
2014-11-22 18:02:12 +01:00
Juergen Hoeller 05bdc2cf77 Consistent declaration and use of UTF-8 Charset constants, plus related polishing 2014-11-11 02:38:30 +01:00
Rossen Stoyanchev 53eec48ffd Fix HttpUrlConnection DELETE without body
The following commit allowed HTTP DELETE with body:
584b831bb9

However it broke buffered requests even without a body since JDK 1.6
and 1.7 do not support calls to getOutputStream with HTTP DELETE.

This commit set the doOutput flag back to false if the actual buffered
body is 0 length.

Issue: SPR-12361
2014-11-10 14:20:59 -05:00
Juergen Hoeller bf9295bec3 ShallowEtagHeaderFilter skips "Cache-Control" header check on Servlet 2.5
Issue: SPR-12414
2014-11-06 22:48:08 +01:00
Rossen Stoyanchev d8941ca098 Normalize 2+ '/' in path in UriComponentsBuilder
Issue: SPR-12398
2014-10-30 14:51:04 -04:00
Juergen Hoeller 1146d5ba1d Polishing 2014-10-29 22:44:59 +01:00
Rossen Stoyanchev 584b831bb9 Allow HTTP delete with request entity
Issue: SPR-12361
2014-10-27 16:48:59 -04:00
Rossen Stoyanchev 083dece106 Polish netty client support
Mostly updates based on:
https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Code-Style
2014-10-27 14:12:53 -04:00
Arjen Poutsma 7de0a70f0c Netty support for (Async)RestTemplate
This commit introduces an AsyncClientHttpRequestFactory based on Netty
4, for use with the (Async)RestTemplate.
2014-10-27 13:57:37 -04:00
Sam Brannen 6463878f2d Polish Javadoc for @RequestMapping 2014-10-24 14:59:58 +02:00
Brian Clozel a0c210457b Use response encoding when escaping HTML
With SPR-9293, it is now possible to HTML escape text while taking into
account the current response encoding. When using UTF-* encodings, only
XML markup significant characters are escaped, since UTF-* natively
support those characters.

This commit adds a new servlet context parameter to enable this fix by
default in a Spring MVC application:

    <context-param>
      <param-name>responseEncodedHtmlEscape</param-name>
      <param-value>true</param-value>
    </context-param>

Issue: SPR-12350, SPR-12132
2014-10-24 11:53:47 +02:00
Rossen Stoyanchev d5eb669416 Add mention of java.util.Optional in @MVC
Issue: SPR-12370
2014-10-23 16:53:00 -04:00
Craig Andrews d5bf6713ed Add author attribution for htmlEscape methods
Issue: SPR-9293
2014-10-23 11:29:32 -07:00
Juergen Hoeller 2035b17925 Polishing 2014-10-23 17:24:00 +02:00
Sebastien Deleuze 1c217aae40 Support text/xml and application/*+xml in Jackson XML message converter
Issue: SPR-12366
2014-10-23 16:48:11 +02:00
Rossen Stoyanchev 051c5fb66a Update javadoc 2014-10-22 22:28:21 -04:00
Rossen Stoyanchev df090235bb Update documentation for Map arguments
Issue: SPR-12347
2014-10-22 22:17:51 -04:00
Brian Clozel a011b360d1 Polish SPR-12286
Issue: SPR-12286
2014-10-22 21:15:34 +02:00
Brian Clozel 86d97baf65 Allow defining default content negotiation strategy
During the HTTP Content Negotiation phase, the ContentNegotiationManager
uses configured ContentNegotiationStrategy(ies) to define the list of
content types accepted by the client.

When HTTP clients don't send Accept headers, nor use a configured
file extension in the request, nor a request param, developers can
define a default content type using the
ContentNegotiationConfigurer.defaultContentType() method.

This change adds a new overloaded defaultContentType method that takes a
ContentNegotiationStrategy as an argument. This strategy will take the
current request as an argument and return a default content type.

Issue: SPR-12286
2014-10-22 16:32:12 +02:00
Juergen Hoeller 3106905877 Polishing 2014-10-22 01:19:14 +02:00
Brian Clozel 369cabf064 Conditionally htmlEscape chars based on encoding
This commit adds new htmlEscape methods that take the character encoding
as a parameter. According to specs and recommendations, the list of
chars to be html escaped depends on the encoding used in the response.
If the current char encoding supports chars natively, we shouldn't
escape those; of course, reserved chars (<,>,',",&) should always be
escaped.

See: http://www.w3.org/TR/html4/sgml/entities.html#h-24.3
See: spring-projects/spring-framework#385 by @candrews

Issue: SPR-9293
2014-10-21 17:49:37 +02:00
Sam Brannen 66069333f1 Fix JUnit imports in SourceHttpMessageConverterTests
When org.junit.Assert.* is statically imported, the class does not
compile in Eclipse/STS since XMLAssert extends junit.framework.Assert.
2014-10-21 16:18:23 +02:00
Juergen Hoeller 8325b10080 Consistent formatting of license headers, package javadocs, and import declarations 2014-10-21 01:44:07 +02:00
Rossen Stoyanchev 956b66bbd4 Fix issue with async return value type determination
Before this change, the type of asynchronously produced return values
(e.g. Callable, DeferredResult, ListenableFuture) could not be
properly determined with an actual resulting value of null. Or even
with an actual value returned, the generic type could not be properly
determined. This change fixes both of those issues.

Issue: SPR-12287
2014-10-15 16:39:03 -04:00
Juergen Hoeller c7e7d11156 Polishing 2014-10-14 14:27:03 +02:00
Juergen Hoeller d501137f4e Consistently accept empty Content-Type header and empty character encoding
Issue: SPR-12173
2014-10-14 14:26:07 +02:00
Juergen Hoeller 0fb8f0b469 Polishing 2014-10-13 17:58:15 +02:00
Juergen Hoeller 8760be7d64 ResponseEntity's HeadersBuilder allows for specifying existing HttpHeaders
Issue: SPR-12324
2014-10-13 17:22:27 +02:00
Brian Clozel 0a68d265fb Polish indentation 2014-10-08 17:02:26 +02:00
Sebastien Deleuze f518ad9009 Add (de)serializerByType() and mixIn() to Jackson2ObjectMapperBuilder
Issue: SPR-12313
2014-10-08 10:57:29 +02:00
Tadaya Tsuyukubo 25bb58a1e8 Add shortcuts for Jackson mix-in annotations registration
This commit adds support for direct Jackson mix-in annotations registration in
Jackson2ObjectMapperFactoryBean and Jackson2ObjectMapperBuilder.

Issue: SPR-12144
2014-10-07 18:07:00 +02:00
Juergen Hoeller 20a8416c2e Jackson2ObjectMapperBuilder allows for regular constructor usage as well
Issue: SPR-12243
2014-10-01 02:29:46 +02:00
Juergen Hoeller 3a3c52dbdd Polishing 2014-10-01 01:10:25 +02:00
Juergen Hoeller d778037f40 Jackson2ObjectMapperFactoryBean builds on revised Jackson2ObjectMapperBuilder now
Issue: SPR-12243
2014-10-01 01:04:16 +02:00
Juergen Hoeller 69998e3d50 Remove outdated references to ContextLoaderServlet
Issue: SPR-7725
(cherry picked from commit b45d08f)
2014-10-01 01:02:56 +02:00
Sam Brannen 62fc39cca1 Suppress warnings in MappingJackson2XmlHttpMessageConverterTests 2014-09-30 16:58:47 +02:00
Sebastien Deleuze 77abe07807 Set Jackson DEFAULT_VIEW_INCLUSION property to false by default
Issue: SPR-12179
2014-09-30 05:18:15 +02:00
Sebastien Deleuze 42aef5f5dc Set Jackson FAIL_ON_UNKNOWN_PROPERTIES property to false by default
Issue: SPR-11891
2014-09-30 05:18:15 +02:00
Sebastien Deleuze 4e24d66ff7 Create a builder for Jackson ObjectMapper
Jackson2ObjectMapperBuilder now allows to create ObjectMapper and XmlMapper
instances easily thanks to its fluent API.

This builder is used in Jackson message converters and views to instantiate default
ObjectMapper and XmlMapper.

This commit also add a createXmlMapper property to
Jackson2ObjectMapperFactoryBean in order to allow to create easily a XmlMapper
instance.

Issue: SPR-12243
2014-09-30 05:18:15 +02:00
Juergen Hoeller 7bc8e5199e Polishing 2014-09-29 23:50:23 +02:00
Juergen Hoeller 7f43f02a13 FormHttpMessageConverter uses a delegate class for JavaMail-based MIME encoding (isolating the JavaMail API dependency)
Issue: SPR-12108
2014-09-29 22:35:13 +02:00
Juergen Hoeller bf99d6a3b5 WebAsyncManager avoids concurrentResult.toString() and builds correct DeferredResultProcessingInterceptor keys
Issue: SPR-12253
2014-09-26 14:15:21 +02:00
Sam Brannen 24d09a3b8d Fix Javadoc link to DEFAULT_NONE in @RequestMapping 2014-09-26 12:56:25 +02:00
Rossen Stoyanchev 2a64834a44 Fix test dependency 2014-09-26 00:03:46 -04:00
Rossen Stoyanchev 9be0cf21e5 Support writing multipart non-ASCII file names
Issue: SPR-12108
2014-09-25 18:00:55 -04:00
Rossen Stoyanchev 6cbe1433e2 Polish FormHttpMessageConverter 2014-09-25 16:32:01 -04:00
Juergen Hoeller 1f3e195dac Polishing 2014-09-25 17:00:45 +02:00
Juergen Hoeller cfc821d179 DataBinder unwraps Optional objects and allows for proper handling of Optional.empty()
Issue: SPR-12241
2014-09-25 17:00:36 +02:00
Brian Clozel 26326fb40b Mention DEFAULT_NONE in @RequestMapping's Javadoc
This change mentions `ValueConstants.DEFAULT_NONE` in @RequestMapping's
Javadoc, in order to explain the default value.

Issue: SPR-9967
2014-09-22 18:38:19 +02:00
Brian Clozel b9348bb89c Fix Protobuf support - HTTP headers already written
Prior to this commit, the `ProtobufHttpMessageConverter` would call
`outputMessage.getBody()` at the beginning of the `writeInternal`
method, thus writing HTTP headers. Since this method is trying to write
"x-protobuf" headers after that, protobuf support wasn't working
properly for the default "x-protobuf" media type.

Thanks Toshiaki Maki for the repro project!

Also fixed:
* improve `MockHttpOutputMessage` behavior to reproduce the read-only
state of HTTP headers once they've been written.

Issue: SPR-12229
2014-09-22 14:02:35 +02:00
Sebastien Deleuze 2989fe4203 Support Jackson based XML serialization in RestTemplate
Issue: SPR-12225
2014-09-22 01:10:21 +02:00
Sam Brannen 4aa97f8945 Remove references to CommonsHttpInvokerRequestExecutor 2014-09-21 19:53:54 +02:00
Phillip Webb 2667956a30 Initialize JNDI to fix failing Environment test
Issue: SPR-12223
2014-09-20 09:01:16 -07:00
Juergen Hoeller a833889c2a Polishing 2014-09-17 21:55:46 +02:00
Juergen Hoeller 15320db414 Polishing 2014-09-17 02:35:41 +02:00
Juergen Hoeller f394c8aa2a Polishing
Issue: SPR-12196
2014-09-16 15:03:21 +02:00
Juergen Hoeller 26a93b6a33 Client request implementations enforce RFC 6265 (cookies in a single header)
Issue: SPR-12196
2014-09-16 15:02:21 +02:00
Juergen Hoeller 70412a9d0a Accept empty Content-Type header
Issue: SPR-12173
2014-09-12 16:44:56 +02:00