cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1137793 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/model/wadl/
Date Mon, 20 Jun 2011 21:39:32 GMT
Author: sergeyb
Date: Mon Jun 20 21:39:31 2011
New Revision: 1137793

URL: http://svn.apache.org/viewvc?rev=1137793&view=rev
Log:
[CXF-3591] Better linking to schema elements from JAX-RS Response

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1137793&r1=1137792&r2=1137793&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Mon Jun 20 21:39:31 2011
@@ -586,7 +586,7 @@ public class WadlGenerator implements Re
                 doWriteParam(sb, p, type, type, p.getName() == null ? "request" : p.getName(),
anns);
                 sb.append("</representation>");
             } else  { 
-                type = getActualJaxbType(type, opMethod, inbound);
+                type = ResourceUtils.getActualJaxbType(type, opMethod, inbound);
                 if (qnameResolver != null && mt.getSubtype().contains("xml") &&
jaxbTypes.contains(type)) {
                     generateQName(sb, qnameResolver, clsMap, type,
                                   getBodyAnnotations(ori, inbound));
@@ -629,18 +629,6 @@ public class WadlGenerator implements Re
         }
     }
 
-    protected Class<?> getActualJaxbType(Class<?> type, Method resourceMethod,
boolean inbound) {
-        ElementClass element = resourceMethod.getAnnotation(ElementClass.class);
-        if  (element != null) {
-            Class<?> cls = inbound ? element.request() : element.response();
-            if (cls != Object.class) {
-                return cls;
-            }
-        }
-        return type;
-        
-    }
-
     protected List<OperationResourceInfo> sortOperationsByPath(Set<OperationResourceInfo>
ops) {
         List<OperationResourceInfo> opsWithSamePath = new LinkedList<OperationResourceInfo>(ops);
         Collections.sort(opsWithSamePath, new Comparator<OperationResourceInfo>() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1137793&r1=1137792&r2=1137793&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Mon Jun 20 21:39:31 2011
@@ -55,6 +55,7 @@ import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -83,6 +84,7 @@ import org.apache.cxf.jaxrs.model.Parame
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.model.UserOperation;
 import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.model.wadl.ElementClass;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.resource.ResourceManager;
@@ -456,24 +458,38 @@ public final class ResourceUtils {
         return types;
     }
 
+    public static Class<?> getActualJaxbType(Class<?> type, Method resourceMethod,
boolean inbound) {
+        ElementClass element = resourceMethod.getAnnotation(ElementClass.class);
+        if  (element != null) {
+            Class<?> cls = inbound ? element.request() : element.response();
+            if (cls != Object.class) {
+                return cls;
+            }
+        }
+        return type;
+    }
+    
     private static void getAllTypesForResource(ClassResourceInfo resource, Map<Class<?>,
Type> types,
                                                boolean jaxbOnly) {
         for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos())
{
             Class<?> cls = ori.getMethodToInvoke().getReturnType();
-            Type type = ori.getMethodToInvoke().getGenericReturnType();
+            if (cls == Response.class) {
+                cls = getActualJaxbType(cls, ori.getMethodToInvoke(), false);
+            }
             if (jaxbOnly) {
                 checkJaxbType(cls, types);
             } else {
+                Type type = ori.getMethodToInvoke().getGenericReturnType();
                 types.put(cls, type);
             }
             for (Parameter pm : ori.getParameters()) {
                 if (pm.getType() == ParameterType.REQUEST_BODY) {
                     Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
-                    Type type2 = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
                     if (jaxbOnly) {
                         checkJaxbType(inType, types);
                     } else {
-                        types.put(inType, type2);
+                        Type type = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
+                        types.put(inType, type);
                     }
                 }
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java?rev=1137793&r1=1137792&r2=1137793&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
Mon Jun 20 21:39:31 2011
@@ -20,13 +20,19 @@ package org.apache.cxf.jaxrs.model.wadl;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.model.wadl.jaxb.Book;
 
 @Path("/")
 public class BookStoreWithSingleSlash {
 
     @GET
     @Path("book")
-    public String getBookName() {
-        return "book";
+    @ElementClass(response = Book.class)
+    @Produces("application/xml")
+    public Response getBookName() {
+        return null;
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1137793&r1=1137792&r2=1137793&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Mon Jun 20 21:39:31 2011
@@ -227,6 +227,7 @@ public class WadlGeneratorTest extends A
                                                                  WadlGenerator.WADL_NS, "resource");
         assertEquals(1, resourceEls.size());        
         assertEquals("book", resourceEls.get(0).getAttribute("path"));
+        checkGrammars(doc.getDocumentElement(), "thebook", null, "thechapter");
     }
     
     private void checkResponse(Response r) throws Exception {
@@ -274,17 +275,24 @@ public class WadlGeneratorTest extends A
         assertEquals("http://superbooks", schemasEls.get(0).getAttribute("targetNamespace"));
         List<Element> elementEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

                             XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
-        assertEquals(3, elementEls.size());
+        
+        int size = book2El == null ? 2 : 3;
+        
+        assertEquals(size, elementEls.size());
         assertTrue(checkElement(elementEls, bookEl, "tns:book"));
-        assertTrue(checkElement(elementEls, book2El, "tns:book2"));
+        if (book2El != null) {
+            assertTrue(checkElement(elementEls, book2El, "tns:book2"));
+        }
         assertTrue(checkElement(elementEls, chapterEl, "tns:chapter"));
         
         List<Element> complexTypesEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

                                         XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType");
-        assertEquals(3, complexTypesEls.size());
+        assertEquals(size, complexTypesEls.size());
         
         assertTrue(checkComplexType(complexTypesEls, "book"));
-        assertTrue(checkComplexType(complexTypesEls, "book2"));
+        if (book2El != null) {
+            assertTrue(checkComplexType(complexTypesEls, "book2"));
+        }
         assertTrue(checkComplexType(complexTypesEls, "chapter"));
     }
     



Mime
View raw message