GWT, CDI & JAX-RS A match made in heaven Heiko Braun - - PowerPoint PPT Presentation

gwt cdi jax rs
SMART_READER_LITE
LIVE PREVIEW

GWT, CDI & JAX-RS A match made in heaven Heiko Braun - - PowerPoint PPT Presentation

GWT, CDI & JAX-RS A match made in heaven Heiko Braun <hbraun@redhat.com> About me Heiko Braun Senior Software Engineer JBoss / Red Hat 4 years JBoss, 12 years industry Focus on SOA, BPM, GWT Contributor:


slide-1
SLIDE 1

GWT, CDI & JAX-RS

“A match made in heaven”

Heiko Braun <hbraun@redhat.com>

slide-2
SLIDE 2

About me

  • Heiko Braun
  • Senior Software Engineer JBoss / Red Hat
  • 4 years JBoss, 12 years industry
  • Focus on SOA, BPM, GWT
  • Contributor:

JBossWS, jBPM, Riftsaw, Errai, SAM, Savarra > http://jboss.org

slide-3
SLIDE 3

Topics

  • GWT ecosystem
  • Integrating with CDI
  • When to use JAX-RPC
slide-4
SLIDE 4

GWT ecosystem

slide-5
SLIDE 5

GWT: Strong client side

  • GWT SDK: Tools & API to build Ajax clients &

frameworks

  • Integration capabilities:
  • GWT RPC
  • XHR (Request Builder)
  • Data formats: JSON, XML
  • Rich set of widget libraries:
  • Mosaic, Smart GWT, etc
slide-6
SLIDE 6

GWT: Weak server side

  • Service implementation choice:
  • rely on GWT RPC
  • or handle the low level protocol manually
  • Existing domain & component model?
  • Adapters, DTO’s, parallel hierarchy, etc
  • TX, Security, etc
  • A lot of boilerplate needs to be written
slide-7
SLIDE 7

Backend implementation

  • ptions
slide-8
SLIDE 8

Java EE choices

  • CDI: Context and dependency injection for

the EE platform (http://jcp.org/en/jsr/summary?id=299)

  • Java API for RESTful web services

(http://jcp.org/en/jsr/detail?id=311)

  • Both part of EE 6
slide-9
SLIDE 9

Relation to Errai

  • CDI integration build on Errai

(http://jboss.org/errai)

  • Integration is actually an extension to Errai

and vice versa

  • Knowledge about Errai Message Bus helpful,

but not mandatory

slide-10
SLIDE 10

GWT & CDI

slide-11
SLIDE 11

GWT & CDI goals

  • Similar to GWT
  • RPC:
  • re-use domain model
  • transparent wire protocol (serialization)
  • In addition to GWT
  • RPC:
  • Bypass the servlet tier (merely transport)
  • Deep integration with EE component model
  • Richer programming model & reduction of boiler

plate

slide-12
SLIDE 12

CDI Concepts

  • Portable Extensions
  • Integration point when container bootstraps
  • Create beans, annotation processing, meta data

modifications

  • Scope & Lifecycle
  • ApplicationScoped, RequestScoped, ConversationScoped
  • Bean context & reference
  • Lookup and instance (reference) creation

12

slide-13
SLIDE 13

GWT & CDI Samples

slide-14
SLIDE 14

Using Pub/Sub

  • Most low level use cases

(Errai Bus, Pub/Sub)

  • Similar to MessageDriven

Bean (actual maps to it)

  • Service implementation

fully managed by CDI container

  • Message Bus instance

injected

CDI Component GWT Client

14

slide-15
SLIDE 15

Exposing RPC endpoints

  • Exposes a typed

interface

  • Similar to EJB Session

beans (maps to it)

  • RPC style, type safe

client API

CDI Component Remote interface GWT Client

15

slide-16
SLIDE 16

Working with CDI events

  • Bi-directional event

exchange

  • Discriminate on:
  • Event Type
  • Qualifier Annotations
  • Exposes high level CDI

client API

  • Integrate with default and

custom CDI events

CDI Component GWT Client

16

slide-17
SLIDE 17

When to integrate with CDI

  • Benefits of Java EE 6 and GWT as an

alternative view layer technology

  • Concise Java component model
  • Tool chain: GWT, EJB, CDI, JPA, JCA, JMS

17

slide-18
SLIDE 18

GWT & JAX-RPC

slide-19
SLIDE 19

GWT & JAX-RPC goals

  • RESTful web services:
  • RESTful API: open to non-java clients
  • Intermediaries: proxies, gateways, firewalls
  • [...] (See other Jazoon talks on this topic)
  • Expose low level protocol with a decent API
  • Directly expose XML, HTML from other resources
  • BIRT reporting (mashup, iframe)
  • Use of XML documents
  • Integrate with XHR (RequestBuilder)
  • Reuse domain model (serialization)
slide-20
SLIDE 20

JAX-RPC Concepts

@Path("/customerservice/")

@Produces("application/xml") public class CustomerService { @GET @Path("/customers/{id}") @Produces("application/json") public Customer getCustomer(@PathParam("id") String id) { ...... } @PUT @Path("/customers/{id}") @Consumes("application/xml") public Response updateCustomer(@PathParam("id") Long id, Customer customer) { ...... } @POST @Path("/customers") public Response addCustomer(Customer customer) { ...... } @DELETE @Path("/customers/{id}/") public Response deleteCustomer(@PathParam("id") String id) { ...... } }

slide-21
SLIDE 21

GWT & JAX-RPC samples

slide-22
SLIDE 22

Request a JAX-RPC resource

GWT Client Server Resource

slide-23
SLIDE 23

Conclusion

  • CDI integration probably most reasonable choice for

within EE 6 environments

  • Integration & boilerplate missing: Errai [1] to the rescue
  • JAX-RPC is more open, but very low level.

Still better then writing your own servlet code

  • Remember:

You can mix and match JAX-RPC and CDI within the same components (at least on JBoss 6)

[1] http://anonsvn.jboss.org/repos/errai/projects/weld-integration/trunk/

slide-24
SLIDE 24

Q&A

> http://jboss.org/errai > http://errai-blog.blogspot.com/

slide-25
SLIDE 25

Appendix A: Errai Message Bus

slide-26
SLIDE 26

Errai Basics

  • Backbone to application

design

  • Federated architecture
  • Asynchronous & bi-

directional

  • Supports POJO

serialization

  • Common shared API
  • Supports OpenHUB spec
  • HTTP + NIO
slide-27
SLIDE 27

Errai API

Publisher Subscriber