road to grails 3.0
DESCRIPTION
Speaker: Graeme Rocher In this talk Grails project lead, Graeme Rocher, will talk through the latest and greatest happenings in the world of Grails including a walk through of the features included Grails 2.3 and upcoming in Grails 3.0TRANSCRIPT
![Page 1: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/1.jpg)
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Road to Grails 3.0By Graeme Rocher
Friday, September 13, 13
![Page 2: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/2.jpg)
Agenda
§What’s new in Grails 2.3?§What’s planned for Grails 3.0?§Summary / Q & A
Friday, September 13, 13
![Page 3: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/3.jpg)
S P R I N G I O E X E C U T I O N :
Grails
Friday, September 13, 13
![Page 4: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/4.jpg)
What’s new in Grails 2.3?
• Forked Execution and Test Daemon• Dependency Resolution with Aether• Complete Server-Side REST Support• Async Programmings APIs• New Data Binding APIs
4
2.3
Friday, September 13, 13
![Page 5: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/5.jpg)
What’s new in Grails 2.3?
• XSS Prevention• Hibernate 4 Support (via Plugin)• RESTful Scaffolding v2.0• Controller Namespaces• ... and much, much more
5
2.3
Friday, September 13, 13
![Page 6: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/6.jpg)
G R A I L S
DemoAether & Forked Execution
Friday, September 13, 13
![Page 7: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/7.jpg)
Aether & Dependency Management• Aether == Same dependency
resolution engine as Maven– No snapshot troubles– Same local repo– No Ivy bugs
• New dependency-report command to visualize graph
7Friday, September 13, 13
![Page 8: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/8.jpg)
Forked Execution• Build and test / runtime split
into separate JVMs• Daemon used to speed test
execution• Correctly isolates classpaths• test-app can’t break run-app!
8Friday, September 13, 13
![Page 9: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/9.jpg)
G R A I L S
DemoREST Support
Friday, September 13, 13
![Page 10: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/10.jpg)
REST: URL Mappings• RESTful Mappings
– Single or Multiple resources– Versioning– Nested resources
• New url-mappings-report command to mappings
10Friday, September 13, 13
![Page 11: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/11.jpg)
REST: @Resource Transformation• Automatically exposes a
domain class as a REST resource
• Configurable formats• Configuration HTTP
methods
11Friday, September 13, 13
![Page 12: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/12.jpg)
REST: @Resource Transformation• Automatically exposes a
domain class as a REST resource
• Configurable formats• Configuration HTTP
methods
11
import grails.rest.*
@Resourceclass Person { String name}
Friday, September 13, 13
![Page 13: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/13.jpg)
REST: The respond method• Sends the most
appropriate response for the given object
• For HTML calculates a model by convention and delegates to view
12Friday, September 13, 13
![Page 14: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/14.jpg)
REST: The respond method• Sends the most
appropriate response for the given object
• For HTML calculates a model by convention and delegates to view
12
class PersonController {
def index() {respond Book.list()
}}
Friday, September 13, 13
![Page 15: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/15.jpg)
REST: HAL, JSON, XML Renderers• Rendering customizable
in resources.groovy• HAL, Atom, Vnd.Error
renders included• Flexible and complete
13Friday, September 13, 13
![Page 16: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/16.jpg)
REST: HAL, JSON, XML Renderers• Rendering customizable
in resources.groovy• HAL, Atom, Vnd.Error
renders included• Flexible and complete
13
import grails.rest.render.hal.*beans = { halBookRenderer(HalJsonRenderer, rest.test.Book)}
Friday, September 13, 13
![Page 17: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/17.jpg)
REST: HAL, JSON, XML Renderers• Rendering customizable
in resources.groovy• HAL, Atom, Vnd.Error
renders included• Flexible and complete
13
import grails.rest.render.hal.*beans = { halBookRenderer(HalJsonRenderer, rest.test.Book)}
import grails.rest.render.xml.*beans = { bookRenderer(XmlRenderer, Book) { includes = ['title'] }}
Friday, September 13, 13
![Page 18: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/18.jpg)
REST: Scaffolding 2.0• Scaffolding support now a plugin
– http://grails.org/plugin/scaffolding• Generated controllers now
RESTful• New generate-async-controller command for Async support
14Friday, September 13, 13
![Page 19: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/19.jpg)
REST: Misc Goodies• grails.rest.RestfulController
– Controller base class for inheriting RESTful actions• The respond method
– Chooses most appropriate response format• Versioning support via URL mapping or Accept-Version
header• Find out more http://grails.org/doc/2.3.x/guide/
webServices.html#REST
15Friday, September 13, 13
![Page 20: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/20.jpg)
G R A I L S
DemoAsync
Friday, September 13, 13
![Page 21: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/21.jpg)
Async: Promise Primitives• Foundational API for Async
programming• Includes notion of Promise• Ability to combine / chain
promises
17Friday, September 13, 13
![Page 22: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/22.jpg)
Async: Promise Primitives• Foundational API for Async
programming• Includes notion of Promise• Ability to combine / chain
promises
17
import static grails.async.Promises.*
def p1 = task { 2 * 2 }def p2 = task { 4 * 4 }def p3 = task { 8 * 8 }assert [ 4, 16, 64 ] == waitAll(p1, p2, p3)
Friday, September 13, 13
![Page 23: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/23.jpg)
Async: @DelegateAsync Transform• Transform any synchronous
API into an asynchronous one
• Takes each method and returns a promise
18Friday, September 13, 13
![Page 24: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/24.jpg)
Async: @DelegateAsync Transform• Transform any synchronous
API into an asynchronous one
• Takes each method and returns a promise
18
import grails.async.*
class AsyncBookService { @DelegateAsync BookService bookService}
Friday, September 13, 13
![Page 25: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/25.jpg)
Async: GORM• Makes all GORM methods
async• Deals with binding session
to background thread• Works across all
datastores (MongoDB, GORM for REST etc.)
19Friday, September 13, 13
![Page 26: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/26.jpg)
Async: GORM• Makes all GORM methods
async• Deals with binding session
to background thread• Works across all
datastores (MongoDB, GORM for REST etc.)
19
def p1 = Person.async.get(1)def p2 = Person.async.get(2)def p3 = Person.async.get(3)
def results = waitAll(p1, p2, p3)
Friday, September 13, 13
![Page 27: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/27.jpg)
Async: Request Processing• Handle requests
asynchronously• Uses Servlet 3.0 async
under the covers• Create asynchronous
models
20Friday, September 13, 13
![Page 28: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/28.jpg)
Async: Request Processing• Handle requests
asynchronously• Uses Servlet 3.0 async
under the covers• Create asynchronous
models
20
import static grails.async.Promises.*
class PersonController { def index() { tasks books: Book.async.list(), total: Book.async.count(), otherValue: { // do hard work } }}
Friday, September 13, 13
![Page 29: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/29.jpg)
G R A I L S
DemoData Binding
Friday, September 13, 13
![Page 30: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/30.jpg)
Data Binder: @BindingFormat • Per property formatting• Extensible
22Friday, September 13, 13
![Page 31: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/31.jpg)
Data Binder: @BindingFormat • Per property formatting• Extensible
22
class Person { @BindingFormat('MMddyyyy') Date birthDate @BindingFormat('Uppercase') String salutation}
Friday, September 13, 13
![Page 32: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/32.jpg)
Data Binder: @BindUsing • For cases where more
flexibility is needed• Can be applied to class
or property• Takes a closure or a class
that implements BindingHelper
23Friday, September 13, 13
![Page 33: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/33.jpg)
Data Binder: @BindUsing • For cases where more
flexibility is needed• Can be applied to class
or property• Takes a closure or a class
that implements BindingHelper
23
class Person { @BindUsing({ obj, source -‐> source['name']? .toUpperCase() }) String salutation}
Friday, September 13, 13
![Page 34: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/34.jpg)
Data Binding: XML/JSON Command Objects• Can now bind XML/JSON
data to command objects• Binding can be customized
using the BindingSource and BindingSourceCreator interfaces
24Friday, September 13, 13
![Page 35: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/35.jpg)
Data Binding: XML/JSON Command Objects• Can now bind XML/JSON
data to command objects• Binding can be customized
using the BindingSource and BindingSourceCreator interfaces
24
class PersonController { def save(PersonCmd p) { ... }}
Friday, September 13, 13
![Page 36: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/36.jpg)
Data Binding: Auto Query if Domain Object• If command object is a
domain class query on id• Passes null if domain class
not found• If found binds XML, JSON
or params
25Friday, September 13, 13
![Page 37: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/37.jpg)
Data Binding: Auto Query if Domain Object• If command object is a
domain class query on id• Passes null if domain class
not found• If found binds XML, JSON
or params
25
class PersonController { def save(Person p) { ... }}
Friday, September 13, 13
![Page 38: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/38.jpg)
G R A I L S
DemoXSS Prevention
Friday, September 13, 13
![Page 39: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/39.jpg)
XSS Prevention• All GSP expressions and scriptlets now escaped by
default• Double-encoding prevention • New raw method to mark data as safe
27Friday, September 13, 13
![Page 40: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/40.jpg)
XSS Prevention• All GSP expressions and scriptlets now escaped by
default• Double-encoding prevention • New raw method to mark data as safe
27
// Inside GSP<section>${raw(page.content)}</section>
Friday, September 13, 13
![Page 41: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/41.jpg)
Other Goodies: Hibernate 4 Support• Hibernate 3 and 4 binary incompatible, so new plugin• Not all plugins that work with Hibernate 3 will work with
Hibernate 4
28Friday, September 13, 13
![Page 42: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/42.jpg)
Other Goodies: Hibernate 4 Support• Hibernate 3 and 4 binary incompatible, so new plugin• Not all plugins that work with Hibernate 3 will work with
Hibernate 4
28
// add to BuildConfigcompile ':hibernate::hibernate4:4.1.11.1'
Friday, September 13, 13
![Page 43: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/43.jpg)
Other Goodies: @Transactional Transform• Can be applied to any class• No proxies required!• Works with controllers• Replacement for Spring’s
@Transactional annotation
29Friday, September 13, 13
![Page 44: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/44.jpg)
Other Goodies: @Transactional Transform• Can be applied to any class• No proxies required!• Works with controllers• Replacement for Spring’s
@Transactional annotation
29
import grails.transactions.*
@Transactionalclass PersonService {
...}
Friday, September 13, 13
![Page 45: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/45.jpg)
Other Goodies: @DirtyCheck Transform• Can be applied to any class
to add dirty checking• Tracks calls to setters that
modify state• Classes implement the DirtyCheckable interface
30Friday, September 13, 13
![Page 46: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/46.jpg)
Other Goodies: @DirtyCheck Transform• Can be applied to any class
to add dirty checking• Tracks calls to setters that
modify state• Classes implement the DirtyCheckable interface
30
@DirtyCheckclass Person {
...}def p = new Person(name:'Bob')p.trackChanges()assert !p.hasChanged()p.name = 'Fred'assert p.hasChanged()
Friday, September 13, 13
![Page 47: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/47.jpg)
Other Goodies: Action Error Handlers• Actions that define an exception as the first argument get
invoked if the exception is thrown from any other action
31Friday, September 13, 13
![Page 48: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/48.jpg)
Other Goodies: Action Error Handlers• Actions that define an exception as the first argument get
invoked if the exception is thrown from any other action
31
class PersonController { ... def tooOld(TooOldException e) { render view: 'tooOld' }}
Friday, September 13, 13
![Page 49: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/49.jpg)
Other Goodies: Controller Namespaces• Controllers can now define a namespace• URL Mappings can map to a specific namespace
32Friday, September 13, 13
![Page 50: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/50.jpg)
Other Goodies: Controller Namespaces• Controllers can now define a namespace• URL Mappings can map to a specific namespace
32
class PersonController { ... static namespace = 'admins' }
Friday, September 13, 13
![Page 51: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/51.jpg)
Q & AGrails 2.3
2.3
Friday, September 13, 13
![Page 52: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/52.jpg)
The FutureGrails 3.0
3.0
Friday, September 13, 13
![Page 53: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/53.jpg)
Grails 3.0: Goals
• Embrace Gradle• Abstract Packaging / Deployment• Reach outside the Servlet Container• App Profiles: Netty, Servlet, Batch, Hadoop• Deployment with run-app• Extend the reach of Grails
35
3.03.0
Friday, September 13, 13
![Page 54: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/54.jpg)
Grails 3.0: Gradle
• Deprecate existing build system• Replace with Gradle build• Easier now everything is forked in 2.3.x• All the flexibility of a powerful build
system• Legacy bridge layer for running old
36Friday, September 13, 13
![Page 55: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/55.jpg)
Grails 3.0: App Profiles
• Each profile will have distinct plugins, runtimes and packaging (JAR, WAR etc.)
37Friday, September 13, 13
![Page 56: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/56.jpg)
Grails 3.0: App Profiles
• Each profile will have distinct plugins, runtimes and packaging (JAR, WAR etc.)
37
$ grails create-‐app myapp -‐-‐profile=netty $ cd myapp$ grails package$ java -‐jar target/myapp.jar
Friday, September 13, 13
![Page 57: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/57.jpg)
Grails 3.0: Challenges
• Compatibility– Plugins– Build System
• Modularization– Servlet API independence– Refactoring
38
3.0
Friday, September 13, 13
![Page 58: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/58.jpg)
Q & AGrails 3.0
3.0
Friday, September 13, 13
![Page 59: Road to Grails 3.0](https://reader035.vdocuments.us/reader035/viewer/2022081400/554f742db4c9058a148b54ea/html5/thumbnails/59.jpg)
Learn More. Stay Connected.
Also by me“RESTfully Async with Grails 2.3” - Wednesday 2:30pmWeb: grails.orgTwitter: twitter.com/grailsframeworkLinkedIn: http://linkedin.com/groups/Grails-User-Group-39757 Google +: https://plus.google.com/communities/109558563916416343008
Friday, September 13, 13