|
1 | 1 | package io.quarkus.resteasy.reactive.server.runtime.devui; |
2 | 2 |
|
3 | | -import java.util.ArrayList; |
4 | | -import java.util.Collections; |
5 | 3 | import java.util.List; |
| 4 | +import java.util.Map; |
| 5 | +import java.util.TreeMap; |
| 6 | +import java.util.stream.Collectors; |
| 7 | + |
| 8 | +import jakarta.ws.rs.core.MediaType; |
6 | 9 |
|
7 | 10 | import org.jboss.resteasy.reactive.server.core.RuntimeExceptionMapper; |
8 | 11 | import org.jboss.resteasy.reactive.server.util.ScoreSystem; |
9 | 12 |
|
10 | 13 | import io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder; |
| 14 | +import io.vertx.core.json.JsonArray; |
| 15 | +import io.vertx.core.json.JsonObject; |
11 | 16 |
|
12 | 17 | public class ResteasyReactiveJsonRPCService { |
13 | 18 |
|
14 | | - public ScoreSystem.EndpointScores getEndpointScores() { |
| 19 | + public JsonObject getEndpointScores() { |
| 20 | + JsonObject endpointScore = new JsonObject(); |
| 21 | + |
15 | 22 | ScoreSystem.EndpointScores result = ScoreSystem.latestScores; |
16 | 23 | if (result != null) { |
17 | | - return result; |
| 24 | + endpointScore.put("score", result.score); |
| 25 | + JsonArray endpoints = new JsonArray(); |
| 26 | + for (ScoreSystem.EndpointScore endpoint : result.endpoints) { |
| 27 | + JsonObject e = new JsonObject(); |
| 28 | + e.put("className", endpoint.className); |
| 29 | + e.put("httpMethod", endpoint.httpMethod); |
| 30 | + e.put("fullPath", endpoint.fullPath); |
| 31 | + e.put("producesHeaders", endpoint.produces.stream() |
| 32 | + .map(MediaType::toString) |
| 33 | + .collect(Collectors.toList())); |
| 34 | + e.put("consumesHeaders", endpoint.consumes.stream() |
| 35 | + .map(MediaType::toString) |
| 36 | + .collect(Collectors.toList())); |
| 37 | + |
| 38 | + JsonObject diagnostics = new JsonObject(); |
| 39 | + Map<ScoreSystem.Category, List<ScoreSystem.Diagnostic>> sortedDiagnostics = new TreeMap<>(endpoint.diagnostics); |
| 40 | + for (Map.Entry<ScoreSystem.Category, List<ScoreSystem.Diagnostic>> diagnostic : sortedDiagnostics.entrySet()) { |
| 41 | + JsonArray diagnosticValues = new JsonArray(); |
| 42 | + for (ScoreSystem.Diagnostic value : diagnostic.getValue()) { |
| 43 | + JsonObject diagnosticValue = new JsonObject(); |
| 44 | + diagnosticValue.put("message", value.message); |
| 45 | + diagnosticValue.put("score", value.score); |
| 46 | + diagnosticValues.add(diagnosticValue); |
| 47 | + } |
| 48 | + diagnostics.put(diagnostic.getKey().name(), diagnosticValues); |
| 49 | + } |
| 50 | + e.put("diagnostics", diagnostics); |
| 51 | + e.put("requestFilterEntries", endpoint.requestFilterEntries.stream() |
| 52 | + .map(ScoreSystem.RequestFilterEntry::getName) |
| 53 | + .collect(Collectors.toList())); |
| 54 | + e.put("score", endpoint.score); |
| 55 | + endpoints.add(e); |
| 56 | + } |
| 57 | + endpointScore.put("endpoints", endpoints); |
| 58 | + } else { |
| 59 | + endpointScore.put("score", 0); |
18 | 60 | } |
19 | 61 |
|
20 | | - return new ScoreSystem.EndpointScores(0, Collections.emptyList()); |
| 62 | + return endpointScore; |
21 | 63 | } |
22 | 64 |
|
23 | | - public List<ResteasyReactiveExceptionMapper> getExceptionMappers() { |
24 | | - List<ResteasyReactiveExceptionMapper> all = new ArrayList<>(); |
| 65 | + public JsonArray getExceptionMappers() { |
| 66 | + JsonArray all = new JsonArray(); |
25 | 67 | var mappers = RuntimeExceptionMapper.getMappers(); |
26 | 68 | for (var entry : mappers.entrySet()) { |
27 | | - all.add(new ResteasyReactiveExceptionMapper(entry.getKey().getName(), entry.getValue().getClassName(), |
28 | | - entry.getValue().getPriority())); |
| 69 | + JsonObject m = new JsonObject(); |
| 70 | + m.put("name", entry.getKey().getName()); |
| 71 | + m.put("className", entry.getValue().getClassName()); |
| 72 | + m.put("priority", entry.getValue().getPriority()); |
| 73 | + all.add(m); |
29 | 74 | } |
30 | 75 | return all; |
31 | 76 | } |
32 | 77 |
|
33 | | - public List<ResteasyReactiveParamConverterProvider> getParamConverterProviders() { |
34 | | - List<ResteasyReactiveParamConverterProvider> all = new ArrayList<>(); |
| 78 | + public JsonArray getParamConverterProviders() { |
| 79 | + JsonArray all = new JsonArray(); |
35 | 80 | var providers = ResteasyReactiveRecorder.getCurrentDeployment().getParamConverterProviders() |
36 | 81 | .getParamConverterProviders(); |
37 | 82 | for (var provider : providers) { |
38 | | - all.add(new ResteasyReactiveParamConverterProvider(provider.getClassName(), |
39 | | - provider.getPriority())); |
| 83 | + JsonObject m = new JsonObject(); |
| 84 | + m.put("className", provider.getClassName()); |
| 85 | + m.put("priority", provider.getPriority()); |
| 86 | + all.add(m); |
40 | 87 | } |
41 | 88 | return all; |
42 | 89 | } |
|
0 commit comments