cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6238] Adding a new ResponseStatus annotation
Date Wed, 04 Feb 2015 17:28:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ad8e4ddff -> 6bf377f6a


[CXF-6238] Adding a new ResponseStatus annotation


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

Branch: refs/heads/master
Commit: 6bf377f6afae1172cb5693b32cf4c46bdecde705
Parents: ad8e4dd
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Feb 4 17:28:37 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Feb 4 17:28:37 2015 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/ext/ResponseStatus.java    | 31 ++++++++++++++++++++
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 20 +++++++++++--
 .../apache/cxf/jaxrs/model/wadl/BookStore.java  |  3 +-
 .../cxf/jaxrs/model/wadl/WadlGeneratorTest.java |  2 ++
 4 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6bf377f6/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResponseStatus.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResponseStatus.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResponseStatus.java
new file mode 100644
index 0000000..19dd4cc
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResponseStatus.java
@@ -0,0 +1,31 @@
+/**
+ * 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.jaxrs.ext;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD })
+public @interface ResponseStatus {
+    int[] value();
+}
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/6bf377f6/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index dd86d37..fd0946d 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -101,6 +101,7 @@ import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.Oneway;
+import org.apache.cxf.jaxrs.ext.ResponseStatus;
 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.xml.XMLName;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
@@ -578,9 +579,12 @@ public class WadlGenerator implements ContainerRequestFilter {
         startMethodResponseTag(sb, ori);
         Class<?> returnType = getMethod(ori).getReturnType();
         boolean isVoid = void.class == returnType;
-        if (isVoid) {
+        ResponseStatus responseStatus = getMethod(ori).getAnnotation(ResponseStatus.class);
+        if (responseStatus != null) {
+            setResponseStatus(sb, responseStatus.value());
+        } else if (isVoid) {
             boolean oneway = getMethod(ori).getAnnotation(Oneway.class) != null;
-            sb.append(" status=\"" + (oneway ? 202 : 204) + "\"");
+            setResponseStatus(sb, oneway ? 202 : 204);
         }
         sb.append(">");
         handleDocs(anns, sb, DocTarget.RESPONSE, false, isJson);
@@ -598,6 +602,18 @@ public class WadlGenerator implements ContainerRequestFilter {
         return resourceTagOpened;
     }
 
+    private void setResponseStatus(StringBuilder sb, int... statuses) {
+        sb.append(" status=\"");
+        for (int i = 0; i < statuses.length; i++) {
+            if (i > 0) {
+                sb.append(" ");
+            }
+            sb.append(statuses[i]);
+        }
+        sb.append("\"");
+        
+    }
+
     protected boolean compareOperations(OperationResourceInfo ori1, OperationResourceInfo
ori2) {
         if (ori1 == null || ori2 == null
             || !ori1.getURITemplate().getValue().equals(ori2.getURITemplate().getValue())

http://git-wip-us.apache.org/repos/asf/cxf/blob/6bf377f6/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
index 23304b3..ceb5969 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
@@ -40,6 +40,7 @@ import javax.ws.rs.core.Response;
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.cxf.aegis.type.java5.IgnoreProperty;
+import org.apache.cxf.jaxrs.ext.ResponseStatus;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.ext.xml.ElementClass;
 import org.apache.cxf.jaxrs.ext.xml.XMLName;
@@ -108,7 +109,7 @@ public class BookStore implements BookDescription {
         @Description(value = "Response", target = DocTarget.RESPONSE),
         @Description(value = "Resource books/{bookid}", target = DocTarget.RESOURCE)
     })
-    
+    @ResponseStatus({201, 200 })
     //CHECKSTYLE:OFF
     @POST
     @Path("books/{bookid}")

http://git-wip-us.apache.org/repos/asf/cxf/blob/6bf377f6/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
index 09dd51b..82c766f 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
@@ -534,6 +534,8 @@ public class WadlGeneratorTest extends Assert {
         verifyXmlJsonRepresentations(requestEls.get(0), book2El, "InputBook");
         List<Element> responseEls = getElements(methodEls.get(0), "response", 1);
         checkDocs(responseEls.get(0), "", "Response", "");
+        String status = responseEls.get(0).getAttribute("status");
+        assertTrue("201 200".equals(status) || "200 201".equals(status));
         verifyXmlJsonRepresentations(responseEls.get(0), bookEl, "Requested Book");
         
         // PUT


Mime
View raw message