SlideShare a Scribd company logo
1 of 43
Download to read offline
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
OSGi Community Event 2016
co-located at
EclipseCon Europe 2016
Dynamically assembled REST microservices
using JAX-RS and... microservices?
Neil Bartlett
http://www.paremus.com
info@paremus.com
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Introduction
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
What are Microservices?
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
What are Microservices?
• Ignoring the “OSGi Services are microservices” argument for now!
• Microservices are commonly understood to be:
• Small, independently deployable units of functionality;
• Decoupled from internal details;
• Resilient to failure;
• Potentially implemented in heterogeneous languages.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
The Isolation Curve
Monolithic
Method
Classes
OSGi
Isolation
Cost
Process
VM Physical
Server
Regional
Datacentre
Datacentre on
Mars
Container
“Microservices”
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Process/Container Level Isolation
• Communication implies networking.
• Serialisation, deserialisation, addressing, etc.
• Many approaches taken over the years!
• CORBA
• RMI
• COM
• SOAP
• DDS
• Thrift, Avro, Protobuf …
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
RESTful Microservices
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
What is REST
• REpresentational State Transfer – from Roy Fielding’s dissertation.
• An architectural style that focuses on:
• Resources vs Procedures
• Limited set of operations (e.g. CRUD)
• Flexibility and adaptability
• Compliance with web and internet structures.
• “It’s how the Web works”.
• Bonus: plays nicely with caches and proxies.
• Does not dictate message formats. Clients can request preferred format.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Advantages of REST vs RPC
• Excellent cross-language support compatibility.
• Well defined behaviour, e.g. idempotency.
• Adaptable — easier for client and server to evolve and deploy
independently.
• In theory unversioned, self-documenting APIs.
• Clients can navigate links and “discover” the shape of the API.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Disadvantages of REST vs RPC
• Impedance mismatch with mainstream languages.
• RPC is easier for quick-and-dirty jobs.
• In practice, REST APIs are versioned… much to Fielding’s disgust!
• See Docker, GitHub, etc.
• In practice, clients do expect specific versions, and break on mismatch.
• Coding a fully flexible, adaptive client is a lot of work!
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS
• Java API for RESTful Web Services.
• Eases the impedance mismatch for writing REST resources in Java.
• Java EE specification.
• JSR 311 defined JAX-RS 1.1 in 2009.
• JSR 339 defined JAX-RS 2.0 in 2013.
• Added client API, async HTTP on server side, filters and interceptors.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Resource Classes
• JAX-RS allows us to define Resources as plain Java classes.
• Annotations control how the resource responds to web requests:
• @Path – specifies a relative path for the resource or a method
• @GET, @PUT, @POST, @DELETE, @HEAD, @OPTIONS specify the
HTTP request type for a resource method
• @Produces – specifies the media type a method will produce
• @Consumes – specifies the media type a method can accept
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Simple Example
@Path(“foo”)
public class Foo {
@GET @Path(“test”)
@Produces(TEXT_PLAIN)
public String getFoo() { return “hello”; }
@GET @Path(“test”)
@Produces(APPLICATION_JSON)
public String getFooJson() { return “{‘hello’:’’}”; }
}
• The JAX-RS engine chooses which method to call based on the client’s
Accept header. E.g. Accept: application/json
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Parameterised Paths
@GET @Path(“test/{name}”)
public String getFoo(@PathParam(“name”) String name) {
return “hello ” + name;
}
• The JAX-RS engine chooses which method to call based on the client’s
Accept header. E.g. Accept: application/json
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Field Injection
@Path(“foo”)
public class Foo {
@Context HttpHeaders headers;
@Context UriInfo uriInfo;
@GET @Path(“test”)
public String getFoo(String name) {
headers.getRequestHeaders()
.getFirst(“Last-Event-ID”);
…
}
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Automatic Transformation
• Use JAXB to define mapping to JSON or XML.
• Saves complicated manual serialisation.
• NB: Requires JAXB annotations on the Product class.
@Path(“foo”)
public class Foo {
@GET
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public Product getProduct(String id) {
Product p = // …
return p;
}
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS in OSGi
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS in OSGi
• Using JAX-RS directly in OSGi is tricky.
• Resources configured by class name… not ideal in a modular world.
• Could use the Web Application spec (WABs) but then we lose a lot of
OSGi goodness like Declarative Services.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS in OSGi
• Mapping OSGi Services to JAX-RS is fairly obvious idea.
• Whiteboard style: to provide a Resource, simply provide a Service.
• Several open source implementations.
• Most notably osgi-jaxrs-connector from EclipseSource.
• Time to standardise!
• Apply latest techniques and lessons from enRoute.
• RFC 217 under development.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS in OSGi
• JAX-RS Resources are similar to Servlets.
• We already have the Http Whiteboard…
• Why not reuse it?
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS Resource Service
• Publish a service of any type.
• Attach marker property osgi.jaxrs.resource.base.
• Marks the property as a JAX-RS resource, and defines the base URI.
osgi.jaxrs.resource.base=example
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS Resource Component
• Publish a service of any type.
• Attach marker property osgi.jaxrs.resource.base.
• Marks the property as a JAX-RS resource, and defines the base URI.
@Component(
service=Object.class,
property=“osgi.jaxrs.resource.base=jaxrs")
@Path(“foo”)
public class Foo {
@GET
public String getFoo() { … }
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS Resource Component
• Note: service=Object.class
• The component must be published as a service of some type.
• The component does not implement an interface…
• therefore bnd would not normally declare a service element.
• The service attribute forces bnd to declare a service element.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
What’s the Path?
@Component(
service=Object.class,
property=“osgi.jaxrs.resource.base=example")
@Path(“foo”)
public class Foo {
@GET
@Path(“test”)
public String getFoo() { … }
}
• http://<host>:<port>/example/foo/test
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Scopes
• In “plain” JAX-RS, resources objects are created and destroyed on each
request.
• This doesn’t match the normal OSGi service lifecycle.
• The previous example runs as a “singleton” in JAX-RS terms.
• We can switch to prototype scope by specifying:
scope=ServiceScope.PROTOTYPE
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Scopes
• NB: don’t use injected @Context fields in a singleton!
• Use as method parameters instead.
• Or use prototype scope if the component is cheap to create.
@GET @Path(“{name}”)
public String getFoo(
@PathParam(“name”) String name,
@Context HttpHeaders headers) {
// …
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
JAX-RS Applications
• Sometimes we cluster related Resources into an Application.
• Applications are provided in the same way.
• Note slightly different property declaration.
@Component(
service=Object.class,
property=“osgi.jaxrs.application.base=example")
@Path(“myapp”)
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Stream.of(MyResource1.class,
MyResource2.class, …)
.collect(toSet());
}
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Endpoint Advertisement
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Problem
• You are writing a microservices client…
• Where is the back-end service??
• Choices:
• Hard code URL;
• Manually configure URL;
• DNS tricks.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
OSGi Remote Services
• Remote Services is a specification for publishing and invoking services
across a network.
Provider Consumer
Remote Services Provider Remote Services Provider
???
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Consuming REST Resources
• But a REST resource cannot be invoked like a normal service!
• We don’t use Remote Services this way.
• The JAX-RS whiteboard provides an Endpoint service with no methods.
• That service carries a property named osgi.jaxrs.uri
• … the URI that can be used to access the JAX-RS resource.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Consuming REST Resources
REST
Resource
HTTP
Server
Endpoint
URI=http://.../rest
REST
Client
http
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Consuming REST Resources
• Declarative Services code snippet.
• Note: our component depends on the remote REST resource!
• Can depend on multiple resources, using different target filters.
• This component could be another JAX-RS resource!
@Reference(target = “(osgi.jaxrs.name=MyResource)”)
void setEndpoint(Endpoint ep, Map<String,Object> props) {
this.uri = converter
.convert(props.get(“osgi.jaxrs.uri”))
.to(String.class);
}
// Later…
client.target(uri).request();
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Dynamically Connecting/Reconnecting, Self-
Assembling Distributed Applications
• If a part crashes, just restart anywhere else.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Coding Clients
• Use the JAX-RS 2.0 Client API. ClientBuilder is available as a
service.
• Integrated with OSGi Promises for async invocation.
PromiseHandler<String> handler = new PromiseHandler<>();
clientBuilder.build()
.target(uri)
.path(“/foo”).path(“/{name}”)
.resolveTemplate(“name”, getNameParam())
.request().async().get(handler);
Promise<String> result = handler.getPromise();
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Reminder: Promises are Cool
• Promises can be used to chain together a series of async REST calls.
requestMapCoords(postcode)
.flatMap(c -> findNearestSchool(c))
.flatMap(s -> requestExamRanking(s))
…
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Implementation & Demo
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Specification Status
• RFC 217
• View on GitHub: github.com/osgi/design → rfcs/rfc0217
• Expected in OSGi Release 7, around Q2-Q3 2017.
• Not yet a chapter in the Early Draft compendium.
• RFC Author: Tim Ward, Paremus.
• RI will be developed by Liferay.
• Based on CXF JAX-RS.
• Ongoing implementation work in Apache Aries.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
DEMO
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Want to See More?
• Go to Tim Ward’s talk tomorrow at 10:15 in Schubartsaal.
• “Transaction Control – A functional approach to modular transaction
management”
• Demo includes a CRUD microservice implemented with this spec.
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
www.paremus.com @Paremus info@paremus.com
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016

More Related Content

What's hot

Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
Mario Heiderich
 

What's hot (20)

Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
 
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
 
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
Lior rotkovitch   ASM WAF  unified learning – building policy with asm v12Lior rotkovitch   ASM WAF  unified learning – building policy with asm v12
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
 
Top Ten Web Hacking Techniques of 2012
Top Ten Web Hacking Techniques of 2012Top Ten Web Hacking Techniques of 2012
Top Ten Web Hacking Techniques of 2012
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Agile and Secure SDLC
Agile and Secure SDLCAgile and Secure SDLC
Agile and Secure SDLC
 
Android Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and OrganizationAndroid Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and Organization
 
Introduction to CRI and OCI
Introduction to CRI and OCIIntroduction to CRI and OCI
Introduction to CRI and OCI
 
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Oracle Flex ASM - What’s New and Best Practices by Jim Williams
Oracle Flex ASM - What’s New and Best Practices by Jim WilliamsOracle Flex ASM - What’s New and Best Practices by Jim Williams
Oracle Flex ASM - What’s New and Best Practices by Jim Williams
 
Android Security & Penetration Testing
Android Security & Penetration TestingAndroid Security & Penetration Testing
Android Security & Penetration Testing
 
Directory Traversal & File Inclusion Attacks
Directory Traversal & File Inclusion AttacksDirectory Traversal & File Inclusion Attacks
Directory Traversal & File Inclusion Attacks
 
Top 10 Web Application vulnerabilities
Top 10 Web Application vulnerabilitiesTop 10 Web Application vulnerabilities
Top 10 Web Application vulnerabilities
 

Viewers also liked

Viewers also liked (12)

REST and Microservices
REST and MicroservicesREST and Microservices
REST and Microservices
 
Modularity, Microservices and Containerisation - Neil Bartlett, Derek Baum
Modularity, Microservices and Containerisation - Neil Bartlett, Derek BaumModularity, Microservices and Containerisation - Neil Bartlett, Derek Baum
Modularity, Microservices and Containerisation - Neil Bartlett, Derek Baum
 
Of Microservices and Microservices - Robert Munteanu
Of Microservices and Microservices -  Robert MunteanuOf Microservices and Microservices -  Robert Munteanu
Of Microservices and Microservices - Robert Munteanu
 
OSGi toolchain from the ground up - Matteo Rulli
OSGi toolchain from the ground up - Matteo RulliOSGi toolchain from the ground up - Matteo Rulli
OSGi toolchain from the ground up - Matteo Rulli
 
Microservices and OSGi: Better together?
Microservices and OSGi: Better together?Microservices and OSGi: Better together?
Microservices and OSGi: Better together?
 
WebSockets and Equinox OSGi in a Servlet Container - Nedelcho Delchev
WebSockets and Equinox OSGi in a Servlet Container - Nedelcho DelchevWebSockets and Equinox OSGi in a Servlet Container - Nedelcho Delchev
WebSockets and Equinox OSGi in a Servlet Container - Nedelcho Delchev
 
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
 
Lean Microservices with OSGi - Christian Schneider
Lean Microservices with OSGi - Christian SchneiderLean Microservices with OSGi - Christian Schneider
Lean Microservices with OSGi - Christian Schneider
 
Writing Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmWriting Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly Swarm
 
OSGi for outsiders - Milen Dyankov
OSGi for outsiders - Milen DyankovOSGi for outsiders - Milen Dyankov
OSGi for outsiders - Milen Dyankov
 
Eclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia KissEclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia Kiss
 
Microservices Platforms - Which is Best?
Microservices Platforms - Which is Best?Microservices Platforms - Which is Best?
Microservices Platforms - Which is Best?
 

Similar to Dynamically assembled REST Microservices using JAX-RS and... Microservices? - Neil Bartlett

Kick Start your Application Development and Management Strategy
Kick Start your Application Development and Management Strategy Kick Start your Application Development and Management Strategy
Kick Start your Application Development and Management Strategy
WSO2
 
Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB
WSO2
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
Akana
 
Product Release Webinar- WSO2 Developer Studio 3.5
Product Release Webinar- WSO2 Developer Studio 3.5Product Release Webinar- WSO2 Developer Studio 3.5
Product Release Webinar- WSO2 Developer Studio 3.5
WSO2
 
Jax WS JAX RS and Java Web Apps with WSO2 Platform
Jax WS JAX RS and Java Web Apps with WSO2 PlatformJax WS JAX RS and Java Web Apps with WSO2 Platform
Jax WS JAX RS and Java Web Apps with WSO2 Platform
WSO2
 

Similar to Dynamically assembled REST Microservices using JAX-RS and... Microservices? - Neil Bartlett (20)

APIdays 2016 - The State of Web API Languages
APIdays 2016  - The State of Web API LanguagesAPIdays 2016  - The State of Web API Languages
APIdays 2016 - The State of Web API Languages
 
Kick Start your Application Development and Management Strategy
Kick Start your Application Development and Management Strategy Kick Start your Application Development and Management Strategy
Kick Start your Application Development and Management Strategy
 
Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)
 
What's new in the Java API for JSON Binding
What's new in the Java API for JSON BindingWhat's new in the Java API for JSON Binding
What's new in the Java API for JSON Binding
 
UKOUG - Implementing Enterprise API Management in the Oracle Cloud
UKOUG - Implementing Enterprise API Management in the Oracle CloudUKOUG - Implementing Enterprise API Management in the Oracle Cloud
UKOUG - Implementing Enterprise API Management in the Oracle Cloud
 
RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009
 
Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB
 
Leverage integration cloud_service_for_ebs_
Leverage integration cloud_service_for_ebs_Leverage integration cloud_service_for_ebs_
Leverage integration cloud_service_for_ebs_
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
 
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
 
PHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the foolPHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the fool
 
Spring Cloud Servicesの紹介 #pcf_tokyo
Spring Cloud Servicesの紹介 #pcf_tokyoSpring Cloud Servicesの紹介 #pcf_tokyo
Spring Cloud Servicesの紹介 #pcf_tokyo
 
Spark and scala reference architecture
Spark and scala reference architectureSpark and scala reference architecture
Spark and scala reference architecture
 
Product Release Webinar- WSO2 Developer Studio 3.5
Product Release Webinar- WSO2 Developer Studio 3.5Product Release Webinar- WSO2 Developer Studio 3.5
Product Release Webinar- WSO2 Developer Studio 3.5
 
Jax WS JAX RS and Java Web Apps with WSO2 Platform
Jax WS JAX RS and Java Web Apps with WSO2 PlatformJax WS JAX RS and Java Web Apps with WSO2 Platform
Jax WS JAX RS and Java Web Apps with WSO2 Platform
 
Oracle Code Online: Building a Serverless State Service for the Cloud
Oracle Code Online: Building a Serverless State Service for the CloudOracle Code Online: Building a Serverless State Service for the Cloud
Oracle Code Online: Building a Serverless State Service for the Cloud
 
API Description Languages: Which Is The Right One For Me?
 API Description Languages: Which Is The Right One For Me?  API Description Languages: Which Is The Right One For Me?
API Description Languages: Which Is The Right One For Me?
 
OpenAPI v.Next - Events, Alternative Schemas & the Road Ahead
OpenAPI v.Next - Events, Alternative Schemas & the Road AheadOpenAPI v.Next - Events, Alternative Schemas & the Road Ahead
OpenAPI v.Next - Events, Alternative Schemas & the Road Ahead
 
RMOUG MySQL 5.7 New Features
RMOUG MySQL 5.7 New FeaturesRMOUG MySQL 5.7 New Features
RMOUG MySQL 5.7 New Features
 

More from mfrancis

Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
mfrancis
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
mfrancis
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
mfrancis
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 

More from mfrancis (20)

Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
 
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank LyaruuOSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
 
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
 
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
 
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
 
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Dynamically assembled REST Microservices using JAX-RS and... Microservices? - Neil Bartlett

  • 1. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 OSGi Community Event 2016 co-located at EclipseCon Europe 2016 Dynamically assembled REST microservices using JAX-RS and... microservices? Neil Bartlett http://www.paremus.com info@paremus.com
  • 2. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Introduction
  • 3. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 What are Microservices?
  • 4. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 What are Microservices? • Ignoring the “OSGi Services are microservices” argument for now! • Microservices are commonly understood to be: • Small, independently deployable units of functionality; • Decoupled from internal details; • Resilient to failure; • Potentially implemented in heterogeneous languages.
  • 5. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 The Isolation Curve Monolithic Method Classes OSGi Isolation Cost Process VM Physical Server Regional Datacentre Datacentre on Mars Container “Microservices”
  • 6. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Process/Container Level Isolation • Communication implies networking. • Serialisation, deserialisation, addressing, etc. • Many approaches taken over the years! • CORBA • RMI • COM • SOAP • DDS • Thrift, Avro, Protobuf …
  • 7. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 RESTful Microservices
  • 8. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 What is REST • REpresentational State Transfer – from Roy Fielding’s dissertation. • An architectural style that focuses on: • Resources vs Procedures • Limited set of operations (e.g. CRUD) • Flexibility and adaptability • Compliance with web and internet structures. • “It’s how the Web works”. • Bonus: plays nicely with caches and proxies. • Does not dictate message formats. Clients can request preferred format.
  • 9. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Advantages of REST vs RPC • Excellent cross-language support compatibility. • Well defined behaviour, e.g. idempotency. • Adaptable — easier for client and server to evolve and deploy independently. • In theory unversioned, self-documenting APIs. • Clients can navigate links and “discover” the shape of the API.
  • 10. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Disadvantages of REST vs RPC • Impedance mismatch with mainstream languages. • RPC is easier for quick-and-dirty jobs. • In practice, REST APIs are versioned… much to Fielding’s disgust! • See Docker, GitHub, etc. • In practice, clients do expect specific versions, and break on mismatch. • Coding a fully flexible, adaptive client is a lot of work!
  • 11. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS
  • 12. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS • Java API for RESTful Web Services. • Eases the impedance mismatch for writing REST resources in Java. • Java EE specification. • JSR 311 defined JAX-RS 1.1 in 2009. • JSR 339 defined JAX-RS 2.0 in 2013. • Added client API, async HTTP on server side, filters and interceptors.
  • 13. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Resource Classes • JAX-RS allows us to define Resources as plain Java classes. • Annotations control how the resource responds to web requests: • @Path – specifies a relative path for the resource or a method • @GET, @PUT, @POST, @DELETE, @HEAD, @OPTIONS specify the HTTP request type for a resource method • @Produces – specifies the media type a method will produce • @Consumes – specifies the media type a method can accept
  • 14. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Simple Example @Path(“foo”) public class Foo { @GET @Path(“test”) @Produces(TEXT_PLAIN) public String getFoo() { return “hello”; } @GET @Path(“test”) @Produces(APPLICATION_JSON) public String getFooJson() { return “{‘hello’:’’}”; } } • The JAX-RS engine chooses which method to call based on the client’s Accept header. E.g. Accept: application/json
  • 15. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Parameterised Paths @GET @Path(“test/{name}”) public String getFoo(@PathParam(“name”) String name) { return “hello ” + name; } • The JAX-RS engine chooses which method to call based on the client’s Accept header. E.g. Accept: application/json
  • 16. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Field Injection @Path(“foo”) public class Foo { @Context HttpHeaders headers; @Context UriInfo uriInfo; @GET @Path(“test”) public String getFoo(String name) { headers.getRequestHeaders() .getFirst(“Last-Event-ID”); … } }
  • 17. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Automatic Transformation • Use JAXB to define mapping to JSON or XML. • Saves complicated manual serialisation. • NB: Requires JAXB annotations on the Product class. @Path(“foo”) public class Foo { @GET @Produces({ APPLICATION_JSON, APPLICATION_XML }) public Product getProduct(String id) { Product p = // … return p; } }
  • 18. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS in OSGi
  • 19. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS in OSGi • Using JAX-RS directly in OSGi is tricky. • Resources configured by class name… not ideal in a modular world. • Could use the Web Application spec (WABs) but then we lose a lot of OSGi goodness like Declarative Services.
  • 20. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS in OSGi • Mapping OSGi Services to JAX-RS is fairly obvious idea. • Whiteboard style: to provide a Resource, simply provide a Service. • Several open source implementations. • Most notably osgi-jaxrs-connector from EclipseSource. • Time to standardise! • Apply latest techniques and lessons from enRoute. • RFC 217 under development.
  • 21. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS in OSGi • JAX-RS Resources are similar to Servlets. • We already have the Http Whiteboard… • Why not reuse it?
  • 22. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS Resource Service • Publish a service of any type. • Attach marker property osgi.jaxrs.resource.base. • Marks the property as a JAX-RS resource, and defines the base URI. osgi.jaxrs.resource.base=example
  • 23. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS Resource Component • Publish a service of any type. • Attach marker property osgi.jaxrs.resource.base. • Marks the property as a JAX-RS resource, and defines the base URI. @Component( service=Object.class, property=“osgi.jaxrs.resource.base=jaxrs") @Path(“foo”) public class Foo { @GET public String getFoo() { … } }
  • 24. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS Resource Component • Note: service=Object.class • The component must be published as a service of some type. • The component does not implement an interface… • therefore bnd would not normally declare a service element. • The service attribute forces bnd to declare a service element.
  • 25. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 What’s the Path? @Component( service=Object.class, property=“osgi.jaxrs.resource.base=example") @Path(“foo”) public class Foo { @GET @Path(“test”) public String getFoo() { … } } • http://<host>:<port>/example/foo/test
  • 26. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Scopes • In “plain” JAX-RS, resources objects are created and destroyed on each request. • This doesn’t match the normal OSGi service lifecycle. • The previous example runs as a “singleton” in JAX-RS terms. • We can switch to prototype scope by specifying: scope=ServiceScope.PROTOTYPE
  • 27. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Scopes • NB: don’t use injected @Context fields in a singleton! • Use as method parameters instead. • Or use prototype scope if the component is cheap to create. @GET @Path(“{name}”) public String getFoo( @PathParam(“name”) String name, @Context HttpHeaders headers) { // … }
  • 28. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 JAX-RS Applications • Sometimes we cluster related Resources into an Application. • Applications are provided in the same way. • Note slightly different property declaration. @Component( service=Object.class, property=“osgi.jaxrs.application.base=example") @Path(“myapp”) public class MyApplication extends Application { @Override public Set<Class<?>> getClasses() { return Stream.of(MyResource1.class, MyResource2.class, …) .collect(toSet()); } }
  • 29. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Endpoint Advertisement
  • 30. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Problem • You are writing a microservices client… • Where is the back-end service?? • Choices: • Hard code URL; • Manually configure URL; • DNS tricks.
  • 31. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 OSGi Remote Services • Remote Services is a specification for publishing and invoking services across a network. Provider Consumer Remote Services Provider Remote Services Provider ???
  • 32. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Consuming REST Resources • But a REST resource cannot be invoked like a normal service! • We don’t use Remote Services this way. • The JAX-RS whiteboard provides an Endpoint service with no methods. • That service carries a property named osgi.jaxrs.uri • … the URI that can be used to access the JAX-RS resource.
  • 33. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Consuming REST Resources REST Resource HTTP Server Endpoint URI=http://.../rest REST Client http
  • 34. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Consuming REST Resources • Declarative Services code snippet. • Note: our component depends on the remote REST resource! • Can depend on multiple resources, using different target filters. • This component could be another JAX-RS resource! @Reference(target = “(osgi.jaxrs.name=MyResource)”) void setEndpoint(Endpoint ep, Map<String,Object> props) { this.uri = converter .convert(props.get(“osgi.jaxrs.uri”)) .to(String.class); } // Later… client.target(uri).request();
  • 35. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Dynamically Connecting/Reconnecting, Self- Assembling Distributed Applications • If a part crashes, just restart anywhere else.
  • 36. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Coding Clients • Use the JAX-RS 2.0 Client API. ClientBuilder is available as a service. • Integrated with OSGi Promises for async invocation. PromiseHandler<String> handler = new PromiseHandler<>(); clientBuilder.build() .target(uri) .path(“/foo”).path(“/{name}”) .resolveTemplate(“name”, getNameParam()) .request().async().get(handler); Promise<String> result = handler.getPromise();
  • 37. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Reminder: Promises are Cool • Promises can be used to chain together a series of async REST calls. requestMapCoords(postcode) .flatMap(c -> findNearestSchool(c)) .flatMap(s -> requestExamRanking(s)) …
  • 38. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Implementation & Demo
  • 39. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Specification Status • RFC 217 • View on GitHub: github.com/osgi/design → rfcs/rfc0217 • Expected in OSGi Release 7, around Q2-Q3 2017. • Not yet a chapter in the Early Draft compendium. • RFC Author: Tim Ward, Paremus. • RI will be developed by Liferay. • Based on CXF JAX-RS. • Ongoing implementation work in Apache Aries.
  • 40. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 DEMO
  • 41. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Want to See More? • Go to Tim Ward’s talk tomorrow at 10:15 in Schubartsaal. • “Transaction Control – A functional approach to modular transaction management” • Demo includes a CRUD microservice implemented with this spec.
  • 42. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 www.paremus.com @Paremus info@paremus.com
  • 43. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016