Commit Graph

2485 Commits

Author SHA1 Message Date
Juergen Hoeller 188a11bdb9 Fixed setFavorPathExtension delegation code 2013-02-06 21:01:51 +01:00
Phillip Webb f464a45ba4 Polish formatting
Minor formatting polish across that codebase. Primarily fixing
whitespace issues.
2013-02-04 10:35:25 -08:00
Phillip Webb 065b1c0e46 Fix unused local variable warnings 2013-01-25 14:35:19 -08:00
Phillip Webb 88f5dd6ce1 Fix 'is already an instance of type' warnings 2013-01-25 11:29:54 -08:00
Rossen Stoyanchev 3c09b07652 Raise exception on missing request parameters
Issue: SPR-10193
2013-01-22 18:11:49 -05:00
Rossen Stoyanchev a3e190e1bf Support sub-types of ResponseEntity
Issue: SPR-10207
2013-01-22 17:26:51 -05:00
Sam Brannen 2a41de00e3 Polish Javadoc in Spring MVC async support
This commit fixes some typographical and grammatical errors in various
classes in Spring MVC's async support.
2013-01-22 12:09:00 +01:00
Chris Beams 3cdb866bda Relax ConfigurableWebEnvironment signatures
ConfigurableWebEnvironment was introduced in 3.2.0.M1 with SPR-9439 in
order to break a cyclic dependency. At the same time, certain signatures
such as AbstractRefreshableWebApplicationContext#getEnviroment and
GenericWebApplicationContext#getEnvironment were updated to take
advantage of covariant return types and return this newer, more narrow
type and providing cast-free calls to ConfigurableWebEnvironment methods
where necessary. Similar changes were made to HttpServletBean in
3.2.0.M2 with SPR-9763.

Narrowing #getEnvironment signatures in this fashion required enforcing
at the #setEnvironment level that any Environment instance provided
(explicitly or via the EnvironmentAware callback) must be an instance of
ConfigurableWebEnvironment. This is a reasonable assertion in typical
web application scenarios, but as SPR-10138 demonstrates, there are
valid use cases in which one may want or need to inject a non-web
ConfigurableEnvironment variant, e.g. during automated unit/integration
testing.

On review, it was never strictly necessary to narrow #getEnvironment
signatures, although doing so did provided convenience and type safety.
In order to maintain as flexible and backward-compatible an arrangement
as possible, this commit relaxes these #getEnvironment signatures back
to their original, pre-3.2 state. Namely, they now return
ConfigurableEnvironment as opposed to ConfigurableWebEnvironment, and in
accordance, all instanceof assertions have been removed or relaxed to
ensure that injected Environment instances are of type
ConfigurableEnvironment.

These changes have been verified against David Winterfeldt's Spring by
Example spring-rest-services project, as described at SPR-10138.

Issue: SPR-10138, SPR-9763, SPR-9439
2013-01-22 11:33:37 +01:00
Chris Beams d9a4fb410d Introduce "dummy" Environment implementation
For testing purposes in which an Environment implementation is required
but a ConfigurableEnvironment is not desirable.

All methods are no-ops and return null, therefore NPEs are likely.
2013-01-22 11:33:37 +01:00
Rossen Stoyanchev 660458a649 Fix init order issue in RequestMappingHandlerMapping
Issue: SPR-10173
2013-01-21 14:52:41 -05:00
Rossen Stoyanchev 902a136b6e Add helpful error message to DispServlet initializer
Issue: SPR-10168
2013-01-21 14:41:31 -05:00
Rossen Stoyanchev e4fcad9f93 Fix exception message about producible media types
Issue: SPR-10175
2013-01-21 12:34:56 -05:00
Sam Brannen f3e5f8bb4e Update copyright year, author tags, and Javadoc 2013-01-15 12:11:44 +01:00
Rossen Stoyanchev 9dc7b5feef Use MessageSource to resolve @ResponseStatus.reason
The reason attribute of @ResponseStatus can now be a code resolvable
through the ApplicationContext's MessageSource.

Issue: SPR-6044
2013-01-14 22:00:55 -05:00
Rossen Stoyanchev ad025b59c5 Prepend context/servlet path to FormTag action
The Form tag now fills in the context and servlet path if not present
in the specified action.

Issue: SPR-8684
2013-01-14 22:00:54 -05:00
Rossen Stoyanchev 2f6e45ff06 Add protected method to AbstractHandlerMethodMapping 2013-01-09 05:44:23 -05:00
Rossen Stoyanchev 68d4a70f8e Add option to always append 'must-revalidate'
Issue: SPR-9248
2013-01-08 11:44:24 -05:00
Chris Beams 0829cbfdd3 Update license header for recently modified files
Issue: SPR-7763, SPR-10140, SPR-10132, SPR-10093, SPR-10103
2013-01-08 16:23:46 +01:00
Rossen Stoyanchev c7d0054a9e Remove closing tag in form tag's extra hidden fields
The fields returned from a RequestDataValueProcessor are now
written as hidden fields without a closing tag.

Before:
<input type="hidden" name="xxx" value="yyy"></input>

After:
<input type="hidden" name="xxx" value="yyy" />

Issue: SPR-10103
2013-01-08 10:01:51 -05:00
Rossen Stoyanchev 87109b348c Add decoding matrix variable values
Issue: SPR-10140
2013-01-08 10:01:51 -05:00
Rossen Stoyanchev 7bc9667913 Add support for placeholders in @RequestMapping
@RequestMapping annotations now support ${...} placeholders.

Issue: SPR-9935
2013-01-07 18:06:47 -05:00
Rossen Stoyanchev 153508a300 Support "X-Forwarded-Host" in UriComponentsBuilder
ServletUriComponentsBuilder now supports setting the host to the
value held in the X-Forwarded-Host [0] header used in reverse
proxy scenarios.

[0] http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10

Issue: SPR-10110
2013-01-07 16:55:09 -05:00
Chris Beams 895feda349 Merge branch 'cleanup-3.2.x' into 3.2.x
* cleanup-3.2.x:
  Eliminate AJ @Async warning in test case
  Update Apache license headers for moved files
  Move namespace tests to root integration module
  Fix several miscellaneous compiler/Eclipse warnings
  Remove duplicate test resources
  Fix warnings due to unused import statements
  Update Apache license headers for affected sources
  Remove duplicate test classes
  Replace test beans with test objects
  Polish test sourceSet dependencies
  Add test dependencies sources for testCompile
2013-01-04 12:24:07 +01:00
Chris Beams 15e9fe638c Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.

This change was prompted by associated Eclipse warnings, which have now
been quelled.

Issue: SPR-9431
2013-01-04 11:38:58 +01:00
Chris Beams 51b307681a Fix warnings due to unused import statements
Issue: SPR-9431
2013-01-04 11:04:54 +01:00
Phillip Webb 42b5d6dd7e Remove duplicate test classes
Prior to this commit many test utility classes and sample beans were
duplicated across projects. This was previously necessary due to the
fact that dependent test sources were not shared during a gradle
build. Since the introduction of the 'test-source-set-dependencies'
gradle plugin this is no longer the case.

This commit attempts to remove as much duplicate code as possible,
co-locating test utilities and beans in the most suitable project.
For example, test beans are now located in the 'spring-beans'
project.

Some of the duplicated code had started to drift apart when
modifications made in one project where not ported to others. All
changes have now been consolidated and when necessary existing tests
have been refactored to account for the differences.

Conflicts:
	spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java
	spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java
	spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java
2013-01-04 10:02:29 +01:00
Chris Beams 7a737bebdd Merge branch '3.2.x' into master
* 3.2.x:
  Fix ClassCastException when setting media types
  Enable execution of TestNG tests in spring-test
  Polish support for topic branch-specific versions
  Segregate add'l long-running and performance tests
  Eliminate EBR dependencies and repository config
  Skip creation of IDEA metadata for spring-aspects
  Fix Eclipse compilation error in Gradle plugin
  Polish build.gradle
  Fix null parameterName issue in content negotiation
  Recursively add test dependencies
