SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS and CDI Bike the
(Reactive) Bridge
CON2549
David Delabassée (@delabassee) - Oracle
José Paumard (@josepaumard) - Consultant
October, 2017
2
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 3
@delabassee
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 4
@JosePaumard
@JosePaumard
https://github.com/JosePaumard
https://www.slideshare.net/jpaumard
https://www.youtube.com/user/JPaumard
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
6
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 7
reactive
adjective | re·ac·tive |  rē-ˈak-tiv 
1 :of, relating to, or marked by reaction or reactance
2 a :readily responsive to a stimulus
https://www.merriam-webster.com/dictionary/reactive
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS
8
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS 2.1
• JSR 370
– Java EE 8
• Async
– New Reactive Client API
– New method for pausing resquest processing, etc.
• Server-Sent Event support
• JSON-P & JSON-B support
• …
Java API for RESTful Web Services
9
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
// JAX-RS 2.0
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
10
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>>() {});
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
• Synchronous invoker
• Asynchronous invoker
JAX-RS 2.0 Invokers
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);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
Asynchronous invocation
13
Future<String> fCity = client.target("http://locati.on/api")
.queryParam("city", "Paris")
.request()
.async()
.get(String.class);
String city = fCity.get();
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
Asynchronous invocation
14
Future<String> fCity = client.target("http://locati.on/api")
.queryParam("city", "Paris")
.request()
.async()
.get(String.class);
try {
String city = fCity.get(5, TimeUnit.SECONDS);
} catch(TimeoutException timeout) {
// …
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
Asynchronous invocation
15
// Set ClientProperties.CONNECT_TIMEOUT & READ_TIMEOUT
Future<String> fCity = client.target("http://locati.on/api")
.queryParam("city", "Paris")
.request()
.async()
.get(String.class);
while ( !fCity.isDone() ) {
// response hasn't been received yet
}
String city = fCity.get();
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
• InvocationCallback Interface
– javax.ws.rs.client.InvocationCallback<RESPONSE>
• Container will receive async processing events from an invocation
– completed(RESPONSE response)
– failed(Throwable throwable)
Asynchronous invocation
16
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
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 customer
}
@Override
public void failed (Throwable throwable) {
// Oops!
}
});
…
InvocationCallback
17
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
18
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
• Customer details: 150 ms
• Recommended destinations: 250 ms
• Price calculation for a customer and destination: 170 ms (each)
• Weather forecast for a destination: 330 ms (each)
Synchronous
19
5 400 ms
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
Asynchronous
20
730 ms
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
21
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
22
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();
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
23
// cont.
@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 }
});
// ...
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Client API
New JAX-RS Reactive Invoker
24
// JAX-RS 2.0
Response response = client.target(recommandationService)
.request()
.get();
Future<Response> futureResponse = client.target(recommandationService)
.request()
.async()
.get();
// JAX-RS 2.1
CompletionStage<Response> completionStageResp = client.target(recommandationService)
.request()
.rx()
.get();
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
CompletionStage API
• A model for a Task
– That performs an action and may return a value
– That can be triggered by another task
– That may trigger another task
– That can be executed in a different thread
• A CompletionStage is an element of an asynchronous chain
25
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
CompletionStage Pipeline
26
CS1 CS21
CS22
CS31 CS41
CS32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
27
CompletionStage<JsonObject> queryForecastCS = client.target("forecast")
.queryParam("format", "json").request()
.rx()
.get(JsonObject.class);
Function<JsonObject, Forecast> unmarshallForecast =
jsonObject -> JsonBuilder.create().fromJson(jsonObject.toString(), Forecast.class);
Function<Destination, CompletionStage<Void>> populateWithForecast =
destination ->
queryForecastCS.thenApply(unmarshallForecast)
.thenAccept(forecast -> destination.setForecast(forecast));
Function<Destination, CompletionStage<Void>> populateWithQuotation =
destination ->
queryQuotationCS.thenApply(unmarshallQuotation)
.thenAccept(quotation -> destination.setQuotation(quotation));
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
28
Function<Destination, CompletableFuture<Void>> populateDestination =
destination ->
CompletableFuture.allOf(
populateWithForecast.apply(destination).toCompletableFuture(),
populateWithQuotation.apply(destination).toCompletableFuture()
)
.toCompletableFuture();
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
29
Function<Destination, CompletableFuture<Void>> populateDestination =
destination ->
CompletableFuture.allOf(
populateWithForecast.apply(destination).toCompletableFuture(),
populateWithQuotation.apply(destination).toCompletableFuture()
)
.toCompletableFuture();
Function<List<Destination>, CompletableFuture<?>[]> populateDestinations =
destinations ->
destinations.stream().map(populateDestination)
.toArray(CompletableFuture[]::new);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
30
@GET
public void populateDestination(@Suspended final AsyncResponse asyncResponse) {
CompletionStage<List<Destination>> destinationCS = client.target("destination")
.queryParam("format", "json").request()
.rx()
.get(/* some JSONB code */);
CompletionStage<List<Destination>> updatedDestinationsCS =
destinationCS.thenCompose(CompletableFuture.allOf(populateDestinations));
asyncResponse.resume(updatedDestinationsCS.toCompletableFuture().get());
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Travel Service
31
@GET
public CompletionStage<Destination> populateDestination() {
CompletionStage<List<Destination>> destinationCS = client.target("destination")
.queryParam("format", "json").request()
.rx()
.get(/* some JSONB code */);
CompletionStage<List<Destination>> updatedDestinationsCS =
destinationCS.thenCompose(CompletableFuture.allOf(populateDestinations));
return updatedDestinationsCS;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
32
CS1 CS21
CS22
CS31 CS41
CS32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
Returns a new CompletionStage
• That completes when the CS completes
• Either with the same result (normal completion)
• Or with the transformed exception
33
exceptionaly()
stage.exceptionaly( // Function
exception -> doSomethingNotTooStupidWith(exception));
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
Returns a new CompletionStage
• That completes when the CS completes
• Calls the BiFunction with a null as result or exception
34
handle()
stage.handle( // BiFunction
(result, exception) -> doSomethingWith(result, exception));
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
Returns a new CompletionStage
• With the same result or exception as this stage
• That executes the given action when this stage completes
35
whenComplete()
stage.whenComplete( // BiConsumer + async version
(result, exception) -> doSomethingWith(result, exception));
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
36
CompletionStage<Void> quotation = client.target("quotation")
.request().rx().get(JsonObject.class)
.thenApply(unmarshallQuotation)
.exceptionnaly(throwable -> null)
.thenAccept(destination::setQuotation);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Exception Handling
37
CompletionStage<Void> quotation = client.target("quotation")
.request().rx().get(JsonObject.class)
.thenApply(unmarshallQuotation)
.handle(((quotation, throwable) -> {
if (throwable == null) {
destination.setQuotation(quotation);
} else {
// try to do something smart with the exception
}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Reactive Extensions
• Supported on all HTTP Methods of the Client API
– DELETE
– GET
– HEAD
– OPTIONS
– POST
– PUT
– TRACE
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JAX-RS Reactive Extensions
• Implementations MUST support an invoker for CompletionStage
• Implementations MAY support other reactive APIs
• Jersey
– CompletionStageRxInvoker (Default)
– RxListenableFutureInvoker – Guava
39
https://github.com/jersey/jersey/tree/master/ext/rx
client.register(RxFlowableInvokerProvider.class);
client.target(...)...
.rx(RxFlowableInvoker.class)
.get();
– RxObservableInvoker – RxJava
– RxFlowableInvoker – RxJava2
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
CDI
40
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
CDI 2.0
• JSR 365
– Java EE 8
• Java SE focus
– Modular specification
– CDI Container bootstraping
• Observers Ordering
• Asynchronous Events
• …
Context and Dependency Injection
41
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Asynchronous Events
42
// Producer
@Inject
Event<Payload> event;
public void aCriticalBusinessMethod() {
CompletionStage<Payload> cs = event.fireAsync(new Payload());
}
// Consumer
public void anOberser(@ObservesAsync Payload event) {
// do something with the payload
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Asynchronous Events
43
// Producer
@Inject
Event<Payload> event;
public void aCriticalBusinessMethod() {
CompletionStage<Payload> cs =
event.fireAsync(new Payload(), executor);
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Asynchronous Events
44
// Producer
@Inject
Event<Payload> event;
public void aCriticalBusinessMethod() {
CompletionStage<Payload> cs =
event.fireAsync(new Payload(), SwingUtilities::invokeLater);
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Wrap-up
45
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Java EE 8 – Modernization & Simplification
46
CDI 2.0
JSON-B 1.0 (*)
Security 1.0 (*)
Bean Validation 2.0
JSF 2.3
Servlet 4.0
JSON-P 1.1
JAX-RS 2.1 Reactive Client API, Server-Sent Events, …
HTTP/2, Server Push, …
Java <-> JSON binding
Updates to JSON standards, JSON Collectors, …
Async Event, Observers ordering, SE support, …
Embrace Java SE 8, new constraints, …
Improved CDI, WebSocket, SE 8 integration, …
Portable Identity Store, Authentication & Security Context
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge

Weitere ähnliche Inhalte

Was ist angesagt?

JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter PilgrimJavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
Arun Gupta
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
Peter Pilgrim
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scala
Stratio
 

Was ist angesagt? (20)

Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter PilgrimJavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Java EE 8 - What’s new on the Web front
Java EE 8 - What’s new on the Web frontJava EE 8 - What’s new on the Web front
Java EE 8 - What’s new on the Web front
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
 
What's new in DWR version 3
What's new in DWR version 3What's new in DWR version 3
What's new in DWR version 3
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 
Project Jigsaw in JDK9
Project Jigsaw in JDK9Project Jigsaw in JDK9
Project Jigsaw in JDK9
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scala
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
Java: Create The Future Keynote
Java: Create The Future KeynoteJava: Create The Future Keynote
Java: Create The Future Keynote
 
Nashorn: JavaScript Running on Java VM (English)
Nashorn: JavaScript Running on Java VM (English)Nashorn: JavaScript Running on Java VM (English)
Nashorn: JavaScript Running on Java VM (English)
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 

Andere mochten auch

Better Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design ThinkingBetter Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design Thinking
Jeff Gothelf
 

Andere mochten auch (20)

Java 9 modulo les modules devoxx fr 2017
Java 9 modulo les modules devoxx fr 2017Java 9 modulo les modules devoxx fr 2017
Java 9 modulo les modules devoxx fr 2017
 
Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016
 
NightClazz Java 8 Decouverte
NightClazz Java 8 DecouverteNightClazz Java 8 Decouverte
NightClazz Java 8 Decouverte
 
What HTTP/2.0 Will Do For You
What HTTP/2.0 Will Do For YouWhat HTTP/2.0 Will Do For You
What HTTP/2.0 Will Do For You
 
How can your applications benefit from Java 9?
How can your applications benefit from Java 9?How can your applications benefit from Java 9?
How can your applications benefit from Java 9?
 
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelleAgile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
 
NightClazz Build Tools & Continuous Delivery Avancé
NightClazz Build Tools & Continuous Delivery AvancéNightClazz Build Tools & Continuous Delivery Avancé
NightClazz Build Tools & Continuous Delivery Avancé
 
Going reactive in java
Going reactive in javaGoing reactive in java
Going reactive in java
 
HTTP2 : ce qui va changer par Julien Landuré
HTTP2 : ce qui va changer par Julien LanduréHTTP2 : ce qui va changer par Julien Landuré
HTTP2 : ce qui va changer par Julien Landuré
 
Http2
Http2Http2
Http2
 
Business intelligence v0.3
Business intelligence v0.3Business intelligence v0.3
Business intelligence v0.3
 
Introducing HTTP/2
Introducing HTTP/2Introducing HTTP/2
Introducing HTTP/2
 
The Case for HTTP/2
The Case for HTTP/2The Case for HTTP/2
The Case for HTTP/2
 
Open Data v0.3
Open Data v0.3Open Data v0.3
Open Data v0.3
 
So, you wanna migrate to Java 9?
So, you wanna migrate to Java 9?So, you wanna migrate to Java 9?
So, you wanna migrate to Java 9?
 
Optimisez la performance de votre service client tout en maîtrisant votre b...
Optimisez la performance  de votre service client  tout en maîtrisant votre b...Optimisez la performance  de votre service client  tout en maîtrisant votre b...
Optimisez la performance de votre service client tout en maîtrisant votre b...
 
Company_Profile_Digital_1
Company_Profile_Digital_1Company_Profile_Digital_1
Company_Profile_Digital_1
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
Matinale DevOps / Docker
Matinale DevOps / DockerMatinale DevOps / Docker
Matinale DevOps / Docker
 
Better Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design ThinkingBetter Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design Thinking
 

Ähnlich wie JAX RS and CDI bike the reactive bridge

Ähnlich wie JAX RS and CDI bike the reactive bridge (20)

Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
 
Coherence RoadMap 2018
Coherence RoadMap 2018Coherence RoadMap 2018
Coherence RoadMap 2018
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Adopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updateAdopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS update
 
Reactive Jersey Client
Reactive Jersey ClientReactive Jersey Client
Reactive Jersey Client
 
Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)
 
Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 
Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018
 
12 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 212 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 2
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for Graphs
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1
 
JAX-RS.next
JAX-RS.nextJAX-RS.next
JAX-RS.next
 
Developing Web Services from Scratch - For DBAs and Database Developers
Developing Web Services from Scratch - For DBAs and Database DevelopersDeveloping Web Services from Scratch - For DBAs and Database Developers
Developing Web Services from Scratch - For DBAs and Database Developers
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
 
Mashups
MashupsMashups
Mashups
 

Mehr von José Paumard

Mehr von José Paumard (20)

Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
 
The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern Matching
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Designing functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsDesigning functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patterns
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Designing functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternDesigning functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor Pattern
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn Flow
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
 
Streams in the wild
Streams in the wildStreams in the wild
Streams in the wild
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 
L'API Collector dans tous ses états
L'API Collector dans tous ses étatsL'API Collector dans tous ses états
L'API Collector dans tous ses états
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 

Kürzlich hochgeladen

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

JAX RS and CDI bike the reactive bridge

  • 1.
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS and CDI Bike the (Reactive) Bridge CON2549 David Delabassée (@delabassee) - Oracle José Paumard (@josepaumard) - Consultant October, 2017 2
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 3 @delabassee
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 4 @JosePaumard @JosePaumard https://github.com/JosePaumard https://www.slideshare.net/jpaumard https://www.youtube.com/user/JPaumard
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 5
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 6
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 7 reactive adjective | re·ac·tive | rē-ˈak-tiv 1 :of, relating to, or marked by reaction or reactance 2 a :readily responsive to a stimulus https://www.merriam-webster.com/dictionary/reactive
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS 8
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS 2.1 • JSR 370 – Java EE 8 • Async – New Reactive Client API – New method for pausing resquest processing, etc. • Server-Sent Event support • JSON-P & JSON-B support • … Java API for RESTful Web Services 9
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | // JAX-RS 2.0 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 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 JAX-RS 2.0 Invokers 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 invocation 13 Future<String> fCity = client.target("http://locati.on/api") .queryParam("city", "Paris") .request() .async() .get(String.class); String city = fCity.get();
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API Asynchronous invocation 14 Future<String> fCity = client.target("http://locati.on/api") .queryParam("city", "Paris") .request() .async() .get(String.class); try { String city = fCity.get(5, TimeUnit.SECONDS); } catch(TimeoutException timeout) { // … }
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API Asynchronous invocation 15 // Set ClientProperties.CONNECT_TIMEOUT & READ_TIMEOUT Future<String> fCity = client.target("http://locati.on/api") .queryParam("city", "Paris") .request() .async() .get(String.class); while ( !fCity.isDone() ) { // response hasn't been received yet } String city = fCity.get();
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API • InvocationCallback Interface – javax.ws.rs.client.InvocationCallback<RESPONSE> • Container will receive async processing events from an invocation – completed(RESPONSE response) – failed(Throwable throwable) Asynchronous invocation 16
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Client API 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 customer } @Override public void failed (Throwable throwable) { // Oops! } }); … InvocationCallback 17
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 18
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service • Customer details: 150 ms • Recommended destinations: 250 ms • Price calculation for a customer and destination: 170 ms (each) • Weather forecast for a destination: 330 ms (each) Synchronous 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. | The Travel Service 21
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 22 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. | The Travel Service 23 // cont. @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. | JAX-RS Client API New JAX-RS Reactive Invoker 24 // JAX-RS 2.0 Response response = client.target(recommandationService) .request() .get(); Future<Response> futureResponse = client.target(recommandationService) .request() .async() .get(); // JAX-RS 2.1 CompletionStage<Response> completionStageResp = client.target(recommandationService) .request() .rx() .get();
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | CompletionStage API • A model for a Task – That performs an action and may return a value – That can be triggered by another task – That may trigger another task – That can be executed in a different thread • A CompletionStage is an element of an asynchronous chain 25
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | CompletionStage Pipeline 26 CS1 CS21 CS22 CS31 CS41 CS32
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 27 CompletionStage<JsonObject> queryForecastCS = client.target("forecast") .queryParam("format", "json").request() .rx() .get(JsonObject.class); Function<JsonObject, Forecast> unmarshallForecast = jsonObject -> JsonBuilder.create().fromJson(jsonObject.toString(), Forecast.class); Function<Destination, CompletionStage<Void>> populateWithForecast = destination -> queryForecastCS.thenApply(unmarshallForecast) .thenAccept(forecast -> destination.setForecast(forecast)); Function<Destination, CompletionStage<Void>> populateWithQuotation = destination -> queryQuotationCS.thenApply(unmarshallQuotation) .thenAccept(quotation -> destination.setQuotation(quotation));
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 28 Function<Destination, CompletableFuture<Void>> populateDestination = destination -> CompletableFuture.allOf( populateWithForecast.apply(destination).toCompletableFuture(), populateWithQuotation.apply(destination).toCompletableFuture() ) .toCompletableFuture();
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 29 Function<Destination, CompletableFuture<Void>> populateDestination = destination -> CompletableFuture.allOf( populateWithForecast.apply(destination).toCompletableFuture(), populateWithQuotation.apply(destination).toCompletableFuture() ) .toCompletableFuture(); Function<List<Destination>, CompletableFuture<?>[]> populateDestinations = destinations -> destinations.stream().map(populateDestination) .toArray(CompletableFuture[]::new);
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 30 @GET public void populateDestination(@Suspended final AsyncResponse asyncResponse) { CompletionStage<List<Destination>> destinationCS = client.target("destination") .queryParam("format", "json").request() .rx() .get(/* some JSONB code */); CompletionStage<List<Destination>> updatedDestinationsCS = destinationCS.thenCompose(CompletableFuture.allOf(populateDestinations)); asyncResponse.resume(updatedDestinationsCS.toCompletableFuture().get()); }
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Travel Service 31 @GET public CompletionStage<Destination> populateDestination() { CompletionStage<List<Destination>> destinationCS = client.target("destination") .queryParam("format", "json").request() .rx() .get(/* some JSONB code */); CompletionStage<List<Destination>> updatedDestinationsCS = destinationCS.thenCompose(CompletableFuture.allOf(populateDestinations)); return updatedDestinationsCS; }
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling 32 CS1 CS21 CS22 CS31 CS41 CS32
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling Returns a new CompletionStage • That completes when the CS completes • Either with the same result (normal completion) • Or with the transformed exception 33 exceptionaly() stage.exceptionaly( // Function exception -> doSomethingNotTooStupidWith(exception));
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling Returns a new CompletionStage • That completes when the CS completes • Calls the BiFunction with a null as result or exception 34 handle() stage.handle( // BiFunction (result, exception) -> doSomethingWith(result, exception));
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling Returns a new CompletionStage • With the same result or exception as this stage • That executes the given action when this stage completes 35 whenComplete() stage.whenComplete( // BiConsumer + async version (result, exception) -> doSomethingWith(result, exception));
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling 36 CompletionStage<Void> quotation = client.target("quotation") .request().rx().get(JsonObject.class) .thenApply(unmarshallQuotation) .exceptionnaly(throwable -> null) .thenAccept(destination::setQuotation);
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Exception Handling 37 CompletionStage<Void> quotation = client.target("quotation") .request().rx().get(JsonObject.class) .thenApply(unmarshallQuotation) .handle(((quotation, throwable) -> { if (throwable == null) { destination.setQuotation(quotation); } else { // try to do something smart with the exception } }
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Reactive Extensions • Supported on all HTTP Methods of the Client API – DELETE – GET – HEAD – OPTIONS – POST – PUT – TRACE 38
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JAX-RS Reactive Extensions • Implementations MUST support an invoker for CompletionStage • Implementations MAY support other reactive APIs • Jersey – CompletionStageRxInvoker (Default) – RxListenableFutureInvoker – Guava 39 https://github.com/jersey/jersey/tree/master/ext/rx client.register(RxFlowableInvokerProvider.class); client.target(...)... .rx(RxFlowableInvoker.class) .get(); – RxObservableInvoker – RxJava – RxFlowableInvoker – RxJava2
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | CDI 40
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | CDI 2.0 • JSR 365 – Java EE 8 • Java SE focus – Modular specification – CDI Container bootstraping • Observers Ordering • Asynchronous Events • … Context and Dependency Injection 41
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Asynchronous Events 42 // Producer @Inject Event<Payload> event; public void aCriticalBusinessMethod() { CompletionStage<Payload> cs = event.fireAsync(new Payload()); } // Consumer public void anOberser(@ObservesAsync Payload event) { // do something with the payload }
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Asynchronous Events 43 // Producer @Inject Event<Payload> event; public void aCriticalBusinessMethod() { CompletionStage<Payload> cs = event.fireAsync(new Payload(), executor); }
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Asynchronous Events 44 // Producer @Inject Event<Payload> event; public void aCriticalBusinessMethod() { CompletionStage<Payload> cs = event.fireAsync(new Payload(), SwingUtilities::invokeLater); }
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Wrap-up 45
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Java EE 8 – Modernization & Simplification 46 CDI 2.0 JSON-B 1.0 (*) Security 1.0 (*) Bean Validation 2.0 JSF 2.3 Servlet 4.0 JSON-P 1.1 JAX-RS 2.1 Reactive Client API, Server-Sent Events, … HTTP/2, Server Push, … Java <-> JSON binding Updates to JSON standards, JSON Collectors, … Async Event, Observers ordering, SE support, … Embrace Java SE 8, new constraints, … Improved CDI, WebSocket, SE 8 integration, … Portable Identity Store, Authentication & Security Context