List of usage examples for org.springframework.util.concurrent ListenableFutureAdapter ListenableFutureAdapter
protected ListenableFutureAdapter(ListenableFuture<S> adaptee)
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * @return the list of supported operations under /v2 *///from w w w. j a va 2 s. c o m public ListenableFuture<Map<String, String>> getV2() { ListenableFuture<ResponseEntity<JsonNode>> responseFuture = request(HttpMethod.GET, baseURL + "v2", null, JsonNode.class); return new ListenableFutureAdapter<Map<String, String>, ResponseEntity<JsonNode>>(responseFuture) { @Override protected Map<String, String> adapt(ResponseEntity<JsonNode> result) throws ExecutionException { Map<String, String> services = new HashMap<>(); result.getBody().fields() .forEachRemaining(entry -> services.put(entry.getKey(), entry.getValue().textValue())); return services; } }; }
From source file:com.orange.ngsi.client.NgsiClient.java
/** * Make an HTTP request//w ww .ja va2 s. c o m */ protected <T, U> ListenableFuture<T> request(HttpMethod method, String url, HttpHeaders httpHeaders, U body, Class<T> responseType) { if (httpHeaders == null) { httpHeaders = getRequestHeaders(url, null); } HttpEntity<U> requestEntity = new HttpEntity<>(body, httpHeaders); ListenableFuture<ResponseEntity<T>> future = asyncRestTemplate.exchange(url, method, requestEntity, responseType); return new ListenableFutureAdapter<T, ResponseEntity<T>>(future) { @Override protected T adapt(ResponseEntity<T> result) throws ExecutionException { return result.getBody(); } }; }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Retrieve the list of all Registrations * @return a list of registrations//from w ww. j a v a 2 s . com */ public ListenableFuture<List<Registration>> getRegistrations() { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/registrations"); ListenableFuture<ResponseEntity<Registration[]>> e = request(HttpMethod.GET, builder.toUriString(), null, Registration[].class); return new ListenableFutureAdapter<List<Registration>, ResponseEntity<Registration[]>>(e) { @Override protected List<Registration> adapt(ResponseEntity<Registration[]> result) throws ExecutionException { return new ArrayList<>(Arrays.asList(result.getBody())); } }; }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Create a new subscription// w w w .j a v a 2 s. com * @param subscription the Subscription to add * @return subscription Id */ public ListenableFuture<String> addSubscription(Subscription subscription) { ListenableFuture<ResponseEntity<Void>> s = request(HttpMethod.POST, UriComponentsBuilder.fromHttpUrl(baseURL).path("v2/subscriptions").toUriString(), subscription, Void.class); return new ListenableFutureAdapter<String, ResponseEntity<Void>>(s) { @Override protected String adapt(ResponseEntity<Void> result) throws ExecutionException { return extractId(result); } }; }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
private <T> ListenableFuture<T> adapt(ListenableFuture<ResponseEntity<T>> responseEntityListenableFuture) { return new ListenableFutureAdapter<T, ResponseEntity<T>>(responseEntityListenableFuture) { @Override/* w ww .j a v a 2 s .c om*/ protected T adapt(ResponseEntity<T> result) throws ExecutionException { return result.getBody(); } }; }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
private <T> ListenableFuture<Paginated<T>> adaptPaginated( ListenableFuture<ResponseEntity<T[]>> responseEntityListenableFuture, int offset, int limit) { return new ListenableFutureAdapter<Paginated<T>, ResponseEntity<T[]>>(responseEntityListenableFuture) { @Override//from w w w . j av a2 s . co m protected Paginated<T> adapt(ResponseEntity<T[]> result) throws ExecutionException { return new Paginated<>(Arrays.asList(result.getBody()), offset, limit, extractTotalCount(result)); } }; }