2013-01-03 22:31:52 +01:00
Rossen Stoyanchev 9f9f1ed253 Fix ClassCastException when setting media types
Issue: SPR-10019
2013-01-03 15:13:19 -05:00
Chris Beams 961dbdb68a Merge branch '3.2.x' into master
* 3.2.x:
  Exclude spring-build-src from maven publish
  Move spring-build-junit into spring-core
  Relocate MergePlugin package
  Develop a gradle plugin to add test dependencies
  Expose Gradle buildSrc for IDE support
  Fix [deprecation] compiler warnings
  Upgrade to xmlunit version 1.3
  Improve 'build' folder ignores
  Fix regression in static setter method support
  Fix SpEL JavaBean compliance for setters

Conflicts:
	spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java
2013-01-02 10:36:57 +01:00
Chris Beams 70eaf02b7f Revert "Merge branch 'SPR-10130' into cleanup-master"
This reverts commit 45fa50821a, reversing
changes made to a312d900f8.
2013-01-02 10:33:59 +01:00
Phillip Webb 6626a38730 Fix [deprecation] compiler warnings
Fix deprecation compiler warnings by refactoring code or applying
@SuppressWarnings("deprecation") annotations. JUnit tests of
internally deprecated classes are now themselves marked as
@Deprecated.

Numerous EasyMock deprecation warnings will remain until the
migration to mockito can be completed.
2013-01-01 13:42:15 -08:00
Chris Beams b2a048b6f3 Update Apache license headers for affected sources 2012-12-28 23:57:33 +01:00
Chris Beams 3b40ce76bf Add @Override annotations to main sources
Issue: SPR-10130
2012-12-28 23:53:24 +01:00
Chris Beams 8472a2b2ab Update Apache license headers for affected sources 2012-12-28 23:09:31 +01:00
Chris Beams 4c8cd7b0bd Add @Override annotations to test sources
Issue: SPR-10129
2012-12-28 23:05:44 +01:00
Chris Beams 4d97ff2479 Fix [dep-ann] warnings with @Deprecated 2012-12-28 22:50:45 +01:00
Phillip Webb 6c14eaad61 Fix [cast] compiler warnings 2012-12-28 22:41:06 +01:00
Phillip Webb b0986049a3 Fix [serial] compiler warnings
Fix serialization warnings by applying @SuppressWarnings("serial")
when appropriate.

In certain cases and for unknown reasons, a correctly-placed
@SuppressWarnings("serial") annotation will fix the warning at the
javac level (i.e. the Gradle command-line), but will produce an
"unnecessary @SuppressWarnings" warning within Eclipse. In these
cases, a private static final serialVersionUID field has been added
with the default value of 1L.
2012-12-28 22:41:06 +01:00
Phillip Webb 731d5be644 Fix warnings due to unused import statements 2012-12-28 22:40:49 +01:00
Chris Beams 9540d2c81b Replace <code> with {@code} throughout Javadoc
Issue: SPR-10128
2012-12-28 22:36:02 +01:00
Chris Beams 8597ec25ec Fix various Javadoc warnings
Issue: SPR-10128
2012-12-28 22:36:02 +01:00
Phillip Webb 2cf45bad86 Replace space indentation with tabs
Issue: SPR-10127
2012-12-28 20:49:56 +01:00
Phillip Webb 1762157ad1 Remove trailing whitespace in source files
find . -type f -name "*.java" -or -name "*.aj" | \
    xargs perl -p -i -e "s/[ \t]*$//g" {} \;

Issue: SPR-10127
2012-12-28 20:49:45 +01:00
Juergen Hoeller 531318a4b2 Polishing 2012-12-13 00:03:26 +01:00
Juergen Hoeller b9df7d68d9 Consistent fine-tuning of synchronized and concurrent data structures
In particular, avoiding synchronized Sets and Maps wherever possible (preferring a ConcurrentHashMap even instead of a synchronized Set) and specifying appropriate ConcurrentHashMap initial capacities (even if we end up choosing 16).
2012-12-12 23:46:26 +01:00
Chris Beams f26534700a Eliminate all Javadoc warnings
- Support external Javadoc links using Gradle's javadoc.options.links

 - Fix all other Javadoc warnings, such as typos, references to
   non-existent (or no longer existent) types and members, etc,
   including changes related to the Quartz 2.0 upgrade (SPR-8275) and
   adding the HTTP PATCH method (SPR-7985).

 - Suppress all output for project-level `javadoc` tasks in order to
   hide false-negative warnings about cross-module @see and @link
   references (e.g. spring-core having a @see reference to spring-web).
   Use the `--info` (-i) flag to gradle at any time to see project-level
   javadoc warnings without running the entire `api` task. e.g.
   `gradle :spring-core:javadoc -i`

 - Favor root project level `api` task for detection of legitimate
   Javadoc warnings. There are now zero Javadoc warnings across the
   entirety of spring-framework. Goal: keep it that way.

 - Remove all @link and @see references to types and members that exist
   only in Servlet <= 2.5 and Hibernate <= 4.0, favoring 3.0+ and 4.0+
   respectively. This is necessary because only one version of each of
   these dependencies can be present on the global `api` javadoc task's
   classpath. To that end, the `api` task classpath has now been
   customized to ensure that the Servlet 3 API and Hibernate Core 4 jars
   have precedence.

 - SPR-8896 replaced our dependency on aspectjrt with a dependency on
   aspectjweaver, which is fine from a POM point of view, but causes
   a spurious warning to be emitted from the ant iajc task that it
   "cannot find aspectjrt on the classpath" - even though aspectjweaver
   is perfectly sufficient. In the name of keeping the console quiet, a
   new `rt` configuration has been added, and aspectjrt added as a
   dependency to it. In turn, configurations.rt.asPath is appended to
   the iajc classpath during both compileJava and compileTestJava for
   spring-aspects.

Issue: SPR-10078, SPR-8275, SPR-7985, SPR-8896
2012-12-12 12:55:10 +01:00
Juergen Hoeller c55446da9d Polishing 2012-12-12 03:29:47 +01:00
Juergen Hoeller 9deaefe74d AbstractCachingViewResolver uses a cache limit of 1024 by default, avoiding overflow for redirect URLs
Issue: SPR-10065
2012-12-12 03:29:45 +01:00
Rossen Stoyanchev 85a552daed Fix package cycle among http message converters
This change introduces a new AllEncompassingFormHttpMessageConverter
class that adds JSON and XML converters for individual mime parts of
a multi-part request. The new converter is used in place of the
previously used XmlAwareFormHttpMessageConverter.

Issue: SPR-10055
2012-12-07 18:12:11 -05:00
Rossen Stoyanchev 3643d92cb8 Fix issue with creating ServletRequestAttributes
Prevously the FrameworkServlet created a new ServletRequestAttributes
instance for every request, unless the RequestContextHolder already
contained an instance whose type is not ServletRequestAttributes.
The main intent was that if RequestContextHolder contains a
PortletRequestAttributes, it should be left in place.

This change does an "instanceof" check against the request in
RequestContextHolder instead of an "equals" check on the type.
It still leaves PortletRequestAttributes in place but also allows
the previous request to be any sub-class of ServletRequestAttributes.

Issue: SPR-10025
2012-12-07 15:19:38 -05:00
Sam Brannen 2233949a0f Fix typo 2012-12-07 12:06:21 +01:00
Rossen Stoyanchev 9cc4bd892a Fix issue with suffix pattern match
Spring Framework 3.2 M2 added the ability to map requests using only
file extensions registered through the configured through a
ContentNeotiationManager, as opposed to allowing any file extension
(i.e. ".*"). The MVC namespace the MVC Java config automatically
register extensions such as ".json" and ".xml" depending on libraries
found on the classpath. That in turn causes issues in cases where
additional extensions are in use but not registered (e.g. ".html").

This change ensures that matching with registered file extensions only
works only if explicitly enabled through a property on
RequestMappingHandlerMapping.

Issue: SPR-10061, SPR-8474
2012-12-06 18:31:32 -05:00
Rob Winch 149e6f6425 polish web.Mock* classpath
Previously when running the tests for spring-web, spring-webmvc,
spring-test-mvc, and spring-orm there were possible collissions in the
classpath due to the fact that each had its own copy of the web.Mock*
classes in it. This causes uncertainty for which class the code was
running against. Furthermore, the maintance of keeping the copies up to
date was tedious.

