Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share

Building RESTful services using SCA and JAX-RS

on

  • 13,212 views

REST is an important aspect of the Web 2.0 world. Building RESTful services can be a challenge as REST is just an architectural style. JAX-RS emerges as the programming model that guides Java ...

REST is an important aspect of the Web 2.0 world. Building RESTful services can be a challenge as REST is just an architectural style. JAX-RS emerges as the programming model that guides Java developers to develop services in REST. On the other hand, we often need to assemble services, including RESTful and traditional ones, into an enterprise composite application. SCA gives us the power to define and composite services in a technology neutral fashion. This talk is to share the interesting ideas to combine the power of both SCA and JAX-RS that we explore in Apache Tuscany project with the JAX-RS runtime from Apache Wink project. The Tuscany Java SCA runtime provides the integration with REST services out of the box via several extensions. Tuscany REST binding (binding.rest) leverage JAX-RS annotations to map business operations to HTTP operations such as POST, GET, PUT and DELETE to provide a REST view to SCA services. The REST binding also allows SCA components to invoke existing RESTful services via a JAX-RS annotated interfaces without messing around HTTP clients. JAX-RS applications and resources can be dropped into the SCA assembly as JAX-RS implementation (implementation.jaxrs). Tuscany also enrich the JAX-RS runtime with more databindings to provide support for data representations and transformation without the interventions from application code. This session will teach you how to model, implement, invoke and expose RESTful services using SCA and JAX-RS. We'll walk you through a sample application developed using Apache Tuscany and Wink.

Statistics

Views

Total Views
13,212
Views on SlideShare
7,149
Embed Views
6,063

Actions

Likes
1
Downloads
184
Comments
0

38 Embeds 6,063

