All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.plugins.interceptors.encoding.ClientContentEncodingAnnotationFeature Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package org.jboss.resteasy.plugins.interceptors.encoding;

import org.jboss.resteasy.annotations.ContentEncoding;

import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.Configurable;
import javax.ws.rs.core.FeatureContext;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
@ConstrainedTo(RuntimeType.SERVER)
public class ClientContentEncodingAnnotationFeature implements DynamicFeature
{
   @Override
   public void configure(ResourceInfo resourceInfo, FeatureContext configurable)
   {
      final Class declaring = resourceInfo.getResourceClass();
      final Method method = resourceInfo.getResourceMethod();

      if (declaring == null || method == null) return;

      for (Annotation[] annotations : method.getParameterAnnotations())
      {
         String encoding = getEncoding(annotations);
         if (encoding != null)
         {
            configurable.register(new ClientContentEncodingAnnotationFilter(encoding));
            return;
         }
      }
   }

   protected String getEncoding(Annotation[] annotations)
   {
      for (Annotation annotation : annotations)
      {
         if (annotation.annotationType().isAnnotationPresent(ContentEncoding.class))
         {
            return annotation.annotationType().getAnnotation(ContentEncoding.class).value();
         }
      }
      return null;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy