cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1148077 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml
Date Mon, 18 Jul 2011 22:30:52 GMT
Author: sergeyb
Date: Mon Jul 18 22:30:51 2011
New Revision: 1148077

URL: http://svn.apache.org/viewvc?rev=1148077&view=rev
Log:
[CXF-3662] Better support for multiple response elements

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1148077&r1=1148076&r2=1148077&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Mon Jul 18 22:30:51 2011
@@ -576,9 +576,29 @@ public class SourceGenerator {
     private boolean writeResponseType(List<Element> responseEls, StringBuilder sbCode,
                                    Set<String> imports, Set<String> typeClassNames,

                                    GrammarInfo gInfo) {
-        List<Element> repElements = responseEls.size() == 1 
-            ? DOMUtils.getChildrenWithName(responseEls.get(0), WadlGenerator.WADL_NS, "representation")
-            : CastUtils.cast(Collections.emptyList(), Element.class);
+        List<Element> repElements = null;
+        if (responseEls.size() >= 1) {
+            Element okResponse = null;
+            if (responseEls.size() > 1) {
+                for (int i = 0; i < responseEls.size(); i++) {
+                    String statusValue = responseEls.get(0).getAttribute("status");
+                    try {
+                        int status = statusValue.isEmpty() ? 200 : Integer.valueOf(statusValue);
+                        if (status == 200) {
+                            okResponse = responseEls.get(i);
+                            break;
+                        }
+                    } catch (NumberFormatException ex) {
+                        // ignore
+                    }
+                }
+            } else {
+                okResponse = responseEls.get(0);
+            }
+            repElements = DOMUtils.getChildrenWithName(okResponse, WadlGenerator.WADL_NS,
"representation");
+        } else {
+            repElements = CastUtils.cast(Collections.emptyList(), Element.class);
+        }
         if (repElements.size() == 0) {    
             sbCode.append("void ");
             return false;

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml?rev=1148077&r1=1148076&r2=1148077&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml Mon Jul 18 22:30:51
2011
@@ -32,11 +32,14 @@
     </method>
     <resource path="/books">
      <method name="GET">
-      <response>
+      <response status="200">
        <representation mediaType="text/plain">
         <param name="result" style="plain" type="xs:string"/>
        </representation>
       </response>
+      <response status="400">
+        <representation mediaType="application/json"/>
+      </response>
     </method>
    </resource>
     



Mime
View raw message