Now there are two copies of the web.Mock* classes. The ones that exist
in spring-test main sources and a copy that supports servlet 3 within
spring-web test sources. The copy in spring-web test sources has been
moved to a new package to avoid having the classes exist twice on the
classpath within Eclipse.
2012-11-30 11:15:58 -05:00
Juergen Hoeller 48f405e8fd Finally added generics to JasperReports API signatures (motivated by JasperReports 5.0) 2012-11-29 23:15:41 +01:00
Rob Winch 157a1d6ee2 Rename MvcAsyncTask to WebAsyncTask
The name MvcAsyncTask is misleading because the class is part of Spring
Web as apposed to Spring MVC. This is also inconsistent with the other
async classes which use Web instead of Mvc.

This commit changes MvcAsyncTask to WebAsyncTask making it more
consistent with the jar it is found in and the other async classes.

Issue: SPR-10051
2012-11-28 16:55:45 -05:00
Rossen Stoyanchev 5cb1930550 Fix issue in Callable processing interceptor chain 2012-11-26 16:04:17 -05:00
Juergen Hoeller b8d86330d1 Deprecated Spring's own JSP expression evaluation
Since web applications declaring a Servlet 2.3 web.xml become really rare now, we're finally deprecating Spring's own ExpressionEvaluationUtils class. As a consequence, we're also setting "springJspExpressionSupport" to false by default, avoiding the potential double EL evaluation problem on pre-Servlet-3.0 containers.

Issue: SPR-5308
2012-11-26 00:35:47 +01:00
Rossen Stoyanchev 2d8bacace7 Set the ApplicationContext prop of ExceptionResolver
The MVC Java config now sets the ApplicationContext property of
ExceptionHandlerExceptionResolver.

Issue: SPR-9997
2012-11-23 15:12:52 -05:00
Rossen Stoyanchev b7f7fae78a Fix issue with @RequestBody args that are type vars
The change to support generic @RequestBody arguments introduced in
3.2 M2 also introduced a regression in reading arguments that are
type variables. This change fixes the issue.

Issue: SPR-9964
2012-11-22 11:35:22 -05:00
Rossen Stoyanchev 11cf978394 Define behavior of null Callable or DeferredResult
When a controller method declares Callable or DeferredResult as its
return value, and returns null, async processing will not start and
the request will be considered "handled" by the controller method.

Issue: SPR-9951
2012-11-20 15:12:58 -05:00
Rossen Stoyanchev 77223d7ced Deprecate pre 3.1 @MVC support classes
Issue: SPR-10005
2012-11-20 14:59:01 -05:00
Rossen Stoyanchev ecce7520fb Support HttpMessageConverter refs in mvc namespace
Issue: SPR-9469
2012-11-13 21:47:59 -05:00
Rossen Stoyanchev 62f2858f7f Fix issue with SpEL in mvc namespace
This change ensures that the location attribute of a resource mapping
and the path attribute of an interceptor mapping support SpEL
expressions.

Issue: SPR-9291, SPR-9848
2012-11-13 21:13:52 -05:00
Phillip Webb 950f00a280 Fix Collections import
Replace backport Collections class with stock JDK version
2012-11-12 13:15:25 -08:00
Chris Beams 1070e4d5c1 Initialize FrameworkServlet property sources eagerly
Prior to this change,
FrameworkServlet#configureAndRefreshWebApplicationContext called
 #postProcessWebApplicationContext(wac) and #applyInitializers(wac)
prior to #refresh, but because servlet-based property source stubs were
not replaced until #refresh, any post-processing or initialization
routines could not benefit from accessing the Environment to retrieve
properties from the ServletContext or ServletConfig.

The workaround to this problem is detailed in SPR-9610 - the user simply
needed to call WebApplicationContextUtils#initServletPropertySources
manually within their ApplicationContextInitializer (or overridden
 #postProcessWebApplicationContext method)

This commit ensures that
FrameworkServlet#configureAndRefreshWebApplicationContext calls
WebApplicationContextUtils#initServletPropertySources eagerly, prior to
invoking #postProcessWebApplicationContext and #applyInitializers.
Related Javadoc has also been updated throughout to clarify the behavior
of #initServletPropertySources, when it can be called and what the
effects are, etc.

Note also that a reproduction issue was added to demonstrate the problem
and verify its resolution [1].

[1]: https://github.com/SpringSource/spring-framework-issues/tree/master/SPR-9610

Issue: SPR-9610
2012-11-02 13:05:48 +01:00
Rossen Stoyanchev c0baea58c0 Fix issue with generic @RequestBody arguments
The original commit c9b7b1 ensured the ability to read parameterized
type @RequestBody arguments via GenericHttpMessageConverter (e.g.
application/json and List<String>). However, it also affected the
ability to read @RequestBody arguments that happen are parameterized
but aren't treated as such (e.g. application/x-www-form-urlencoded and
MultiValueMap<String, String>). This commit corrects the issue.

Issue: SPR-9570
2012-10-31 21:15:16 -04:00
Rossen Stoyanchev 0e3aa0eec4 Peek into the content for @RequestBody(required=false)
For @RequestBody(required=false), it is not sufficient to check if the
InputStream is null. This change reads the first byte of the request
InputStream to determine if the request body is empty or not.

If the InputStream implementation supports mark(int) and reset(), then
we use those. Otherwise we use PushbackInputStream to read and unread
the first byte.

All of this is done only if the required flag of @RequestBody is set
to "false" (default is "true").

Issue: SPR-9942
2012-10-31 21:15:15 -04:00
Sam Brannen 8bb19f05ea Fix typos in Javadoc 2012-10-31 16:22:16 +01:00
Rossen Stoyanchev 1acd5cff8f Polish methods to register async interceptors 2012-10-30 22:38:39 -04:00
Rossen Stoyanchev d701464517 Add onTimeout/onCompletion callbacks to DeferredResult
Issue: SPR-9914
2012-10-30 21:58:44 -04:00
Rossen Stoyanchev d8469d118b Fix issue with extracting matrix variables
The servlet spec recommends removing path parameters from the
contextPath, servletPath, and pathInfo but not from the requestURI.
This poses a challenge for the UrlPathHelper, which determines the
lookup path by comparing the above.

This change introduces a method that matches the requestURI to the
contextPath and servletPath ignoring path parameters (i.e. matrix
variables) for comparison purposes while also preserving them in the
resulting lookup path.
2012-10-29 19:09:00 -04:00
Rossen Stoyanchev 826057bcde Expose convenience method in MVC Java config
The new method allows modifying or overriding the
ConfigurableWebBindingInitializer instance used for data binder
initialization.

Issue: SPR-8984
2012-10-29 05:56:30 -04:00
Rossen Stoyanchev f7ec738857 Sync up MockAsyncContext implementations in src/test 2012-10-28 12:10:38 -04:00
Sam Brannen 591aa01741 Configurable locales in MockHttpServletRequest
Prior to this commit the MockHttpServletRequest constructor chain set
the preferred local to Locale.ENGLISH. Furthermore, it was possible to
add additional preferred locales "in front" of ENGLISH; however, it was
not possible to delete ENGLISH from the list of preferred locales.

This commit documents the fact that ENGLISH is the default preferred
locale and makes it possible to set the list of preferred locales via a
new setPreferredLocales(List<Locale> locales) method.

Issue: SPR-9724
2012-10-27 18:13:13 +02:00
Rossen Stoyanchev e14ba9dec3 Add config options for MVC async interceptors
The MVC namespace and the MVC Java config now allow configuring
CallableProcessingInterceptor and DeferredResultProcessingInterceptor
instances.

Issue: SPR-9914
2012-10-26 21:29:54 -04:00
Rossen Stoyanchev e4a13cd4ad Polish (minor) RequestMappingHandlerAdapter
Revise order of fields reflecting configurable vs internal fields and
also grouping them accordingly.
2012-10-26 18:24:22 -04:00
Rossen Stoyanchev f036ed639f Polish (major) MVC async processing interceptors
New afterTimeout and afterCompletion callbacks

afterTimeout can provide a concurrent result to be used instead of the
one that could not be set or returned on time

Interceptor exceptions cause async processing to resume treating the
exception as the concurrent result

Adapter classes for convenient implementation of the interfaces

Issue: SPR-9914
2012-10-26 18:04:27 -04:00
Rossen Stoyanchev c7e7e80a3a Update AbstractView with method to set content type
Before this change View implementations set the response content type
to the fixed value they were configured with.

