[BLOSSOM-167] Support Spring MVC 3.1 MVC handler methods Created: 07/Feb/14  Updated: 19/Oct/15  Resolved: 11/Apr/14

Status: Closed
Project: Blossom
Component/s: None
Affects Version/s: None
Fix Version/s: 3.0.2

Type: Improvement Priority: Neutral
Reporter: Tobias Mattsson Assignee: Tobias Mattsson
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File FlashMapEnabledAnnotationMethodHandlerAdapter.java     Text File RedirectAttributesWebArgumentResolver.java    
Issue Links:
causality
is causing BLOSSOM-226 Call to annotated method @RequestMapp... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

With the release of Spring 4 the 3.2.x line went into maintenance mode and the 3.1.x line is retired.

With 3.1.x Spring Web MVC got a overhaul and many of the core classes got replacements and the old classes were deprecated. The Blossom module should be updated to use these new classes and the archetypes should be updated as well.

We should support both lines out of the box.

See http://spring.io/blog/2014/01/28/spring-framework-4-0-1-3-2-7-released-and-3-1-x-retired.

Specifically this involves:

  • BlossomHandlerMapping should no longer require AbstractUrlHandlerMapping.
  • TemplateExporter should also introspect RequestMappingInfoHandlerMapping and should not extend AbstractUrlMappedHandlerPostProcessor.
  • BlossomWebArgumentResolver can be used as is if wrapped in a ServletWebArgumentResolverAdapter but we should provide a HandlerMethodArgumentResolver implementation.


 Comments   
Comment by Tobias Mattsson [ 28/Feb/14 ]

The need for this was recently highlighted on the user list [1]. It's not possible to use flash scope in Spring 3.0.x MVC. There's no way to get RedirectAttributes to an annotated methods and the input flash map isn't put in the model before the next execution.

As a workaround you'd have to interact with the flash maps directly.

For setting flash attributes you'd do:

RequestContextUtils.getOutputFlashMap(request).put("flashMessage", "Some message");

And for picking it up after the redirect you'd do:

String flashMessage = null;
Map<String, ?> inputFlashMap = RequestContextUtils.getInputFlashMap(request);
if (inputFlashMap != null)
    flashMessage = (String) inputFlashMap.get("flashMessage");

It is possible to get it working with 3.0.x style MVC but it's kind of a hack, see the attached the files. They're configured like this:

<bean class="info.magnolia.blossom.sample.module.support.FlashMapEnabledAnnotationMethodHandlerAdapter">
  <property name="customArgumentResolvers">
    <list>
      <bean class="info.magnolia.blossom.sample.module.support.RedirectAttributesWebArgumentResolver" />
      <bean class="info.magnolia.module.blossom.web.BlossomWebArgumentResolver" />
    </list>
  </property>
</bean>

[1] http://forum.magnolia-cms.com/forum/thread.html?threadId=a4a17380-52b0-4ec0-9754-b01aee949c66

Comment by Tobias Mattsson [ 11/Apr/14 ]

Here's how to use the new classes:

  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="customArgumentResolvers">
      <list>
        <bean class="info.magnolia.module.blossom.web.BlossomHandlerMethodArgumentResolver" />
      </list>
    </property>
    <!-- For @Valid - JSR-303 Bean Validation API -->
    <property name="webBindingInitializer">
      <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
        <property name="validator">
          <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
        </property>
      </bean>
    </property>
  </bean>

  <bean class="info.magnolia.module.blossom.preexecution.BlossomHandlerMapping">
    <property name="targetHandlerMappings">
      <list>
        <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
          <property name="useSuffixPatternMatch" value="false" />
        </bean>
        <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
      </list>
    </property>
  </bean>
Comment by Jan Haderka [ 06/Dec/14 ]

Bulk close of old resolved tickets.

Generated at Sun Feb 11 23:30:48 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.