@GetMapping(path = BLOCKING_PATH) @SuppressWarnings("unused") public String getBlocking() { logger.info("Blocking endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); return BLOCKING_RESULT; }
@GetMapping(path = WILDCARD_PATH_PREFIX + "/**") @SuppressWarnings("unused") public String getWildcard() { logger.info("Wildcard endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); return WILDCARD_RESULT; }
@GetMapping(path = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/{somePathParam}") @SuppressWarnings("unused") public String getPathParam(@PathVariable String somePathParam) { logger.info("Path param endpoint hit - somePathParam: {}", somePathParam); sleepThread(SLEEP_TIME_MILLIS); return PATH_PARAM_ENDPOINT_RESULT; }
@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 = ASYNC_CALLABLE_PATH) @SuppressWarnings("unused") public Callable<String> getAsyncCallable() { logger.info("Async endpoint hit (Callable)"); return callableWithTracing(() -> { logger.info("Async endpoint (Callable) async logic"); sleepThread(SLEEP_TIME_MILLIS); return ASYNC_CALLABLE_RESULT; }); }
@GetMapping(path = ASYNC_FUTURE_PATH) @SuppressWarnings("unused") public CompletableFuture<String> getAsyncCompletableFuture() { logger.info("Async endpoint hit (CompletableFuture)"); return CompletableFuture.supplyAsync(supplierWithTracing( () -> { logger.info("Async endpoint (CompletableFuture) async logic"); sleepThread(SLEEP_TIME_MILLIS); return ASYNC_FUTURE_RESULT; }), executor ); }
@GetMapping(path = ASYNC_ERROR_PATH) @SuppressWarnings("unused") public DeferredResult<String> getAsyncError() { logger.info("Async error endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); DeferredResult<String> deferredResult = new DeferredResult<>(); deferredResult.setErrorResult(new RuntimeException("Intentional exception by asyncError endpoint")); return deferredResult; }
@GetMapping(path = ASYNC_DEFERRED_RESULT_PATH) @SuppressWarnings("unused") public DeferredResult<String> getAsyncDeferredResult() { logger.info("Async endpoint hit (DeferredResult)"); DeferredResult<String> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { logger.info("Async endpoint (DeferredResult) async logic"); sleepThread(SLEEP_TIME_MILLIS); asyncResponse.setResult(ASYNC_DEFERRED_RESULT_PAYLOAD); })); return asyncResponse; }
@GetMapping(path = SPAN_INFO_CALL_PATH) @SuppressWarnings("unused") public EndpointSpanInfoDto getSpanInfoCall(HttpServletRequest request) { logger.info("Span info endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); return new EndpointSpanInfoDto(request, Tracer.getInstance().getCurrentSpan(), userIdHeaderKeys); }
@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; }