Greach 2014 - Road to Grails 3.0
-
Upload
graemerocher -
Category
Technology
-
view
2.200 -
download
1
description
Transcript of Greach 2014 - Road to Grails 3.0
![Page 1: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/1.jpg)
By Graeme RocherRoad to Grails 3.0
![Page 2: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/2.jpg)
Agenda
§ State of Nation § What’s new in Grails 2.3? § What’s planned for Grails 2.4? § What’s planned for Grails 3.0? § Summary / Q & A
![Page 3: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/3.jpg)
State of Nation
§ Grails 2.3.7 most recent version § One release per month § Hundreds of bugs fixed in the last 3
months § More than 1,000 plugins now for
Grails
![Page 4: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/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
![Page 5: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/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
![Page 6: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/6.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
!6
![Page 7: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/7.jpg)
REST: URL Mappings• RESTful Mappings
– Single or Multiple resources – Versioning – Nested resources
• New url-mappings-report command to mappings
!7
![Page 8: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/8.jpg)
REST: @Resource Transformation• Automatically exposes a
domain class as a REST resource
• Configurable formats • Configuration HTTP
methods
!8
import grails.rest.* !@Resource class Person { String name }
![Page 9: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/9.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
!9
class PersonController {
def index() { respond Book.list()
} }
![Page 10: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/10.jpg)
REST: HAL, JSON, XML Renderers• Rendering customizable
in resources.groovy • HAL, Atom, Vnd.Error
renders included • Flexible and complete
!10
import grails.rest.render.hal.* beans = { halBookRenderer(HalJsonRenderer, rest.test.Book) }
import grails.rest.render.xml.* beans = { bookRenderer(XmlRenderer, Book) { includes = ['title'] } }
![Page 11: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/11.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
!11
![Page 12: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/12.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
!12
![Page 13: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/13.jpg)
Async: Promise Primitives• Foundational API for Async
programming • Includes notion of Promise • Ability to combine / chain
promises
!13
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)
![Page 14: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/14.jpg)
Async: @DelegateAsync Transform• Transform any synchronous
API into an asynchronous one
• Takes each method and returns a promise
!14
!import grails.async.* !class AsyncBookService { @DelegateAsync BookService bookService }
![Page 15: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/15.jpg)
Async: GORM• Makes all GORM methods
async • Deals with binding session
to background thread • Works across all
datastores (MongoDB, GORM for REST etc.)
!15
!def p1 = Person.async.get(1) def p2 = Person.async.get(2) def p3 = Person.async.get(3) !def results = waitAll(p1, p2, p3)
![Page 16: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/16.jpg)
Async: Request Processing• Handle requests
asynchronously • Uses Servlet 3.0 async
under the covers • Create asynchronous
models
!16
import static grails.async.Promises.* !class PersonController { def index() { tasks books: Book.async.list(), total: Book.async.count(), otherValue: { // do hard work } } }
![Page 17: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/17.jpg)
Data Binder: @BindingFormat • Per property formatting • Extensible
!17
!class Person { @BindingFormat('MMddyyyy') Date birthDate @BindingFormat('Uppercase') String salutation }
![Page 18: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/18.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
!18
!class Person { @BindUsing({ obj, source -‐> source['name']? .toUpperCase() }) String salutation }
![Page 19: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/19.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
!19
!class PersonController { def save(PersonCmd p) { ... } }
![Page 20: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/20.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
!20
!class PersonController { def save(Person p) { ... } }
![Page 21: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/21.jpg)
XSS Prevention• All GSP expressions and scriptlets now escaped by
default • Double-encoding prevention • New raw method to mark data as safe
!21
!// Inside GSP <section>${raw(page.content)}</section>
![Page 22: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/22.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
!22
!// add to BuildConfig compile ‘:hibernate::hibernate4:4.3.4.2’
![Page 23: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/23.jpg)
Other Goodies: @Transactional Transform• Can be applied to any class • No proxies required! • Replacement for Spring’s
@Transactional annotation
!23
import grails.transactions.* !@Transactional class PersonService {
... }
![Page 24: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/24.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
!24
@DirtyCheck class Person {
... } def p = new Person(name:'Bob') p.trackChanges() assert !p.hasChanged() p.name = 'Fred' assert p.hasChanged()
![Page 25: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/25.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
!25
!class PersonController { ... def tooOld(TooOldException e) { render view: 'tooOld' } }
![Page 26: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/26.jpg)
Other Goodies: Controller Namespaces• Controllers can now define a namespace • URL Mappings can map to a specific namespace
!26
!class PersonController { ... static namespace = 'admins' }
![Page 27: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/27.jpg)
!Q & AGrails 2.3
2.3
![Page 28: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/28.jpg)
!The FutureGrails 2.4
2.4
![Page 29: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/29.jpg)
Grails 2.4: Goals
• Spring 4.0 Upgrade • Java 8 Support • Groovy 2.3 Upgrade • Improved @CompileStatic Support • Asset Pipeline Plugin • Moduralization of Codebase • GORM & GSP Standalone
!29
3.02.4
![Page 30: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/30.jpg)
Spring 4.0
• Native GroovyBeanDefinitionReader (ported from BeanBuilder) – https://spring.io/blog/2014/03/03/groovy-
bean-configuration-in-spring-framework-4 • Spring Web Socket
– https://github.com/zyro23/grails-spring-websocket
!30
![Page 31: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/31.jpg)
Groovy 2.3
• Traits • Java 8 • Implicit closure coercion • Lots more!
• http://groovy.codehaus.org/Roadmap
!31
![Page 32: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/32.jpg)
Asset Pipeline Plugin• Resources replaced with Asset
Pipeline – https://github.com/bertramdev/asset-
pipeline/wiki/Why-asset-pipeline-over-grails-resources-plugin
• Full documentation – http://bertramdev.github.io/asset-
pipeline/ • Many thanks to David Estes!
!32
![Page 33: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/33.jpg)
Modularization
!33
grails-web
grails-web-mvc
grails-web-sitemesh
grails-web-gsp grails-web-jsp
grails-web-servlet
grails-web-common
grails-core
grails-encoder
grails-project-api
grails-validation
![Page 34: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/34.jpg)
Standalone• GORM for Hibernate 4 in Spring Boot
– https://gist.github.com/graemerocher/d31648899fdb461609fb • GORM for MongoDB in Spring Boot
– https://gist.github.com/graemerocher/9683543 • GSP standalone coming
!34
![Page 35: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/35.jpg)
!The FutureGrails 3.0
3.0
![Page 36: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/36.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 !
!36
3.03.0
![Page 37: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/37.jpg)
Grails 3.0: Goals
• Plugin Model / Event Driven • Support Multi Project Builds • Support Micro Services • Remove Bloat • Reduce Dependencies • Discourage “Monolothic App” development
!37
3.03.0
![Page 38: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/38.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 • Plugins can provide Gradle extensions
!38
![Page 39: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/39.jpg)
Grails 3.0: App Profiles
• Each profile will have distinct plugins, runtimes and packaging (JAR, WAR etc.)
!39
!$ grails create-‐app myapp -‐-‐profile=netty $ cd myapp $ grails package $ java -‐jar target/myapp.jar !
![Page 40: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/40.jpg)
Grails 3.0 Plugin Delineation
!40
grails.sh static void main
GradleBuild Forked Grails Runtime
test-app
run-app
console
shell
Codegen Plugins Build Time Plugins
Runtime Plugins
![Page 41: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/41.jpg)
Grails 3.0 Deprecations / Removals• Servlet 2.5 support (no web.xml) • Gant & Current Build System • GDoc - Replaced by AsciiDoctor • Integration Tests - Replaced by more
Mixins • Converters / Codecs plugins -
Replaced by Groovy extensions • Filters - Replaced by new mechanism
!41
![Page 42: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/42.jpg)
Grails 3.0: Challenges
• Compatibility – Plugins – Build System
• Modularization – Servlet API independence – Refactoring
!42
3.0
![Page 43: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/43.jpg)
!Q & AGrails 3.0
3.0
![Page 44: Greach 2014 - Road to Grails 3.0](https://reader034.fdocuments.in/reader034/viewer/2022042700/554f6a79b4c905c8088b5163/html5/thumbnails/44.jpg)
Stay Connected.
!!!!
Web: grails.org Twitter: twitter.com/grailsframework LinkedIn: http://linkedin.com/groups/Grails-User-Group-39757 Google +: https://plus.google.com/communities/109558563916416343008