SlideShare a Scribd company logo
Groovy & Grails
   Scripting for Modern Web Applications




Rohit Nayak
Talentica Software
Agenda

    Demo: Quick intro to Grails

    Scripting, Web Applications and Grails/Groovy

    REST service in Grails
    −   Demo
    −   Internals

    Web Client in Grails
    −   Demo
    −   Internals

    Perspective
Demo

Quick Intro to Grails
Maggi

    grails create-app Maggi

    Domain class: Noodle, Packaging

    grails generate-all Noodle, Packaging

    grails run-app
Web Frameworks with Scripting

    Ruby on Rails (2004)


    CakePHP (2005)


    Django / Python (2005)


    Groovy on Grails (2006)
Power of these frameworks

    Baked Experience


    The Language


    Agility / Productivity
Baked Experience

    Model View Controller

    Object-Relational Mapping

    Templates

    Layout

    URL rewriting

    Ajax support

    XML / JSON support
The Language

    Dynamic

    More expressive code

    Smaller code

    Native support for Lists, Hashmaps

    Lang. support for IO, Net, XML

    Idioms for common Design Patterns
Agile

    Scaffolding

    Unit tests

    No compile cycles

    Built-in webservers

    Fail faster!
http://www.zacker.org/ruby-on-rails (Nov 2nd)
http://www.zacker.org/ruby-on-rails (Nov 2nd)
HelloWorld.java
public class HelloWorld {
    String name;
    public void setName(String name)
        { this.name = name; }
    public String getName() { return name; }
    public String hello()
        { return “Hello “+ name; }
    public static void main(String args[]) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName(“Java”);
        System.out.println( helloWorld. hello() );
    }
}
HelloWorld.groovy
class HelloWorld {
    String name
    def hello() { "Hello $name" }
}
def helloWorld = new HelloWorld(name:"Groovy")
println helloWorld.hello()
Key Groovy Features

    Java-like syntax

    Complements Java

    Object-oriented

    Targets Java VM (JSR-241)
    −   Invoke Java class within Groovy
    −   Invoke Groovy class within Java

    Dynamic

    Scripting (JSR-223)

    Brevity
Brevity

    Optional semicolons, package prefixes

    Automatic imports (java.util.*, java.net.*,
    java.io.*, groovy…)

    GroovyBeans (generated accessors)

    Optional typing

    Optional return
Groovy Gravy

    GStrings: ”$book.title: $book.author (${book.reviewers.length})”

    Regular expressions: assert ‘12345’ =~ /d+/

    Only objects: primitives converted to Reference Types

    Lists: def list = [1, 2, 'hello', new java.util.Date()]

    Maps: def map = ['name':‘Indic Threads', 'location':‘Pune']

    Closures [1,2,3].collect {it*2} ===> [2, 4, 6]

    String literals – single, double, triple quotes
Closures

    Block of statements

    First class objects

    Parameters including default values

    Carries local context
    def foo(n) {   // method
             return { n += it }   // returns closure
    }
    def accumulator = foo(1) //curried closure
    assert accumulator(2) == 3 //assert used for self-documenting, unit-testing
    assert accumulator(1) == 4
Dynamic Programming

    Add methods, properties to classes/objects
    at run-time

    Mixins to inject behaviour

    Can extend class field-access mechanism

    Dynamic method invocation
Poolster

    Online “football pools” application

    Entities: Game, User

    Game  Stake, Option, Ends

    To join User chooses an Option

    REST Webservice backend

    Clients: iPhone, Grails, Android, Silverlight
Demo

The Poolster Webservice
Grails – Philosophy

    Convention over Configuration
     −   Magic directories
     −   Implicit table names, column names

    Don’t Repeat Yourself
     −   Database maps to domain
     −   hasMany defines relationship & declares variable
     −   Layout, form validations

    Lightweight
     −   Modify and F5

    Strong shoulders
     −   Spring (Grails MVC, DI, Transactions)
     −   Hibernate (GORM)
     −   Ant, JUnit, SiteMesh
Grails – Key Features

    Database constraints, composition

    MySQL integration

    URL Mapping

    Authentication / Filters

    Bootstrapping

    Unit test

    Logging
Demo

Poolster Web Client
Grails Web Application

    Custom Tag libraries

    Session variables

    Sitemesh layout

    Templates

    Internationalization
Unseen Gravy

    JUnit test cases, Mocking/Stubbing

    Web testing with Canoo Webtest

    Bootstrapping

    Pagination
