org.glassfish.jersey.server.model.Resource.getAllMethods()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.glassfish.jersey.server.model.Resource.getAllMethods方法的一些代码示例,展示了Resource.getAllMethods的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.getAllMethods方法的具体详情如下:
包路径:org.glassfish.jersey.server.model.Resource
类名称:Resource
方法名:getAllMethods

Resource.getAllMethods介绍

[英]Provides resource methods and resource locator are available on the resource. The list is ordered so that resource methods are positioned first before resource locator.
[中]提供资源上可用的资源方法和资源定位器。对列表进行排序,以便将资源方法放在资源定位器之前。

代码示例

代码示例来源:origin: Graylog2/graylog2-server

private void logResources(List<Resource> resources) {
  final List<ResourceDescription> resourceDescriptions = new ArrayList<>();
  for (Resource resource : resources) {
    for (ResourceMethod resourceMethod : resource.getAllMethods()) {
      final String path = RestTools.getPathFromResource(resource);
      resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses()));
    }
  }
  Collections.sort(resourceDescriptions);
  for (ResourceDescription resource : resourceDescriptions) {
    LOG.debug(resource.toString());
  }
}

代码示例来源:origin: dropwizard/dropwizard

private List<EndpointLogLine> logMethodLines(Resource resource, String contextPath) {
  final List<EndpointLogLine> methodLines = new ArrayList<>();
  for (ResourceMethod method : resource.getAllMethods()) {
    if ("OPTIONS".equalsIgnoreCase(method.getHttpMethod())) {
      continue;

代码示例来源:origin: mtakaki/dropwizard-circuitbreaker

@Override
public void onEvent(final ApplicationEvent event) {
  if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
    event.getResourceModel().getResources().parallelStream()
        .filter(Objects::nonNull)
        .forEach(resource -> {
          this.registerCircuitBreakerAnnotations(resource.getAllMethods());
          resource.getChildResources().parallelStream()
              .filter(Objects::nonNull)
              .forEach(childResource -> {
                this.registerCircuitBreakerAnnotations(
                    childResource.getAllMethods());
              });
        });
  }
}

代码示例来源:origin: org.graylog2/graylog2-server

private void logResources(List<Resource> resources) {
  final List<ResourceDescription> resourceDescriptions = new ArrayList<>();
  for (Resource resource : resources) {
    for (ResourceMethod resourceMethod : resource.getAllMethods()) {
      final String path = RestTools.getPathFromResource(resource);
      resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses()));
    }
  }
  Collections.sort(resourceDescriptions);
  for (ResourceDescription resource : resourceDescriptions) {
    LOG.debug(resource.toString());
  }
}

代码示例来源:origin: icode/ameba

/**
 * <p>getRoutes.</p>
 *
 * @return a {@link java.util.List} object.
 */
@GET
public List<String> getRoutes() {
  List<Resource> resourceList = resourceContext.getResourceModel().getResources();
  List<String> routeList = Lists.newArrayList();
  for (Resource resource : resourceList) {
    String path = resource.getPath().startsWith("/") ? "" : "/" + resource.getPath();
    if (resource.getAllMethods().size() > 0) {
      routeList.add(path);
    }
    routeList.addAll(
        resource.getChildResources()
            .stream()
            .map(res -> path + (res.getPath().startsWith("/") ? "" : "/") + res.getPath())
            .collect(Collectors.toList())
    );
  }
  return routeList;
}

代码示例来源:origin: com.thesett.jenerator.utils/jenerator_util_dropwizard_0.9

public void onEvent(ApplicationEvent event) {
  if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
    for (Resource resource : event.getResourceModel().getResources()) {
      for (ResourceMethod method : resource.getAllMethods()) {
        registerAuditedMethodAnnotations(method);
      }
      for (Resource childResource : resource.getChildResources()) {
        for (ResourceMethod method : childResource.getAllMethods()) {
          registerAuditedMethodAnnotations(method);
        }
      }
    }
  }
}

代码示例来源:origin: com.thesett.jenerator.utils/jenerator_util_dropwizard_0.9

public void onEvent(ApplicationEvent event) {
  if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
    for (Resource resource : event.getResourceModel().getResources()) {
      for (ResourceMethod method : resource.getAllMethods()) {
        registerUnitOfWorkWithDetachAnnotations(method);
      }
      for (Resource childResource : resource.getChildResources()) {
        for (ResourceMethod method : childResource.getAllMethods()) {
          registerUnitOfWorkWithDetachAnnotations(method);
        }
      }
    }
  }
}

