List of usage examples for org.springframework.web.client AsyncRestTemplate AsyncRestTemplate
public AsyncRestTemplate()
From source file:io.getlime.security.powerauth.app.server.service.behavior.CallbackUrlBehavior.java
/** * Tries to asynchronously notify all callbacks that are registered for given application. * @param applicationId Application for the callbacks to be used. * @param activationId Activation ID to be notified about. *//*from ww w. j a va 2s . co m*/ public void notifyCallbackListeners(Long applicationId, String activationId) { final Iterable<CallbackUrlEntity> callbackUrlEntities = callbackUrlRepository .findByApplicationIdOrderByName(applicationId); Map<String, String> callbackData = new HashMap<>(); callbackData.put("activationId", activationId); AsyncRestTemplate template = new AsyncRestTemplate(); for (CallbackUrlEntity callbackUrl : callbackUrlEntities) { HttpEntity<Map<String, String>> request = new HttpEntity<>(callbackData); template.postForEntity(callbackUrl.getCallbackUrl(), request, Map.class, new HashMap<>()); } }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> getArticlesAround(@RequestParam Double lat, @RequestParam Double lon) throws InterruptedException, ExecutionException, JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GEO_URL).queryParam("lat", lat.toString()) .queryParam("lon", lon.toString()); RestTemplate template = new RestTemplate(); List<Map<String, Object>> geoResponse = template.getForObject(builder.build().encode().toUri(), List.class); Iterator<Map<String, Object>> it = geoResponse.iterator(); List<Future<ResponseEntity<Map>>> jobs = new ArrayList<>(); // to be able to merge answers from rating to geoitems there is a need // to map the article to its articleID // (articleID) => (articleItem) Map<String, Map<String, Object>> mappedResponseObjects = new HashMap<>(); while (it.hasNext()) { Map<String, Object> item = it.next(); AsyncRestTemplate async = new AsyncRestTemplate(); Future<ResponseEntity<Map>> futureResult = async.getForEntity((String) item.get("rating"), Map.class); jobs.add(futureResult);/* w w w .ja v a2 s .co m*/ mappedResponseObjects.put((String) item.get("articleID"), item); } for (Future<ResponseEntity<Map>> job : jobs) { Map<String, Object> ratingMap = job.get().getBody(); String articleID = (String) ratingMap.get("articleID"); if ((Boolean) ratingMap.get("appropriate")) { mappedResponseObjects.get(articleID).putAll(ratingMap); } else { mappedResponseObjects.remove(articleID); } } WeightingPolicy policy = new WeightingPolicyImpl(); List<Map<String, Object>> orderedResponse = policy.sortIncludingRating(mappedResponseObjects.values()); List<Map<String, Object>> result = new ResponseMapFilterImpl().filter(orderedResponse); return new ResponseEntity<>(objectMapper.writeValueAsString(result), HttpStatus.OK); }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles/new", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> getNewArticlesAround(@RequestParam Double lat, @RequestParam Double lon) throws InterruptedException, ExecutionException, JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GEO_URL).queryParam("lat", lat.toString()) .queryParam("lon", lon.toString()); RestTemplate template = new RestTemplate(); List<Map<String, Object>> geoResponse = template.getForObject(builder.build().encode().toUri(), List.class); Iterator<Map<String, Object>> it = geoResponse.iterator(); List<Future<ResponseEntity<Map>>> jobs = new ArrayList<>(); // to be able to merge answers from rating to geoitems there is a need // to map the article to its articleID // (articleID) => (articleItem) Map<String, Map<String, Object>> mappedResponseObjects = new HashMap<>(); while (it.hasNext()) { Map<String, Object> item = it.next(); AsyncRestTemplate async = new AsyncRestTemplate(); Future<ResponseEntity<Map>> futureResult = async.getForEntity((String) item.get("rating"), Map.class); jobs.add(futureResult);//from w ww.j av a 2 s.c o m mappedResponseObjects.put((String) item.get("articleID"), item); } for (Future<ResponseEntity<Map>> job : jobs) { Map<String, Object> ratingMap = job.get().getBody(); String articleID = (String) ratingMap.get("articleID"); mappedResponseObjects.get(articleID).putAll(ratingMap); } WeightingPolicy policy = new WeightingPolicyImpl(); List<Map<String, Object>> orderedResponse = policy.sortExcludingRating(mappedResponseObjects.values()); List<Map<String, Object>> result = new ResponseMapFilterImpl().filter(orderedResponse); return new ResponseEntity<>(objectMapper.writeValueAsString(result), HttpStatus.OK); }