问题描述
是否有办法(例如从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
如果您对创建自己的实现的源代码感兴趣,请拥有看看。
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可能是另一种选择
根据您的要求,您可以使用来记录您的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.
这篇关于WildFly管理 - 列出/检测在WildFly中部署的REST端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!