|
4 | 4 | import io.micronaut.http.annotation.Controller; |
5 | 5 | import io.micronaut.http.annotation.Get; |
6 | 6 | import io.micronaut.http.client.HttpClient; |
| 7 | +import io.micronaut.http.client.annotation.Client; |
| 8 | +import org.reactivestreams.Publisher; |
| 9 | +import reactor.core.publisher.Mono; |
7 | 10 |
|
8 | | -import java.net.URL; |
| 11 | +import staticio.micronaut.http.HttpRequest.GET; |
9 | 12 |
|
10 | 13 | /** |
11 | 14 | * This class is used to demonstrate the `View Traces` command. |
|
21 | 24 | @Controller("/command") |
22 | 25 | public class ViewTraces { |
23 | 26 |
|
| 27 | + private final HttpClient httpClient; |
| 28 | + |
| 29 | + public ViewTraces(@Client("/") HttpClient httpClient) { |
| 30 | + this.httpClient = httpClient; |
| 31 | + } |
| 32 | + |
24 | 33 | /** |
25 | 34 | * Execute the `View Traces` command with your caret anywhere between lines 31 and 38 to see the traces for |
26 | 35 | * the endpoint below. Executing this command will open a list of traces for the given endpoint. Clicking on a |
27 | 36 | * trace will open the trace details. |
28 | 37 | */ |
29 | 38 | @Get("/view-traces") |
30 | | - public HttpResponse<Void> entryEndpoint() throws Exception { |
31 | | - try (HttpClient client = HttpClient.create(new URL("http://localhost:8080"))) { |
32 | | - return client.toBlocking().exchange("/command/view-traces/exit"); |
33 | | - } catch (Exception e) { |
34 | | - return HttpResponse.serverError(); |
35 | | - } |
| 39 | + public Publisher<String> entryEndpoint() { |
| 40 | + return Mono.from(httpClient.retrieve(GET("/command/view-traces/exit"))); |
36 | 41 | } |
37 | 42 |
|
38 | 43 | @Get("/view-traces/exit") |
39 | | - public HttpResponse<Void> exitEndpoint() { |
40 | | - return HttpResponse.ok(); |
| 44 | + public HttpResponse<String> exitEndpoint() { |
| 45 | + return HttpResponse.ok("Success"); |
41 | 46 | } |
42 | 47 | } |
0 commit comments