Java Reference
In-Depth Information
We can use the new CompletableFuture class from Java 8 to be notified about the
completion of a request:
CompletableFuture.<Collection<SeatDto>> supplyAsync(() -> {
try {
return future.get();
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}).thenAccept(seats -> seats.forEach(System.out::println));
After receiving the data, we simply print it out. Another option is to simply create an In-
vocationCallback class and pass it as a second argument to the get method.
Compiling our ticket example
Our sample can reside in a separate Maven module or you can leave it with the server
content (although it is not a good practice). In order to compile our client project with the
REST web service, we need to import the JAX-RS API that is included in the application
server libraries. We will need the following dependencies in our standalone application:
<properties>
. . .
<version.resteasy-client>3.0.6.Final</version.resteasy-client>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version> ${version.resteasy-client}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-p-provider</artifactId>
<version> ${version.resteasy-client}</version>
Search WWH ::




Custom Search