javax.ws.rs.container.ResourceInfo类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(108)

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

ResourceInfo介绍

[英]An injectable class to access the resource class and resource method matched by the current request. Methods in this class MAY return null if a resource class and method have not been matched, e.g. in a standalone, pre-matching ContainerRequestFilter that was not provided by a post-matching PreMatching.
[中]一个可注入类,用于访问与当前请求匹配的资源类和资源方法。如果资源类和方法尚未匹配,则此类中的方法可能返回null,例如,在独立的预匹配ContainerRequestFilter中,该筛选器不是由后期匹配预匹配提供的。

代码示例

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

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final Class<?> resourceClass = resourceInfo.getResourceClass();
    final Method resourceMethod = resourceInfo.getResourceMethod();

    if (serverStatus.hasCapability(ServerStatus.Capability.MASTER))
      return;

    if (resourceMethod.isAnnotationPresent(RestrictToMaster.class) || resourceClass.isAnnotationPresent(RestrictToMaster.class)) {
      context.register(restrictToMasterFilter);
    }
  }
}

代码示例来源:origin: openzipkin/brave

/**
 * Invoked prior to request invocation during {@link ContainerRequestFilter#filter(ContainerRequestContext)}
 * where the resource info was injected from context.
 *
 * <p>Adds the tags {@link #RESOURCE_CLASS} and {@link #RESOURCE_METHOD}. Override or use {@link #NOOP}
 * to change this behavior.
 */
protected void resourceInfo(ResourceInfo resourceInfo, SpanCustomizer customizer) {
 customizer.tag(RESOURCE_CLASS, resourceInfo.getResourceClass().getSimpleName());
 customizer.tag(RESOURCE_METHOD, resourceInfo.getResourceMethod().getName());
}

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

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (resourceInfo.getResourceMethod().getAnnotation(DateRequired.class) != null) {
      context.register(DateNotSpecifiedFilter.class);
    }
  }
}

代码示例来源:origin: resteasy/Resteasy

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext configurable)
{
 @SuppressWarnings("rawtypes")
 final Class declaring = resourceInfo.getResourceClass();
 final Method method = resourceInfo.getResourceMethod();
 if (declaring == null || method == null) return;
 Set<String> encodings = getEncodings(method.getAnnotations());
 if (encodings.size() <= 0)
 {
   encodings = getEncodings(declaring.getAnnotations());
   if (encodings.size() <= 0) return;
 }
 // check if GZIP encoder has been registered
 if (!isGZipRegistered(configurable.getConfiguration()))
 {
   encodings.remove("gzip");
 }
 configurable.register(createFilter(encodings));
}

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

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (DynamicallyBoundFilterResource.class == resourceInfo.getResourceClass()) {
      context.register(DynamicallyBoundFilter.class);
    }
  }
}

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

public MeteredMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) {
  final Metered annotation = resourceInfo.getResourceMethod().getAnnotation(Metered.class);
  meter = metricRegistry.meter(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod()));
}
@Override

代码示例来源:origin: oracle/helidon

private SecurityDefinition getMethodSecurity(Method definitionMethod) {
  // Check cache
  if (resourceMethodSecurity.containsKey(definitionMethod)) {
    return resourceMethodSecurity.get(definitionMethod);
  }
  // Jersey model 'definition method' is the method that contains JAX-RS/Jersey annotations. JAX-RS does not support
  // merging annotations from a parent, so we don't have to look for annotations on corresponding methods of interfaces
  // and abstract classes implemented by the definition method.
  // Jersey model does not have a 'definition class', so we have to find it from a handler class
  Class<?> definitionClass = getDefinitionClass(resourceInfo.getResourceClass());
  SecurityDefinition definition = this.resourceClassSecurity
      .computeIfAbsent(definitionClass, aClass -> securityForClass(definitionClass, appWideSecurity));
  Authenticated atn = definitionMethod.getAnnotation(Authenticated.class);
  Authorized atz = definitionMethod.getAnnotation(Authorized.class);
  Audited audited = definitionMethod.getAnnotation(Audited.class);
  SecurityDefinition methodDef = definition.copyMe();
  methodDef.add(atn);
  methodDef.add(atz);
  methodDef.add(audited);
  addCustomAnnotations(methodDef.getOperationScope(), definitionMethod);
  resourceMethodSecurity.put(definitionMethod, methodDef);
  for (AnnotationAnalyzer analyzer : analyzers) {
    AnnotationAnalyzer.AnalyzerResponse analyzerResponse = analyzer.analyze(definitionMethod,
                                        definition.analyzerResponse(analyzer));
    methodDef.analyzerResponse(analyzer, analyzerResponse);
  }
  return methodDef;
}

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

