This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 9900e83b59 CXF-8797: NameBinding ignored when implementing interface 
(#1045)
9900e83b59 is described below

commit 9900e83b5970c32d40b797584d5cf6739952a97f
Author: Andriy Redko <[email protected]>
AuthorDate: Tue Dec 27 17:16:20 2022 -0500

    CXF-8797: NameBinding ignored when implementing interface (#1045)
---
 .../cxf/jaxrs/model/OperationResourceInfo.java     |  4 +-
 .../cxf/jaxrs/model/OperationResourceInfoTest.java | 65 +++++++++++++++++++++-
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
index 84a5d3525f..f59144e927 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
@@ -80,9 +80,11 @@ public class OperationResourceInfo {
     public OperationResourceInfo(Method mInvoke, Method mAnnotated, 
ClassResourceInfo cri) {
         methodToInvoke = mInvoke;
         annotatedMethod = mAnnotated;
+        // Combine the name bindings from annotated method and method to invoke
+        
nameBindings.addAll(AnnotationUtils.getNameBindings(mInvoke.getAnnotations()));
         if (mAnnotated != null) {
             parameters = ResourceUtils.getParameters(mAnnotated);
-            nameBindings = 
AnnotationUtils.getNameBindings(mAnnotated.getAnnotations());
+            
nameBindings.addAll(AnnotationUtils.getNameBindings(mAnnotated.getAnnotations()));
         }
         classResourceInfo = cri;
         checkMediaTypes(null, null);
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
index 96b0d34068..bf6daa896b 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
@@ -19,13 +19,21 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.NameBinding;
 import jakarta.ws.rs.Produces;
 import jakarta.ws.rs.core.MediaType;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -51,6 +59,30 @@ public class OperationResourceInfoTest {
         };
 
     }
+    
+    @Produces("text/xml")
+    @Consumes("application/xml")
+    interface TestInteface {
+        @Produces("text/plain")
+        void doIt();
+
+        @CustomNameBinding
+        @Consumes("application/atom+xml")
+        void doThat();
+    }
+
+    static class TestClass2 implements TestInteface {
+        @CustomNameBinding
+        @Override
+        public void doIt() {
+        }
+
+        @Override
+        public void doThat() {
+        }
+
+    }
+
 
     @Test
     public void testConsumeTypes() throws Exception {
@@ -136,6 +168,31 @@ public class OperationResourceInfoTest {
         assertEquals(0, result);
     }
 
+    @Test
+    public void testNameBindingsClass() throws NoSuchMethodException, 
SecurityException {
+        final Method method = TestClass2.class.getMethod("doIt", new 
Class[]{});
+
+        OperationResourceInfo ori = new OperationResourceInfo(
+                method,
+                AnnotationUtils.getAnnotatedMethod(TestClass2.class,  method),
+                new ClassResourceInfo(TestClass2.class));
+
+        final Set<String> names = ori.getNameBindings();
+        assertEquals(Collections.singleton(CustomNameBinding.class.getName()), 
names);
+    }
+
+    @Test
+    public void testNameBindingsInterface() throws NoSuchMethodException, 
SecurityException {
+        final Method method = TestClass2.class.getMethod("doThat", new 
Class[]{});
+
+        OperationResourceInfo ori = new OperationResourceInfo(
+                method,
+                AnnotationUtils.getAnnotatedMethod(TestClass2.class, method),
+                new ClassResourceInfo(TestClass2.class));
+
+        Set<String> names = ori.getNameBindings();
+        assertEquals(Collections.singleton(CustomNameBinding.class.getName()), 
names);
+    }
 
     private static Message createMessage() {
         Message m = new MessageImpl();
@@ -148,4 +205,10 @@ public class OperationResourceInfoTest {
         e.put(Endpoint.class, endpoint);
         return m;
     }
-}
\ No newline at end of file
+    
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(value = RetentionPolicy.RUNTIME)
+    @NameBinding
+    public @interface CustomNameBinding {
+    }
+}

Reply via email to