Cons

    Learning curve

    Performance ?!

    Early adopter issues
Scripted In Groovy

    Canoo WebTest

    Tellurium

    Ant / Maven config files

    SoapUI script step

    Spring beans

    <YOUR APP HERE> 
Invoking Groovy Scripts
import java.io.File;
import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;

public class ScriptEngineEmbedGroovy{
  public static void main(String args[]) throws Throwable{
  String[] paths = {"C:groovy"};
  GroovyScriptEngine gse = new GroovyScriptEngine(paths);
  Binding binding = new Binding();
  Object[] path = {"C:musicmp3"};
  binding.setVariable("args",path);
  gse.run("Songs.groovy", binding);
  }
}
Getting Started

    groovy.codehaus.org

    grails.org

    Free e-books
     −   Beginning Groovy and Grails (Apress)
     −   Getting started with Grails (InfoQ)

    refcardz.com cheat sheets

    ibm.com Mastering Grails, Practically Groovy
Thanks

More Related Content

What's hot (20)

Hack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security Training
ColdFusionConference
 
JavaCro'15 - Beyond the basics of SonarQube improve your Java(Script) code ev...
JavaCro'15 - Beyond the basics of SonarQube improve your Java(Script) code ev...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
Max Romanovsky
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Võ Duy Tuấn
 
Docker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testů
Radim Daniel Pánek
 
Automate Yo' Self
Automate Yo' Self
John Anderson
 
Can you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and You
ColdFusionConference
 
Automate Thyself
Automate Thyself
Ortus Solutions, Corp
 
Quick flask an intro to flask
Quick flask an intro to flask
juzten
 
Write php deploy everywhere tek11
Write php deploy everywhere tek11
Michelangelo van Dam
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
Clark Everetts
 
Dependency management with Composer
Dependency management with Composer
Jason Grimes
 
Introduction To Ant1
Introduction To Ant1
Rajesh Kumar
 
Test stack
Test stack
Radim Daniel Pánek
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and Client
ColdFusionConference
 
CommandBox & ForgeBox Package Management
CommandBox & ForgeBox Package Management
Ortus Solutions, Corp
 
Create your own composer package
Create your own composer package
Lattapon Yodsuwan
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Gavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
AppengineJS
AppengineJS
Panagiotis Astithas
 
Hack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security Training
ColdFusionConference
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
Max Romanovsky
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Võ Duy Tuấn
 
Docker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testů
Radim Daniel Pánek
 
Can you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and You
ColdFusionConference
 
Quick flask an intro to flask
Quick flask an intro to flask
juzten
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
Clark Everetts
 
Dependency management with Composer
Dependency management with Composer
Jason Grimes
 
Introduction To Ant1
Introduction To Ant1
Rajesh Kumar
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and Client
ColdFusionConference
 
CommandBox & ForgeBox Package Management
CommandBox & ForgeBox Package Management
Ortus Solutions, Corp
 
Create your own composer package
Create your own composer package
Lattapon Yodsuwan
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Gavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 

Viewers also liked (9)

Madrid GUG - Grails Plugins: Exporter
Madrid GUG - Grails Plugins: Exporter
Iván López Martín
 
Groovy no es java sin punto y coma v3
Groovy no es java sin punto y coma v3
Pablo Alba
 
Jedi knight
Jedi knight
Antonio Mas
 
T3chFest 2016 - De Java a Groovy: ¡Hora de Aventuras!
T3chFest 2016 - De Java a Groovy: ¡Hora de Aventuras!
Iván López Martín
 
Geb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosper
Esther Lozano
 
De Java a Swift pasando por Groovy
De Java a Swift pasando por Groovy
Alberto De Ávila Hernández
 
GriffDnie (Griffon Demo)
GriffDnie (Griffon Demo)
Jorge Aguilera
 
Macro macro, burrito burrit
Macro macro, burrito burrit
Mario García
 
Gorm for cassandra
Gorm for cassandra
Rafael Bermúdez Míguez
 
Madrid GUG - Grails Plugins: Exporter
Madrid GUG - Grails Plugins: Exporter
Iván López Martín
 
Groovy no es java sin punto y coma v3
Groovy no es java sin punto y coma v3
Pablo Alba
 
T3chFest 2016 - De Java a Groovy: ¡Hora de Aventuras!
T3chFest 2016 - De Java a Groovy: ¡Hora de Aventuras!
Iván López Martín
 
