This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 89fb960  CAMEL-17035: camel-core - Rest DSL - Allow to set response 
message quickly
89fb960 is described below

commit 89fb9609e907dc3f1b2e6375d01d3da4517338b9
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Oct 2 07:50:05 2021 +0200

    CAMEL-17035: camel-core - Rest DSL - Allow to set response message quickly
---
 .../apache/camel/model/rest/RestDefinition.java    | 23 ++++++++++++++++++++++
 .../rest/FromRestExplicitComponentTest.java        |  3 +--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 380dbac..777c267 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -447,6 +447,29 @@ public class RestDefinition extends 
OptionalIdentifiedDefinition<RestDefinition>
         return this;
     }
 
+    public RestDefinition responseMessage(int code, String message) {
+        if (getVerbs().isEmpty()) {
+            throw new IllegalArgumentException("Must add verb first, such as 
get/post/delete");
+        }
+        VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+        RestOperationResponseMsgDefinition msg = responseMessage(verb);
+        msg.setCode(String.valueOf(code));
+        msg.setMessage(message);
+        return this;
+    }
+
+    public RestDefinition responseMessage(String code, String message) {
+        if (getVerbs().isEmpty()) {
+            throw new IllegalArgumentException("Must add verb first, such as 
get/post/delete");
+        }
+        VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+        RestOperationResponseMsgDefinition response = responseMessage(verb);
+        response.setCode(code);
+        response.setMessage(message);
+        verb.getResponseMsgs().add(response);
+        return this;
+    }
+
     /**
      * To configure security definitions.
      */
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
index 0d08b6d..a19718a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -40,8 +40,7 @@ public class FromRestExplicitComponentTest extends 
FromRestGetTest {
                         
.defaultValue("b").collectionFormat(CollectionFormat.multi)
                         
.name("header_letter").required(false).endParam().responseMessage().code(300).message("test
 msg")
                         .responseModel(Integer.class).header("rate")
-                        .description("Rate 
limit").dataType("integer").endHeader().endResponseMessage().responseMessage()
-                        .code("error").message("does not 
work").endResponseMessage()
+                        .description("Rate 
limit").dataType("integer").endHeader().endResponseMessage().responseMessage("error",
 "does not work")
                         .to("direct:bye").post().to("mock:update");
 
                 from("direct:hello").transform().constant("Hello World");

Reply via email to