@GetMapping(path = NESTED_BLOCKING_CALL_PATH) @SuppressWarnings("unused") public EndpointSpanInfoDto getNestedBlockingCall() { logger.info("Nested blocking call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar"); logger.info("...Calling: " + nestedCallUri.toString()); EndpointSpanInfoDto returnVal = wingtipsEnabledRestTemplate .exchange(nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class) .getBody(); logger.info("Blocking RestTemplate call complete"); return returnVal; }
@GetMapping(path = NESTED_ASYNC_CALL_PATH) @SuppressWarnings("unused") public DeferredResult<EndpointSpanInfoDto> getNestedAsyncCall() { DeferredResult<EndpointSpanInfoDto> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { try { logger.info("Nested async call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar" ); logger.info("...Calling: " + nestedCallUri.toString()); ListenableFuture<ResponseEntity<EndpointSpanInfoDto>> asyncRestTemplateResultFuture = wingtipsEnabledAsyncRestTemplate.exchange( nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class ); asyncRestTemplateResultFuture.addCallback( successCallbackWithTracing(result -> { logger.info("AsyncRestTemplate call complete"); asyncResponse.setResult(result.getBody()); }), failureCallbackWithTracing(asyncResponse::setErrorResult) ); } catch(Throwable t) { asyncResponse.setErrorResult(t); } })); return asyncResponse; }