Beispiel #1
0
 public void cleanup() {
   parentProviderFactory.getContainerRequestFilterRegistry().getListeners().remove(this);
   parentProviderFactory.getContainerResponseFilterRegistry().getListeners().remove(this);
   parentProviderFactory.getServerWriterInterceptorRegistry().getListeners().remove(this);
   for (ValueInjector param : methodInjector.getParams()) {
     if (param instanceof MessageBodyParameterInjector) {
       parentProviderFactory.getServerReaderInterceptorRegistry().getListeners().remove(param);
     }
   }
 }
 public void registryUpdated(JaxrsInterceptorRegistry registry) {
   if (registry.getIntf().equals(WriterInterceptor.class)) {
     writerInterceptors =
         providerFactory.getServerWriterInterceptorRegistry().postMatch(resourceClass, method);
   } else if (registry.getIntf().equals(ContainerRequestFilter.class)) {
     requestFilters =
         providerFactory.getContainerRequestFilterRegistry().postMatch(resourceClass, method);
   } else if (registry.getIntf().equals(ContainerResponseFilter.class)) {
     responseFilters =
         providerFactory.getContainerResponseFilterRegistry().postMatch(resourceClass, method);
   }
 }
Beispiel #3
0
 public void registryUpdated(JaxrsInterceptorRegistry registry) {
   this.resourceMethodProviderFactory = new ResteasyProviderFactory(parentProviderFactory);
   for (DynamicFeature feature : parentProviderFactory.getServerDynamicFeatures()) {
     feature.configure(resourceInfo, new FeatureContextDelegate(resourceMethodProviderFactory));
   }
   if (registry.getIntf().equals(WriterInterceptor.class)) {
     writerInterceptors =
         resourceMethodProviderFactory
             .getServerWriterInterceptorRegistry()
             .postMatch(resourceClass, method);
   } else if (registry.getIntf().equals(ContainerRequestFilter.class)) {
     requestFilters =
         resourceMethodProviderFactory
             .getContainerRequestFilterRegistry()
             .postMatch(resourceClass, method);
   } else if (registry.getIntf().equals(ContainerResponseFilter.class)) {
     responseFilters =
         resourceMethodProviderFactory
             .getContainerResponseFilterRegistry()
             .postMatch(resourceClass, method);
   }
 }
