Jersey在/application.wadl上提供动态wadl。在我的例子中,我在我的应用程序中暴露了仅内部路径和外部路径。我想从动态wadl生成中排除内部apis。
是否有一些配置告诉Jersey忽略某些路径?
答案 0 :(得分:2)
根据泽西岛文件:https://jersey.java.net/documentation/latest/wadl.html 你有三种方式: 1.在web.xml中设置将禁用整个wadl jersey.config.server.wadl.disableWadl = true 2.使用@ExtendedResource注释不会在默认wadl中显示带注释的方法/类,而只会在扩展的wadl中显示。 3.根据17.2,您也可以使用泽西本身覆盖默认的wadl。
答案 1 :(得分:0)
我最终用这样的东西来压倒它:
@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);
}
}