SlideShare a Scribd company logo
Submit Search
Upload
REST in an Async World
Report
Share
David Delabassee
DevRel - Java Platform Group - Oracle
Follow
•
3 likes
•
2,300 views
1
of
50
REST in an Async World
•
3 likes
•
2,300 views
Report
Share
Download Now
Download to read offline
Software
Presented at Oracle Code Israel (July 2017)
Read more
David Delabassee
DevRel - Java Platform Group - Oracle
Follow
Recommended
JAX-RS 2.1 Reloaded by
JAX-RS 2.1 Reloaded
David Delabassee
1.7K views
•
43 slides
Java EE Next by
Java EE Next
David Delabassee
2.2K views
•
44 slides
Java EE 8 - February 2017 update by
Java EE 8 - February 2017 update
David Delabassee
6K views
•
65 slides
Java EE Next - BeJUG JavaOne Afterglow 2016 by
Java EE Next - BeJUG JavaOne Afterglow 2016
David Delabassee
433 views
•
26 slides
Application Development with Oracle Database by
Application Development with Oracle Database
gvenzl
3.3K views
•
127 slides
Oow MySQL Whats new in security overview sept 2017 v1 by
Oow MySQL Whats new in security overview sept 2017 v1
Mark Swarbrick
98 views
•
42 slides
More Related Content
What's hot
TLV - Whats new in MySQL 8 by
TLV - Whats new in MySQL 8
Mark Swarbrick
222 views
•
41 slides
Rootconf admin101 by
Rootconf admin101
Ligaya Turmelle
516 views
•
45 slides
TDC2018SP | Trilha Java Enterprise - O Java EE morreu? EE4J e so um plugin? E... by
TDC2018SP | Trilha Java Enterprise - O Java EE morreu? EE4J e so um plugin? E...
tdc-globalcode
141 views
•
27 slides
Java @ Rio Meetup #1 - Java @ Oracle Cloud by
Java @ Rio Meetup #1 - Java @ Oracle Cloud
Paulo Alberto Simoes ∴
529 views
•
32 slides
11회 Oracle Developer Meetup 발표 자료: Oracle NoSQL (2019.05.18) oracle-nosql pu... by
11회 Oracle Developer Meetup 발표 자료: Oracle NoSQL (2019.05.18) oracle-nosql pu...
Taewan Kim
342 views
•
61 slides
JSON support in Java EE 8 by
JSON support in Java EE 8
Lukas Jungmann
2.4K views
•
77 slides
What's hot
(20)
TLV - Whats new in MySQL 8 by Mark Swarbrick
TLV - Whats new in MySQL 8
Mark Swarbrick
•
222 views
Rootconf admin101 by Ligaya Turmelle
Rootconf admin101
Ligaya Turmelle
•
516 views
TDC2018SP | Trilha Java Enterprise - O Java EE morreu? EE4J e so um plugin? E... by tdc-globalcode
TDC2018SP | Trilha Java Enterprise - O Java EE morreu? EE4J e so um plugin? E...
tdc-globalcode
•
141 views
Java @ Rio Meetup #1 - Java @ Oracle Cloud by Paulo Alberto Simoes ∴
Java @ Rio Meetup #1 - Java @ Oracle Cloud
Paulo Alberto Simoes ∴
•
529 views
11회 Oracle Developer Meetup 발표 자료: Oracle NoSQL (2019.05.18) oracle-nosql pu... by Taewan Kim
11회 Oracle Developer Meetup 발표 자료: Oracle NoSQL (2019.05.18) oracle-nosql pu...
Taewan Kim
•
342 views
JSON support in Java EE 8 by Lukas Jungmann
JSON support in Java EE 8
Lukas Jungmann
•
2.4K views
Performance in Spark 2.0, PDX Spark Meetup 8/18/16 by pdx_spark
Performance in Spark 2.0, PDX Spark Meetup 8/18/16
pdx_spark
•
701 views
2018 Oracle Impact 발표자료: Oracle Enterprise AI by Taewan Kim
2018 Oracle Impact 발표자료: Oracle Enterprise AI
Taewan Kim
•
444 views
Aneez Hasan_Resume by Aneez Hasan Mohamed Rafi
Aneez Hasan_Resume
Aneez Hasan Mohamed Rafi
•
409 views
Jfokus 2017 Oracle Dev Cloud and Containers by Mika Rinne
Jfokus 2017 Oracle Dev Cloud and Containers
Mika Rinne
•
257 views
MySQL Devops Webinar by Frederic Descamps
MySQL Devops Webinar
Frederic Descamps
•
281 views
Oracle databáze – Konsolidovaná Data Management Platforma by MarketingArrowECS_CZ
Oracle databáze – Konsolidovaná Data Management Platforma
MarketingArrowECS_CZ
•
218 views
토드(Toad) 신제품 및 크로스 플랫폼 전략(1) by mosaicnet
토드(Toad) 신제품 및 크로스 플랫폼 전략(1)
mosaicnet
•
1.5K views
The Future of Java and You by Heather VanCura
The Future of Java and You
Heather VanCura
•
215 views
Introduction to MySQL InnoDB Cluster by Frederic Descamps
Introduction to MySQL InnoDB Cluster
Frederic Descamps
•
334 views
MySQL Innovation: from 5.7 to 8.0 by Frederic Descamps
MySQL Innovation: from 5.7 to 8.0
Frederic Descamps
•
800 views
MySQL Community Meetup in China : Innovation driven by the Community by Frederic Descamps
MySQL Community Meetup in China : Innovation driven by the Community
Frederic Descamps
•
211 views
What's coming in Java EE 8 by David Delabassee
What's coming in Java EE 8
David Delabassee
•
2.3K views
Cisco Connect Vancouver 2017 - Embedding IR into the DNA of the business by Cisco Canada
Cisco Connect Vancouver 2017 - Embedding IR into the DNA of the business
Cisco Canada
•
279 views
DataOps Barcelona - MySQL HA so easy... that's insane ! by Frederic Descamps
DataOps Barcelona - MySQL HA so easy... that's insane !
Frederic Descamps
•
342 views
Similar to REST in an Async World
TDC2018SP | Trilha Arq Java - Crie arquiteturas escalaveis, multi-language e ... by
TDC2018SP | Trilha Arq Java - Crie arquiteturas escalaveis, multi-language e ...
tdc-globalcode
68 views
•
18 slides
Why MySQL High Availability Matters by
Why MySQL High Availability Matters
Mark Swarbrick
315 views
•
42 slides
MySQL Shell - The DevOps Tool for MySQL by
MySQL Shell - The DevOps Tool for MySQL
Miguel Araújo
176 views
•
35 slides
TDC2018 | Trilha Java - The quest to the Language Graal: One VM to rule them... by
TDC2018 | Trilha Java - The quest to the Language Graal: One VM to rule them...
tdc-globalcode
132 views
•
39 slides
CDI 2.0 (JSR 365) - Java Day Tokyo 2017 (English) by
CDI 2.0 (JSR 365) - Java Day Tokyo 2017 (English)
Logico
1.4K views
•
81 slides
Migrating your infrastructure to OpenStack - Avi Miller, Oracle by
Migrating your infrastructure to OpenStack - Avi Miller, Oracle
OpenStack
373 views
•
28 slides
Similar to REST in an Async World
(20)
TDC2018SP | Trilha Arq Java - Crie arquiteturas escalaveis, multi-language e ... by tdc-globalcode
TDC2018SP | Trilha Arq Java - Crie arquiteturas escalaveis, multi-language e ...
tdc-globalcode
•
68 views
Why MySQL High Availability Matters by Mark Swarbrick
Why MySQL High Availability Matters
Mark Swarbrick
•
315 views
MySQL Shell - The DevOps Tool for MySQL by Miguel Araújo
MySQL Shell - The DevOps Tool for MySQL
Miguel Araújo
•
176 views
TDC2018 | Trilha Java - The quest to the Language Graal: One VM to rule them... by tdc-globalcode
TDC2018 | Trilha Java - The quest to the Language Graal: One VM to rule them...
tdc-globalcode
•
132 views
CDI 2.0 (JSR 365) - Java Day Tokyo 2017 (English) by Logico
CDI 2.0 (JSR 365) - Java Day Tokyo 2017 (English)
Logico
•
1.4K views
Migrating your infrastructure to OpenStack - Avi Miller, Oracle by OpenStack
Migrating your infrastructure to OpenStack - Avi Miller, Oracle
OpenStack
•
373 views
Building a Serverless State Service for the Cloud by Edward Burns
Building a Serverless State Service for the Cloud
Edward Burns
•
472 views
MOUG17 Keynote: What's New from Oracle Database Development by Monica Li
MOUG17 Keynote: What's New from Oracle Database Development
Monica Li
•
1.6K views
Data Mobility for the Oracle Database by JWilliams and RGonzalez by Markus Michalewicz
Data Mobility for the Oracle Database by JWilliams and RGonzalez
Markus Michalewicz
•
775 views
Trivadis TechEvent 2017 Leveraging the Oracle Cloud by Kris Bhanushali tech_e... by Trivadis
Trivadis TechEvent 2017 Leveraging the Oracle Cloud by Kris Bhanushali tech_e...
Trivadis
•
91 views
Democratizing Serverless—The Open Source Fn Project - Serverless Summit by CodeOps Technologies LLP
Democratizing Serverless—The Open Source Fn Project - Serverless Summit
CodeOps Technologies LLP
•
6.6K views
NZOUG-GroundBreakers-2018 - Troubleshooting and Diagnosing 18c RAC by Sandesh Rao
NZOUG-GroundBreakers-2018 - Troubleshooting and Diagnosing 18c RAC
Sandesh Rao
•
606 views
Building Modern Applications Using APIs, Microservices and Chatbots by Oracle Developers
Building Modern Applications Using APIs, Microservices and Chatbots
Oracle Developers
•
3.2K views
Polyglot on the JVM with Graal (English) by Logico
Polyglot on the JVM with Graal (English)
Logico
•
5.4K views
Time-series Analytics using Matrix Profile and SAX by SUPREET OBEROI
Time-series Analytics using Matrix Profile and SAX
SUPREET OBEROI
•
459 views
Modern Application Development for the Enterprise by Juarez Junior
Modern Application Development for the Enterprise
Juarez Junior
•
136 views
JCP 20 Year Anniversary by Heather VanCura
JCP 20 Year Anniversary
Heather VanCura
•
168 views
AIOUG : OTNYathra - Troubleshooting and Diagnosing Oracle Database 12.2 and O... by Sandesh Rao
AIOUG : OTNYathra - Troubleshooting and Diagnosing Oracle Database 12.2 and O...
Sandesh Rao
•
701 views
Polyglot on the JVM with Graal (Japanese) by Logico
Polyglot on the JVM with Graal (Japanese)
Logico
•
3.2K views
Harnessing the Power of Optimizer Hints by Maria Colgan
Harnessing the Power of Optimizer Hints
Maria Colgan
•
10.5K views
More from David Delabassee
JVMs in Containers - Best Practices by
JVMs in Containers - Best Practices
David Delabassee
726 views
•
37 slides
JVMs in Containers by
JVMs in Containers
David Delabassee
1.3K views
•
38 slides
Serverless Java Challenges & Triumphs by
Serverless Java Challenges & Triumphs
David Delabassee
1.2K views
•
46 slides
Serverless Java - Challenges and Triumphs by
Serverless Java - Challenges and Triumphs
David Delabassee
282 views
•
41 slides
Randstad Docker meetup - Serverless by
Randstad Docker meetup - Serverless
David Delabassee
322 views
•
37 slides
Java Serverless in Action - Voxxed Banff by
Java Serverless in Action - Voxxed Banff
David Delabassee
232 views
•
22 slides
More from David Delabassee
(20)
JVMs in Containers - Best Practices by David Delabassee
JVMs in Containers - Best Practices
David Delabassee
•
726 views
JVMs in Containers by David Delabassee
JVMs in Containers
David Delabassee
•
1.3K views
Serverless Java Challenges & Triumphs by David Delabassee
Serverless Java Challenges & Triumphs
David Delabassee
•
1.2K views
Serverless Java - Challenges and Triumphs by David Delabassee
Serverless Java - Challenges and Triumphs
David Delabassee
•
282 views
Randstad Docker meetup - Serverless by David Delabassee
Randstad Docker meetup - Serverless
David Delabassee
•
322 views
Java Serverless in Action - Voxxed Banff by David Delabassee
Java Serverless in Action - Voxxed Banff
David Delabassee
•
232 views
Serverless Kotlin by David Delabassee
Serverless Kotlin
David Delabassee
•
251 views
HTTP/2 comes to Java by David Delabassee
HTTP/2 comes to Java
David Delabassee
•
5.9K views
Java EE 8 - Work in progress by David Delabassee
Java EE 8 - Work in progress
David Delabassee
•
2.5K views
HTTP/2 comes to Java (Dec. 2015 version) by David Delabassee
HTTP/2 comes to Java (Dec. 2015 version)
David Delabassee
•
690 views
EJB and CDI - Alignment and Strategy by David Delabassee
EJB and CDI - Alignment and Strategy
David Delabassee
•
31.9K views
HTTP/2 Comes to Java by David Delabassee
HTTP/2 Comes to Java
David Delabassee
•
2.9K views
Java EE 8 - What’s new on the Web front by David Delabassee
Java EE 8 - What’s new on the Web front
David Delabassee
•
960 views
HTTP/2 Comes to Java by David Delabassee
HTTP/2 Comes to Java
David Delabassee
•
10.8K views
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0 by David Delabassee
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0
David Delabassee
•
1.8K views
MVC 1.0 / JSR 371 by David Delabassee
MVC 1.0 / JSR 371
David Delabassee
•
12.7K views
Java EE 8 - An instant snapshot by David Delabassee
Java EE 8 - An instant snapshot
David Delabassee
•
10.7K views
Avatar 2.0 by David Delabassee
Avatar 2.0
David Delabassee
•
1.9K views
Java EE 8 - An instant snapshot by David Delabassee
Java EE 8 - An instant snapshot
David Delabassee
•
1.7K views
HTTP/2 Comes to Java - What Servlet 4.0 Means to You by David Delabassee
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
David Delabassee
•
13.8K views
Recently uploaded
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm
15 views
•
19 slides
EV Charging App Case by
EV Charging App Case
iCoderz Solutions
8 views
•
1 slide
Agile 101 by
Agile 101
John Valentino
9 views
•
20 slides
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke
35 views
•
124 slides
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j
12 views
•
26 slides
Myths and Facts About Hospice Care: Busting Common Misconceptions by
Myths and Facts About Hospice Care: Busting Common Misconceptions
Care Coordinations
6 views
•
1 slide
Recently uploaded
(20)
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm
•
15 views
EV Charging App Case by iCoderz Solutions
EV Charging App Case
iCoderz Solutions
•
8 views
Agile 101 by John Valentino
Agile 101
John Valentino
•
9 views
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke
•
35 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j
•
12 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common Misconceptions
Care Coordinations
•
6 views
The Era of Large Language Models.pptx by AbdulVahedShaik
The Era of Large Language Models.pptx
AbdulVahedShaik
•
7 views
nintendo_64.pptx by paiga02016
nintendo_64.pptx
paiga02016
•
5 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana
•
11 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India
Fleetable
•
12 views
SAP FOR TYRE INDUSTRY.pdf by Virendra Rai, PMP
SAP FOR TYRE INDUSTRY.pdf
Virendra Rai, PMP
•
27 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok
•
11 views
The Path to DevOps by John Valentino
The Path to DevOps
John Valentino
•
5 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the Life
John Valentino
•
6 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source Control
John Valentino
•
5 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik
•
8 views
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisions
Bert Jan Schrijver
•
6 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic
•
12 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy
•
14 views
SAP FOR CONTRACT MANUFACTURING.pdf by Virendra Rai, PMP
SAP FOR CONTRACT MANUFACTURING.pdf
Virendra Rai, PMP
•
13 views
REST in an Async World
1.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | David Delabassee @delabassee Oracle REST in an Async World Israel – July 2017
2.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 2
3.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 3
4.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direcPon. It is intended for informaPon purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or funcPonality, and should not be relied upon in making purchasing decisions. The development, release, and Pming of any features or funcPonality described for Oracle’s products remains at the sole discrePon of Oracle. 4
5.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Agenda • REST & JAX-RS • Synchronous vs. Asynchronous •
Client-side vs. Server-side 5
6.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client-side REST ConfidenPal – Oracle Internal/Restricted/Highly Restricted 6
7.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS • Java API for RESTful Web Services – JAX-RS 2.0 – JSR 339 (*) – JAX-RS 2.1 – JSR 370 • Standard based RESTful framework – Server-side and client-side – Jersey, JBoss RESTEasy, Restlet, Apache CXF, Apache Wink, IBM JAX-RS, … •
Java SE and Java EE 7
8.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 8 Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://weath.er/api") .queryParam("city", "Paris”); Forecast forecast = target.request() .get(Forecast.class); … client.close(); JAX-RS Client API
9.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • Client – Client side container – Customizable & tunable • E.g. executorService() (new in JAX-RS 2.1!) • WebTarget – Target remote URI – Build from a client – path() + resolveTemplates(), queryParam(), matrixParam() javax.ws.rs.client.Client interface 9
10.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • Request invocaPon builder – Build from a WebTarget – acceptXXX(), cookie(), header(), cacheControl()… – HTTP methods javax.ws.rs.client.Client interface 10
11.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • Fluent API – Client Builder è Client è Web Target è Request building è Response javax.ws.rs.client.Client interface 11 List<Forecast> forecast = ClientBuilder.newClient() .target("http://weath.er/cities") .request() .accept("application/json") .header("Foo","bar") .get(new GenericType<List<Forecast>>() {});
12.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • Synchronous invoker • Asynchronous invoker 12 String city = client.target("http://locati.on/api") .queryParam("city", "Paris") .request() .get(String.class); Future<String> fCity = client.target("http://locati.on/api") .queryParam("city", "Paris") .request() .async() .get(String.class);
13.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API Asynchronous invoca.on 13 Future<String> fCity = client.target("http://locati.on/api") … .request() .async() .get(String.class); String city = future.get();
14.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API Asynchronous invoca.on 14 Future<String> fCity = client.target("http://locati.on/api") … .request() .async() .get(String.class); try { String city = future.get(4, TimeUnit.SECONDS); } catch(TimeoutException timeout) { … }
15.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API Asynchronous invoca.on 15 Future<String> future = client.target("http://locati.on/api") … .request() .async() .get(String.class); while (!future.isDone()) { // response hasn't been received yet … } String city = f.get(); … // Set ClientProperties.CONNECT_TIMEOUT & READ_TIMEOUT
16.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • InvocaPonCallback Interface – javax.ws.rs.client.InvocaPonCallback<RESPONSE> • Container will receive asynchronous processing events from an invocaPon – completed(RESPONSE response) – failed(Throwable throwable) 16 Asynchronous invoca.on
17.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API 17 Invoca.onCallback … WebTarget myResource = client.target("http://examp.le/api/read"); Future<Customer> future = myResource.request(MediaType.TEXT_PLAIN) .async() .get(new InvocationCallback<Customer>() { @Override public void completed (Customer customer) { // do something with the given customer } @Override public void failed (Throwable throwable) { // Oops! } });
18.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 18 The Travel Service
19.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service - Synchronous • Customer details: 150 ms • Recommended desPnaPons: 250 ms •
Price calculaPon for a customer and desPnaPon: 170 ms (each) • Weather forecast for a desPnaPon: 330 ms (each) 19 5 400 ms
20.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service - Asynchronous 20 730 ms
21.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 21 The Travel Service
22.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 22 The Travel Service destination.path("recommended").request() .header("Rx-User", "Async") .async() .get(new InvocationCallback<List<Destination>>() { @Override public void completed(final List<Destination> recommended) { final CountDownLatch innerLatch = new CountDownLatch(recommended.size()); final Map<String, Forecast> forecasts = Collections.synchronizedMap(new HashMap<>()); for (final Destination dest : recommended) { forecast.resolveTemplate("dest", dest.getDestination()).request() .async() .get(new InvocationCallback<Forecast>() { @Override public void completed(final Forecast forecast) { forecasts.put(dest.getDestination(), forecast); innerLatch.countDown(); }
23.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 23 JAX-RS 2.0 @Override public void failed(final Throwable throwable) { innerLatch.countDown(); } }); } try { if (!innerLatch.await(10, TimeUnit.SECONDS)) { // timeout } } catch (final InterruptedException e) { // Ooops, interrupted! } // Continue with processing… } @Override public void failed(final Throwable throwable) { // Recommendation error } });
24.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 24 JAX-RS 2.1 // JAX-RS 2.1 CompletionStage<Response> csResponse = ClientBuilder.newClient() .target("http://example.com/api") .request() .rx() .get(); Future<Response> fResponse = ClientBuilder.newClient() .target("http://example.com/api") .request() .async() .get(); Response response = ClientBuilder.newClient() .target("http://example.com/api") .request() .get();
25.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | ComplePonStage interface • “A stage of a possibly asynchronous computaPon, that performs an ac.on or computes a value” • “On termina.on a stage may in turn trigger other dependent stages.” •
Stage execuPon triggered by complePon of – “then” - a single stage – “combine” - both of two stages – “either” - either of two stages 25
26.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | ComplePonStage interface • ComputaPon takes an argument and returns a result? – “apply” – Func.on take result of the previous stage as argument, return a result – “accept” – Consumer only take an argument – “run” – Runnable no argument and doesn’t return a result • How the execuPon of the computaPon is arranged? – Doesn't end with “async” – execute using the stage’s default execuPon facility – End with “async” - use the stage’s default asynchronous execuPon facility •
… 26 hsps://docs.oracle.com/javase/8/docs/api/java/uPl/concurrent/ComplePonStage.html
27.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 27 JAX-RS 2.1 CompletionStage<Number> csPrice = client.target("price/{destination}") .resolveTemplate("destination", "Paris") .request() .rx() .get(Number.class); CompletionStage<String> csForecast = client.target("forecast/{destination}") .resolveTemplate("destination", "Paris") .request() .rx() .get(String.class); csPrice.thenCombine( csForecast, (price, forecast) -> book(price, forecast) );
28.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 28 Demo The Travel Service hsps://github.com/jersey/jersey/tree/master/examples/rx-client-webapp
29.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • REST Client Side container • Synchronous invoker – Default invoker - javax.ws.rs.client.SyncInvoker •
Asynchronous invokers – async() invoker - javax.ws.rs.client.AsyncInvoker • Might block -> InvocaPonCallback – ReacPve rx() invoker - javax.ws.rs.client.RxInvoker • New in JAX-RS 2.1! • ComplePonStage API + other ReacPve library (opt.) 29 Summary
30.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Server-side REST ConfidenPal – Oracle Internal/Restricted/Highly Restricted 30
31.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 31 Server-side @Path("/Item") public class ItemResource { @Path("{id}") @Produces(MediaType.APPLICATION_XML) public ItemResource getItemResource(@PathParam("id") String id) { return ItemResource.getInstance(id); } @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) public Response createItem(@QueryParam("name") String name) { //... return Response.status(Status.OK).entity(…).build(); } }
32.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 32 Server-side Async @Path("/Async") public class ItemResource { @GET public void heavyResource(@Suspended AsyncResponse ar) { mes.execute(new Runnable() { @Override public void run() { try { // long running computation... ar.resume(Response.ok(...).build()); } catch (InterruptedException ex) { // Ooops! } } }); ...
33.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Server-side Async • Provides means for asynchronous server side response processing – Injectable via @Suspended OR – Resource method can return a ComplePonStage<T> instance (new in JAX-RS 2.1!) • Bound to the request – Suspend – Resume – Configure – Cancel 33 AsyncResponse interface
34.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Server-side Async 34 Client Server @Suspended AsyncResponse.resume(…) Long running operaPon… Request Response
35.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Long running REST operaPons è POST ... long running operaPon ... ç ‘201 Created’ + LocaPon 35 è
POST ç ‘202 Accepted’ + Temp LocaPon è GET Temp LocaPon ç ‘200 OK’ (+ ETA) … è GET Temp LocaPon ç ‘303 See Other’ + Final LocaPon
36.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Server-sent Events • Persistent, one-way communicaPon channel • Text protocol, special media type "text/event-stream" •
Server can send mulPple messages (events) to a client • Can contain id, name, comment retry interval • Supported in all modern browsers 36
37.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS 2.1 37 SSE • SseEvent – ID, Name, Comment, … • OutboundSseEvent – Server-side representaPon of a Server-sent event – OutboundSseEvent.Builder() •
InboundSseEvent – Client-side representaPon of a Server-sent event
38.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS 2.1 38 SSE – Server side • SseEventSink – Outbound Server-Sent Events stream – SseBroadcaster @GET @Path ("sse") @Produces(MediaType.SERVER_SENT_EVENTS) public void eventStream(@Context SseEventSink eventSink, @Context SSE sse) { ... eventSink.send( sse.newEvent("an event") ); eventSink.send( sse.newEvent("another event") ); ... eventSink.close(); }
39.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS 2.1 39 SSE – Client side • SseEventSource – Client for processing incoming Server-Sent Events SseEventSource es = SseEventSource.target(SSE_target) .reconnectingEvery(5, SECONDS) .build(); es.register(System.out::println); // InboundSseEvent consumer es.register(...); // Throwable consumer es.open(); ... es.close();
40.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Wrap-up ConfidenPal – Oracle Internal/Restricted/Highly Restricted 40
41.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS • Java API for RESTful Web Services – JAX-RS 2.0 – JSR 339 (*) – JAX-RS 2.1 – JSR 370 • Standard based RESTful framework – Server-side and client-side – Java SE and Java EE – Jersey, JBoss RESTEasy, Restlet, Apache CXF, Apache Wink, IBM JAX-RS, … 41
42.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS – Client-side • REST Client Side container • Invokers – Synchronous •
javax.ws.rs.client.SyncInvoker • Default – Asynchronous • javax.ws.rs.client.AsyncInvoker – ReacPve • New in JAX-RS 2.1! • javax.ws.rs.client.AsyncInvoker 42
43.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS – Client-side 43 Sync Async RX Performance and scalability
✗✗ ✔ ✔ Easy to develop and maintain ✔ ✗ ✔ … complex workflow ✗ ✗ ✔ … error handling ✗ ✗ ✔ Leverage new Java SE feature ✗ ✗ ✔
44.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS –ReacPve Client API • Java SE 8 ComplePon Stage – As mandated by the spec. • Jersey – RxJava - rx.Observable – RxJava 2 - io.reacPvex.Flowable – Guava - ListenableFuture 44
45.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS – Server-side • AsyncResponse – Resume execuPon on a different thread – @Suspended – Resource method returning a ComplePonStage<T> instance • Long running operaPon pasern •
Server-sent Events 45
46.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Java EE 8 46 Bean Valida.on CDI 2.0 JSON-B 1.0 Security 1.0 Bean Valida.on 2.0 JSF 2.3 Servlet 4.0 JSON-P 1.1 JAX-RS 2.1 ReacPve client API, Server-sent events, … HTTP/2, server push, … Java <-> JSON binding Updates to JSON standards, JSON Collectors, … Async event, event priority, SE support, … Embrace Java SE 8, new constraints Improved CDI, WebSocket, SE 8 integraPon, … Standardized IdenPty Store, AuthenPcaPon, Security Context
47.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Java EE 8 • Work in progress – Final Release - Summer 2017 (plan) • Open Source Reference ImplementaPons – hsps://github.com/jersey – hsps://github.com/javaee •
Stay tuned… – hsps://blogs.oracle.com/theaquarium/ 47
48.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | .רבה תודה ConfidenPal – Oracle Internal/Restricted/Highly Restricted
48
49.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Resources • JAX-RS specificaPon – hsps://github.com/jax-rs/api • Jersey – Asynchronous Services and Clients – hsps://jersey.java.net/documentaPon/latest/async.html#d0e8611 – hsps://github.com/jersey/jersey/tree/master/examples/rx-client-webapp •
ComplePonStage – hsps://docs.oracle.com/javase/8/docs/api/java/uPl/concurrent/ComplePonStage.html • Java EE Tutorial – hsps://docs.oracle.com/javaee/7/tutorial/ 49