Beispiel #4
0
  public ResourceMethod(
      Class<?> clazz,
      Method method,
      InjectorFactory injector,
      ResourceFactory resource,
      ResteasyProviderFactory providerFactory,
      Set<String> httpMethods) {
    this.injector = injector;
    this.resource = resource;
    this.parentProviderFactory = providerFactory;
    this.httpMethods = httpMethods;
    this.resourceClass = clazz;
    this.method = method;

    resourceInfo =
        new ResourceInfo() {
          @Override
          public Method getResourceMethod() {
            return ResourceMethod.this.method;
          }

          @Override
          public Class<?> getResourceClass() {
            return ResourceMethod.this.resourceClass;
          }
        };

    this.resourceMethodProviderFactory = new ResteasyProviderFactory(providerFactory);
    for (DynamicFeature feature : providerFactory.getServerDynamicFeatures()) {
      feature.configure(resourceInfo, new FeatureContextDelegate(resourceMethodProviderFactory));
    }

    this.methodInjector =
        injector.createMethodInjector(clazz, method, resourceMethodProviderFactory);

    Produces p = method.getAnnotation(Produces.class);
    if (p == null) p = clazz.getAnnotation(Produces.class);
    if (p == null) p = method.getDeclaringClass().getAnnotation(Produces.class);
    Consumes c = methodConsumes = method.getAnnotation(Consumes.class);
    if (c == null) c = clazz.getAnnotation(Consumes.class);
    if (c == null) c = method.getDeclaringClass().getAnnotation(Consumes.class);

    if (p != null) {
      produces = new MediaType[p.value().length];
      int i = 0;
      for (String mediaType : p.value()) {
        produces[i++] = MediaType.valueOf(mediaType);
        preferredProduces.add(WeightedMediaType.valueOf(mediaType));
      }
    }
    if (c != null) {
      consumes = new MediaType[c.value().length];
      int i = 0;
      for (String mediaType : c.value()) {
        consumes[i++] = MediaType.valueOf(mediaType);
        preferredConsumes.add(WeightedMediaType.valueOf(mediaType));
      }
    }
    Collections.sort(preferredProduces);
    Collections.sort(preferredConsumes);

    requestFilters =
        resourceMethodProviderFactory
            .getContainerRequestFilterRegistry()
            .postMatch(resourceClass, method);
    responseFilters =
        resourceMethodProviderFactory
            .getContainerResponseFilterRegistry()
            .postMatch(resourceClass, method);
    writerInterceptors =
        resourceMethodProviderFactory
            .getServerWriterInterceptorRegistry()
            .postMatch(resourceClass, method);

    // we register with parent to lisen for redeploy evens
    providerFactory.getContainerRequestFilterRegistry().getListeners().add(this);
    providerFactory.getContainerResponseFilterRegistry().getListeners().add(this);
    providerFactory.getServerWriterInterceptorRegistry().getListeners().add(this);
    /*
       We get the genericReturnType for the case of:

       interface Foo<T> {
          @GET
          List<T> get();
       }

       public class FooImpl implements Foo<Customer> {
           public List<Customer> get() {...}
       }
    */
    genericReturnType = Types.getGenericReturnTypeOfGenericInterfaceMethod(clazz, method);
    ContextResolver<GeneralValidator> resolver =
        providerFactory.getContextResolver(GeneralValidator.class, MediaType.WILDCARD_TYPE);
    if (resolver != null) {
      validator =
          providerFactory
              .getContextResolver(GeneralValidator.class, MediaType.WILDCARD_TYPE)
              .getContext(null);
    }
  }
  public ResourceMethodInvoker(
      ResourceMethod method,
      InjectorFactory injector,
      ResourceFactory resource,
      ResteasyProviderFactory providerFactory) {
    this.injector = injector;
    this.resource = resource;
    this.parentProviderFactory = providerFactory;
    this.method = method;

    resourceInfo =
        new ResourceInfo() {
          @Override
          public Method getResourceMethod() {
            return ResourceMethodInvoker.this.method.getAnnotatedMethod();
          }

          @Override
          public Class<?> getResourceClass() {
            return ResourceMethodInvoker.this.method.getResourceClass().getClazz();
          }
        };

    this.resourceMethodProviderFactory = new ResteasyProviderFactory(providerFactory);
    for (DynamicFeature feature : providerFactory.getServerDynamicFeatures()) {
      feature.configure(resourceInfo, new FeatureContextDelegate(resourceMethodProviderFactory));
    }

    this.methodInjector = injector.createMethodInjector(method, resourceMethodProviderFactory);

    // hack for when message contentType == null
    // and @Consumes is on the class
    expectsBody = this.methodInjector.expectsBody();

    requestFilters =
        resourceMethodProviderFactory
            .getContainerRequestFilterRegistry()
            .postMatch(method.getResourceClass().getClazz(), method.getAnnotatedMethod());
    responseFilters =
        resourceMethodProviderFactory
            .getContainerResponseFilterRegistry()
            .postMatch(method.getResourceClass().getClazz(), method.getAnnotatedMethod());
    writerInterceptors =
        resourceMethodProviderFactory
            .getServerWriterInterceptorRegistry()
            .postMatch(method.getResourceClass().getClazz(), method.getAnnotatedMethod());

    // we register with parent to lisen for redeploy evens
    providerFactory.getContainerRequestFilterRegistry().getListeners().add(this);
    providerFactory.getContainerResponseFilterRegistry().getListeners().add(this);
    providerFactory.getServerWriterInterceptorRegistry().getListeners().add(this);
    ContextResolver<GeneralValidator> resolver =
        providerFactory.getContextResolver(GeneralValidator.class, MediaType.WILDCARD_TYPE);
    if (resolver != null) {
      validator =
          providerFactory
              .getContextResolver(GeneralValidator.class, MediaType.WILDCARD_TYPE)
              .getContext(null);
    }
    if (validator != null) {
      isValidatable = validator.isValidatable(getMethod().getDeclaringClass());
      methodIsValidatable = validator.isMethodValidatable(getMethod());
    }
  }