代码示例来源:origin: org.graylog2/graylog2-shared

private void logResources(List<Resource> resources) {
  final List<ResourceDescription> resourceDescriptions = new ArrayList<>();
  for (Resource resource : resources) {
    for (ResourceMethod resourceMethod : resource.getAllMethods()) {
      String path = resource.getPath();
      Resource parent = resource.getParent();
      while (parent != null) {
        if (!path.startsWith("/")) {
          path = "/" + path;
        }
        path = parent.getPath() + path;
        parent = parent.getParent();
      }
      resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses()));
    }
  }
  Collections.sort(resourceDescriptions);
  for (ResourceDescription resource : resourceDescriptions) {
    LOG.debug(resource.toString());
  }
}

代码示例来源:origin: org.codehaus.fabric3/fabric3-binding-rs-jersey

private Resource createResource(F3ResourceHandler handler) {
  Resource template = Resource.from(handler.getInterface());
  Resource.Builder resourceBuilder = Resource.builder(template.getPath());
  for (ResourceMethod resourceMethod : template.getAllMethods()) {
    createMethod(resourceBuilder, resourceMethod, handler);
  }
  for (Resource childTemplate : template.getChildResources()) {
    Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath());
    for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) {
      createMethod(childResourceBuilder, resourceMethod, handler);
    }
    resourceBuilder.addChildResource(childResourceBuilder.build());
  }
  return resourceBuilder.build();
}

代码示例来源:origin: org.glassfish.ozark/ozark

/**
 * Updates the default {@code @Produces} list of every controller method whose list is empty.
 * The new list contains a single media type: "text/html".
 *
 * @param r resource to process.
 * @return newly updated resource.
 */
private static Resource processResource(Resource r) {
  final boolean isControllerClass = isController(r);
  Resource.Builder rb = Resource.builder(r);
  r.getAllMethods().forEach(
      (ResourceMethod m) -> {
        if ((isController(m) || isControllerClass) && m.getProducedTypes().isEmpty()) {
          final ResourceMethod.Builder rmb = rb.updateMethod(m);
          rmb.produces(MediaType.TEXT_HTML_TYPE);
          rmb.build();
        }
      }
  );
  r.getChildResources().forEach(cr -> {
    rb.replaceChildResource(cr, processResource(cr));
  });
  return rb.build();
}

代码示例来源:origin: stackoverflow.com

for (ResourceMethod method : childResource.getAllMethods()) {
  if (method.getType() == ResourceMethod.JaxrsType.RESOURCE_METHOD) {
    final String path = normalizePath(basePath, childResource.getPath());

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-rs-jersey

private Resource createResource(F3ResourceHandler handler) {
  Class<?> interfaze = handler.getInterface();
  Resource template = Resource.from(interfaze);
  if (template == null) {
    throw new Fabric3Exception("Interface is not a JAX-RS resource: " + interfaze.getName());
  }
  // introspect consumes and produces annotations on the JAX-RS type as well as in meta-annotations
  Consumes consumes = AnnotationHelper.findAnnotation(Consumes.class, interfaze);
  String[] consumeTypes = consumes != null ? consumes.value() : EMPTY_ARRAY;
  Produces produces = AnnotationHelper.findAnnotation(Produces.class, interfaze);
  String[] produceTypes = produces != null ? produces.value() : EMPTY_ARRAY;
  Resource.Builder resourceBuilder = Resource.builder(template.getPath());
  for (ResourceMethod resourceMethod : template.getAllMethods()) {
    createMethod(resourceBuilder, resourceMethod, handler, consumeTypes, produceTypes);
  }
  for (Resource childTemplate : template.getChildResources()) {
    Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath());
    for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) {
      createMethod(childResourceBuilder, resourceMethod, handler, consumeTypes, produceTypes);
    }
    resourceBuilder.addChildResource(childResourceBuilder.build());
  }
  return resourceBuilder.build();
}

代码示例来源:origin: org.fabric3/fabric3-binding-rs-jersey

