cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5844] Merging annotations on the output if the annotated and invoked methods are different
Date Fri, 25 Jul 2014 15:10:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 272156399 -> ba167351c


[CXF-5844] Merging annotations on the output if the annotated and invoked methods are different


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ba167351
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ba167351
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ba167351

Branch: refs/heads/master
Commit: ba167351c03a0e72ca4dcd13667b5da55bb8175e
Parents: 2721563
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Jul 25 18:10:15 2014 +0300
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Jul 25 18:10:15 2014 +0300

----------------------------------------------------------------------
 .../jaxrs/interceptor/JAXRSOutInterceptor.java  |  2 +-
 .../cxf/jaxrs/model/OperationResourceInfo.java  | 17 +++++++
 .../systest/jaxrs/BookStoreWithInterface.java   |  3 ++
 .../jaxrs/CustomJaxbElementProvider.java        | 48 ++++++++++++++++++++
 .../resources/jaxrs_proxy/WEB-INF/beans.xml     |  7 ++-
 5 files changed, 75 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ba167351/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
index d0b4baa..13f0647 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
@@ -148,7 +148,7 @@ public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor
{
             ? ori.getAnnotatedMethod() : ori.getMethodToInvoke();
         
         Annotation[] annotations = null;
-        Annotation[] staticAnns = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
+        Annotation[] staticAnns = ori != null ? ori.getOutAnnotations() : new Annotation[]{};
         Annotation[] responseAnns = response.getEntityAnnotations();
         if (responseAnns != null) {
             annotations = new Annotation[staticAnns.length + responseAnns.length];

http://git-wip-us.apache.org/repos/asf/cxf/blob/ba167351/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
----------------------------------------------------------------------
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 d6a5686..c9c9ac1 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
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -235,4 +236,20 @@ public class OperationResourceInfo {
             defaultParamValue = dv.value();
         }
     }
+    public Annotation[] getOutAnnotations() {
+        Annotation[] invokedAnns = methodToInvoke.getAnnotations();
+        if (methodToInvoke != annotatedMethod && annotatedMethod != null) {
+            Annotation[] superAnns = annotatedMethod.getAnnotations();
+            if (invokedAnns.length > 0) {
+                Annotation[] merged = new Annotation[superAnns.length + invokedAnns.length];
+                System.arraycopy(superAnns, 0, merged, 0, superAnns.length);
+                System.arraycopy(invokedAnns, 0, merged, superAnns.length, invokedAnns.length);
+                return merged;
+            } else {
+                return superAnns;
+            }
+        } else {
+            return invokedAnns;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ba167351/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
index eb7d001..741f1c6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
@@ -38,6 +38,8 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import org.apache.cxf.annotations.SchemaValidation;
+
 
 
 
@@ -59,6 +61,7 @@ public class BookStoreWithInterface extends BookStoreStorage implements
BookInte
         return doGetBook(id);
     }
     
+    @SchemaValidation
     public Book getThatBook(Long id) throws BookNotFoundFault {
         checkPostConstruct();
         return doGetBook(id);

http://git-wip-us.apache.org/repos/asf/cxf/blob/ba167351/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
new file mode 100644
index 0000000..76af000
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.annotations.SchemaValidation;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+
+public class CustomJaxbElementProvider extends JAXBElementProvider<Book> {
+    @Context 
+    private UriInfo ui;
+    @Override
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns,
MediaType mt) {
+        if (ui.getRequestUri().toString().endsWith("/test/5/bookstorestorage/thosebooks/123"))
{
+            for (Annotation ann : anns) {
+                if (ann.annotationType() == SchemaValidation.class) {
+                    return super.isWriteable(type, genericType, anns, mt);
+                }
+            }
+            throw new RuntimeException();
+        } else {
+            return super.isWriteable(type, genericType, anns, mt);
+        }
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/ba167351/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
index 12b7093..88c583e 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
@@ -59,7 +59,12 @@
             <ref bean="sfactory2"/>
         </jaxrs:serviceFactories>
     </jaxrs:server>
-    <jaxrs:server id="bookservice5" address="/5" beanNames="bookstorePrototype bookstoreInterfacePrototype"/>
+    <jaxrs:server id="bookservice5" address="/5" 
+        beanNames="bookstorePrototype bookstoreInterfacePrototype">
+    	<jaxrs:providers>
+            <bean class="org.apache.cxf.systest.jaxrs.CustomJaxbElementProvider"/>
+         </jaxrs:providers>
+    </jaxrs:server>
     <jaxrs:server id="bookservice6" address="/6">
         <jaxrs:serviceFactories>
             <ref bean="sfactory5"/>


Mime
View raw message