Java tutorial
/** * Copyright 2014 Andy Godwin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.sdev.async.http.ning; import com.fasterxml.jackson.core.type.TypeReference; import uk.co.sdev.async.http.AbstractSequential2CompletableFutureTest; import uk.co.sdev.async.http.model.Booking; import uk.co.sdev.async.http.model.Login; import uk.co.sdev.async.http.model.User; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import static uk.co.sdev.async.Futures.withFallback; public class Sequential2CompletableFutureClientTest extends AbstractSequential2CompletableFutureTest { @Override protected CompletableFuture<Optional<User>> login(Login login) throws IOException { String body = objectMapper.writeValueAsString(login); return completableFutureClient .post("http://localhost:9101/user/login", body, new TypeReference<Optional<User>>() { }).handle(withFallback(Optional.<User>empty())); } @Override protected CompletableFuture<List<Booking>> findBookings(User user) throws IOException { return completableFutureClient .get("http://localhost:9101/bookings/" + user.getId(), new TypeReference<List<Booking>>() { }).handle(withFallback(Collections.<Booking>emptyList())); } }