Permalink
Browse files

Merge pull request #219 from mwanji/apply_name_binding

Interceptors marked with an @NameBinding should only be applied to Resource methods with the same @NameBinding
  • Loading branch information...
2 parents 1acef75 + b3d5ce1 commit bac723d247ab7ada06cda540284e0548f914d8bb @patriot1burke patriot1burke committed Nov 8, 2012
@@ -6,6 +6,7 @@
import javax.ws.rs.BindingPriority;
import javax.ws.rs.NameBinding;
import javax.ws.rs.container.PreMatching;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
@@ -48,10 +49,7 @@ public Match(Object interceptor, int order)
{
if (annotation.annotationType().isAnnotationPresent(NameBinding.class))
{
- if (nameBound == null)
- {
- nameBound.add(annotation.annotationType());
- }
+ nameBound.add(annotation.annotationType());
}
}
return nameBound;
@@ -0,0 +1,77 @@
+package org.jboss.resteasy.test.core.interception;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry;
+import org.junit.Test;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NameBinding;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.ext.Provider;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JaxrsInterceptorRegistryTest
+{
+
+ @NameBinding
+ @Retention(RUNTIME)
+ public static @interface JaxrsInterceptorRegistryTestNameBinding {
+
+ }
+
+ @JaxrsInterceptorRegistryTestNameBinding
+ @Provider
+ public static class JaxrsInterceptorRegistryTestFilter implements ContainerRequestFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException
+ {
+
+ }
+ }
+
+ @Path("/")
+ public static class JaxrsInterceptorRegistryTestResource {
+
+ @JaxrsInterceptorRegistryTestNameBinding
+ @GET
+ public void get() {
+
+ }
+ }
+
+ @Test
+ public void shouldUseNameBindingAnnotation() throws Exception {
+ final List<Class<? extends Annotation>> bound = new ArrayList<Class<? extends Annotation>>();
+ JaxrsInterceptorRegistry<JaxrsInterceptorRegistryTestFilter> jaxrsInterceptorRegistry = new JaxrsInterceptorRegistry<JaxrsInterceptorRegistryTestFilter>(null, JaxrsInterceptorRegistryTestFilter.class);
+ jaxrsInterceptorRegistry.new AbstractInterceptorFactory(JaxrsInterceptorRegistryTestFilter.class)
+ {
+ {
+ setPrecedence(JaxrsInterceptorRegistryTestFilter.class);
+ bound.addAll(nameBound);
+ }
+
+ @Override
+ protected void initialize()
+ {
+
+ }
+
+ @Override
+ protected Object getInterceptor()
+ {
+ return null;
+ }
+ };
+
+ assertEquals(JaxrsInterceptorRegistryTestNameBinding.class, bound.get(0));
+ }
+}

0 comments on commit bac723d

Please sign in to comment.