Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jürgen Höller on Conversation Management wit Sp...

Jürgen Höller on Conversation Management wit Spring 3

More Decks by Enterprise Java User Group Austria

Other Decks in Technology

Transcript

  1. Bean Scoping (1) • Spring supports bean scoping since 2.0

    – "request": local servlet/portlet request – "session": local servlet/portlet session – "globalSession": shared portal session <bean class="mycompany.MyService" scope="session"/> @Scope("session") public class MyService { … }
  2. Bean Scoping (2) • Scope mechanism is extensible – custom

    "conversation" scope provided by e.g. MyFaces Orchestra – "step" scope in Spring Batch • BeanFactory's Scope SPI – registered through CustomScopeConfigurer public interface Scope { Object get(String name, ObjectFactory objectFactory); … }
  3. Spring MVC Sessions (1) • Spring MVC supports "session attributes"

    – form model attributes stored in a session – SessionAttributeStore SPI in the background @Controller @SessionAttributes("book") public class MyController { @RequestMapping("/edit") public String editBook(@ModelAttribute("book") Book book) { … } }
  4. Spring MVC Sessions (2) • MVC SessionStatus for completing a

    "conversation" @Controller @SessionAttributes("book") public class MyController { @RequestMapping("/store") public String storeBook(@ModelAttribute("book") Book book, SessionStatus sessionStatus) { … sessionStatus.setComplete(); } }
  5. Common Problems (1) • First and foremost: overuse of HttpSession

    – lots of temporary attributes stored in the session • may or may not get cleaned up • potential conflicts in attribute naming • Window isolation – HttpSession identified by cookie • shared among browser windows – UI flow is independent per browser window • e.g. opening same registration form in two windows • independent form state per window • switching back and forth between concurrent windows
  6. Common Problems (2) • Form state cleanup – model attributes

    to be removed from the session once their form has been completed • e.g. what if nobody calls sessionStatus.setComplete() – compare JSF 2.0's view scope • Short-term model state to survive redirects – "flash" scope (also called "click" scope) • actually not a true scope: rather a "flash map" – currently done through temporary storage in session • involves a window isolation problem too – compare JSF 2.0's flash scope
  7. Spring 3.1 Window Scope (1) • Introducing a general window

    scope – probably to be called "window session" – basically an isolated version of a standard session • effectively separated attributes in the HttpSession • Available for bean scoping through scope="windowSession" – as a direct alternative to scope="session" • Window-based Spring MVC session attributes – @SessionAttributes can be globally configured to point to window sessions • SessionAttributeStore backed by window scope
  8. Spring 3.1 Window Scope (2) • Problem no. 1: identifying

    a window – browser requests do not indicate originating window – checking the window name using JavaScript – detecting when a window has been cloned – on-close event to end current window's scope • Problem no. 2: propagating a window id – can't use cookies – need to pass along window id as part of the URL – decorating response.encodeURL • encoding ";window=xxx" element into path • similar to jsessionid when cookies are deactivated
  9. Spring 3.1 Conversations (1) • Introducing a general conversation scope

    – not demarcated by implicit technical concerns like the lifecycle of a browser window – instead, explicitly demarcated by the user • dedicated begin and end calls • Available for bean scoping through scope="conversation" – particularly useful in a JSF environment • where form-backing objects are usually managed beans – less important for Spring MVC • where form-backing model objects are subject to special MVC management
  10. Spring 3.1 Conversations (2) • Flexible conversation lifecycle – driven

    by the user, through API or annotations • Conversation interface • @BeginConversation, @EndConversation on methods – associating a conversation with the web request • propagating the current conversation id along with the current browser window • Conversations can be nested – similar to transactions • sub-conversations with early cleanup of sub-state – for advanced cases only • we have yet to figure out how far to go there…
  11. Spring 3.1 Flash Scope • Spring 3.1 will support a

    flash concept – for Spring MVC • programmatic flash map access • model attributes to be automatically stored in flash map in case of a redirect – transparent model exposure between forwarded view and redirect view • flash map to be cleared once it has been read in a follow-up request – for JSF • access to JSF 2.0 flash scope • probably nothing special to come from Spring – standard JSF externalContext.getFlash() sufficient
  12. Spring 3.1 View Scope • Spring 3.1 will support JSF

    2.0's view scope – for bean scoping through scope="view" • or @Scope("view") – only in JSF environments • strictly following JSF 2.0 view scope semantics • for compatibility with JSF managed bean facility • Not applicable to Spring MVC – no strong concept of a view instance and postbacks to that view in an MVC world – similar behavior achievable through session attributes and SessionStatus handling
  13. Spring 3.1 Roadmap • Spring Framework 3.1 M1 – June

    2010 – including basic window and conversation management capabilities for Spring MVC • Spring Framework 3.1 M2 – July/August 2010 – complete conversation management capabilities for Spring MVC and JSF • Spring Framework 3.1 RC1 – expected for September 2010 – depending on feedback