http://lresende.blogspot.com 4270
http://lresende.blogspot.in 395
http://lresende.blogspot.com.br 198
http://lresende.blogspot.de 170
http://lresende.blogspot.co.uk 143
http://lresende.blogspot.fr 116
http://lresende.blogspot.ca 110
http://lresende.blogspot.com.es 81
http://lresende.blogspot.com.au 81
http://lresende.blogspot.it 73
http://lresende.blogspot.mx 36
http://lresende.blogspot.nl 34
http://lresende.blogspot.com.ar 27
http://lresende.blogspot.kr 26
http://lresende.blogspot.be 25
http://lresende.blogspot.jp 25
http://lresende.blogspot.hk 21
http://lresende.blogspot.co.nz 20
http://lresende.blogspot.se 19
http://lresende.blogspot.co.il 19
http://lresende.blogspot.pt 18
http://lresende.blogspot.co.at 18
http://lresende.blogspot.ru 16
http://lresende.blogspot.tw 16
http://lresende.blogspot.sg 15
http://lresende.blogspot.fi 14
http://lresende.blogspot.no 14
http://lresende.blogspot.ro 13
http://lresende.blogspot.ie 11
http://lresende.blogspot.hu 9
http://lresende.blogspot.ch 9
http://translate.googleusercontent.com 6
http://lresende.blogspot.gr 5
http://lresende.blogspot.dk 3
http://lresende.blogspot.sk 3
http://lresende.blogspot.cz 2
http://www.lresende.blogspot.de 1
http://www.lresende.blogspot.com.br 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Building RESTful services using SCA and JAX-RS Presentation Transcript

  • 1. IBM Software Group RESTful SCA with Apache Tuscany Luciano Resende lresende@apache.org http://lresende.blogspot.com Jean-Sebastien Delfino jsdelfino@apache.org http://jsdelfino.blogspot.com 1 http://tuscany.apache.org
  • 2. IBM Software Group Agenda •  What is Apache Tuscany •  What is Apache Wink •  RESTFul SCA Overview •  Usage and architecture walk-through -  Including a look at various scenarios •  What’s next •  Getting involved 2 http://tuscany.apache.org
  • 3. IBM Software Group What is Apache Tuscany ? 3 http://tuscany.apache.org
  • 4. IBM Software Group Apache Tuscany •  Apache Tuscany provides a component based programming model which simplifies development, assembly and deployment and management of composite applications. •  Apache Tuscany implements SCA standards defined by OASIS OpenCSA and extensions based on real user feedback. 4 http://tuscany.apache.org 4
  • 5. IBM Software Group Building Applications using SCA •  Business functions are defined as SCA Components –  That expose services -  Using different communication protocols (bindings) –  And have dependencies on Collection other services through atom References ShoppingCart Currency Converter Store jsonrpc Total currencyCode=USD http Fruit Catalog Catalog 5 http://tuscany.apache.org
  • 6. IBM Software Group SCA Overview Service Interface Reference Interface - Java Property - Java - WSDL - WSDL Composite A property setting Component Component Service A B Reference promote wire promote Service Binding Implementation Reference Binding Web Service Java Web Service JMS BPEL JMS SLSB PHP SLSB Rest SCA composite Rest JSONRPC Spring JSONRPC JCA EJB module JCA … … … 6 http://tuscany.apache.org
  • 7. IBM Software Group What is Apache Wink? 7 http://tuscany.apache.org
  • 8. IBM Software Group Apache Wink •  Apache Wink is a simple yet solid open source framework for building RESTful Web services. It is comprised of a Server module and a Client module for developing and consuming RESTful Web services. •  The Wink Server module is a complete implementation of the JAX-RS v1.0 specification. On top of this implementation, the Wink Server module provides a set of additional features that were designed to facilitate the development of RESTful Web services. •  The Wink Client module is a Java based framework that provides functionality for communicating with RESTful Web services. The framework is built on top of the JDK HttpURLConnection and adds essential features that facilitate the development of such client applications. 8 http://tuscany.apache.org
  • 9. IBM Software Group RESTful SCA Overview 9 http://tuscany.apache.org
  • 10. IBM Software Group REST-related user stories •  As a developer, I want to expose new or existing services over HTTP in REST styles with the flexibility to use different wire formats including (but not limited to) JSON, XML. •  As a developer, I want to allow RPC services to be accessed via HTTP GET method in REST styles to take advantage of HTTP caching. •  As a developer, I want to configure a service exposed using REST to use different cache control mechanisms to maximize performance of static resources and or cache dynamic content. •  As a developer, I want to invoke existing RESTful services via a business interface without dealing with the HTTP client APIs. •  As a developer, I want to compose services (both RESTful and non- RESTful) into a solution using SCA. 10 http://tuscany.apache.org November 4, 2010
  • 11. IBM Software Group A win-win situation using SCA and JAX-RS •  SCA gives us the power to declare, configure and compose services in a technology neutral fashion. •  REST is an important aspect of the Web 2.0 world. Building RESTful services can be a challenge as REST is just an architectural style. JAX-RS emerges as the standard REST programming model. •  A balanced middle-ground to leverage the power of declarative services using SCA and annotation based REST/HTTP mapping using JAX-RS (without tying business logic to the technology specifics) (try to avoid JAX-RS APIs directly). 11 http://tuscany.apache.org
  • 12. IBM Software Group Tuscany’s offerings for REST •  The Tuscany Java SCA runtime provides the integration with REST services out of the box via several extensions. -  Tuscany REST binding type (binding.rest) •  Leverage JAX-RS annotations to map business operations to HTTP operations such as POST, GET, PUT and DELETE to provide a REST view to SCA services. •  Support RPC over HTTP GET •  Allow SCA components to invoke existing RESTful services via a JAX-RS annotated interfaces without messing around HTTP clients. -  Tuscany JAX-RS implementation type (implementation.jaxrs) •  JAX-RS applications and resources can be dropped into the SCA assembly as JAX-RS implementation (implementation.jaxrs). -  Tuscany also enrich the JAX-RS runtime with more databindings to provide support for data representations and transformation without the interventions from application code. 12 http://tuscany.apache.org
  • 13. IBM Software Group Runtime overview •  Related Tuscany modules -  interface-java-jaxrs (Introspection of JAX-RS annotated interfaces) -  binding-rest (binding.rest XML/Java model) -  binding-rest-runtime (runtime provider) -  implementation-jaxrs (implementation.jaxrs XML/Java model) -  implementation-jaxrs-runtime (runtime provider) •  Tuscany uses Apache Wink 1.1.1-incubating as the JAX-RS runtime -  Contributions were made to the Wink runtime to facilitate embedding Wink and it’s going to be available in Wink 1.1.2 which should be available in the near future 13 http://tuscany.apache.org
  • 14. IBM Software Group Usage and architecture walk-through 14 http://tuscany.apache.org
  • 15. IBM Software Group Use Case #1: Exposing an SCA service to HTTP using REST •  We have an existing SCA service and want to make it RESTful 1.  Define a Java interface with JAX-RS annotations •  Provide URI •  Map between business operations and HTTP methods •  Map Input/Output (Path segments, query parameters, headers, etc) •  Configure wire formats 2.  Each method should have a compatible operation in the SCA service 15 http://tuscany.apache.org
  • 16. IBM Software Group REST Services •  Supports exposing existing SCA components as RESTFul services •  Exposing a service as RESTful resource <component name=”Catalog"> Fruit <implementation.java class="services.FruitsCataloglmpl" /> Catalog <service name=”Catalog"> json <t:binding.rest uri="http://localhost:8080/Cartalog" > <t:wireFormat.json /> <t:operationSelector.jaxrs /> </t:binding.rest> </service> </component> •  Consuming REST Services -  Multiple JavaScript frameworks such as Dojo (XHR) -  Regular Web browsers -  Regular utilities such as cUrl, wGet, etc -  SCA component 16 http://tuscany.apache.org
  • 17. IBM Software Group Mapping business interfaces using JAX-RS @Remotable public interface Catalog{ @GET Item[] getItem(); @GET @Path("{id}") Item getItemById(@PathParam("id") String itemId); @POST void addItem(Item item); @PUT void updateItem(Item item); @DELETE @Path("{id}") void deleteItem(@PathParam("id") String itemId); } 17 http://tuscany.apache.org
  • 18. IBM Software Group REST service binding runtime architecture 18 http://tuscany.apache.org
  • 19. IBM Software Group Use Case #2: Allowing HTTP GET access to an SCA RPC service •  We have an existing RPC SCA service and want to allow remote accesses using HTTP GET -  No standard JAX-RS client is defined by the JAX-RS spec -  We need to figure the URI, parameter passing (positional or name/value pairs, headers, etc) 19 http://tuscany.apache.org
  • 20. IBM Software Group RPC Services over HTTP GET •  The REST binding provides mapping your RPC style calls over HTTP GET •  Exposing a service as RESTful resource Fruit <component name=”Catalog"> Catalog <implementation.java class="services.FruitsCataloglmpl" /> json <service name=”Catalog"> <t:binding.rest uri="http://localhost:8080/Cartalog" /> <t:wireFormat.json /> <t:operationSelector.rpc /> </t:binding.rest> </service> </component> •  Client Invocation -  http://localhost:8085/EchoService?method=echo&msg=Hello RPC -  http://localhost:8085/EchoService? method=echoArrayString&msgArray=Hello RPC1&msgArray=Hello RPC2" 20 http://tuscany.apache.org
  • 21. IBM Software Group Mapping queryString to RPC method parameters @Remotable public interface Echo { String echo(@QueryParam("msg") String msg); int echoInt(int param); boolean echoBoolean(boolean param); String [] echoArrayString(@QueryParam("msgArray") String[] stringArray); int [] echoArrayInt(int[] intArray); } 21 http://tuscany.apache.org
  • 22. IBM Software Group Design note •  As of today, we have a special path to handle the RPC over HTTP GET in the REST binding runtime (operationSelector.rpc). Potentially, we can unify this approach with the runtime design that implements the logic for Use case #1. -  Imaging that you are writing a JAX-RS resource method that supports the RPC style (GET with a list of query parameters, one of them is the “method”) •  For a service method that is not annotated with JAX-RS http method annotations, we will generate a JAX-RS resource class with a mapping so that: -  @GET -  @Path -  @QueryParam for each of the arguments 22 http://tuscany.apache.org
  • 23. IBM Software Group Use Case #3: Access external RESTful services using SCA •  We want to access external RESTful services from an SCA component using SCA references (w/ dependency injection) instead of calling technology APIs such as HTTP client 23 http://tuscany.apache.org
  • 24. IBM Software Group Tuscany SCA client programming model for JAX-RS •  Model as an SCA reference configured with binding.rest in the client component •  Use a JAX-RS annotated interface to describe the outbound HTTP invocations (please note we use the same way to handle inbound HTTP invocations for RESTful services exposed by SCA) •  A proxy is created by Tuscany to dispatch the outbound invocation per the metadata provided by the JAX-RS annotations (such as Path for URI, @GET for HTTP methods, @QueryParam for parameters, etc). -  If no HTTP method is mapped, we use the RPC over HTTP GET 24 http://tuscany.apache.org
  • 25. IBM Software Group Sample configuration •  To invoke a RESTful resource such as getPhotoById(String id): @GET @Path(“/photos/{id}”) InputStream getPhotoById(@PathParam(“id”) String id); •  SCA Reference <reference name=“photoService”> <interface.java interface=“…”/> <tuscany:binding.rest uri=“http://example.com/”/> </reference> 25 http://tuscany.apache.org
  • 26. IBM Software Group REST reference binding runtime architecture 26 http://tuscany.apache.org
  • 27. IBM Software Group Use case #4: Drop in a JAX-RS application into SCA •  We already have a JAX-RS application that is written following JAX-RS programming model (to take full advantage of JAX-RS for the HTTP protocol beyond just business logic). •  We want to encapsulate it as an SCA component so that it can be used in the SCA composite application. (Potentially be able to use SCA @Reference or @Property to inject service providers or property values). 27 http://tuscany.apache.org
  • 28. IBM Software Group Tuscany implemention.jaxrs •  Tuscany introduced an implementation type (under tuscany namespace) to provide out-of-box support for component using JAX- RS 28 http://tuscany.apache.org
  • 29. IBM Software Group implementation.jaxrs runtime archirecture •  Each root resource is translated into an SCA service with binding.rest 29 http://tuscany.apache.org
  • 30. IBM Software Group Sample configuration for implementation.jaxrs •  Composite <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" targetNamespace="http://sample/jaxrs" HelloWorldApp name="HelloWorld"> <component name="HelloWorldApp"> <tuscany:implementation.jaxrs application="helloworld.jaxrs.HelloWorldApp"/> </component> </composite> 30 http://tuscany.apache.org
  • 31. IBM Software Group Summary 31 http://tuscany.apache.org
  • 32. IBM Software Group Summary •  What do we support today ? -  Expose SCA Services as RESTFul services -  Expose RPC SCA Services via HTTP -  Declaratively configure RESTFul services •  Cache Controls Headers and general HTTP Headers -  Consume RESTFul services as SCA References -  Re-use JAX-RS Resources into your composite applications 32 http://tuscany.apache.org
  • 33. IBM Software Group What’s Next ? 33 http://tuscany.apache.org
  • 34. IBM Software Group What’s next ? •  What’s on my “next” todo list ? -  WADL Support via service endpoint ?wadl -  Support for partial response and partial updates •  What’s on yours ? -  Submit your suggestions to our user / development list 34 http://tuscany.apache.org
  • 35. IBM Software Group Getting Involved 35 http://tuscany.apache.org
  • 36. IBM Software Group Resources  Apache Tuscany   http://tuscany.apache.org  Getting Involved   http://tuscany.apache.org/getting-involved.html  Tuscany SCA Java Releases   http://tuscany.apache.org/sca-java-2x-releases.html  Tuscany SCA Java Documentation   http://tuscany.apache.org/java-sca-documentation-menu.html  Apache Wink   http://incubator.apache.org/wink  Getting Involved   http://incubator.apache.org/wink/community.html  Apache Wink Downloads   http://incubator.apache.org/wink/downloads.html 36 http://tuscany.apache.org
  • 37. IBM Software Group Thank You !!! 37 http://tuscany.apache.org