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
commit 2f14ff941faf27e51652e999e34dc486555f2c2c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Nov 22 13:03:07 2022 +0100 CAMEL-18628: REST DSL: Add option to disable REST endpoints. --- .../org/apache/camel/catalog/models/delete.json | 1 + .../org/apache/camel/catalog/models/get.json | 1 + .../org/apache/camel/catalog/models/head.json | 1 + .../org/apache/camel/catalog/models/patch.json | 1 + .../org/apache/camel/catalog/models/post.json | 1 + .../org/apache/camel/catalog/models/put.json | 1 + .../org/apache/camel/catalog/models/rest.json | 1 + .../apache/camel/catalog/schemas/camel-spring.xsd | 24 +++++++ .../org/apache/camel/model/rest/delete.json | 1 + .../resources/org/apache/camel/model/rest/get.json | 1 + .../org/apache/camel/model/rest/head.json | 1 + .../org/apache/camel/model/rest/patch.json | 1 + .../org/apache/camel/model/rest/post.json | 1 + .../resources/org/apache/camel/model/rest/put.json | 1 + .../org/apache/camel/model/rest/rest.json | 1 + .../apache/camel/model/rest/RestDefinition.java | 84 +++++++++++++++++++--- .../apache/camel/model/rest/VerbDefinition.java | 17 ++++- .../component/rest/FromRestDisabledAllTest.java | 60 ++++++++++++++++ .../camel/component/rest/FromRestDisabledTest.java | 62 ++++++++++++++++ .../java/org/apache/camel/xml/in/ModelParser.java | 2 + docs/user-manual/modules/ROOT/pages/rest-dsl.adoc | 36 ++++++++++ .../dsl/yaml/deserializers/ModelDeserializers.java | 42 +++++++++++ .../generated/resources/schema/camel-yaml-dsl.json | 21 ++++++ .../generated/resources/schema/camelYamlDsl.json | 21 ++++++ 24 files changed, 372 insertions(+), 11 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/delete.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/delete.json index 66f60b9b4e2..b5d8e1b317b 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/delete.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/delete.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/get.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/get.json index 366df91903a..362baa2836f 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/get.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/get.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/head.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/head.json index af317c58e3d..dd1cea15080 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/head.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/head.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/patch.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/patch.json index c013951b98f..ad2510f50cc 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/patch.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/patch.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/post.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/post.json index 8dbaaa36c1e..bcb41b6a890 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/post.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/post.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/put.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/put.json index 728d0d886f6..c3704027850 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/put.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/put.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/rest.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/rest.json index 7f5f3afd5ef..de761541a56 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/rest.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/rest.json @@ -15,6 +15,7 @@ "path": { "kind": "attribute", "displayName": "Path", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Path of the rest service, such as \/foo" }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is auto" }, "skipBindingOnErrorCode": { "kind": "attribute", "displayName": "Skip Binding On Error Code", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json \/ xml etc, as success messages otherwise will do. This op [...] "clientRequestValidation": { "kind": "attribute", "displayName": "Client Request Validation", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check: 1) Content-Type header matches what the Rest DSL consumes; returns HTTP Status 415 if validation error. 2) Accept header matches what the Rest D [...] diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd index 59f46d616db..d50e518ee0d 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd @@ -21282,6 +21282,18 @@ be configured on a parent level. </xs:annotation> </xs:attribute> + <xs:attribute name="disabled" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> + <![CDATA[ +Whether to disable this REST service from the route during build time. Once an +REST service has been disabled then it cannot be enabled later at runtime. +Default value: false + ]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="type" type="xs:string"> <xs:annotation> <xs:documentation xml:lang="en"> @@ -22444,6 +22456,18 @@ be configured on a parent level. </xs:annotation> </xs:attribute> + <xs:attribute name="disabled" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> + <![CDATA[ +Whether to disable this REST service from the route during build time. Once an +REST service has been disabled then it cannot be enabled later at runtime. +Default value: false + ]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="bindingMode" type="xs:string"> <xs:annotation> <xs:documentation xml:lang="en"> diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json index 66f60b9b4e2..b5d8e1b317b 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json index 366df91903a..362baa2836f 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json index af317c58e3d..dd1cea15080 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json index c013951b98f..ad2510f50cc 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json index 8dbaaa36c1e..bcb41b6a890 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json index 728d0d886f6..c3704027850 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json @@ -16,6 +16,7 @@ "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "type": { "kind": "attribute", "displayName": "Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is off" }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/rest.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/rest.json index 7f5f3afd5ef..de761541a56 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/rest.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/rest.json @@ -15,6 +15,7 @@ "path": { "kind": "attribute", "displayName": "Path", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Path of the rest service, such as \/foo" }, "consumes": { "kind": "attribute", "displayName": "Consumes", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service consumes (accept as input), such as application\/xml or application\/json. This option will override what may be configured on a parent level" }, "produces": { "kind": "attribute", "displayName": "Produces", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the content type what the REST service produces (uses for output), such as application\/xml or application\/json This option will override what may be configured on a parent level" }, + "disabled": { "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime." }, "bindingMode": { "kind": "attribute", "displayName": "Binding Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "off", "auto", "json", "xml", "json_xml" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "off", "description": "Sets the binding mode to use. This option will override what may be configured on a parent level The default value is auto" }, "skipBindingOnErrorCode": { "kind": "attribute", "displayName": "Skip Binding On Error Code", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json \/ xml etc, as success messages otherwise will do. This op [...] "clientRequestValidation": { "kind": "attribute", "displayName": "Client Request Validation", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check: 1) Content-Type header matches what the Rest DSL consumes; returns HTTP Status 415 if validation error. 2) Accept header matches what the Rest D [...] 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 5d55d3a43d9..57c7acad82f 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 @@ -40,6 +40,7 @@ import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.ToDefinition; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.RestConfiguration; +import org.apache.camel.support.CamelContextHelper; import org.apache.camel.util.FileUtil; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; @@ -60,6 +61,9 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> @XmlAttribute private String produces; @XmlAttribute + @Metadata(label = "advanced", javaType = "java.lang.Boolean") + protected String disabled; + @XmlAttribute @Metadata(defaultValue = "off", enums = "off,auto,json,xml,json_xml") private String bindingMode; @XmlAttribute @@ -142,6 +146,18 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> this.produces = produces; } + public String getDisabled() { + return disabled; + } + + /** + * Whether to disable this REST service from the route during build time. Once an REST service has been disabled + * then it cannot be enabled later at runtime. + */ + public void setDisabled(String disabled) { + this.disabled = disabled; + } + public String getBindingMode() { return bindingMode; } @@ -256,6 +272,40 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> return this; } + /** + * Disables this REST service from the route during build time. Once an REST service has been disabled then it + * cannot be enabled later at runtime. + */ + public RestDefinition disabled() { + disabled("true"); + return this; + } + + /** + * Whether to disable this REST service from the route during build time. Once an REST service has been disabled + * then it cannot be enabled later at runtime. + */ + public RestDefinition disabled(boolean disabled) { + disabled(disabled ? "true" : "false"); + return this; + } + + /** + * Whether to disable this REST service from the route during build time. Once an REST service has been disabled + * then it cannot be enabled later at runtime. + */ + public RestDefinition disabled(String disabled) { + if (getVerbs().isEmpty()) { + this.disabled = disabled; + } else { + // add on last verb as that is how the Java DSL works + VerbDefinition verb = getVerbs().get(getVerbs().size() - 1); + verb.setDisabled(disabled); + } + + return this; + } + /** * To set the tag to use of this REST service */ @@ -684,23 +734,36 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> public List<RouteDefinition> asRouteDefinition(CamelContext camelContext) { ObjectHelper.notNull(camelContext, "CamelContext"); - // sanity check this rest definition do not have duplicates - validateUniquePaths(); - List<RouteDefinition> answer = new ArrayList<>(); + Boolean disabled = CamelContextHelper.parseBoolean(camelContext, this.disabled); + if (disabled != null && disabled) { + return answer; // all rest services are disabled + } + + // only include enabled verbs + List<VerbDefinition> filter = new ArrayList<>(); + for (VerbDefinition verb : verbs) { + disabled = CamelContextHelper.parseBoolean(camelContext, verb.disabled); + if (disabled == null || !disabled) { + filter.add(verb); + } + } + + // sanity check this rest definition do not have duplicates + validateUniquePaths(filter); + RestConfiguration config = camelContext.getRestConfiguration(); if (config.isInlineRoutes()) { // sanity check this rest definition do not have duplicates linked routes via direct endpoints - validateUniqueDirects(); + validateUniqueDirects(filter); } - - addRouteDefinition(camelContext, answer, config.getComponent(), config.getProducerComponent()); + addRouteDefinition(camelContext, filter, answer, config.getComponent(), config.getProducerComponent()); return answer; } - protected void validateUniquePaths() { + protected void validateUniquePaths(List<VerbDefinition> verbs) { Set<String> paths = new HashSet<>(); for (VerbDefinition verb : verbs) { String path = verb.asVerb(); @@ -713,7 +776,7 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> } } - protected void validateUniqueDirects() { + protected void validateUniqueDirects(List<VerbDefinition> verbs) { Set<String> directs = new HashSet<>(); for (VerbDefinition verb : verbs) { ToDefinition to = verb.getTo(); @@ -794,8 +857,9 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> @SuppressWarnings("rawtypes") private void addRouteDefinition( - CamelContext camelContext, List<RouteDefinition> answer, String component, String producerComponent) { - for (VerbDefinition verb : getVerbs()) { + CamelContext camelContext, List<VerbDefinition> verbs, List<RouteDefinition> answer, + String component, String producerComponent) { + for (VerbDefinition verb : verbs) { // use a route as facade for this REST service RouteDefinition route = new RouteDefinition(); if (verb.getTo() == null) { diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java index d30177c3e9f..b6fcdb5c427 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java @@ -53,7 +53,10 @@ public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDe private String consumes; @XmlAttribute private String produces; - @XmlAttribute() + @XmlAttribute + @Metadata(label = "advanced", javaType = "java.lang.Boolean") + protected String disabled; + @XmlAttribute @Metadata(label = "advanced") private String type; @XmlTransient @@ -191,6 +194,18 @@ public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDe this.produces = produces; } + public String getDisabled() { + return disabled; + } + + /** + * Whether to disable this REST service from the route during build time. Once an REST service has been disabled + * then it cannot be enabled later at runtime. + */ + public void setDisabled(String disabled) { + this.disabled = disabled; + } + public String getBindingMode() { return bindingMode; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledAllTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledAllTest.java new file mode 100644 index 00000000000..95c64b9c16a --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledAllTest.java @@ -0,0 +1,60 @@ +/* + * 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.camel.component.rest; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.Registry; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FromRestDisabledAllTest extends ContextTestSupport { + + @Override + protected Registry createRegistry() throws Exception { + Registry jndi = super.createRegistry(); + jndi.bind("dummy-rest", new DummyRestConsumerFactory()); + return jndi; + } + + @Test + public void testDisabled() throws Exception { + getMockEndpoint("mock:translate").expectedBodiesReceived("Hello World"); + template.sendBody("seda:get-translate", "Hello World"); + assertMockEndpointsSatisfied(); + + // should only be 1 route + Assertions.assertEquals(1, context.getRoutes().size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().host("localhost"); + + rest("/say").disabled(true) + .post("/hi").to("mock:hi") + .get("/bye").to("mock:bye"); + + rest("/translate") + .get().to("mock:translate"); + } + }; + } +} diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledTest.java new file mode 100644 index 00000000000..0e212d60b6b --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestDisabledTest.java @@ -0,0 +1,62 @@ +/* + * 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.camel.component.rest; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.Registry; +import org.apache.camel.support.CamelContextHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FromRestDisabledTest extends ContextTestSupport { + + @Override + protected Registry createRegistry() throws Exception { + Registry jndi = super.createRegistry(); + jndi.bind("dummy-rest", new DummyRestConsumerFactory()); + return jndi; + } + + @Test + public void testDisabled() throws Exception { + getMockEndpoint("mock:bye").expectedBodiesReceived("Hello World"); + template.sendBody("seda:get-say-bye", "Hello World"); + assertMockEndpointsSatisfied(); + + // should only be 2 route as 1 is disabled + Assertions.assertEquals(2, context.getRoutes().size()); + + // should NOT have mock://hi endpoint + Assertions.assertEquals(0, CamelContextHelper.getEndpoints(context, e -> e.getEndpointUri().contains("hi")).size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().host("localhost"); + + rest("/say") + .post("/hi").to("mock:hi").disabled() + .get("/bye").to("mock:bye") + .get("/translate").to("mock:translate"); + } + }; + } +} diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java index 9919c38d885..2f30cff942d 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java @@ -1074,6 +1074,7 @@ public class ModelParser extends BaseParser { case "bindingMode": def.setBindingMode(val); break; case "clientRequestValidation": def.setClientRequestValidation(val); break; case "consumes": def.setConsumes(val); break; + case "disabled": def.setDisabled(val); break; case "enableCORS": def.setEnableCORS(val); break; case "path": def.setPath(val); break; case "produces": def.setProduces(val); break; @@ -2950,6 +2951,7 @@ public class ModelParser extends BaseParser { case "clientRequestValidation": def.setClientRequestValidation(val); break; case "consumes": def.setConsumes(val); break; case "deprecated": def.setDeprecated(val); break; + case "disabled": def.setDisabled(val); break; case "enableCORS": def.setEnableCORS(val); break; case "outType": def.setOutType(val); break; case "path": def.setPath(val); break; diff --git a/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc b/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc index 0161e3ac1fc..1e11846bba1 100644 --- a/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc +++ b/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc @@ -233,6 +233,42 @@ If you use Camel Main / Spring Boot / Quarkus / or Camel JBang you can also enab camel.rest.inline-routes = true ---- +== Disabling REST services + +While developing REST services using Rest DSL, you may want to temporary disabled some REST endpoints, +which you can do using `disabled` as shown in the following. + +[source,java] +---- +rest("/customers/") + .get("/{id}").to("direct:customerDetail") + .get("/{id}/orders").to("direct:customerOrders").disabled("{{ordersEnabled}}") + .post("/neworder").to("direct:customerNewOrder").disabled(); +---- + +And in XML: + +[source,xml] +---- +<rest> + <get path="/customers/{id}"> + <to uri="direct:customerDetail"/> + </get> + <get path="/customers/{id}/orders" disabled="{{ordersEnabled}}"> + <to uri="direct:customerOrders"/> + </get> + <post path="/customers/neworder" disabled="true"> + <to uri="direct:customerNewOrder"/> + </post> +</rest> +---- + +In this example the last two REST endpoints are configured with `disabled`. +You can use xref:manual:ROOT:using-propertyplaceholder.adoc[Property Placeholder] to +let a external configuration determine if the REST endpoint is disabled or not. +In this example the `/customers/{id}/orders` endpoint is disabled via a placeholder. +The last REST endpoint is hardcoded to be disabled. + == Binding to POJOs using The Rest DSL supports automatic binding json/xml contents to/from POJOs diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index 56ae69f0acd..f8548a4ff97 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -4164,6 +4164,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -4217,6 +4218,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -5528,6 +5534,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -5581,6 +5588,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -5943,6 +5955,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -5996,6 +6009,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -10070,6 +10088,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -10123,6 +10142,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -10508,6 +10532,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -10561,6 +10586,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -10995,6 +11025,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "deprecated", type = "boolean"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "out-type", type = "string"), @@ -11048,6 +11079,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDeprecated(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); @@ -12604,6 +12640,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "consumes", type = "string"), @YamlProperty(name = "delete", type = "array:org.apache.camel.model.rest.DeleteDefinition"), @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "disabled", type = "boolean"), @YamlProperty(name = "enable-cors", type = "boolean"), @YamlProperty(name = "get", type = "array:org.apache.camel.model.rest.GetDefinition"), @YamlProperty(name = "head", type = "array:org.apache.camel.model.rest.HeadDefinition"), @@ -12653,6 +12690,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setConsumes(val); break; } + case "disabled": { + String val = asText(node); + target.setDisabled(val); + break; + } case "enable-cors": { String val = asText(node); target.setEnableCORS(val); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camel-yaml-dsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camel-yaml-dsl.json index beb1a4929cc..d390d3d2c52 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camel-yaml-dsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camel-yaml-dsl.json @@ -7030,6 +7030,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7099,6 +7102,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7168,6 +7174,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7342,6 +7351,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7411,6 +7423,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7480,6 +7495,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, @@ -7761,6 +7779,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enable-cors" : { "type" : "boolean" }, diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json index 464783519a7..6e8d050fd1d 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json @@ -6931,6 +6931,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7000,6 +7003,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7069,6 +7075,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7243,6 +7252,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7312,6 +7324,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7381,6 +7396,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" }, @@ -7662,6 +7680,9 @@ "description" : { "type" : "string" }, + "disabled" : { + "type" : "boolean" + }, "enableCors" : { "type" : "boolean" },