-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a list of REST Client Reactive clients to Dev Ui
- Loading branch information
1 parent
371b883
commit 8e7a179
Showing
8 changed files
with
228 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...kus/rest/client/reactive/deployment/devconsole/RestClientReactiveDevConsoleProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.rest.client.reactive.deployment.devconsole; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.arc.runtime.BeanLookupSupplier; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; | ||
import io.quarkus.rest.client.reactive.runtime.devconsole.RestClientsContainer; | ||
|
||
public class RestClientReactiveDevConsoleProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public DevConsoleRuntimeTemplateInfoBuildItem devConsoleInfo() { | ||
return new DevConsoleRuntimeTemplateInfoBuildItem("devRestClients", | ||
new BeanLookupSupplier(RestClientsContainer.class)); | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public AdditionalBeanBuildItem beans() { | ||
return AdditionalBeanBuildItem.unremovableOf(RestClientsContainer.class); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...y-reactive/rest-client-reactive/deployment/src/main/resources/dev-templates/embedded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<a href="{urlbase}/rest-clients" class="badge badge-light"> | ||
<i class="fa fa-external-link-alt fa-fw"></i> | ||
REST clients | ||
</a> |
64 changes: 64 additions & 0 deletions
64
...active/rest-client-reactive/deployment/src/main/resources/dev-templates/rest-clients.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{#include main fluid=true} | ||
{#style} | ||
.annotation { | ||
color: gray; | ||
font-style: italic; | ||
} | ||
span.larger-badge { | ||
font-size: 0.9em; | ||
} | ||
span.app-class { | ||
cursor:pointer; | ||
color:blue; | ||
text-decoration:underline; | ||
} | ||
|
||
{/style} | ||
|
||
{#script} | ||
$(document).ready(function(){ | ||
if (!ideKnown()) { | ||
return; | ||
} | ||
$(".class-candidate").each(function() { | ||
var className = $(this).text(); | ||
if (appClassLang(className)) { | ||
$(this).addClass("app-class"); | ||
} | ||
}); | ||
|
||
$(".app-class").on("click", function() { | ||
openInIDE($(this).text()); | ||
}); | ||
}); | ||
{/script} | ||
|
||
{#title}REST Client classes{/title} | ||
{#body} | ||
<table class="table table-striped"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Client interface</th> | ||
<th scope="col">Is a CDI bean (injectable with @RestClient)</th> | ||
<th scope="col">Config prefix</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for client in info:devRestClients.clientData.clients} | ||
<tr> | ||
<td>{client_count}.</td> | ||
<td> | ||
<span class="class-candidate">{client.interfaceClass}</span> | ||
</td> | ||
<td> | ||
<i>{client.isBean}</i> | ||
</td> | ||
<td> | ||
{client.configKey} | ||
</td> | ||
{/for} | ||
</tbody> | ||
</table> | ||
{/body} | ||
{/include} |
12 changes: 12 additions & 0 deletions
12
...ive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...rc/main/java/io/quarkus/rest/client/reactive/runtime/devconsole/RestClientsContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.quarkus.rest.client.reactive.runtime.devconsole; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.client.impl.ClientProxies; | ||
import org.jboss.resteasy.reactive.client.spi.ClientContext; | ||
import org.jboss.resteasy.reactive.client.spi.ClientContextResolver; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.profile.IfBuildProfile; | ||
import io.quarkus.rest.client.reactive.runtime.RestClientRecorder; | ||
|
||
@IfBuildProfile("dev") | ||
@Unremovable | ||
@Singleton | ||
public class RestClientsContainer { | ||
|
||
public static final ClientContextResolver CLIENT_CONTEXT_RESOLVER = ClientContextResolver.getInstance(); | ||
|
||
@Inject | ||
@RestClient | ||
Instance<Object> injectableClients; | ||
|
||
/** | ||
* Used in Dev UI | ||
* | ||
* @return info about exposed clients | ||
*/ | ||
public RestClientData getClientData() { | ||
ClientContext context = CLIENT_CONTEXT_RESOLVER.resolve(Thread.currentThread().getContextClassLoader()); | ||
ClientProxies.ClientData clientData = context.getClientProxies().getClientData(); | ||
|
||
List<RestClientInfo> restClients = new ArrayList<>(); | ||
List<PossibleRestClientInfo> possibleRestClients = new ArrayList<>(); | ||
|
||
for (Class<?> clientClass : clientData.clientClasses) { | ||
Instance<?> select = injectableClients.select(clientClass); | ||
String interfaceName = clientClass.getName(); | ||
if (select.isResolvable()) { | ||
String configKey = RestClientRecorder.getConfigKeys().get(interfaceName); | ||
if (configKey == null) { | ||
configKey = String.format("\"%s\"", interfaceName); | ||
} | ||
restClients.add(new RestClientInfo(interfaceName, true, configKey)); | ||
} else { | ||
restClients.add(new RestClientInfo(interfaceName, false, null)); | ||
} | ||
} | ||
for (Map.Entry<Class<?>, String> clientEntry : clientData.failures.entrySet()) { | ||
possibleRestClients.add(new PossibleRestClientInfo(clientEntry.getKey().getName(), clientEntry.getValue())); | ||
} | ||
return new RestClientData(restClients, possibleRestClients); | ||
} | ||
|
||
public static class RestClientData { | ||
public final List<RestClientInfo> clients; | ||
public final List<PossibleRestClientInfo> possibleClients; | ||
|
||
public RestClientData(List<RestClientInfo> clients, List<PossibleRestClientInfo> possibleClients) { | ||
this.clients = clients; | ||
this.possibleClients = possibleClients; | ||
} | ||
} | ||
|
||
public static class RestClientInfo { | ||
public final String interfaceClass; | ||
public final boolean isBean; | ||
public final String configKey; | ||
|
||
public RestClientInfo(String interfaceClass, boolean isBean, String configKey) { | ||
this.interfaceClass = interfaceClass; | ||
this.isBean = isBean; | ||
this.configKey = configKey == null ? "" : String.format("quarkus.rest.client.%s", configKey); | ||
} | ||
} | ||
|
||
public static class PossibleRestClientInfo { | ||
public final String jaxrsClassName; | ||
public final String failure; | ||
|
||
public PossibleRestClientInfo(String jaxrsClassName, String failure) { | ||
this.jaxrsClassName = jaxrsClassName; | ||
this.failure = failure; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters