Devoxx 2015 - Web Application Development using Grails and Docker
-
Upload
ted-vinke -
Category
Technology
-
view
3.822 -
download
0
Transcript of Devoxx 2015 - Web Application Development using Grails and Docker
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Web Application Development
using Grails and Docker
`
Workshop by Ted Vinke and Koen Aben
First8
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Who are we?
Ted Vinke@tvinke
Koen Aben@koenusTweets
First8@First8BV
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Goal
• Get to know Grails 3 – The
Framework
• Acquire hands-on enough
practical knowledge to get
started with a project at
home or work
• Experience the Fun and Joy
of developing with Grails
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Updates & Feedback
We’d love to have some feedback afterwards!
www.first8.nl/grails3trek
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Much is optional
• Optional braces ( and )
• Optional semi-colons ;
• Less lines
• println instead of
System.out.println
Java
public static void main(String[] args) {System.out.println("Hello world!");
}
Groovy
println "Hello world!"
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Less boilerplateParsing XML
def xmlSlurper = new XmlSlurper()
def list = xmlSlurper.parseText'''
<list>
<company>
<name>First8</name>
</company>
</list>
'''
assert
list.company.name == 'First8'
Parsing JSON
def jsonSlurper = new JsonSlurper()
def company =
jsonSlurper.parseText '{"name": "First8"}'
assert company instanceof Map
assert company.name == 'First8'
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Duck typing
• Instead of a specific type name you can use def
• Usable instead of void in method definition
• Allows for easy tutorials, but also for "duck typing"
Java
int typed = 2
typed = "Some text"
// compiler error: type mismatch
Groovy
def dynamic = 2
dynamic = "Some text" // ok
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
More Groovy
•Return keyword is
optional
• Classes, methods and
properties* are public by
default
• Getters and setters are
generated compile-time
Groovy
double calculateTotal(int number) {
number * 0.21
}
Groovy
class Spaceship {String nameboolean warpCapable
}
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Groovy Closures
• Block of code; assign with curly braces { and }
Groovy
def clos = { println "Hello Duke!" }
println "Executing the Closure:"
clos() // prints "Hello Duke!"
def adder = { a, b -> print a+b }
adder(1, 2) // prints "3"
adder("m", "e") // prints "me"
with parameters
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Lists
• Use [] expression to create a List
Java
List<Person> persons = new ArrayList<>();
persons.add(new Person());
Groovy
def persons = []
persons << new Person()
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Maps
• Use [:] expression to create a Map
Java
Map<String, String> map = new HashMap<>();
map.put("name", "Ted");
Groovy
def map = [name:"Ted", id:1234]
assert map.get("name") == "Ted"
assert map["name"] == "Ted"
assert map.name == "Ted"
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
“Grails is an Open Source, full stack, web
application framework for the JVM. It
takes advantage of the Groovy
programming language and convention
over configuration to provide a productive
and stream-lined development
experience.”
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Distribution
• Latest official
release is 3.0.9
• Latest available
release is 3.1.0.M2
• We’ll be using
3.1.0.M1
For this workshop you don’t
have to download Grails.
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Up ‘n running with Grails
1
Install JDK and
Grails
distribution
2
grails create-app MyFirstApp
3
grails run-app
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Up ‘n running with Gradle
gradlewbootRun
grails run-app
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Step 1: grails-trek.zip
Extract zipped Star Trek
workshop application
from the USB stick.
You can keep it! Take your
time during the workshop –
you can always continue at
home.
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Material
grails-trek3.zip
Eclipse Mars distributions (Win, Linux and Mac)
Docker Toolbox distributions (Win and Mac)
Documents
A - Getting Started.pdf
B - Eclipse Mars Instructions.pdf
C - Tasks in Eclipse.pdf
D - Docker Instructions.pdf
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Step 2: Install IDE
Extract Eclipse Mars from
the USB stick. Install
some plugins and import
the Gradle project.
You can of course use Netbeans or
IntelliJ to import the project and run it with
the Gradle Wrapper, but you won’t be
able to follow the tasks easily…
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Step 3: Tasks in Eclipse
Use the Tasks overview
to follow all assignments
in chronological order.
We’ve used the TODOs in such a
way so Eclipse can display them
nicely in chronological order.
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Step 4: Docker
Instead of in-memory H2,
run integration test
against Postgres in
Docker container.
Windows and Mac users can install
Docker Toolbox from the USB drive.
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Eclipse Mars
Already has:
• Buildship plugin
(Gradle)
Add ourselves:
• Groovy compiler
• GSP editor
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Eclipse Mars
• Import grails-
trek/trek as a
Gradle project
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Eclipse Mars
• Interact with
Gradle
whenever you
have to -- with
the Gradle
Tasks view
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
What tasks can you encounter? (1)
Showcases of several features - just FYI
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
What tasks can you encounter? (2)
Coding tasks - which invite you to actually implement
missing logic or fix a bug
• Solutions are present in the enclosed Git repository as tags
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Sections
• The 40 tasks are divided in sections
• ENGINEER
• SECURITY
• PARTICLE
• MISSIONS
• AWAYTEAM
• A reference of all tasks and a FAQ can be found in the
Tasks in Eclipse PDF
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Install & ENGINEERING
• Get the project up ‘n
running (max 10-20 min)
• Work ENGINEER tasks
• Review in 30 min
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Review ENGINEER
1.Starting the app: bootRun
2.UrlMappings:
"/"(controller:"dashboard")
3.Use i18n messages
4.Scaffolding
5.Controller actions/views
6.Controller returning
model
7.GSP using model
8.Auto-reloading
9.404 error page
10.Groovy
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
SECURITY
• Work SECURITY tasks
• Logging framework
• Testing with Spock
• GSP and TagLibs
• H2 and Hibernate
• Review in 30 min
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Review SECURITY
1.Logback logging
framework
2.Testing with Spock
(UserController)
3.Groovy Expressions
4.GSP variables
5.TagLib FYI
6.TagLib impl change
7.TagLib test change
8.TagLib attributes
9.BootStrap
10.dbconsole
11.Dynamic Finders
12.PersonTagLib impl
change
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
PARTICLE
• Work PARTICLE tasks
• Spring beans, Spring Boot Actuator
• Event processing
• Groovy class annotation
• Grails configuration
• JSON
@tvinke @koenusTweets @First8BV#Devoxx #grails3trek
Review PARTICLE
• Spring beans
instantiation & wiring
• Event processing with
Reactor
• Groovy class annotations
• Grails configuration
• JSON
• Health & metrics