Commit Graph

258 Commits

Author SHA1 Message Date
Juergen Hoeller
be2c2e9a86 Backported "Support opaque URIs in UriComponentsBuilder"
Issue: SPR-9798
Issue: SPR-9804
2012-10-10 23:33:50 +02:00
Rossen Stoyanchev
470c85ade0 Update MediaType's includes method
An additional update (after the last commit) of the "includes" and
"isCompatibleWith" methods of MediaType to accomodate wildcards
in media types with a suffix.

Issue: SPR-9841
2012-10-06 11:07:47 -04:00
Rossen Stoyanchev
01d8d64200 Recognize wildcards in media types with a suffix
The "includes" and "isCompatibleWith" methods of MediaType take into
account media types with suffices (e.g. application/soap+xml) including
wildcards with suffices (e.g. application/*+xml). However before this
change, the isWildcardSubtype() method returned true only for subtype
"*". Now a media type such as application/*+xml is also recognized as
having a wildcard subtype.

Issue: SPR-9841
2012-10-06 10:20:14 -04:00
Rossen Stoyanchev
229537288a Backport fixes in HandlerMethod and sub-classes
Issue: SPR-9747, SPR-9748, SPR-9218, SPR-8946, SPR-9159
Backport Issue: SPR-9622
2012-09-10 15:01:41 -04:00
Juergen Hoeller
8b09b52720 media types in HTTP Accept headers can be parsed with single quotes (-> Android 2.x)
Issue: SPR-9734
2012-08-31 17:03:28 +02:00
Rossen Stoyanchev
e8deba2915 Fix issue with encoded params in UriComponentsBuilder
The fromUri method of UriComponentsBuilder used uri.getXxx() methods,
which decode the URI parts causing URI parsing issues. The same method
now uses uri.getRawXxx().

Issue: SPR-9317
Backport-Issue: SPR-9549
Backport-Commit: a33fe6fa0a
2012-06-27 10:51:45 -04:00
Rossen Stoyanchev
24c30eac49 Raise RestClientException for unknown status codes
HttpStatus cannot be created with an unknown status code. If a server
returns a status code that's not in the HttpStatus enum values, an
IllegalArgumentException is raised. Rather than allowing it to
propagate as such, this change ensures the actual exception raised is
a RestClientException.

Issue: SPR-9406
Backport-Issue: SPR-9502
2012-06-26 17:56:31 -04:00
Rossen Stoyanchev
9e370208d0 Fix content negotiation issue with sort by q-value
Before this fix the q-value of media types in the Accept header were
ignored when using the new RequestMappingHandlerAdapter in combination
with @ResponseBody and HttpMessageConverters.

Issue: SPR-9160
Backport-Issue: SPR-9168
Backport-Commit: 982cb2f258
2012-06-26 17:28:52 -04:00
Rossen Stoyanchev
c9a2dbdbfd Add Jackson 2 HttpMessageConverter and View
Jackson 2 uses completely new package names and new maven artifact ids.
This change adds Jackson 2 as an optional dependency and also provides
MappingJackson2HttpMessageConverter and MappingJackson2JsonView for use
with the new version.

The MVC namespace and the MVC Java config detect and use
MappingJackson2HttpMessageConverter if Jackson 2 is present.
Otherwise if Jackson 1.x is present,
then MappingJacksonHttpMessageConverter is used.

Issue: SPR-9302
Backport-Issue: SPR-9507
Backport-Commit: e63ca04fdb
2012-06-26 16:52:51 -04:00
Chris Beams
fc416bcb0b Apply @Configuration BeanNameGenerator consistently
Since the introduction of the AnnotationConfig(Web)ApplicationContext
types in Spring 3.0, it has been possible to specify a custom
bean name generation strategy via the #setBeanNameGenerator methods
available on each of these classes.

If specified, that BeanNameGenerator was delegated to the underlying
AnnotatedBeanDefinitionReader and ClassPathBeanDefinitionScanner. This
meant that any @Configuration classes registered or scanned directly
from the application context, e.g. via #register or #scan methods would
respect the custom name generation strategy as intended.

However, for @Configuration classes picked up via @Import or implicitly
registered due to being nested classes would not be aware of this
strategy, and would rather fall back to a hard-coded default
AnnotationBeanNameGenerator.

This change ensures consistent application of custom BeanNameGenerator
strategies in the following ways:

 - Introduction of AnnotationConfigUtils#CONFIGURATION_BEAN_NAME_GENERATOR
   singleton

   If a custom BeanNameGenerator is specified via #setBeanNameGenerator
   the AnnotationConfig* application contexts will, in addition to
   delegating this object to the underlying reader and scanner, register
   it as a singleton bean within the enclosing bean factory having the
   constant name mentioned above.

   ConfigurationClassPostProcessor now checks for the presence of this
   singleton, falling back to a default AnnotationBeanNameGenerator if
   not present. This singleton-based approach is necessary because it is
   otherwise impossible to parameterize CCPP, given that it is
   registered as a BeanDefinitionRegistryPostProcessor bean definition
   in AnnotationConfigUtils#registerAnnotationConfigProcessors

 - Introduction of ConfigurationClassPostProcessor#setBeanNameGenerator

   As detailed in the Javadoc for this new method, this allows for
   customizing the BeanNameGenerator via XML by dropping down to direct
   registration of CCPP as a <bean> instead of using
   <context:annotation-config> to enable  @Configuration class
   processing.

 - Smarter defaulting for @ComponentScan#beanNameGenerator

   Previously, @ComponentScan's #beanNameGenerator attribute had a
   default value of AnnotationBeanNameGenerator. The value is now the
   BeanNameGenerator interface itself, indicating that the scanner
   dedicated to processing each @ComponentScan should fall back to an
   inherited generator, i.e. the one originally specified against the
   application context, or the original default provided by
   ConfigurationClassPostProcessor. This means that name generation
   strategies will be consistent with a single point of configuration,
   but that individual @ComponentScan declarations may still customize
   the strategy for the beans that are picked up by that particular
   scanning.

Issue: SPR-9124
2012-02-15 15:33:35 +01:00
Arjen Poutsma
edc80ffa95 Use request contentType/encoding in ServletServetHttpRequest/Response
ServletServerHttpRequest now falls back on the contentType and the
the characterEncoding of the ServletRequest, if the headers of the
incoming request don't specify one. Similary ServletServerHttpResponse
sets the contentType and the characterEncoding of the ServletResponse
if not already set.

This allows using the CharacterEncodingFilter to set a character
encoding where the request doesn't specify one and have it be used
in HttpMessageConverter's.

SPR-9096
2012-02-09 12:34:27 -05:00
Arjen Poutsma
3ec78e2c04 SPR-9093: UriTemplate not throwing IllegalArgumentException when URIVariables map missing values 2012-02-07 15:40:50 +01:00
Rossen Stoyanchev
871336a8c8 Better support for @SessionAttributes in clustered environments
A list of "known" session attributes (listed in @SessionAttributes)
was gradually built as attributes get added to the model. In a
failover scenario that knowledge is lost causing session attributes
to be potentially re-initialized via @ModelAttribute methods.

With this change @SessionAttributes listed by name are immediately
added to he list of "known" session attributes thus this knowledge
is not lost after a failover. Attributes listed by type however
still must be discovered as they get added to the model.
2012-02-03 12:23:24 -05:00
Rossen Stoyanchev
010abd06e3 SPR-9077 Remove empty path segments from input to UriComponentsBuilder. 2012-02-01 19:51:00 -05:00
Rossen Stoyanchev
8530828eb4 SPR-9076 Add normalize() method to UriComponents. 2012-02-01 19:12:52 -05:00
Rossen Stoyanchev
64a69f7cf8 SPR-9079 Don't check for "POST" multipart request method arg resolvers 2012-02-01 13:22:12 -05:00
Arjen Poutsma
8980ce712d SPR-8986 RestTemplate throws IllegalArgumentException when HTTP status is not in the HttpStatus enum
- Added getRawStatusCode
2012-01-23 14:26:11 +01:00
Arjen Poutsma
ff9ad7adc6 SPR-8986 RestTemplate throws IllegalArgumentException when HTTP status is not in the HttpStatus enum
- Added status codes from Wikipedia
2012-01-23 14:03:14 +01:00
Rossen Stoyanchev
bcd8355e61 SPR-8974 Fix regression in UriUtils.java 2012-01-19 23:47:31 -05:00
Rossen Stoyanchev
e8fc90ce3e SPR-8917 Fix issue with quoted parameter values in MediaType. 2012-01-13 15:25:53 -05:00
Chris Beams
41c405998e Convert CRLF=>LF on files missed earlier
Complete pass with `dos2unix` found additional files missed on earlier
related commit.

Issue: SPR-5608
2011-12-22 14:06:44 +01:00
Chris Beams
88913f2b23 Convert CRLF (dos) to LF (unix)
Prior to this change, roughly 5% (~300 out of 6000+) of files under the
source tree had CRLF line endings as opposed to the majority which have
LF endings.

This change normalizes these files to LF for consistency going forward.

Command used:

$ git ls-files | xargs file | grep CRLF | cut -d":" -f1 | xargs dos2unix

Issue: SPR-5608
2011-12-21 14:52:47 +01:00
Juergen Hoeller
1c45c51fe1 overhaul of support package arrangements for handler method processing; added missing package-info files 2011-12-12 23:20:03 +00:00
Chris Beams
23e58aa718 Preserve programmatically set context config locations
Prior to this fix, ContextLoader(Listener)'s would overwrite any
value set directly against a WebApplicationContext's #setConfigLocation
method. This is a likely scenario when using Spring 3.1's new
WebApplicationInitializer support.

Now a check is performed to ensure that the ContextLoader init-param
value is non-null before doing the overwriting.

Added tests to ensure that all expected precedence, overwriting and
defaulting of context config locations works as expected.

Issue: SPR-8510
2011-12-12 14:42:24 +00:00
Juergen Hoeller
8f69e81197 polishing 2011-12-11 22:07:37 +00:00
Arjen Poutsma
3beef9a92e SPR-8883 - RestTemplate.headForHeaders throws "IllegalArgumentException: No InputStream specified" on server resource which status code are 4xx 2011-12-08 19:17:48 +00:00
Rossen Stoyanchev
c472a163f1 SPR-8572 Support Void.class as response type in RestTemplate. 2011-12-08 03:59:28 +00:00
Juergen Hoeller
bea5016e53 fixed validation test failures 2011-12-03 17:03:33 +00:00
Juergen Hoeller
49a2aaf023 added SmartValidator interface with general support for validation hints; added custom @Valid annotation with support for JSR-303 validation groups; JSR-303 SpringValidatorAdapter and MVC data binding provide support for validation groups (SPR-6373) 2011-12-03 15:44:33 +00:00
Arjen Poutsma
53cb529162 SPR-8809 - RestTemplate headers not sent when bufferRequestBody is false 2011-12-02 11:29:47 +00:00
Arjen Poutsma
91c14bd1fe SPR-8809 - RestTemplate headers not sent when bufferRequestBody is false 2011-11-30 11:07:38 +00:00
Rossen Stoyanchev
a9a068e678 SPR-8867 Fix issue with Content-Length header and UTF-8 charset.
The AbstractHttpMessageConverter was using the requested Content-Type
rather than the actual response Content-Type to determine the length
of the content. This can lead to a problem when a controller returns
a ResponseEntity with a Content-Type header that ignores (overrides)
the requested Content-Type. The fix ensures that actual response 
Content-Type is the one used both to write to the response and to 
determine the length of the content.
2011-11-28 18:42:57 +00:00
Rossen Stoyanchev
60ee0bb8f4 SPR-8020 Support UriComponentsBuilder as a controller method argument.
The UriComponentsBuilder instance passed into the method is initialized
with current request information including host, scheme, port, context
path, and the servlet mapping's literal part.

Also added shortcut methods to buildAndExpand in UriComponentsBuilder.
2011-11-18 14:36:44 +00:00
Rossen Stoyanchev
01cc76f8e3 SPR-8697 Flag '*/subtype' as illegal. 2011-11-17 20:15:49 +00:00
Rossen Stoyanchev
63e235f215 SPR-8750 Refine 'Content-Type' update in MockHttpServletRequest/Response.
The initial solution kept these three in full sync at all times:
contentType field, characterEncoding field, 'Content-Type' header.
That is correct behavior, however it breaks existing tests that rely
on contentType and characterEncoding being equal to exactly what 
they were set to.

For example, consider:
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");

Ideally both contentType and the 'Content-Type' header would now be
"text/plain;charset=UTF-8". However, existing tests would expect 
that contentType is equal to "text/plain".

To avoid breaking existing tests, contentType and characterEncoding
will continue to be equal to exactly what they were set to while
the 'Content-Type' header will always include both the content 
type and the charset.

The only exception to this rule is when a 'Content-Type' header
is set explicitly, the contentType and characterEncoding fields will 
be updated accordingly, possibly overriding the existing values.
2011-11-17 15:07:15 +00:00
Rossen Stoyanchev
7918810366 SPR-8750 Update MockHttpServletRequest/Response handling of contentType.
The Content-Type header and the contentType field in HttpServletRequest/Response
are now always in sync. When a header is added the contentType field is updated
as well and vice versa. 

Similarly when the Content-Type header or the contentType field includes a charset 
field, the character encoding is updated and vice versa.
2011-11-16 23:28:48 +00:00
Rossen Stoyanchev
2a39f34d33 SPR-8803 Refine UriComponentsBuilder.replaceQueryParam().
If no values are given, the query parameter is removed.
2011-11-10 15:08:24 +00:00
Rossen Stoyanchev
c9acaaf9d8 SPR-8823 ServletUriComponentsBuilder polish and reference doc update. 2011-11-08 17:49:38 +00:00
Rossen Stoyanchev
d1d48ac940 SPR-8823 Add ServletUriComponentsBuilder. 2011-11-07 21:04:23 +00:00
Rossen Stoyanchev
d3f4c69f00 SPR-8803 Add UriComponentsBuilder methods to replace path/query. 2011-11-04 16:43:03 +00:00
Arjen Poutsma
78fbceff82 Added check for illegal characters when creating an encoded UriComponents object 2011-11-03 11:57:25 +00:00
Arjen Poutsma
e8dd35ce5e Added check for expanding already encoded UriComponents object 2011-11-02 11:49:45 +00:00
Rossen Stoyanchev
b08c7f6e00 SPR-6801 @ModelAttribute instantiation refinement.
Instantiate the model attribute from a URI var or a request param only
if the name matches and there is a registered Converter<String, ?>.
2011-09-27 22:48:12 +00:00
Arjen Poutsma
67fda70cb8 SPR-8713 - DefaultResponseErrorHandler IOException Bug 2011-09-27 08:16:33 +00:00
Rossen Stoyanchev
6bc4ea058c POLISH ARGUMENT RESOLVERS AND RETURN VALUE HANDLERS. 2011-09-24 11:34:07 +00:00
Rossen Stoyanchev
fb526f534a SPR-8700 REFINE ORDER OF ARGUMENT RESOLUTION AND RETURN VALUE HANDLING.
1. Consider single-purpose return value types like HttpEntity, Model,
View, and ModelAndView ahead of annotations like @ResponseBody and
@ModelAttribute. And reversely consider multi-purpose return value 
types like Map, String, and void only after annotations like
@RB and @MA.

2. Order custom argument resolvers and return value handlers after the
built-in ones also clarifying the fact they cannot be used to override
the built-in ones in Javadoc throughout.

3. Provide hooks in RequestMappingHandlerAdapter that subclasses can use
to programmatically modify the list of argument resolvers and return
value handlers, also adding new getters so subclasses can get access
to what they need for the override.

4. Make SessionStatus available through ModelAndViewContainer and 
provide an argument resolver for it.

5. Init test and javadoc improvements.
2011-09-22 16:00:22 +00:00
Rossen Stoyanchev
b2d88ba858 SPR-6464 Polish following code review. 2011-09-15 18:12:30 +00:00
Arjen Poutsma
aeba9d244a SPR-5973: now dealing with path followed by segments (and vice-versa) correctly. 2011-09-15 10:24:21 +00:00
Arjen Poutsma
3f2ea7f50e SPR-5973: UriComponents now encapsulates a PathCompont, switching between string paths and path segment lists automatically. 2011-09-14 14:09:57 +00:00
Arjen Poutsma
663f056329 SPR-5973: UriComponents no longer a Map, moved all static methods from UriComponents to builder, added expand method to UriComponents 2011-09-13 14:12:54 +00:00