Esempio n. 1
0
  protected BrowserCache.Entry getEntry(ClientRequest request) throws Exception {
    String uri = request.getUri();

    BrowserCache.Entry entry = null;
    String acceptHeader = request.getHeaders().getFirst(HttpHeaders.ACCEPT);
    if (acceptHeader != null) {
      List<WeightedMediaType> waccepts = new ArrayList<WeightedMediaType>();
      String[] split = acceptHeader.split(",");
      for (String accept : split) {
        waccepts.add(WeightedMediaType.valueOf(accept));
      }
      Collections.sort(waccepts);
      List<MediaType> accepts = new ArrayList<MediaType>();
      for (WeightedMediaType accept : waccepts) {
        accepts.add(new MediaType(accept.getType(), accept.getSubtype(), accept.getParameters()));
      }
      for (MediaType accept : accepts) {
        entry = cache.get(uri, accept);
        if (entry != null) return entry;
      }
    } else {
      return cache.getAny(uri);
    }

    return null;
  }
Esempio n. 2
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);
    }
  }