Geb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosper
Esther Lozano
 
GriffDnie (Griffon Demo)
GriffDnie (Griffon Demo)
Jorge Aguilera
 
Macro macro, burrito burrit
Macro macro, burrito burrit
Mario García
 
Ad

Similar to Groovy - Grails as a modern scripting language for Web applications (20)

Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
rohitnayak
 
intoduction to Grails Framework
intoduction to Grails Framework
Harshdeep Kaur
 
Java Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.Easy
roialdaag
 
Groovy and Grails intro
Groovy and Grails intro
Miguel Pastor
 
Groovy & Grails
Groovy & Grails
Marcel Overdijk
 
Grails 101
Grails 101
David Jacobs
 
Introduction to Grails 2013
Introduction to Grails 2013
Gavin Hogan
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf
 
Groovy and Grails talk
Groovy and Grails talk
desistartups
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik
 
Groovy And Grails Introduction
Groovy And Grails Introduction
Eric Weimer
 
Introduction To Groovy 2005
Introduction To Groovy 2005
Tugdual Grall
 
Magic with groovy & grails
Magic with groovy & grails
George Platon
 
Grails
Grails
Gabriel Dogaru
 
One-stop solution for Grails web app development
One-stop solution for Grails web app development
OnGraph Technologies Pvt. Ltd.
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
Jonathan Felch
 
Polyglot Grails
Polyglot Grails
Marcin Gryszko
 
Groovy and Grails in Google App Engine
Groovy and Grails in Google App Engine
Guillaume Laforge
 
Introduction To Grails
Introduction To Grails
Eric Berry
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
Guillaume Laforge
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
rohitnayak
 
intoduction to Grails Framework
intoduction to Grails Framework
Harshdeep Kaur
 
Java Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.Easy
roialdaag
 
Groovy and Grails intro
Groovy and Grails intro
Miguel Pastor
 
Introduction to Grails 2013
Introduction to Grails 2013
Gavin Hogan
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf
 
Groovy and Grails talk
Groovy and Grails talk
desistartups
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik
 
Groovy And Grails Introduction
Groovy And Grails Introduction
Eric Weimer
 
Introduction To Groovy 2005
Introduction To Groovy 2005
Tugdual Grall
 
Magic with groovy & grails
Magic with groovy & grails
George Platon
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
Jonathan Felch
 
Groovy and Grails in Google App Engine
Groovy and Grails in Google App Engine
Guillaume Laforge
 
Introduction To Grails
Introduction To Grails
Eric Berry
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
Guillaume Laforge
 
Ad

More from IndicThreads (20)

Http2 is here! And why the web needs it
Http2 is here! And why the web needs it
IndicThreads
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Building Resilient Microservices
Building Resilient Microservices
IndicThreads
 
App using golang indicthreads
App using golang indicthreads
IndicThreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices indicthreads
IndicThreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
IndicThreads
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreads
IndicThreads
 
Real world IoT for enterprises
Real world IoT for enterprises
IndicThreads
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
IndicThreads
 
Functional Programming Past Present Future
Functional Programming Past Present Future
IndicThreads
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
IndicThreads
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java Carputer
IndicThreads
 
Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedback
IndicThreads
 
Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
IndicThreads
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 
Http2 is here! And why the web needs it
Http2 is here! And why the web needs it
IndicThreads
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Building Resilient Microservices
Building Resilient Microservices
IndicThreads
 
App using golang indicthreads
App using golang indicthreads
IndicThreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices indicthreads
IndicThreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
IndicThreads
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreads
IndicThreads
 
Real world IoT for enterprises
Real world IoT for enterprises
IndicThreads
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
IndicThreads
 
Functional Programming Past Present Future
Functional Programming Past Present Future
IndicThreads
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
IndicThreads
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java Carputer
IndicThreads
 
Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedback
IndicThreads
 
Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
IndicThreads
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 

Recently uploaded (20)

Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 

