View
12
Download
0
Category
Preview:
Citation preview
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails – Fast, Robust and Plugin-basedWeb Development with Groovy
Christian Wulf and Florian Fittkau
29.01.2013
1/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
2/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
2/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Motivation
Web development is greatly supported in the Javaenvironment, e.g., by JSF and custom JSF componentsHowever, you need to write very much code due toJava, XML files and the lack of scaffoldingMoreover, much configuration has to be done to getyour JSF app run as you like
3/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
the search is over.
Web application framework for the JVMOpen sourceUtilizes Groovy and "convention over configuration"Implements concepts of Rails to reduces complexityBuilds on already established Java technologies likeSpring and Hibernate
4/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
the search is over.
Web application framework for the JVMOpen sourceUtilizes Groovy and "convention over configuration"Implements concepts of Rails to reduces complexityBuilds on already established Java technologies likeSpring and Hibernate
4/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
An Excerpt of Features
ScaffoldingUncluttered source code, e.g., only uncheckedexceptionsIntegrated ready-to-use support for AJAX calls, Spring,GAnt, i18n, Hibernate (GORM), ...Hundreds of plug-ins: Validation, less css, excelim-/export, authorization, Maven integration, jobexecution, ...Convention over configurationCustomizable deployment environment (built-in:development, test, and production)
5/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
5/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Language Features
Dynamic language for the Java Virtual MachineProvides the ability to statically type check andstatically compile your codeHas additional power features inspired by languages likePython, Ruby and SmalltalkSeamlessly integrates with all existing Java classes andlibraries
6/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Syntax & Semantics
Private attributes, public methodsImplicit getter and setter definitionClosuresAdditional convenient methods for standard Java classessuch as Object, List and Map
Multi-line stringsString evaluation...
7/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Code Examples� �
1 def myList = [ 5, 7, 9, 12 ]23 myList.eachWithIndex{ num, idx -> println "$idx: $num" }45 myList.collect { ++it } // returns [ 6, 8, 10, 13 ]67 def s = ’’’a multi-line8 string in groovy printing out the9 contents of mylist: ${myList}’’’
1011 def scores = ["Brett":100, Pete:"Hello", "Andrew":86.87934]� �
8/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
A Groovy Class� �
1 class Person {2 def firstname3 String lastname4 private birthday56 def sayHello() {7 "Hello $firstname $lastname born in ${birthday.year}"8 }9 }� �� �1 def p = new Person(firstname: "Bart", lastname: "Simpson")� �
9/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
9/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Schematic Architecture
0http://www-igm.univ-mlv.fr/~dr/XPOSE2009/Groovy_and_Grails/grails_architecture.php
10/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Project Architecture
11/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Model-View-Controller (MVC)
Domain classes represent the model saved in the DBand simultaneously provide the interface to the DBController classes are (only) responsible for renderingand navigationView files (Groovy Server Page (GSP)) containsGSP-tags, javascript, html, and css
12/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Further Artefacts
Services contain re-usable Groovy/Java code used incontrollersTag Libraries represents custom GSP-tags withre-usable GSP code used in GSP filesGroovy & Java Classes that should be not stored inthe DB, but are used temporarily
13/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Processing a Request
� �1 class UserController {2 def authorizationService // automatically injected34 def list() {5 def users = User.findAll()6 def currentUser = authorizationService.currentUser7 render template: "usermgmt", model:[users:users,
currentUsername:currentUser.username]8 }9 }� �This example maps to the /user/list URI.
14/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
GORM
Abstracted hibernate 3 in Groovy (and helper methods)� �1 class Person {2 String name3 Integer age4 }56 def charlie = new Person(name: "Charlie", age: 20)7 charlie.save()89 def charlieFromDatabase = Person.findByName("Charlie")
10 charlieFromDatabase.delete()� �15/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Tests
Unit testsIntegrations tests (with Grails environment)Functional tests (with HTTP requests against therunning application)Integrated Mocking API
16/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Deployment
grails run-app
Grails listens for code changes (hot deploy)grails war MyApp.war
grails test-app
17/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Environments
grails prod run-app
grails prod war MyApp.war� �1 switch (Environment.current) {2 case Environment.DEVELOPMENT:3 configureForDevelopment()4 break5 case Environment.PRODUCTION:6 configureForProduction()7 break8 }� �
18/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
18/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Plug-in Concept
A plug-in is a standard Grails projectIntegrated support for installing from and publishing toa Maven or SVN repositoryBuilt-in versioningArtifact API
19/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Plug-in Concept
Technical View Domain View
Domain component
Domain component
Domain component
Domain component
Domain component
Plug-In
Domain model
Controller
Service
Job
View
Layer
20/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Grails’ Dependency Resolution
Integrated dependency resolutionMaven, SVN� �
1 repositories {2 mavenRepo name: "repo-releases", root: "http://localhost
:8080/nexus/content/repositories/releases"3 }45 plugins {6 compile ":mail:1.0.1"7 }� �
21/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
A Selection of Freely Available Plug-ins
quartz2 (job definition and scheduling)shiro (authorization etc.)excel-importmailwslite (REST and JSON)cached-resourcesbrowser-detection
22/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Authorization – Shiro
grails shiro-quick-start
Generates User and Role classes� �1 <shiro:hasPermission permission="printer:query">2 ...3 </shiro:hasPermission>� �� �1 if (SecurityUtils.subject.isPermitted("printer:query")) {2 ...3 }� �
23/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Resources – cached-resources
Automatically generates hash for each resource (image,css, js...)Automatically sets parameter for caching on the clientside� �
1 <img src="${resource(dir: ’images’, file: ’logo.png’)} />"� �
24/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Outline
1 Introduction
2 Groovy
3 Grails’ Architecture
4 Grails’ Plug-ins
5 Conclusions
24/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Tool Support
Groovy & Grails Tool Suite (GGTS)CodeNarc1
Jenkins plug-in for Grails commands
1http://codenarc.sourceforge.net/25/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
Conclusions
Combination of concepts from Rails with GroovyAll Java libraries can be re-usedRapid web development (bunch of plug-ins)
26/26
Grails – Fast,Robust andPlugin-based
Web Developmentwith Groovy
Christian Wulf andFlorian Fittkau
1. Introduction
2. Groovy
3. Grails’Architecture
4. Grails’ Plug-ins
5. Conclusions
References
appendix
Recommended