SlideShare ist ein Scribd-Unternehmen logo
1 von 23
RESTful SCA with Apache Tuscany Raymond Feng Luciano Resende
Overview
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. 3 IBM Confidential July 22, 2010
A win-win of 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 programming model that guides Java developers to develop services in REST.  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 technologyspecifics) (try to avoid JAX-RS APIs directly).
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.
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 (Apache License 2.0) as the JAX-RS runtime
Usage and architecture walk-through
Use Case #1: Exposing an SCA service to HTTP using REST We have an existing SCA service and want to make it RESTful 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 Each method should have a compatible operation in the SCA service
REST Services Supports exposing existing SCA components as RESTFullservices Exposing a service as RESTfull resource Consuming REST Services  Multiple JavaScript frameworks such as Dojo (XHR)  Regular Web browsers   Regular utilities such as cUrl, wGet, etc  SCA component <component name=”Catalog">     <implementation.java class="services.FruitsCataloglmpl" />     <service name=”Catalog">         <t:binding.resturi="http://localhost:8080/Cartalog" /> <t:wireFormat.json />         <t:operationSelector.jaxrs />     </service> </component> Fruit Catalog json
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); }
REST service binding runtime architecture Tuscany invocation chain Tuscany JAX-RS Servlet JAX-RS annotated Java interface SCA Component Generated JAX-RS resource class HTTP SCA proxy JAX-RS runtime (Apache Wink) Tuscany runtime
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)
RPC Services over HTTP GET The REST binding provides mapping your RPC style calls over HTTP GET Exposing a service as RESTful resource Client Invocation   http://localhost:8085/EchoService?method=echo&msg=Hello RPC  http://localhost:8085/EchoService?method=echoArrayString&msgArray=Hello RPC1&msgArray=Hello RPC2" Fruit Catalog <component name=”Catalog">     <implementation.java class="services.FruitsCataloglmpl" />     <service name=”Catalog">         <t:binding.resturi="http://localhost:8080/Cartalog" /> <t:wireFormat.json />         <t:operationSelector.rpc />     </service> </component> json
Mapping queryString to RPC method parameters @Remotable public interface Echo {     String echo(@QueryParam("msg") String msg); intechoInt(intparam); booleanechoBoolean(booleanparam);     String [] echoArrayString(@QueryParam("msgArray") String[] stringArray); int [] echoArrayInt(int[] intArray); }
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
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
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 by Tuscany created 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
Sample configuration To invoke a RESTful resource such as getPhotoById(String id): @GET @Path(“/photos/{id}”) InputStreamgetPhotoById(@PathParam(“id”) String id); SCA Reference <reference name=“photoService”> 	<interface.java interface=“…”/> 	<tuscany:binding.resturi=“http://example.com/”/> </reference>
REST reference binding runtime architecture Tuscany invocation chain REST binding invoker JAX-RS annotated Java interface SCA Component HTTP JAX-RS client(Apache Wink) Tuscany runtime
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).
Tuscany implemention.jaxrs Tuscany introduced an implementation type (under tuscany namespace) to provide out-of-box support for component using JAX-RS
implementation.jaxrs runtime archirecture Each root resource is translated into an SCA service with binding.rest SCA Component REST binding JAX-RS application Resource class Resource class JAX-RS runtime (Apache Wink) Tuscany runtime
Sample configuration for implementation.rest 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" name="HelloWorld">     <component name="HelloWorldApp">         <tuscany:implementation.jaxrs application="helloworld.jaxrs.HelloWorldApp"/>     </component> </composite>

Weitere ähnliche Inhalte

Ähnlich wie RESTful SCA with Apache Tuscany

Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSLuciano Resende
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
There is time for rest
There is time for rest There is time for rest
There is time for rest SoftServe
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in JavaAnirban Majumdar
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPdatamantra
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restfulknight1128
 
JSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikJSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikChristoph Pickl
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax IntroductionOliver Cai
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicTimothy Perrett
 
Communication Protocols And Web Services
Communication Protocols And Web ServicesCommunication Protocols And Web Services
Communication Protocols And Web ServicesOmer Katz
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 

Ähnlich wie RESTful SCA with Apache Tuscany (20)

Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RS
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
There is time for rest
There is time for rest There is time for rest
There is time for rest
 
SCDJWS 6. REST JAX-P
SCDJWS 6. REST  JAX-PSCDJWS 6. REST  JAX-P
SCDJWS 6. REST JAX-P
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in Java
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTP
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 
JSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikJSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian Motlik
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Apex REST
Apex RESTApex REST
Apex REST
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Communication Protocols And Web Services
Communication Protocols And Web ServicesCommunication Protocols And Web Services
Communication Protocols And Web Services
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Resthub lyonjug
Resthub lyonjugResthub lyonjug
Resthub lyonjug
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 

Mehr von Raymond Feng

Working with LoopBack Models
Working with LoopBack ModelsWorking with LoopBack Models
Working with LoopBack ModelsRaymond Feng
 
Building a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 MinutesBuilding a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 MinutesRaymond Feng
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsRaymond Feng
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsRaymond Feng
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsRaymond Feng
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyRaymond Feng
 

Mehr von Raymond Feng (6)

Working with LoopBack Models
Working with LoopBack ModelsWorking with LoopBack Models
Working with LoopBack Models
 
Building a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 MinutesBuilding a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 Minutes
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIs
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache Tuscany
 

Kürzlich hochgeladen

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Kürzlich hochgeladen (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

RESTful SCA with Apache Tuscany

  • 1. RESTful SCA with Apache Tuscany Raymond Feng Luciano Resende
  • 3. 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. 3 IBM Confidential July 22, 2010
  • 4. A win-win of 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 programming model that guides Java developers to develop services in REST. 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 technologyspecifics) (try to avoid JAX-RS APIs directly).
  • 5. 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.
  • 6. 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 (Apache License 2.0) as the JAX-RS runtime
  • 7. Usage and architecture walk-through
  • 8. Use Case #1: Exposing an SCA service to HTTP using REST We have an existing SCA service and want to make it RESTful 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 Each method should have a compatible operation in the SCA service
  • 9. REST Services Supports exposing existing SCA components as RESTFullservices Exposing a service as RESTfull resource Consuming REST Services Multiple JavaScript frameworks such as Dojo (XHR) Regular Web browsers Regular utilities such as cUrl, wGet, etc SCA component <component name=”Catalog"> <implementation.java class="services.FruitsCataloglmpl" /> <service name=”Catalog"> <t:binding.resturi="http://localhost:8080/Cartalog" /> <t:wireFormat.json /> <t:operationSelector.jaxrs /> </service> </component> Fruit Catalog json
  • 10. 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); }
  • 11. REST service binding runtime architecture Tuscany invocation chain Tuscany JAX-RS Servlet JAX-RS annotated Java interface SCA Component Generated JAX-RS resource class HTTP SCA proxy JAX-RS runtime (Apache Wink) Tuscany runtime
  • 12. 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)
  • 13. RPC Services over HTTP GET The REST binding provides mapping your RPC style calls over HTTP GET Exposing a service as RESTful resource Client Invocation http://localhost:8085/EchoService?method=echo&msg=Hello RPC http://localhost:8085/EchoService?method=echoArrayString&msgArray=Hello RPC1&msgArray=Hello RPC2" Fruit Catalog <component name=”Catalog"> <implementation.java class="services.FruitsCataloglmpl" /> <service name=”Catalog"> <t:binding.resturi="http://localhost:8080/Cartalog" /> <t:wireFormat.json /> <t:operationSelector.rpc /> </service> </component> json
  • 14. Mapping queryString to RPC method parameters @Remotable public interface Echo { String echo(@QueryParam("msg") String msg); intechoInt(intparam); booleanechoBoolean(booleanparam); String [] echoArrayString(@QueryParam("msgArray") String[] stringArray); int [] echoArrayInt(int[] intArray); }
  • 15. 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
  • 16. 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
  • 17. 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 by Tuscany created 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
  • 18. Sample configuration To invoke a RESTful resource such as getPhotoById(String id): @GET @Path(“/photos/{id}”) InputStreamgetPhotoById(@PathParam(“id”) String id); SCA Reference <reference name=“photoService”> <interface.java interface=“…”/> <tuscany:binding.resturi=“http://example.com/”/> </reference>
  • 19. REST reference binding runtime architecture Tuscany invocation chain REST binding invoker JAX-RS annotated Java interface SCA Component HTTP JAX-RS client(Apache Wink) Tuscany runtime
  • 20. 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).
  • 21. Tuscany implemention.jaxrs Tuscany introduced an implementation type (under tuscany namespace) to provide out-of-box support for component using JAX-RS
  • 22. implementation.jaxrs runtime archirecture Each root resource is translated into an SCA service with binding.rest SCA Component REST binding JAX-RS application Resource class Resource class JAX-RS runtime (Apache Wink) Tuscany runtime
  • 23. Sample configuration for implementation.rest 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" name="HelloWorld"> <component name="HelloWorldApp"> <tuscany:implementation.jaxrs application="helloworld.jaxrs.HelloWorldApp"/> </component> </composite>