[ 
https://issues.apache.org/jira/browse/CXF-7743?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16488786#comment-16488786
 ] 

ASF GitHub Bot commented on CXF-7743:
-------------------------------------

coheigea commented on a change in pull request #419: [CXF-7743] wadl2java: 
generate throws declaration for fault response
URL: https://github.com/apache/cxf/pull/419#discussion_r190542316
 
 

 ##########
 File path: 
tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
 ##########
 @@ -1203,20 +1211,26 @@ private void writeJaxrResponse(StringBuilder sbCode, 
Set<String> imports) {
         sbCode.append(Response.class.getSimpleName()).append(" ");
     }
 
-    private Element getOKResponse(List<Element> responseEls) {
-        for (int i = 0; i < responseEls.size(); i++) {
-            String statusValue = responseEls.get(i).getAttribute("status");
-            if (statusValue.length() == 0) {
-                return responseEls.get(i);
-            }
-            String[] statuses = statusValue.split("\\s");
-            for (String status : statuses) {
-                if (HTTP_OK_STATUSES.contains(status)) {
-                    return responseEls.get(i);
+    private static Element getOKResponse(List<Element> responseEls) {
+        final List<Element> result = getResponses(responseEls, 
HTTP_OK_STATUSES);
+        return !result.isEmpty() ? result.get(0) : null;
+    }
+
+    private static List<Element> getErrorResponses(List<Element> responseEls) {
+        return getResponses(responseEls, HTTP_ERROR_STATUSES);
+    }
+
+    private static List<Element> getResponses(List<Element> responseEls, 
Predicate<Integer> checker) {
+        final List<Element> result = new ArrayList<>();
+        for (Element responseEl : responseEls) {
+            for (String statusValue : 
responseEl.getAttribute("status").split("\\s")) {
 
 Review comment:
   "status" is optional right? In which case it might be better to wrap this in 
an if statement : if (responseEl.hasAttribute("status")) {}

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> wadl2java: generate throws declaration for fault response
> ---------------------------------------------------------
>
>                 Key: CXF-7743
>                 URL: https://issues.apache.org/jira/browse/CXF-7743
>             Project: CXF
>          Issue Type: New Feature
>          Components: Tooling
>    Affects Versions: 3.2.4
>            Reporter: Alexey Markevich
>            Assignee: Alexey Markevich
>            Priority: Major
>
> According to [1] the response status attribute can contains status code. In 
> case 4xx-5xx representation/param/@type can be set to java exception class 
> name.
> Previously the impl can use unchecked exceptions only with raw 
> ResponseExceptionMapper<Exception> on client side.
> 1. https://www.w3.org/Submission/wadl/#x3-200002.10



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to