Grails Integration Strategies

Preview:

DESCRIPTION

Slides from the Grails Integration Strategies BOF at JavaOne 2009. You can see these in context in a video shot by Bryan Williams of the Chicago Groovy User Group - http://cgug.blip.tv

Citation preview

Grails Enterprise Integration Strategies

Dave KleinContegix Beyond Managed Hosting

2

3

Use the coupon code “javaone” for a 30% discounthttp://groovymag.com

4

Beta version available now at http://pragprog.com

Birds of a Feather

5

Grails [buzzword] [buzzword] Strategies

What do we mean by Enterprise Integration?

6

7

Java Enterprise Edition

8

EJ E

9

JEE

JEE JEE

JEE JEE

JEEJEE

Why Bother?Why not leave well enough alone?

10

Grails: More Than Just a Cool Framework

> Undeniable productivity gains> Built on top of proven technologies> Less code means less bugs> Allows you to embrace change> Reduce developer turnover (who would quit a Grails job?)

> Simple and painless deployment

11

Itʼs a Really Cool Framework!

12

Integration Strategies

> Calling EJB Session Beans from a Grails App• EJB 2• EJB 3

> Accessing JNDI Resources from a Grails App• Using JNDI Datasources• Other JNDI Resources

> Legacy Databases• GORM DSL• Annotations

13

Integration Strategies

> Calling Grails Actions from Non-Grails Apps• From the server side using wget or curl

• From the client using AJAX

> Java Message Service> Reuse Existing Spring Beans> Reuse Existing Hibernate Entities> What else?

14

Calling an EJB 2 Session Bean From Grails

15

In app/grails-app/conf/spring/resources.groovybeans = { ejbJndi(org.springframework.jndi.JndiTemplate){ environment = [ "java.naming.factory.initial":"weblogic.jndi.WLInitialContextFactory", "java.naming.provider.url" : "t3://some.enterprise.server:7001", "java.naming.security.principal" : "dave", "java.naming.security.credentials" : "1234" ] } empSession(org.springframework.ejb.access. SimpleRemoteStatelessSessionProxyFactoryBean){ jndiName = "EmpSession" businessInterface = "com.enterprise.some.ejb.session.EmpSession" jndiTemplate = ref("ejbJndi") }}

Calling an EJB 3 Session Bean From Grails

16

In app/grails-app/conf/spring/resources.groovybeans = { ejbJndi(org.springframework.jndi.JndiTemplate){ environment = [ "java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory", "java.naming.provider.url" : "t3://some.enterprise.server:7001" "java.naming.security.principal" : "dave", "java.naming.security.credentials" : "1234" ] }

empSession(org.springframework.jndi.JndiObjectFactoryBean){ jndiName = "CoverageSession#org.foo.app.ejb.session.IEmpSessionRemote" jndiTemplate = ref("ejbJndi") }}

17

Integration Strategies

> Calling EJB Session Beans from Grails Services• EJB 2• EJB 3

> Accessing JNDI Resources from a Grails App• Using JNDI Datasources• Other JNDI Services

> Legacy Databases• GORM DSL• Annotations

JNDI Datasources: Too Easy Not To Use

18

In app/grails-app/conf/DataSource.groovy

dataSource{ jndiName = “java:comp/env/jdbc/EnterpriseData”}

Or in app/grails-app/conf/spring/resources.groovy

beans = { dataSource(org.springframework.jndi.JndiObjectFactoryBean){ jndiName = “java:comp/env/jdbc/EnterpriseData” }}

Other JNDI Resources

19

In app/grails-app/conf/spring/resources.groovybeans = {

jndi(org.springframework.jndi.JndiTemplate){ environment = [ "java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory", "java.naming.provider.url" : "t3://some.enterprise.server:7001" "java.naming.security.principal" : "dave", "java.naming.security.credentials" : "1234" ] }

}

20

Integration Strategies

> Calling EJB Session Beans from a Grails App• EJB 2• EJB 3

> Accessing JNDI Resources from a Grails App• Using JNDI Datasources• Other JNDI Services

> Legacy Databases• GORM DSL• Annotations

21

TABLE BK01Column Name Date TypeID_BK_PK NUMBERBK_TITLE VARCHAR2(100)BK_AUTHOR VARCHAR2(100)BK_PGS NUMBERID_PUB_FK NUMBERSEQUENCE ID_BK_PK_SEQ

class Book { String title String author Integer pages Publisher publisher static belongsTo = Publisher

static mapping = { table 'BK01' columns{ id column: 'ID_BK_PK' title column: 'BK_TITLE' author column: 'BK_AUTHOR' pages column: 'BK_PGS' publisher column: 'ID_PUB_FK' } id generator: 'sequence', params:[sequence:'ID_BK_PK_SEQ'] }}

22

Or you can use annotations

(if you really want to)

@

Brief Tangent on How to Sneak Introduce Groovy and Grails Into The Enterprise

> Unit Testing> Utility Scripts> Internal Web Applications> Prototypes> JDBC -> GSQL> XML Processing> Itʼs easier to get forgiveness than permission> Success Sells!

23

24

Integration Strategies

> Calling Grails Actions from Non-Grails Apps• From the server side using wget or curl

• From the client using AJAX

> Java Message Service> Reuse Existing Spring Beans> Reuse Existing Hibernate Entities> What else?

> Calling Grails Actions from Non-Grails Apps

> REST• URL Mapping DSL

> SOAP• Plugins for XFire, Axis, SpringWS and more

> Plain Old HTTP Call > Execute process in Grails > Return data - HTML, XML, JSON

• Grails Converters are awesome!

25

26

Integration Strategies

> Calling Grails Actions from Non-Grails Apps• From the server side using wget or curl

• From the client using AJAX

> Java Message Service> Reuse Existing Spring Beans> Reuse Existing Hibernate Entities> What else?

25

Dave Kleindave.klein@contegix.com

Blog: dave-klein.blogspot.comTwitter: daveklein

Recommended