This change makes it possible to configure a View implementation with
a more general media type, e.g. "application/*+xml", and then set the
response type to the more specific requested media type, e.g.
"application/vnd.example-v1+xml".

Issue: SPR-9807.
2012-10-22 17:23:57 -04:00
Rossen Stoyanchev dbcbdace9e Parameterize AsyncTask type 2012-10-15 12:17:39 -04:00
Rossen Stoyanchev e98dc50f99 Fix issue in PatternsRequestCondition 2012-10-15 12:17:39 -04:00
Rossen Stoyanchev dc01f088f7 Fix issue in message conversion
This change ensures that when the Accept and the Producible media types
are equally specific, we use the one from the Accept header, which may
for example carry a different charset.
2012-10-12 08:49:30 -04:00
Juergen Hoeller 014f7f0242 Changes along with 3.1.3 backport
Aside from minor polishing, this change sets the "systemProperties" and "systemEnvironment" beans at each factory level as well.

Issue: SPR-9756
Issue: SPR-9764
2012-10-10 23:34:22 +02:00
Rossen Stoyanchev d4fa5c0331 Fix NPE in AbstractMessageConverterMethodProcessor
Issue: SPR-9868
2012-10-10 09:00:43 -04:00
Rossen Stoyanchev 3552173b81 Fix issue in AnnotationMethodHandlerExceptionResolver
Caching of resovled exceptions introduced in SPR-7703 also introduced a
side effect whereby if exactly one exception was previously cached, any
other exception would appear as a match to the previously matched
@ExceptionHandler method.

This change ensures use of a fresh map when determining matching
@ExceptionHandler methods while also updating the cache.

Issue: SPR-9209
2012-10-06 21:58:34 -04:00
Rossen Stoyanchev 7718936158 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:01:56 -04:00
Rossen Stoyanchev 7513e2124a Sync up MockHttpServletResponse copies in test sources 2012-10-02 15:57:22 -04:00
Rossen Stoyanchev 4566db82f5 Polish MockFilterChain
A reset method now allows it to be invoked more than once each time
storing the request and response with which it was invoked.
2012-09-27 12:06:35 -04:00
Rossen Stoyanchev 7b30ffd522 Work around Servlet dependency in content negotiation
Before this change the PathExtensionContentNegotiationStrategy accessed
the ServletContext via request.getServletContext, which is Servlet 3
specific. To work around it, there is now a Servlet-specific sub-class
that accepts a ServletContext as a constructor argument.

The ContentNegotiationManagerFactoryBean is now ServletContextAware and
if it has a ServletContext it creates the Servlet-specific sub-class
of PathExtensionContentNegotiationStrategy.

The ContentNegotiationManagerFactoryBean is now also used in several
places internally -- MVC namespace, MVC Java config, and the
ContentNegotiatingViewResolver -- to reduce duplication.

Issue: SPR-9826
2012-09-26 09:28:43 -04:00
Rossen Stoyanchev ef9d35c473 Add PATCH to "Allow" header for OPTIONS requests 2012-09-24 19:57:04 -04:00
Phillip Webb c0729756d7 Protect RequestCondition against unkown HTTP methods
The RequestMethodsRequestCondition is now protected against HTTP
request method values not present in the RequestMethod enumeration
(e.g. PROPFIND).

Issue: SPR-9815
2012-09-21 11:05:45 -04:00
Phillip Webb b0153ada19 Polish trailing whitespace 2012-09-21 10:55:17 -04:00
Phillip Webb 4767f44671 Delete CopyOfRequestMappingHandlerMapping class
Previously committed in error.

Issue: SPR-9814
2012-09-20 17:25:00 -07:00
Rossen Stoyanchev 57c36dd395 Add interceptors for async processing
This change introduces two new interceptors with callback methods
for concurrent request handling. These interfaces are
CallableProcessingInterceptor and DeferredResultProcessingInterceptor.

Unlike a HandlerInterceptor, and its AsyncHandlerInterceptor sub-type,
which intercepts the invocation of a handler in he main request
processing thread, the two new interfaces are aimed at intercepting the
asynchronous execution of a Callable or a DeferredResult.

This allows for the registration of thread initialization logic in the
case of Callable executed with an AsyncTaskExecutor, or for centralized
tracking of the completion and/or expiration of a DeferredResult.
2012-09-19 09:25:50 -04:00
Rossen Stoyanchev 97f97c4e9f Polish async support
Added handler argument to the signature of
AsyncHandlerInterceptor.afterConcurrentHandlingStarted(..).

Renamed AsyncWebUtils to WebAsyncUtils.
2012-09-17 14:58:56 -04:00
Phillip Webb 8e7622bb8a Fix Windows-related build issues
- Increase max heap size in gradle wrapper.
- Use MockProperties implementation to protect against security
  exceptions.
- Replace windows CRLF with LF in various tests.
- Increase Thread.sleep times to account for lack of precision on
  Windows.

Issue: SPR-9717
2012-09-11 15:04:55 +02:00
Rossen Stoyanchev 48b963aaa5 Add error request attribute for 500 reponses
DefaultHandlerExceptionResolver and ResponseEntityExceptionHandler now
both set the "javax.servlet.error.exception" request attribute to the
raised exception, allowing custom error pages configured via web.xml.

Issue: SPR-9653
2012-09-10 18:26:43 -04:00
Rossen Stoyanchev 0a877afa06 Optimize use of HandlerMethod and sub-classes
While HandlerMethod instances are cached for lookup purposes, a new
ServletInvocableHandlerMethod instance has to be created prior to each
invocation since handlers may have non-singleton scope semantics.

This change reduces the overhead of creating per request instances
by using a logger with a fixed name rather than relying on getClass()
and also by copying introspected method parameters from the cached
HandlerMethod instance.

Issue: SPR-9747, SPR-9748
2012-09-10 14:01:01 -04:00
Rossen Stoyanchev 70b0b97b54 Fix cyclical package dependency 2012-09-07 22:14:49 -04:00
Rossen Stoyanchev 6e85dd8917 Polish async request processing
This change fixes a cyclical package dependency.

The change also improves the implementation of
WebAsyncManager.hasConcurrentResult() following the resolution of
Apache issue id=53632 and the release of Apache Tomcat 7.0.30 that
contains the fix.
2012-09-07 21:30:11 -04:00
Chris Beams 6517517ca9 Refactor to lazy Environment creation where possible
This commit avoids eager creation of Environment instances, favoring
delegation of already existing Environment objects where possible. For
example, FrameworkServlet creates an ApplicationContext; both require
a StandardServletEnvironment instance, and prior to this change, two
instances were created where one would suffice - indeed these two
instances may reasonably be expected to be the same. Now, the
FrameworkServlet defers creation of its Environment, allowing users to
supply a custom instance via its #setEnvironment method (e.g. within a
WebApplicationInitializer); the FrameworkServlet then takes care to
delegate that instance to the ApplicationContext created
in #createWebApplicationContext.

This behavior produces more consistent behavior with regard to
delegation of the environment, saves unnecessary cycles by avoiding
needless instantiation and calls to methods like
StandardServletEnvironment#initPropertySources and leads to better
logging output, as the user sees only one Environment created and
initialized when working with the FrameworkServlet/DispatcherServlet.

This commit also mirrors these changes across the corresponding
Portlet* classes.

Issue: SPR-9763
2012-09-05 22:33:55 +02:00
Rob Winch c92a06f003 Support Filters/Servlet invocation in MockFilterChain
This commit adds the ability to allow the MockFilterChain to invoke
a List of Filter's and/or a Servlet.

Issue: SPR-9745
2012-09-05 01:30:46 -04:00
Rossen Stoyanchev cb564b287f Provide support for filter registrations
The AbstractDispatcherServletInitializer now provides support for
the registration of filters to be mapped to the DispatcherServlet.
It also sets the asyncSupported flag by default on the
DispatcherServlet and all registered filters.

Issue: SPR-9696
2012-08-28 22:29:23 -04:00
Rossen Stoyanchev 473de081b8 Improve no-match handling for @RequestMapping methods
Issue: SPR-9603
2012-08-28 15:56:02 -04:00
Rossen Stoyanchev 2201dd8c45 Add support for matrix variables
A new @MatrixVariable annotation allows injecting matrix variables
into @RequestMapping methods. The matrix variables may appear in any
path segment and should be wrapped in a URI template for request
mapping purposes to ensure request matching is not affected by the
order or the presence/absence of such variables. The @MatrixVariable
annotation has an optional "pathVar" attribute that can be used to
refer to the URI template where a matrix variable is located.

Previously, ";" (semicolon) delimited content was removed from the
path used for request mapping purposes. To preserve backwards
compatibility that continues to be the case (except for the MVC
namespace and Java config) and may be changed by setting the
"removeSemicolonContent" property of RequestMappingHandlerMapping to
"false". Applications using the  MVC namespace and Java config do not
need to do anything further to extract and use matrix variables.

Issue: SPR-5499, SPR-7818
2012-08-28 13:21:12 -04:00
Rossen Stoyanchev da05b094f5 Polish standard Spring MVC exception handling
Rename ExceptionHandlerSupport to ResponseEntityExceptionHandler and
emphasize the contrast to DefaultHandlerExceptionResovler -- i.e.
one returns a ResponseEntity and relies on message converters while
the other returns a ModelAndView and relies on view resolution.

Issue: SPR-9290
2012-08-27 14:06:06 -04:00
Arjen Poutsma 0a6b1167a7 Improved Javadoc 2012-08-27 15:04:11 +02:00
Rossen Stoyanchev c9b7b132fb Support generic types in @RequestBody arguments
This change makes it possible to declare an @RequestBody argument with
a generic type (e.g. List<Foo>). If a GenericHttpMessageConverter
implementation supports the method argument, then the request will be
converted to the apropiate target type.

The new GenericHttpMessageConverter is implemented by the
MappingJacksonHttpMessageConverter and also by a new
Jaxb2CollectionHttpMessageConverter that can read read a generic
Collection where the generic type is a JAXB type annotated with
@XmlRootElement or @XmlType.

Issue: SPR-9570
2012-08-23 09:58:45 -04:00
Rossen Stoyanchev de6f74fa40 Encode UTF-8 characters used in Java test sources
A pass-through the native2ascii tool.

Issue: SPR-9657
2012-08-22 11:43:48 -04:00
Rossen Stoyanchev 888835445c Update error message in DispatcherServlet
Issue: SPR-8338
2012-08-21 15:35:06 -04:00
Rossen Stoyanchev 364bb696e0 Decode target parameters prior to saving a FlashMap
The target parameters for a FlashMap must be decoded to be able to
match them to the parameters of incoming requests given that the
HttpServletRequest returns decoded request parameters.

SPR-9657
2012-08-21 15:27:21 -04:00
Rossen Stoyanchev af1561634c Allow Errors after @RequestBody and @RequestPart
An @RequestBody or an @RequestPart argument can now be followed by an
Errors/BindingResult argument making it possible to handle validation
errors (as a result of an @Valid annotation) locally within the
@RequestMapping method.

Issue: SPR-7114
2012-08-21 14:34:05 -04:00
Rossen Stoyanchev 06d95915a0 Add error message for missing servlet request param.
The DefaultHandlerExceptionResolver now provides an error message in
addition to setting the status of the response.

Issue: SPR-9312
2012-08-21 12:35:17 -04:00
Rossen Stoyanchev 1cf4a2facd Add ExceptionHandlerSupport class
The new class is functionally equivalent to the
DefaultHandlerExceptionResolver (i.e. it translates Spring MVC
exceptions to various status codes) but uses an @ExceptionHandler
returning a ResponseEntity<Object>, which means it can be customized to
write error content to the body of the response.

Issue: SPR-9290
2012-08-21 11:32:11 -04:00
Rossen Stoyanchev 9c8c967caa Add async options to MVC namespace and Java config
The MVC Java config method to implement is
WebMvcConfigurer.configureAsyncSupport(AsyncSupportConfigurer)

The MVC namespace element is:
<mvc:annotation-driven>
  <mvc:async-support default-timeout="2500" task-executor="myExecutor" />
</mvc:annotation-driven>

Issue: SPR-9694
2012-08-17 17:05:16 -04:00
Rossen Stoyanchev cdab04a032 Set timeout value and task executor per async request
Methods returning DeferredResult can now specify a timeout value
through constructor arg while methods returning a Callable can wrap it
in an AsyncTask that also accepts a timeout and a specific task
executor.

Issue: SPR-9399
2012-08-17 13:09:51 -04:00
Rossen Stoyanchev 4407f6a4c0 Make DeferredResult more usable and testable
DeferredResult now has a setErrorResult method that can be set to an
Exception or an error object, error view, etc.

The new isSetOrExpired() method can be used to check pro-actively if
the DeferredResult is still usable or not.

The setDeferredResultHandler method is now public so tests may use it.

Issue: SPR-9690, SPR-9689
2012-08-17 13:09:51 -04:00
Sam Brannen 3b9833c538 Update MockHttpSession across the test suite 2012-08-16 13:38:51 +02:00
Rossen Stoyanchev e65b930e7a Introduced ControllerAdvice annotation
Classes with this annotation can contain @ExceptionHandler,
@InitBinder, and @ModelAttribute methods that apply to all controllers.
The new annotation is also a component annotation allowing
implementations to be discovered through component scanning.

Issue: SPR-9112
2012-08-14 16:35:37 -04:00
Rossen Stoyanchev 529e62921d Refactor Servlet 3 async support
As a result of the refactoring, the AsyncContext dispatch mechanism is
used much more centrally. Effectively every asynchronously processed
request involves one initial (container) thread, a second thread to
produce the handler return value asynchronously, and a third thread
as a result of a dispatch back to the container to resume processing
of the asynchronous resuilt.

Other updates include the addition of a MockAsyncContext and support
of related request method in the test packages of spring-web and
spring-webmvc. Also an upgrade of a Jetty test dependency required
to make tests pass.

Issue: SPR-9433
2012-08-03 19:15:53 -04:00
Sam Brannen 37dc211f58 Support named dispatchers in MockServletContext
Currently the getNamedDispatcher(String) method of MockServletContext
always returns null. This poses a problem in certain testing scenarios
since one would always expect at least a default Servlet to be present.
This is specifically important for web application tests that involve
the DefaultServletHttpRequestHandler which attempts to forward to the
default Servlet after retrieving it by name. Furthermore, there is no
way to register a named RequestDispatcher with the MockServletContext.

This commit addresses these issues by introducing the following in
MockServletContext.

 - a new defaultServletName property for configuring the name of the
   default Servlet, which defaults to "default"
 - named RequestDispatchers can be registered and unregistered
 - a MockRequestDispatcher is registered for the "default" Servlet
   automatically in the constructor
 - when the defaultServletName property is set to a new value the
   the current default RequestDispatcher is unregistered and replaced
   with a MockRequestDispatcher for the new defaultServletName

Issue: SPR-9587
2012-07-26 03:06:07 +02:00
Rossen Stoyanchev 914557b975 Use a default for INTROSPECT_TYPE_LEVEL_MAPPING
Usually this request attribute is set for all sub-classes of
AbstractUrlHandlerMapping and therefore whenever
AnnotationMethodHandlerAdapter is used. However, having a
default value to fall back on in AnnotationMethodHandlerAdapter
is still appropriate in general and also considering the Javadoc
of HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING.

Issue: SPR-9629
2012-07-25 19:22:15 -04:00
Rossen Stoyanchev 7c6a1a1bf0 Improve tests for detection of @MVC annotations
Issue: SPR-9601
2012-07-25 19:10:46 -04:00
Sam Brannen 060b37ca8d Fix typo in MockFilterChain 2012-07-25 01:03:33 +02:00
Rossen Stoyanchev 64d939bb16 Add ContentNegotiationManagerFactoryBean
The new FactoryBean facilitates the creation of a
ContentNegotiationManager in XML configuration.

Issue: SPR-8420
2012-07-21 06:16:42 -04:00
Rossen Stoyanchev 028e15faa3 Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.

Issue: SPR-8420
2012-07-20 21:32:02 -04:00
Rossen Stoyanchev 92759ed1f8 Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.

Issue: SPR-6570
2012-07-20 14:47:46 -04:00
Rossen Stoyanchev 6cc512b51c Ensure async Callables are in sync with the call stack
After this change each call stack level pushes and pops an async
Callable to ensure the AsyncExecutionChain is in sync with the
call stack. Before this change, a controller returning a "forward:"
prefixed string caused the AsyncExecutionChain to contain a
extra Callables that did not match the actual call stack.

Issue: SPR-9611
2012-07-20 12:50:01 -04:00
Rossen Stoyanchev d3d00696a4 Create StandardServletAsyncWebRequest via reflection
Issue: SPR-9500
2012-07-18 10:02:15 -04:00
Rossen Stoyanchev eab6e1d134 Parameterize DeferredResult
Issue: SPR-9579
2012-07-18 09:43:03 -04:00
Rossen Stoyanchev a1b7a314c1 Add BindException to DefaultHandlerExceptionResolver
Previously DefaultHandlerExceptionResolver did not handle BindException
but after this change it does. A BindException is raised when an
@ModelAttribute annotated argument is not followed by a BindingResult
argument. Hence this is unlikely to affect browser rendering.
For programmatic clients however this change ensures an unhandled
BindException is at least turned into a 400 error.

Issue: SPR-9310
2012-07-10 17:32:13 -04:00
Rossen Stoyanchev e860fa9a8b Move feed message converters ahead of jackson/jaxb2
The Atom/RSS message converters are now registered ahead of the
Jackson and the JAXB2 message converters by default. Since the Atom
and RSS converters convert to and from very specific object types
Feed and Channel respectively, that shouldn't introduce any regressions
and will work more intuitively when the requested media type is "*/*".

Issue: SPR-9054
2012-07-10 17:12:06 -04:00
Rossen Stoyanchev cf147a82ef Fix issue with incorrect class import
Issue: SPR-9112
2012-07-09 20:34:05 -04:00
Rossen Stoyanchev c846198e46 Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.

The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.

When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).

Issue: SPR-9112
2012-07-09 17:27:03 -04:00
Juergen Hoeller d97a4b5b3c polishing 2012-07-05 00:31:51 +02:00
Rossen Stoyanchev e870c9a392 Reduce logging in HandlerExecutionChain
Before this change the HandlerExecitionChain logged errors each time a
an AsyncHandlerInterceptor returned a null async Callable, a condition
which is acceptable.

SPR-9524
2012-07-02 17:56:39 -04:00
Chris Beams dc822cdca0 Reflect 3.2=>3.1.2 backports in @since tags etc
Issue: SPR-9443, SPR-6847, SPR-9446, SPR-9444, SPR-9439, SPR-9302,
       SPR-9507, SPR-9238, SPR-9397, SPR-9406, SPR-9502
2012-06-27 23:07:48 +02:00
Rossen Stoyanchev 7dff02b2c1 Fix import issue introduced in prior commit
Issue: SPR-9289
2012-06-26 18:07:12 -04:00
Rossen Stoyanchev 3f5fa44d32 Polish PathVariableMapMethodArgumentResolver
Return an empty map when there are no path variables, rather than
raising an exception. This is consistent with similar resolvers for
extracting headers and request parameters.

Issue: SPR-9289
2012-06-26 10:23:01 -04:00
Rossen Stoyanchev 4fd7645efd Enable smart suffix pattern match for request mapping
Following the introduction of ContentNegotiationManager that allows,
among other things, to configure the file extensions to use for content
negotiation, this change adds "smart" suffix pattern match that matches
against the configured file extensions only rather than against any
extension.

Given the request mapping "/jobs/{jobName}" and one configured file
extension ("json"), a request for "/jobs/my.job" will select the
pattern "/jobs/{jobName}" while a request for "/jobs/my.job.json" will
select the pattern "/jobs/{jobName}.json". Previously, both requests
would have resulted in the pattern "/jobs/{jobName}.*".

Issue: SPR-7632, SPR-8474
2012-06-25 21:30:10 -04:00
Rossen Stoyanchev f94aed8386 Polish ContentNegotiationStrategy support
Issue: SPR-8410, SPR-8417, SPR-8418,SPR-8416, SPR-8419,SPR-7722
2012-06-25 15:24:05 -04:00
Rossen Stoyanchev a0747458e7 Add support for HTTP PATCH method
The HTTP PATCH method is now supported whereever HTTP methods are used.
Annotated controllers can be mapped to RequestMethod.PATCH.

On the client side the RestTemplate execute(..) and exchange(..)
methods can be used with HttpMethod.PATCH. In terms of HTTP client
libraries, Apache HttpComponents HttpClient version 4.2 or later is
required (see HTTPCLIENT-1191). The JDK HttpURLConnection does not
support the HTTP PATCH method.

Issue: SPR-7985
2012-06-22 16:57:22 -04:00
Rossen Stoyanchev f05e2bc56f Add abstractions for content negotiation
Introduced ContentNeogtiationStrategy for resolving the requested
media types from an incoming request. The available implementations
are based on path extension, request parameter, 'Accept' header,
and a fixed default content type. The logic for these implementations
is based on equivalent options, previously available only in the
ContentNegotiatingViewResolver.

Also in this commit is ContentNegotiationManager, the central class to
use when configuring content negotiation options. It accepts one or
more ContentNeogtiationStrategy instances and delegates to them.

The ContentNeogiationManager can now be used to configure the
following classes:

- RequestMappingHandlerMappingm
- RequestMappingHandlerAdapter
- ExceptionHandlerExceptionResolver
- ContentNegotiatingViewResolver

Issue: SPR-8410, SPR-8417, SPR-8418,SPR-8416, SPR-8419,SPR-7722
2012-06-22 11:55:46 -04:00
Chris Beams 2a2b6eef91 Introduce ConfigurableWebEnvironment
Changes introduced in Spring 3.1 for Environment support inadvertently
established a cyclic dependency between the
org.springframework.web.context and
org.springframework.web.context.support packages, specifically through
web.context.ContextLoader's invocation of
web.context.support.WebApplicationContextUtils#initServletPropertySources.

This commit introduces ConfigurableWebEnvironment to break this cyclic
dependency. All web.context.ConfigurableWebApplicationContext types now
return web.context.ConfigurableWebEnvironment from their #getEnvironment
methods; web.context.support.StandardServletEnvironment now implements
ConfigurableWebEnvironment and makes the call to
web.context.support.WebApplicationContextUtils#initServletPropertySources
within its implementation of #initPropertySources. This means that
web.context.ContextLoader now invokes
web.context.ConfigurableWebEnvironment#initPropertySources instead of
web.context.support.WebApplicationContextUtils#initServletPropertySources
and thus the cycle is broken.

Issue: SPR-9439
2012-05-26 14:35:57 +03:00
Chris Beams 9fcfd7e827 Introduce ConfigurableEnvironment#merge
Prior to this change, AbstractApplicationContext#setParent replaced the
child context's Environment with the parent's Environment if available.
This has the negative effect of potentially changing the type of the
child context's Environment, and in any case causes property sources
added directly against the child environment to be ignored. This
situation could easily occur if a WebApplicationContext child had a
non-web ApplicationContext set as its parent. In this case the parent
Environment type would (likely) be StandardEnvironment, while the child
Environment type would (likely) be StandardServletEnvironment. By
directly inheriting the parent environment, critical property sources
such as ServletContextPropertySource are lost entirely.

This commit introduces the concept of merging an environment through
the new ConfigurableEnvironment#merge method. Instead of replacing the
child's environment with the parent's,
AbstractApplicationContext#setParent now merges property sources as
well as active and default profile names from the parent into the
child. In this way, distinct environment objects are maintained with
specific types and property sources preserved. See #merge Javadoc for
additional details.

Issue: SPR-9444, SPR-9439
2012-05-26 14:33:53 +03:00
Chris Beams 5874383ef0 Polish
Issue: SPR-9439
2012-05-26 14:33:52 +03:00
Rossen Stoyanchev 4027b38903 Merge rather than add URI vars to data binding values
As of Spring 3.1 URI variables can be used for data binding purposes in
addition to request parameters (including query string and form params)

In some cases URI variables and request params can overlap (e.g. form
contains a child entity with an entityId as hidden form input while the
URI contains the entityId of the parent entity) and that can lead to
surprises if the application already exists.

This change ensures that request parameters are used first and URI
vars are added only if they don't overlap. Ideally however an
application should not use the same uri variable name as the name of
a request parameter where they don't refer to the same value.

