从 Jersey application.wadl 中排除资源路径?

Exclude resource paths from Jersey application.wadl?

Jersey 在 /application.wadl 提供动态 wadl。就我而言,我的应用程序中同时公开了内部路径和外部路径。我想从动态 wadl 生成中排除内部 api。

是否有一些配置告诉 Jersey 忽略某些路径?

根据 Jersey 文档:https://jersey.java.net/documentation/latest/wadl.html 你有三种方式:

  1. web.xml 中的设置将禁用整个 wadl jersey.config.server.wadl.disableWadl=真
  2. 使用@ExtendedResource 注释不会在默认 wadl 中显示注释 method/class, 但仅限于扩展版。
  3. 根据17.2,你也可以覆盖 使用 Jersey 本身的默认 wadl。

我最终用这样的东西覆盖了它:

@Context
protected UriInfo uriInfo;

@Context
protected WadlApplicationContext wadlContext;

@GET
@Path("/wadl")
@Produces({"application/vnd.sun.wadl+xml", MediaType.APPLICATION_XML})
public Response wadl() {

        // most of this is lifted from org.glassfish.jersey.server.wadl.internal.WadlResource
        try {
            boolean detailedWadl = WadlUtils.isDetailedWadlRequested(uriInfo);
            String lastModified = new SimpleDateFormat(WadlResource.HTTPDATEFORMAT).format(new Date());
            ApplicationDescription applicationDescription = wadlContext.getApplication(uriInfo, detailedWadl);
            Application application = applicationDescription.getApplication();
            application.getResources().stream().findFirst().get().getResource().removeIf(resource -> !resource.getPath().startsWith("/public_api"));
            ByteArrayInputStream wadl = marshal(application);
            return Response.ok(wadl).header("Last-modified", lastModified).build();
        } catch (Exception e) {
            throw new ProcessingException("Error generating WADL", e);
        }
}