@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
  final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
  // check to see if it has cache control annotation
  final CacheControl cc = am.getAnnotation(CacheControl.class);
  if (cc != null) {
    configuration.register(new CacheControlledResponseFilter(cc));
  }
}

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

Class<?> resourceClass = resourceInfo.getResourceClass();
List<Role> classRoles = extractRoles(resourceClass);
Method resourceMethod = resourceInfo.getResourceMethod();
List<Role> methodRoles = extractRoles(resourceMethod);

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

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (DynamicallyBoundInterceptorResource.class == resourceInfo.getResourceClass()) {
      context.register(DynamicallyBoundInterceptor.class);
    }
  }
}

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

public TimedMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) {
  final Timed annotation = resourceInfo.getResourceMethod().getAnnotation(Timed.class);
  timer = metricRegistry.timer(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod()));
}

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

.getProducibleMediaTypes(requestProvider.get(), extendedUriInfoProvider.get(), null);
final Class<?> resourceClass = resourceInfoProvider.get().getResourceClass();
if (viewable instanceof ImplicitViewable) {

代码示例来源:origin: scouter-project/scouter

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (resourceInfo.getResourceClass().getName().indexOf("scouterx.") == 0) {
      if (resourceInfo.getResourceMethod().getAnnotation(NoAuth.class) == null) {
        context.register(AuthFilter.class);
      }
    }
  }
}

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

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final Require va = resourceInfo.getResourceMethod().getAnnotation(Require.class);
    if (va != null) {
      context.register(new CustomHeaderFilter(va.headerName(), va.headerValue()));
    }
  }
}

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

@Provider
@Priority(Priorities.AUTHORIZATION)
public class MyFilter implements ContainerRequestFilter
  @Context // request scoped proxy
  private ResourceInfo resourceInfo;

  @Override
  public void filter(ContainerRequestContext requestContext) throws IOException {
    if (resourceInfo.getResourceClass().isAnnotationPresent(MyAnnotationion.class) ||
      resourceInfo.getResourceMethod().isAnnotationPresent(MyOtherAnnotation.class)) {

代码示例来源:origin: org.kantega.respiro/respiro-message-collector-plugin

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
  if (!resourceInfo.getResourceClass().isAnnotationPresent(DoNotCollect.class)
      && ! metricsDisabled(resourceInfo.getResourceClass())) {
    context.register(ContainerCollectingFilter.class);
  }
}

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

public ExceptionMeteredMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) {
  final ExceptionMetered annotation = resourceInfo.getResourceMethod().getAnnotation(ExceptionMetered.class);
  meter = metricRegistry.meter(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod(), ExceptionMetered.DEFAULT_NAME_SUFFIX));
  exceptionClass = annotation.cause();
}

代码示例来源:origin: com.github.phillip-kruger/apiee-core

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    if(!classes.contains(resourceClass)){
      classes.add(resourceClass);
      log.log(Level.FINEST, "Apiee adding class [{0}]", resourceClass);
    }
  }
}

代码示例来源:origin: apache/shiro

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
  List<Annotation> authzSpecs = new ArrayList<Annotation>();
  for (Class<? extends Annotation> annotationClass : shiroAnnotations) {
    // XXX What is the performance of getAnnotation vs getAnnotations?
    Annotation classAuthzSpec = resourceInfo.getResourceClass().getAnnotation(annotationClass);
    Annotation methodAuthzSpec = resourceInfo.getResourceMethod().getAnnotation(annotationClass);
    if (classAuthzSpec != null) authzSpecs.add(classAuthzSpec);
    if (methodAuthzSpec != null) authzSpecs.add(methodAuthzSpec);
  }
  if (!authzSpecs.isEmpty()) {
    context.register(new AnnotationAuthorizationFilter(authzSpecs), Priorities.AUTHORIZATION);
  }
}

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

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
  final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
  final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
  final Class<?>[] parameterTypes = am.getParameterTypes();
        if (type == Optional.class) {
          final ContainerRequestFilter filter = authFilterMap.get(paramType);
          context.register(new WebApplicationExceptionCatchingFilter(filter));
          return;
        } else {
          context.register(authFilterMap.get(type));
          return;

相关文章

微信公众号

最新文章

更多