private Resource createResource(F3ResourceHandler handler) {
  Class<?> interfaze = handler.getInterface();
  Resource template = Resource.from(interfaze);
  if (template == null) {
    throw new Fabric3Exception("Interface is not a JAX-RS resource: " + interfaze.getName());
  }
  // introspect consumes and produces annotations on the JAX-RS type as well as in meta-annotations
  Consumes consumes = AnnotationHelper.findAnnotation(Consumes.class, interfaze);
  String[] consumeTypes = consumes != null ? consumes.value() : EMPTY_ARRAY;
  Produces produces = AnnotationHelper.findAnnotation(Produces.class, interfaze);
  String[] produceTypes = produces != null ? produces.value() : EMPTY_ARRAY;
  Resource.Builder resourceBuilder = Resource.builder(template.getPath());
  for (ResourceMethod resourceMethod : template.getAllMethods()) {
    createMethod(resourceBuilder, resourceMethod, handler, consumeTypes, produceTypes);
  }
  for (Resource childTemplate : template.getChildResources()) {
    Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath());
    for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) {
      createMethod(childResourceBuilder, resourceMethod, handler, consumeTypes, produceTypes);
    }
    resourceBuilder.addChildResource(childResourceBuilder.build());
  }
  return resourceBuilder.build();
}

代码示例来源:origin: io.dropwizard.metrics/metrics-jersey2

private void registerMetricsForModel(ResourceModel resourceModel) {
  for (final Resource resource : resourceModel.getResources()) {
    final Timed classLevelTimed = getClassLevelAnnotation(resource, Timed.class);
    final Metered classLevelMetered = getClassLevelAnnotation(resource, Metered.class);
    final ExceptionMetered classLevelExceptionMetered = getClassLevelAnnotation(resource, ExceptionMetered.class);
    final ResponseMetered classLevelResponseMetered = getClassLevelAnnotation(resource, ResponseMetered.class);
    for (final ResourceMethod method : resource.getAllMethods()) {
      registerTimedAnnotations(method, classLevelTimed);
      registerMeteredAnnotations(method, classLevelMetered);
      registerExceptionMeteredAnnotations(method, classLevelExceptionMetered);
      registerResponseMeteredAnnotations(method, classLevelResponseMetered);
    }
    for (final Resource childResource : resource.getChildResources()) {
      final Timed classLevelTimedChild = getClassLevelAnnotation(childResource, Timed.class);
      final Metered classLevelMeteredChild = getClassLevelAnnotation(childResource, Metered.class);
      final ExceptionMetered classLevelExceptionMeteredChild = getClassLevelAnnotation(childResource, ExceptionMetered.class);
      final ResponseMetered classLevelResponseMeteredChild = getClassLevelAnnotation(childResource, ResponseMetered.class);
      for (final ResourceMethod method : childResource.getAllMethods()) {
        registerTimedAnnotations(method, classLevelTimedChild);
        registerMeteredAnnotations(method, classLevelMeteredChild);
        registerExceptionMeteredAnnotations(method, classLevelExceptionMeteredChild);
        registerResponseMeteredAnnotations(method, classLevelResponseMeteredChild);
      }
    }
  }
}

代码示例来源:origin: io.dropwizard/dropwizard-jersey

private void populate(String basePath, Class<?> klass, boolean isLocator, Resource resource,
           Set<EndpointLogLine> endpointLogLines) {
  if (!isLocator) {
    basePath = normalizePath(basePath, resource.getPath());
  }
  for (ResourceMethod method : resource.getResourceMethods()) {
    endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), basePath, klass));
  }
  for (Resource childResource : resource.getChildResources()) {
    for (ResourceMethod method : childResource.getAllMethods()) {
      if (method.getType() == ResourceMethod.JaxrsType.RESOURCE_METHOD) {
        final String path = normalizePath(basePath, childResource.getPath());
        endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), path, klass));
      } else if (method.getType() == ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR) {
        final String path = normalizePath(basePath, childResource.getPath());
        final ResolvedType responseType = TYPE_RESOLVER
            .resolve(method.getInvocable().getResponseType());
        final Class<?> erasedType = !responseType.getTypeBindings().isEmpty() ?
            responseType.getTypeBindings().getBoundType(0).getErasedType() :
            responseType.getErasedType();
        if (Resource.from(erasedType) == null) {
          endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), path, erasedType));
        } else {
          populate(path, erasedType, true, endpointLogLines);
        }
      }
    }
  }
}

相关文章