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 SO...
Topics


•   GWT ecosystem
•   Integrating with CDI
•   When to use JAX-RPC
GWT ecosystem
GWT: Strong client side
•   GWT SDK: Tools & API to build Ajax clients &
    frameworks

•   Integration capabilities:
   ...
GWT: Weak server side

•   Service implementation choice:
    - rely on GWT RPC
    - or handle the low level protocol man...
Backend implementation
       options
Java EE choices

•   CDI: Context and dependency injection for
    the EE platform
    (http://jcp.org/en/jsr/summary?id=2...
Relation to Errai

•   CDI integration build on Errai
    (http://jboss.org/errai)
•   Integration is actually an extensio...
GWT & CDI
GWT & CDI goals
•   Similar to GWT-RPC:

    •   re-use domain model

    •   transparent wire protocol (serialization)

•...
CDI Concepts
•   Portable Extensions

    •   Integration point when container bootstraps

    •   Create beans, annotatio...
GWT & CDI Samples
Using Pub/Sub
                               GWT Client

•   Most low level use cases
    (Errai Bus, Pub/Sub)

•   Simila...
Exposing RPC endpoints
                             GWT Client



•   Exposes a typed
    interface

•   Similar to EJB Se...
Working with CDI events
                                 GWT Client



•   Bi-directional event
    exchange

•   Discrimi...
When to integrate with
        CDI

•   Benefits of Java EE 6 and GWT as an
    alternative view layer technology
•   Conci...
GWT & JAX-RPC
GWT & JAX-RPC goals
•   RESTful web services:
    - RESTful API: open to non-java clients
    - Intermediaries: proxies, g...
JAX-RPC Concepts
@Path("/customerservice/")
@Produces("application/xml")
public class CustomerService {

    @GET
    @Pat...
GWT & JAX-RPC
   samples
Request a JAX-RPC
            resource
GWT Client




Server Resource
Conclusion

•   CDI integration probably most reasonable choice for
    within EE 6 environments

    •   Integration & bo...
Q&A
> http://jboss.org/errai
> http://errai-blog.blogspot.com/
Appendix A:
Errai Message Bus
Errai Basics
•   Backbone to application
    design

•   Federated architecture

•   Asynchronous & bi-
    directional

•...
Errai API
Publisher




Subscriber
Upcoming SlideShare
Loading in …5
×

Gwt cdi jaxrs_hbraun

2,779 views
2,679 views

Published on

Every non-trivial GWT application requires integration with the server side. While GWT itself ships with the integration capabilities (i.e GWT RPC) it doesn't go beyond that. Developers have to decide how to build the backend to their GWT applications. While freedom of choice is a good thing, it doesn’t always lead to a good decision. In this session we’ll look at two options, JSR-299 [1] and JSR-311 [2], both part of the EE6 specification and see how they interplay with GWT. We'll discuss the use cases and justifications for each technology see how they are applied in practice by looking at some code examples.

[1] JSR-299: Java Contexts and Dependency Injection for the Java EE platform (CDI) is the new Java standard for dependency injection and contextual lifecycle management.

[2] JSR-311: A that specification defines a set of Java APIs for the development of Web services built according to the Representational State Transfer[1] (REST) architectural style.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,779
On SlideShare
0
From Embeds
0
Number of Embeds
695
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Gwt cdi jaxrs_hbraun

  1. 1. GWT, CDI & JAX-RS “A match made in heaven” Heiko Braun <hbraun@redhat.com>
  2. 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
  3. 3. Topics • GWT ecosystem • Integrating with CDI • When to use JAX-RPC
  4. 4. GWT ecosystem
  5. 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
  6. 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
  7. 7. Backend implementation options
  8. 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
  9. 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
  10. 10. GWT & CDI
  11. 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
  12. 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
  13. 13. GWT & CDI Samples
  14. 14. Using Pub/Sub GWT Client • Most low level use cases (Errai Bus, Pub/Sub) • Similar to MessageDriven Bean (actual maps to it) CDI Component • Service implementation fully managed by CDI container • Message Bus instance injected 14
  15. 15. Exposing RPC endpoints GWT Client • Exposes a typed interface • Similar to EJB Session beans (maps to it) CDI Component • RPC style, type safe Remote interface client API 15
  16. 16. Working with CDI events GWT Client • Bi-directional event exchange • Discriminate on: - Event Type - Qualifier Annotations CDI Component • Exposes high level CDI client API • Integrate with default and custom CDI events 16
  17. 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
  18. 18. GWT & JAX-RPC
  19. 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)
  20. 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) { ...... } }
  21. 21. GWT & JAX-RPC samples
  22. 22. Request a JAX-RPC resource GWT Client Server Resource
  23. 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/
  24. 24. Q&A > http://jboss.org/errai > http://errai-blog.blogspot.com/
  25. 25. Appendix A: Errai Message Bus
  26. 26. Errai Basics • Backbone to application design • Federated architecture • Asynchronous & bi- directional • Supports POJO serialization • Common shared API • Supports OpenHUB spec • HTTP + NIO
  27. 27. Errai API Publisher Subscriber

×