Groovy - Grails as a modern scripting language for Web applications

  • 1. Groovy & Grails Scripting for Modern Web Applications Rohit Nayak Talentica Software
  • 2. Agenda  Demo: Quick intro to Grails  Scripting, Web Applications and Grails/Groovy  REST service in Grails − Demo − Internals  Web Client in Grails − Demo − Internals  Perspective
  • 4. Maggi  grails create-app Maggi  Domain class: Noodle, Packaging  grails generate-all Noodle, Packaging  grails run-app
  • 5. Web Frameworks with Scripting  Ruby on Rails (2004)  CakePHP (2005)  Django / Python (2005)  Groovy on Grails (2006)
  • 6. Power of these frameworks  Baked Experience  The Language  Agility / Productivity
  • 7. Baked Experience  Model View Controller  Object-Relational Mapping  Templates  Layout  URL rewriting  Ajax support  XML / JSON support
  • 8. The Language  Dynamic  More expressive code  Smaller code  Native support for Lists, Hashmaps  Lang. support for IO, Net, XML  Idioms for common Design Patterns
  • 9. Agile  Scaffolding  Unit tests  No compile cycles  Built-in webservers  Fail faster!
  • 12. HelloWorld.java public class HelloWorld { String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String hello() { return “Hello “+ name; } public static void main(String args[]) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(“Java”); System.out.println( helloWorld. hello() ); } }
  • 13. HelloWorld.groovy class HelloWorld { String name def hello() { "Hello $name" } } def helloWorld = new HelloWorld(name:"Groovy") println helloWorld.hello()
  • 14. Key Groovy Features  Java-like syntax  Complements Java  Object-oriented  Targets Java VM (JSR-241) − Invoke Java class within Groovy − Invoke Groovy class within Java  Dynamic  Scripting (JSR-223)  Brevity
  • 15. Brevity  Optional semicolons, package prefixes  Automatic imports (java.util.*, java.net.*, java.io.*, groovy…)  GroovyBeans (generated accessors)  Optional typing  Optional return
  • 16. Groovy Gravy  GStrings: ”$book.title: $book.author (${book.reviewers.length})”  Regular expressions: assert ‘12345’ =~ /d+/  Only objects: primitives converted to Reference Types  Lists: def list = [1, 2, 'hello', new java.util.Date()]  Maps: def map = ['name':‘Indic Threads', 'location':‘Pune']  Closures [1,2,3].collect {it*2} ===> [2, 4, 6]  String literals – single, double, triple quotes
  • 17. Closures  Block of statements  First class objects  Parameters including default values  Carries local context def foo(n) { // method return { n += it } // returns closure } def accumulator = foo(1) //curried closure assert accumulator(2) == 3 //assert used for self-documenting, unit-testing assert accumulator(1) == 4
  • 18. Dynamic Programming  Add methods, properties to classes/objects at run-time  Mixins to inject behaviour  Can extend class field-access mechanism  Dynamic method invocation
  • 19. Poolster  Online “football pools” application  Entities: Game, User  Game  Stake, Option, Ends  To join User chooses an Option  REST Webservice backend  Clients: iPhone, Grails, Android, Silverlight
  • 21. Grails – Philosophy  Convention over Configuration − Magic directories − Implicit table names, column names  Don’t Repeat Yourself − Database maps to domain − hasMany defines relationship & declares variable − Layout, form validations  Lightweight − Modify and F5  Strong shoulders − Spring (Grails MVC, DI, Transactions) − Hibernate (GORM) − Ant, JUnit, SiteMesh
  • 22. Grails – Key Features  Database constraints, composition  MySQL integration  URL Mapping  Authentication / Filters  Bootstrapping  Unit test  Logging
  • 24. Grails Web Application  Custom Tag libraries  Session variables  Sitemesh layout  Templates  Internationalization
  • 25. Unseen Gravy  JUnit test cases, Mocking/Stubbing  Web testing with Canoo Webtest  Bootstrapping  Pagination
  • 26. Cons  Learning curve  Performance ?!  Early adopter issues
  • 27. Scripted In Groovy  Canoo WebTest  Tellurium  Ant / Maven config files  SoapUI script step  Spring beans  <YOUR APP HERE> 
  • 28. Invoking Groovy Scripts import java.io.File; import groovy.lang.Binding; import groovy.util.GroovyScriptEngine; public class ScriptEngineEmbedGroovy{ public static void main(String args[]) throws Throwable{ String[] paths = {"C:groovy"}; GroovyScriptEngine gse = new GroovyScriptEngine(paths); Binding binding = new Binding(); Object[] path = {"C:musicmp3"}; binding.setVariable("args",path); gse.run("Songs.groovy", binding); } }
  • 29. Getting Started  groovy.codehaus.org  grails.org  Free e-books − Beginning Groovy and Grails (Apress) − Getting started with Grails (InfoQ)  refcardz.com cheat sheets  ibm.com Mastering Grails, Practically Groovy