栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

自省Jersey资源模型Jersey 2.x

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

自省Jersey资源模型Jersey 2.x

可以在

org.glassfish.jersey.server.model
包中找到适用于Jersey 2.x的新API 。

我可以想到的一些等效项:

  • AbstractResource
    ==
    Resource

  • IntrospectionModeller.createResource
    ==我相信
    Resource.from(baseResource.class)

  • AbstractResourceMethod
    ==
    ResourceMethod

  • resource.getSubResourceMethods()
    ==
    getChildResources()
    ,实际上只返回一个
    List<Resource>

  • AbstractSubResourceLocator
    ==似乎不存在。我们只需检查上面的子资源,看看它是否是定位器

    for (Resource childResource: resource.getChildResources()) {if (childResource.getResourceLocator() != null) {    ResourceMethod method = childResource.getResourceLocator();    Class locatorType = method.getInvocable().getRawResponseType();}

    }

您还可以使用枚举

ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR
检查它是否等于
ResourceMethod.getType()

    if (resourceMethod.getType()        .equals(ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR) {}

这就是我能想到的,以匹配您所得到的。

import com.wordnik.swagger.annotations.ApiOperation;import org.glassfish.jersey.server.model.Resource;import org.glassfish.jersey.server.model.ResourceMethod;public class ApiScanner {    public static void main(String[] args) {        ApiScanner scanner = new ApiScanner();        scanner.xyz();    }    public void xyz() {        Resource resource = Resource.from(baseResource.class);        abc(resource.getPath(), resource);    }    public void abc(String uriPrefix, Resource resource) {        for (ResourceMethod resourceMethod: resource.getResourceMethods()) { String uri = uriPrefix; System.out.println("-- Resource Method --"); System.out.println(resourceMethod.getHttpMethod() + "t" + uri); ApiOperation api = resourceMethod.getInvocable().getDefinitionMethod()    .getAnnotation(ApiOperation.class);        }        for (Resource childResource: resource.getChildResources()) { System.out.println("-- Child Resource --"); System.out.println(childResource.getPath() + "t" + childResource.getName()); if (childResource.getResourceLocator() != null) {     System.out.println("-- Sub-Resource Locator --");     ResourceMethod method = childResource.getResourceLocator();     Class locatorType = method.getInvocable().getRawResponseType();     System.out.println(locatorType);     Resource subResource = Resource.from(locatorType);     abc(childResource.getPath(), subResource);         }        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/609746.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号