WildFly管理 - 列出/检测在WildFly中部署的REST端点 [英] WildFly management - list/detect REST endpoints deployed in WildFly
问题描述
是否有办法(例如从WildFly管理控制台)列出在WildFly中部署的所有REST端点?或者在服务器启动时将它们列在日志中?
Is there a way (e.g. from a WildFly management console) to list all REST endpoints deployed in WildFly? Or to list them in a log while a server is starting?
推荐答案
使用 RegistryStatsResource
使用RESTEasy(随WildFly一起提供),您可以将以下内容添加到 web.xml
:
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>org.jboss.resteasy.plugins.stats.RegistryStatsResource</param-value>
</context-param>
然后请求以下网址:
http://[hostname]:[port]/[context]/[api-path]/resteasy/registry
此类端点可以生成XML和JSON内容。只需将 Accept
标头添加到具有所需媒体类型的请求中:
Such endpoint can produce XML and JSON content. Just add the Accept
header to the request with the desired media type:
-
application / xml
-
application / json
application/xml
application/json
如果您对创建自己的实现的源代码感兴趣,请拥有看看 RegistryStatsResource
GitHub上的类。
If you are interested in the source code to create your own implementation, have a look at the RegistryStatsResource
class on GitHub.
源代码中最相关的部分如下所示(它特定于RESTEasy):
The most relevant part of the source code is shown below (it's RESTEasy specific):
ResourceMethodRegistry registry = (ResourceMethodRegistry)
ResteasyProviderFactory.getContextData(Registry.class);
for (String key : registry.getBounded().keySet()){
List<ResourceInvoker> invokers = registry.getBounded().get(key);
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker rm = (ResourceMethodInvoker) invoker;
// Extract metadata from the ResourceMethodInvoker
}
}
Swagger可能是另一种选择
根据您的要求,您可以使用 Swagger 来记录您的API。它附带一个一套注释描述您的REST端点。
Swagger may be an alternative
Depending on your requirements, you can use Swagger to document your API. It comes with a set of annotations to describe your REST endpoints.
然后使用 Swagger UI 为您的API提供实时文档。
Then use Swagger UI to provide a live documentation for your API.
注意:截至2017年2月,看起来像 RegistryStatsResource
类完全没有记录。我在挖掘RESTEasy源代码以进行调试时偶尔会发现它。此外,我发现了 JBoss EAP问题,该问题跟踪该课程缺乏文档。
Note: As of February 2017, looks like the RegistryStatsResource
class is completely undocumented. I occasionally discovered it when digging into the RESTEasy source code for debugging purposes. Also, I found this JBoss EAP issue that tracks the lack of documentation for that class.
这篇关于WildFly管理 - 列出/检测在WildFly中部署的REST端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!