Issue: SPR-9349
2012-05-23 18:50:43 -04:00
Arjen Poutsma f64c13ad2e Add convenient WebAppInitializer base classes
This commit introduces three abstract WebApplicationInitializers, to be
used in the typical setup of a Spring-based web application.

 - AbstractContextLoaderInitializer provides an abstract base class for
   registering a ContextLoaderListener.

 - AbstractDispatcherServletInitializer provides an abstract base class
   for registering a DispatcherServlet, with an optional root context.

 - AbstractAnnotationConfigDispatcherServletInitializer provides an
   abstract base class for registering a DispatcherServlet and optional
   ContextLoaderListener based on annotated (e.g. @Configuration)
   classes.

Issue: SPR-9300
2012-05-22 17:31:55 +03:00
Chris Beams f3bcb6e2e4 Update spring.schemas to reflect 3.2 schemas
Commit 180c5b2ef6 introduced 3.2 versions
of all spring-* schemas; this commit updates spring.schemas mapping
files to include these new versions.
2012-05-18 14:31:33 +03:00
Sam Brannen 09d98fd3ae Delete superfluous fail() invocations in RequestResponseBodyMethodProcessorTests
Several test methods in RequestResponseBodyMethodProcessorTests
are currently annotated with @Test(expected=…) and additionally contain:

    fail("Expected exception");

This combination is superfluous, and the unnecessary fail() invocations
have therefore been removed.
2012-05-18 03:10:13 +02:00
Rossen Stoyanchev 77ae101402 Add required flag to @RequestBody
If true and there is no body => HttpMessageNotReadableException
If false and there is no body, the argument resolves to null.

Issue: SPR-9239
2012-05-17 17:48:48 -04:00
Rossen Stoyanchev 0105c5ebb9 Decode path vars in pre-3.1 `@MVC` support clases too
See the commit comments for:
57307a0b2e

This commit also applies the change to pre-3.1 `@MVC` suppor classes.

Issue: SPR-6951
2012-05-17 16:35:55 -04:00
Rossen Stoyanchev 57307a0b2e Decode path vars when url decoding is turned off
When URL decoding is turned off in AbstractHandlerMapping, the
extracted path variables are also not encoded. Turning off URL decoding
may be necessary for request mapping to work correctly when the path
may contain the (encoded) special character '/'. At the same time there
is no good reason not to leave path variables encoded. This change
ensures path variables are encoded when URL decoding is turned off.

Issue: SPR-9098
2012-05-17 16:01:20 -04:00
Rossen Stoyanchev cf5d55173b Pattern suffix issue in AnnotationMethodHandlerAdapter
SPR-9333
2012-05-16 13:22:50 -04:00
Rossen Stoyanchev 01a9dd9772 Add option to set Content-Length in JSON Views
MappingJackson2JsonView and MappingJacksonJsonView now provide an
option that will set the Content-Length header of JSON responses.
Use of the option implies buffering of the response and it must be
enabled explicitly.

Issue: SPR-7866
2012-05-15 18:10:24 -04:00
Rossen Stoyanchev 2af294ab26 Add MessageCodesResolver hook to WebMvcConfigurer
This change makes it possible to provide a custom MessageCodesResolver
through the MVC Java config whether using @EnableWebMvc and extending
WebMVcConfigurerAdapter or sub-classing directly from
WebMvcConfigurationSupport.

Issue: SPR-9223
2012-05-15 17:11:28 -04:00
Rossen Stoyanchev bdc3599d3d Add CompositeRequestCondition
The new type makes it easier providing multiple custom request mapping
conditions via setters on RequestMappingHandlerMapping.

Issue: SPR-9350
2012-05-15 13:16:06 -04:00
Rossen Stoyanchev fbb2103e4d Add "excludedExceptions" to SimpleUrlHandlerMapping
The new property can be used to ignore specific exceptions that may
otherwise be matched by the "exceptionMappings" property or resolved
through the defaultErrorView.

Issue: SPR-5193
2012-05-15 13:16:06 -04:00
Rossen Stoyanchev 1d0e484eac Support access to all URI vars via @PathVariable Map
Issue: SPR-9289
2012-05-14 16:01:16 -04:00
Rossen Stoyanchev 59084354e2 Add validation of HTTP method in form tag
SPR-6945
2012-05-14 11:38:58 -04:00
Rossen Stoyanchev d52fc3bd2f Prevent response updates if @ResponseStatus has reason
When @ResponseStatus has a reason and servletResponse.sendError() is
called, the response is committed and should no longer be written to.
After this change, the ServletInvocableHandlerMethod will mark the
response fully handled and will ignore any non-null return values.

Issue: SPR-9159
2012-05-11 17:41:14 -04:00
Rossen Stoyanchev c57d4e2386 Add trySet method to DeferredResult
The method absorbs any potential StaleAsyncWebRequestException and
returns false instead.

Issue: SPR-8517
2012-05-11 16:07:56 -04:00
Rossen Stoyanchev 982cb2f258 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
2012-05-11 14:43:58 -04:00
Rossen Stoyanchev d7efc0db80 Detect controller methods via InitializingBean hook
Previously RequestMappingHandlerMapping detected @RequestMapping
methods through an initApplicationContext() hook. However, the
HandlerMapping may not have been fully set up with all its
dependencies at that point including settings like useSuffixPattern
and others.

This change moves the detection @RequestMapping methods to an
InitializingBean.afterPropertiesSet() hook.

Issue: SPR-9371
2012-05-10 16:42:36 -04:00
Rossen Stoyanchev f61f4a960e Discover controllers based on type @RequestMapping
This was supported in DefaultAnnotationHandlerMapping but not in the
RequestMappingHandlerMapping. The specific scenario where this matters
is a controller decorated with a JDK proxy. In this scenario the
HandlerMapping looks at interfaces only to decide if the bean is a
controller. The @Controller annotation is better left (and required)
on the class.

Issue: SPR-9374
2012-05-10 16:19:14 -04:00
Rossen Stoyanchev e04b322110 Don't decode URI for content negotiation by extension
Minor bug fix in the ContentNegotiatingViewResolver where decoding the
URI prevented proper detection of the file extension in a URL.

Issue: SPR-9390
2012-05-10 15:00:01 -04:00
Rossen Stoyanchev db289495e5 Pretty print option for Jackson converter and view
Jackson serialization supports pretty printing. Usually it's enabled
by invoking ObjectMapper.configure(..), which is not convenient for
apps with XML configuration. The Jackson HttpMessageConverter and View
now both have a prettyPrint property.

A second more serious issue is documented here:
https://github.com/FasterXML/jackson-databind/issues/12

The workaround discussed at the above link has been implemented.

Issue: SPR-7201
2012-05-09 16:29:22 -04:00
Rossen Stoyanchev e63ca04fdb 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
2012-05-09 13:07:25 -04:00
Rossen Stoyanchev e7506b50b2 HanderInterceptor and OSIV async request changes
This change updates Open-Session-in-View filters and interceptors for
use in async requests mainly ensuring the open Hibernate session is
unbound from the main request processing thread and bound to the to
async thread.

Issue: SPR-8517
2012-05-04 16:12:14 -04:00
Rossen Stoyanchev 1eaaa9a446 Add empty location check to ResourceHttpRequestHandler
ResourceHttpRequestHandler now implements InitializingBean and
checks for empty locations.

Issue: SPR-9186
2012-05-01 17:08:19 -04:00
Stevo Slavic effb762558 Fix javadoc warnings
Before this change there were numerous javadoc warnings being reported
while building Spring framework API.

This commit resolves most of the javadoc warnings, reducing the total
number from 265 to 103.

Issue: SPR-9113
2012-04-30 11:31:02 +03:00
Rossen Stoyanchev f37efb4279 Polish Servlet async request processing
* Clarify semantics and behavior of AsyncWebRequest methods in most cases
making a best effort and not raising an exception if async processing
has completed for example due to a timeout. The startAsync() method is
still protected with various checks and will raise ISE under a number
of conditions.
* Return 503 (service unavailable) when requests time out.
* Logging improvements.

Issue: SPR-8517
2012-04-23 12:50:45 -04:00
Rossen Stoyanchev 3642b0f365 Initial cut of Servlet 3.0 based async support
From a programming model perspective, @RequestMapping methods now
support two new return value types:

* java.util.concurrent.Callable - used by Spring MVC to obtain the
return value asynchronously in a separate thread managed transparently
by Spring MVC on behalf of the application.
* org.springframework.web.context.request.async.DeferredResult - used
by the application to produce the return value asynchronously in a
separate thread of its own choosing.

The high-level idea is that whatever value a controller normally
returns, it can now provide it asynchronously, through a Callable or
through a DeferredResult, with all remaining processing --
@ResponseBody, view resolution, etc, working just the same but
completed outside the main request thread.

From an SPI perspective, there are several new types:

* AsyncExecutionChain - the central class for managing async request
processing through a sequence of Callable instances each representing
work required to complete request processing asynchronously.
* AsyncWebRequest - provides methods for starting, completing, and
configuring async request processing.
* StandardServletAsyncWebRequest - Servlet 3 based implementation.
* AsyncExecutionChainRunnable - the Runnable used for async request
execution.

All spring-web and spring-webmvc Filter implementations have been
updated to participate in async request execution.
The open-session-in-view Filter and interceptors implementations in
spring-orm will be updated in a separate pull request.

Issue: SPR-8517
2012-04-18 16:36:09 -04:00
Rossen Stoyanchev cfe2af7690 Use the type of the actual return value in @MVC
The new @MVC support classes select a HandlerMethodArgumentResolver
and a HandlerMethodReturnValueHandler statically, i.e. based on
the signature of the method, which means that a controller method
can't declare a more general return type like Object but actually
return a more specific one, e.g.  String vs RedirectView, and
expect the right handler to be used.

The fix ensures that a HandlerMethodReturnValueHandler is selected
based on the actual return value type, which is something that was
supported with the old @MVC support classes. One consequence
of the change is the selected HandlerMethodReturnValueHandler can
no longer be cached but that matches the behavior of the old
@MVC support classes.

Issues: SPR-9218
2012-04-06 16:50:22 -04:00
Rossen Stoyanchev 97c22fc08e Minor improvement in ExceptionHandlerExceptionResolver
Moved a null check inside a protected method to give protected method
a chance to override what happens in that case.

Issues: SPR-9193
2012-04-06 14:06:23 -04:00
Rossen Stoyanchev ca8b98e947 Fix issue with parsing media types
Invalid Content-Type or Accept header values previously resulted in the
IllegalArgumentException getting propagated. After this change such
errors are detected and generally treated as a "no match", which
may for example result in a 406 in the case of the Accept header.

Issue: SPR-9148
2012-04-02 17:36:23 -04:00
Rossen Stoyanchev 0b02933938 Fix race condition in AnntationMethodHER
Issues: SPR-9138
2012-04-02 15:46:31 -04:00
Rossen Stoyanchev 64ee5e579a Fix bug with custom RequestCondition
A custom RequestCondition which can be provided by overriding methods
in RequestMappingHandlerMapping worked only for conditions that match
and did not return null (as it should have) for conditions that don't
match.

Issues: SPR-9134
2012-04-02 15:19:38 -04:00
Chris Beams 180c5b2ef6 Introduce 3.2 versions of Spring XML namespaces
Copy spring-*-3.1.xsd => spring-*-3.2.xsd; this commit introduces no
substantive changes, but rather prepares for them by creating a clean
baseline. All internal references to 3.1 schemas (e.g. spring-tool) have
also been updated.
2012-03-26 20:06:06 +03:00
Stevo Slavic a9f4206151 Generate bracketless tag id in FreeMarker forms
Before this change if FreeMarker Spring form macro was bound to a path
which contains square brackets, those brackets would also appear in id
of generated tag, making the id invalid.

As of this fix all FreeMarker Spring form macros generate tag with id
that does not contain square brackets.

Issue: SPR-8732
2012-03-04 22:02:38 +01:00
Chris Beams 3e81482760 Sync with 3.1.x
* 3.1.x:
  Demonstrate use of @Configuration as meta-annotation
  Prune dead code from JmsTransactionManager#doBegin
  Apply @Configuration BeanNameGenerator consistently
  Improve @Configuration bean name discovery
  Fix infinite recursion bug in nested @Configuration
  Polish static imports
  Minor fix in ServletResponseMethodArgumentResolver
  extracted ResourceUtils.useCachesIfNecessary(URLConnection) method (SP
  prepared for 3.1.1 release
  CustomSQLExceptionTranslatorRegistry/Registrar etc
  revised CustomSQLExceptionTranslatorRegistry/Registrar method naming
  use custom InputStream traversal instead of a full byte array (SPR-911
  PathMatchingResourcePatternResolver preserves caching for JNLP jar con
  Resource "contentLength()" implementations work with OSGi bundle resou
  fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz
  fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz
2012-02-16 13:00:28 +01:00
Chris Beams ee36c80ca9 Sync with 3.1.x
* 3.1.x: (61 commits)
  Compensate for changes in JDK 7 Introspector
  Avoid 'type mismatch' errors in ExtendedBeanInfo
  Polish ExtendedBeanInfo and tests
  Infer AnnotationAttributes method return types
  Minor fix in MVC reference doc chapter
  Hibernate 4.1 etc
  TypeDescriptor equals implementation accepts annotations in any order
  "setBasenames" uses varargs now (for programmatic setup; SPR-9106)
  @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992
  polishing
  clarified Resource's "getFilename" method to consistently return null
  substituteNamedParameters detects and unwraps SqlParameterValue object
  Replace spaces with tabs
  Consider security in ClassUtils#getMostSpecificMethod
  Adding null check for username being null.
  Improvements for registering custom SQL exception translators in app c
  SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera
  Minor polish in WebMvcConfigurationSupport
  Detect overridden boolean getters in ExtendedBeanInfo
  Polish ExtendedBeanInfoTests
  ...
2012-02-13 15:17:30 +01:00
Chris Beams 0ae973f995 Merge branch '3.1.x'
Conflicts:
	spring-webmvc/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java
	spring-webmvc/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java
2012-02-01 11:39:48 +01:00
Chris Beams 398cf997b3 Merge branch '3.1.x'
This is the first merge from 3.1.x => master after the Gradle build
system migration. Notice how files changed under the 3.1.x directory
structure (org.springframework.*) merge seamlessly into the new
directory structure (spring-*).

Certain files had changed under 3.1.x that have since been deleted with
the Gradle build migration, e.g. all pom.xml files had <license>
sections added. These files showed up as a conflict during the merge,
but the resolution is to simply re-remove them and commit as they are
no longer relevant under 3.2.x / master.

Also noteworthy is the .gitignore file. It has been updated under 3.1.x
to ignore files and directories specific to the new Gradle-based
structure. However, this causes conflicts when trying to merge against
master, given that master should *not* ignore this directories. The
resolution in this situation is to simply force the 'master' version of
the file, i.e. when prompted for merge resolution:

    anakata:~/Work/spring-framework/spring-framework[master|MERGING]
    $ git status -sb
    ## master...springsource/master [ahead 24]
    UU .gitignore

    anakata:~/Work/spring-framework/spring-framework[master|MERGING]
    $ git checkout master .gitignore

    anakata:~/Work/spring-framework/spring-framework[master|MERGING]
    $ git commit

It is helpful in situations like this one to enable git's "rerere"
feature beforehand, which records and remembers resolution strategies,
avoiding the need to repeat them in future merges:

    $ git config --global rerere.enabled 1

See:
    http://progit.org/2010/03/08/rerere.html
    http://gitfu.wordpress.com/2008/04/20/git-rerere-rereremember-what-you-did-last-time

Conflicts:
    .gitignore
    .springframework.*/pom.xml
2012-01-31 16:03:24 +01:00
Chris Beams 6235a341a7 Remove bundlor support 2012-01-31 14:37:11 +01:00
Chris Beams 02a4473c62 Rename modules {org.springframework.*=>spring-*}
This renaming more intuitively expresses the relationship between
subprojects and the JAR artifacts they produce.

Tracking history across these renames is possible, but it requires
use of the --follow flag to `git log`, for example

    $ git log spring-aop/src/main/java/org/springframework/aop/Advisor.java

will show history up until the renaming event, where

    $ git log --follow spring-aop/src/main/java/org/springframework/aop/Advisor.java

will show history for all changes to the file, before and after the
renaming.

See http://chrisbeams.com/git-diff-across-renamed-directories
2012-01-31 14:37:10 +01:00