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 0839bf7 Polish and cleanup documentation 0839bf7 is described below commit 0839bf7967b6d70fefa357e5c9fc2c64101bf374 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Aug 12 10:29:00 2021 +0200 Polish and cleanup documentation --- .../org/apache/camel/catalog/docs/toD-eip.adoc | 24 +- .../main/camel-main-configuration-metadata.json | 4 +- .../camel/catalog/models/restConfiguration.json | 2 +- .../org/apache/camel/spi/RestConfiguration.java | 8 +- .../src/main/docs/modules/eips/pages/toD-eip.adoc | 24 +- .../apache/camel/model/rest/restConfiguration.json | 2 +- .../model/rest/RestConfigurationDefinition.java | 2 +- .../camel-main-configuration-metadata.json | 4 +- core/camel-main/src/main/docs/main.adoc | 4 +- .../camel/main/RestConfigurationProperties.java | 2 +- docs/components/modules/others/pages/main.adoc | 4 +- docs/user-manual/modules/ROOT/pages/rest-dsl.adoc | 392 +++++++-------------- 12 files changed, 192 insertions(+), 280 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/toD-eip.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/toD-eip.adoc index 1589429..b0fbed1 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/toD-eip.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/toD-eip.adoc @@ -140,19 +140,35 @@ as documented next. == Using optimised components -But a better solution would be if the HTTP component could be optimised to handle the variations of dynamic computed endpoint uris. +A better solution would be if the HTTP component could be optimised to handle the variations of dynamic computed endpoint uris. This is with among the following components, which have been optimised for `toD`: - camel-http - camel-jetty - camel-netty-http - camel-undertow +- camel-vertx-http + +A number of non-HTTP components has been optimised as well: + +- camel-activemq +- camel-amqp +- camel-file +- camel-ftp +- camel-jms +- camel-kafka +- camel-paho-mqtt5 +- camel-paho +- camel-rabbitmq +- camel-sjms +- camel-sjms2 +- camel-spring-rabbitmq For the optimisation to work, then: -1. The optimisation is detected and activated during startup of the Camel routes with `toD`'s. -2. The dynamic uri in `toD` must provide the component name as either static or resolved via property placeholders. -3. The supported components must be on the classpath. +. The optimisation is detected and activated during startup of the Camel routes with `toD`'s. +. The dynamic uri in `toD` must provide the component name as either static or resolved via property placeholders. +. The supported components must be on the classpath. The HTTP based components will be optimised to use the same hostname:port for each endpoint, and the dynamic values for context-path and query parameters will be provided as headers: diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json index f86d92f..0b4aea9 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json @@ -181,7 +181,7 @@ { "name": "camel.rest.apiContextListing", "description": "Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.rest.apiContextPath", "description": "Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.apiContextRouteId", "description": "Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, - { "name": "camel.rest.apiHost", "description": "To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.rest.apiHost", "description": "To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.apiProperties", "description": "Sets additional options on api level", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "object", "javaType": "java.util.Map" }, { "name": "camel.rest.apiVendorExtension", "description": "Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.rest.bindingMode", "description": "Sets the binding mode to be used by the REST consumer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "object", "javaType": "org.apache.camel.spi.RestBindingMode", "defaultValue": "RestBindingMode.off", "enum": [ "auto", "off", "json", "xml", "json_xml" ] }, @@ -202,7 +202,7 @@ { "name": "camel.rest.producerComponent", "description": "Sets the name of the Camel component to use as the REST producer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.scheme", "description": "Sets the scheme to use by the REST consumer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.skipBindingOnErrorCode", "description": "Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, - { "name": "camel.rest.useXForwardHeaders", "description": "WWhether to use X-Forward headers to set host etc. for Swagger. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "name": "camel.rest.useXForwardHeaders", "description": "Whether to use X-Forward headers to set host etc. for Swagger. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, { "name": "camel.rest.xmlDataFormat", "description": "Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.threadpool.allowCoreThreadTimeOut", "description": "Sets default whether to allow core threads to timeout", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean", "defaultValue": "false" }, { "name": "camel.threadpool.config", "description": "Adds a configuration for a specific thread pool profile (inherits default values)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.Map" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/restConfiguration.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/restConfiguration.json index 8a1def3..2dc40d3 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/restConfiguration.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/restConfiguration.json @@ -16,7 +16,7 @@ "producerComponent": { "kind": "attribute", "displayName": "Producer Component", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the name of the Camel component to use as the REST producer" }, "scheme": { "kind": "attribute", "displayName": "Scheme", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http" }, "host": { "kind": "attribute", "displayName": "Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The hostname to use for exposing the REST service." }, - "apiHost": { "kind": "attribute", "displayName": "Api Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use an specific hostname for the API documentation This can be used to override the generated host with this configured hostname" }, + "apiHost": { "kind": "attribute", "displayName": "Api Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname" }, "useXForwardHeaders": { "kind": "attribute", "displayName": "Use XForward Headers", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to use X-Forward headers for Host and related setting. The default value is true." }, "port": { "kind": "attribute", "displayName": "Port", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apa [...] "producerApiDoc": { "kind": "attribute", "displayName": "Producer Api Doc", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to re [...] diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/RestConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/spi/RestConfiguration.java index d73f1e6..358da21 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/RestConfiguration.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/RestConfiguration.java @@ -172,7 +172,7 @@ public class RestConfiguration { } /** - * WWhether to use X-Forward headers to set host etc. for Swagger. + * Whether to use X-Forward headers to set host etc. for Swagger. * <p/> * This option is default <tt>true</tt>. */ @@ -181,11 +181,9 @@ public class RestConfiguration { } /** - * WWhether to use X-Forward headers to set host etc. for Swagger. + * Whether to use X-Forward headers to set host etc. for Swagger. * <p/> * This option is default <tt>true</tt>. - * - * @param useXForwardHeaders whether to use X-Forward headers */ public void setUseXForwardHeaders(boolean useXForwardHeaders) { this.useXForwardHeaders = useXForwardHeaders; @@ -196,7 +194,7 @@ public class RestConfiguration { } /** - * To use an specific hostname for the API documentation (eg swagger) + * To use a specific hostname for the API documentation (such as swagger or openapi) * <p/> * This can be used to override the generated host with this configured hostname */ diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc index 1589429..b0fbed1 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc @@ -140,19 +140,35 @@ as documented next. == Using optimised components -But a better solution would be if the HTTP component could be optimised to handle the variations of dynamic computed endpoint uris. +A better solution would be if the HTTP component could be optimised to handle the variations of dynamic computed endpoint uris. This is with among the following components, which have been optimised for `toD`: - camel-http - camel-jetty - camel-netty-http - camel-undertow +- camel-vertx-http + +A number of non-HTTP components has been optimised as well: + +- camel-activemq +- camel-amqp +- camel-file +- camel-ftp +- camel-jms +- camel-kafka +- camel-paho-mqtt5 +- camel-paho +- camel-rabbitmq +- camel-sjms +- camel-sjms2 +- camel-spring-rabbitmq For the optimisation to work, then: -1. The optimisation is detected and activated during startup of the Camel routes with `toD`'s. -2. The dynamic uri in `toD` must provide the component name as either static or resolved via property placeholders. -3. The supported components must be on the classpath. +. The optimisation is detected and activated during startup of the Camel routes with `toD`'s. +. The dynamic uri in `toD` must provide the component name as either static or resolved via property placeholders. +. The supported components must be on the classpath. The HTTP based components will be optimised to use the same hostname:port for each endpoint, and the dynamic values for context-path and query parameters will be provided as headers: diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/restConfiguration.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/restConfiguration.json index 8a1def3..2dc40d3 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/restConfiguration.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/restConfiguration.json @@ -16,7 +16,7 @@ "producerComponent": { "kind": "attribute", "displayName": "Producer Component", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the name of the Camel component to use as the REST producer" }, "scheme": { "kind": "attribute", "displayName": "Scheme", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http" }, "host": { "kind": "attribute", "displayName": "Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The hostname to use for exposing the REST service." }, - "apiHost": { "kind": "attribute", "displayName": "Api Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use an specific hostname for the API documentation This can be used to override the generated host with this configured hostname" }, + "apiHost": { "kind": "attribute", "displayName": "Api Host", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname" }, "useXForwardHeaders": { "kind": "attribute", "displayName": "Use XForward Headers", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to use X-Forward headers for Host and related setting. The default value is true." }, "port": { "kind": "attribute", "displayName": "Port", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apa [...] "producerApiDoc": { "kind": "attribute", "displayName": "Producer Api Doc", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to re [...] diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java index c2bf3ee..ef7709d 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java @@ -209,7 +209,7 @@ public class RestConfigurationDefinition { } /** - * To use an specific hostname for the API documentation + * To use a specific hostname for the API documentation (such as swagger or openapi) * <p/> * This can be used to override the generated host with this configured hostname */ diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json index f86d92f..0b4aea9 100644 --- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json +++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json @@ -181,7 +181,7 @@ { "name": "camel.rest.apiContextListing", "description": "Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.rest.apiContextPath", "description": "Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.apiContextRouteId", "description": "Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, - { "name": "camel.rest.apiHost", "description": "To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.rest.apiHost", "description": "To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.apiProperties", "description": "Sets additional options on api level", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "object", "javaType": "java.util.Map" }, { "name": "camel.rest.apiVendorExtension", "description": "Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.rest.bindingMode", "description": "Sets the binding mode to be used by the REST consumer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "object", "javaType": "org.apache.camel.spi.RestBindingMode", "defaultValue": "RestBindingMode.off", "enum": [ "auto", "off", "json", "xml", "json_xml" ] }, @@ -202,7 +202,7 @@ { "name": "camel.rest.producerComponent", "description": "Sets the name of the Camel component to use as the REST producer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.scheme", "description": "Sets the scheme to use by the REST consumer", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.rest.skipBindingOnErrorCode", "description": "Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, - { "name": "camel.rest.useXForwardHeaders", "description": "WWhether to use X-Forward headers to set host etc. for Swagger. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "name": "camel.rest.useXForwardHeaders", "description": "Whether to use X-Forward headers to set host etc. for Swagger. This option is default true.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": true }, { "name": "camel.rest.xmlDataFormat", "description": "Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.", "sourceType": "org.apache.camel.spi.RestConfiguration", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.threadpool.allowCoreThreadTimeOut", "description": "Sets default whether to allow core threads to timeout", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean", "defaultValue": "false" }, { "name": "camel.threadpool.config", "description": "Adds a configuration for a specific thread pool profile (inherits default values)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.Map" }, diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 704e22c..9ba985b 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -161,7 +161,7 @@ The camel.rest supports 28 options, which are listed below. | *camel.rest.apiContextListing* | Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use. | false | boolean | *camel.rest.apiContextPath* | Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. | | String | *camel.rest.apiContextRouteId* | Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id. | | String -| *camel.rest.apiHost* | To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname | | String +| *camel.rest.apiHost* | To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname | | String | *camel.rest.apiProperties* | Sets additional options on api level | | Map | *camel.rest.apiVendorExtension* | Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs. | false | boolean | *camel.rest.bindingMode* | Sets the binding mode to be used by the REST consumer | RestBindingMode.off | RestBindingMode @@ -182,7 +182,7 @@ The camel.rest supports 28 options, which are listed below. | *camel.rest.producerComponent* | Sets the name of the Camel component to use as the REST producer | | String | *camel.rest.scheme* | Sets the scheme to use by the REST consumer | | String | *camel.rest.skipBindingOnError{zwsp}Code* | Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true. | true | boolean -| *camel.rest.useXForwardHeaders* | WWhether to use X-Forward headers to set host etc. for Swagger. This option is default true. | true | boolean +| *camel.rest.useXForwardHeaders* | Whether to use X-Forward headers to set host etc. for Swagger. This option is default true. | true | boolean | *camel.rest.xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. | | String |=== diff --git a/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java index 959e60e..f66a693 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java @@ -104,7 +104,7 @@ public class RestConfigurationProperties extends RestConfiguration implements Bo } /** - * To use an specific hostname for the API documentation (eg swagger) + * To use a specific hostname for the API documentation (such as swagger or openapi) * <p/> * This can be used to override the generated host with this configured hostname */ diff --git a/docs/components/modules/others/pages/main.adoc b/docs/components/modules/others/pages/main.adoc index a896c26..92683aa 100644 --- a/docs/components/modules/others/pages/main.adoc +++ b/docs/components/modules/others/pages/main.adoc @@ -163,7 +163,7 @@ The camel.rest supports 28 options, which are listed below. | *camel.rest.apiContextListing* | Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use. | false | boolean | *camel.rest.apiContextPath* | Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. | | String | *camel.rest.apiContextRouteId* | Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id. | | String -| *camel.rest.apiHost* | To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname | | String +| *camel.rest.apiHost* | To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname | | String | *camel.rest.apiProperties* | Sets additional options on api level | | Map | *camel.rest.apiVendorExtension* | Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs. | false | boolean | *camel.rest.bindingMode* | Sets the binding mode to be used by the REST consumer | RestBindingMode.off | RestBindingMode @@ -184,7 +184,7 @@ The camel.rest supports 28 options, which are listed below. | *camel.rest.producerComponent* | Sets the name of the Camel component to use as the REST producer | | String | *camel.rest.scheme* | Sets the scheme to use by the REST consumer | | String | *camel.rest.skipBindingOnError{zwsp}Code* | Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true. | true | boolean -| *camel.rest.useXForwardHeaders* | WWhether to use X-Forward headers to set host etc. for Swagger. This option is default true. | true | boolean +| *camel.rest.useXForwardHeaders* | Whether to use X-Forward headers to set host etc. for Swagger. This option is default true. | true | boolean | *camel.rest.xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. | | String |=== diff --git a/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc b/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc index 3959aee..46ff783 100644 --- a/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc +++ b/docs/user-manual/modules/ROOT/pages/rest-dsl.adoc @@ -1,9 +1,9 @@ -= REST DSL Component +[[RestDSL-RestDSL]] += REST DSL -*Since Camel 2.16* +Apache Camel offers a REST styled DSL. -Apache Camel offers a REST styled DSL which can be used with Java or -XML. The intention is to allow end users to define REST services using a +The intention is to allow end users to define REST services (hosted by Camel) using a REST style with verbs such as get, post, delete etc. == How it works @@ -16,73 +16,60 @@ others that has native REST integration. == Components supporting Rest DSL -The following Camel components supports the Rest DSL. See the bottom of -this page for how to integrate a component with the Rest DSL. +The following Camel components supports the Rest DSL: * xref:components::rest-component.adoc[camel-rest] *required* contains the base rest component needed by Rest DSL -* xref:components::netty-http-component.adoc[camel-netty-http] (also -supports Swagger Java) -* xref:components::jetty-component.adoc[camel-jetty] (also -supports Swagger Java) -* xref:components::servlet-component.adoc[camel-servlet] (also -supports Swagger Java) -* xref:components::undertow-component.adoc[camel-undertow] (also -supports Swagger Java) - -== Rest DSL with Java - -To use the Rest DSL in Java then just do as with regular Camel routes by +* xref:components::netty-http-component.adoc[camel-netty-http] +* xref:components::jetty-component.adoc[camel-jetty] +* xref:components::platform-http-component.adoc[camel-platform-http] +* xref:components::servlet-component.adoc[camel-servlet] +* xref:components::undertow-component.adoc[camel-undertow] + +== Rest DSL with Java DSL + +To use the Rest DSL in Java DSL then just do as with regular Camel routes by extending the `RouteBuilder` and define the routes in the `configure` method. -A simple REST service can be define as follows, where we use rest() to +A simple REST service can be defined as follows, where we use `rest()` to define the services as shown below: [source,java] ---- -protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - rest("/say") - .get("/hello").to("direct:hello") - .get("/bye").consumes("application/json").to("direct:bye") - .post("/bye").to("mock:update"); - - from("direct:hello") - .transform().constant("Hello World"); - from("direct:bye") - .transform().constant("Bye World"); - } - }; +@Override +public void configure() throws Exception { + rest("/say") + .get("/hello").to("direct:hello") + .get("/bye").consumes("application/json").to("direct:bye") + .post("/bye").to("mock:update"); + + from("direct:hello") + .transform().constant("Hello World"); + + from("direct:bye") + .transform().constant("Bye World"); } ---- - - This defines a REST service with the following url mappings: [width="100%",cols="25%,25%,25%,25%",options="header",] |=== |Base Path |Uri template |Verb |Consumes - |/say |/hello |get |_all_ - |/say |/bye |get |application/json - |/say |/bye |post |_all_ |=== Notice that in the REST service we route directly to a Camel endpoint -using the to(). This is because the Rest DSL has a short-hand for -routing directly to an endpoint using to(). An alternative is to embed a -Camel route directly using route() - there is such an example further +using `to()`. This is because the Rest DSL has a short-hand for +routing directly to an endpoint using `to()`. An alternative is to embed a +Camel route directly using `route()`; there is such an example further below. -== Rest DSL with XML +== Rest DSL with XML DSL -The REST DSL supports the XML DSL also using either Spring or Blueprint. -The example above can be define in XML as shown below: +The example above can be defined in XML as shown below: [source,xml] ---- @@ -115,9 +102,9 @@ The example above can be define in XML as shown below: == Using base path -The REST DSL allows to define base path to make the DSL a bit more DRY. +The REST DSL allows defining base path to make the DSL a bit more DRY. For example to define a customer path, we can set the base path in -rest("/customer") and then provide the uri templates in the verbs, as +`rest("/customer")` and then provide the uri templates in the verbs, as shown below: [source,java] @@ -147,7 +134,7 @@ And using XML DSL it becomes: TIP: The REST DSL will take care of duplicate path separators when using base path and uri templates. In the example above the rest base path ends -with a slash ( / ) and the verb starts with a slash ( / ). But Apache +with a slash `/` and the verb starts with a slash `/`. Camel will take care of this and remove the duplicated slash. It is not required to use both base path and uri templates. You can omit @@ -169,32 +156,31 @@ only. The example above can be defined as: </rest> ---- -TIP: You can combine path parameters to build complex expressions. +You can combine path parameters to build complex expressions. For example: + [source,java] ---- - rest("items/") - .get("{id}/{filename}.{content-type}") - .to("direct:item") + rest("items/") + .get("{id}/{filename}.{content-type}") + .to("direct:item") ---- == Using Dynamic To in Rest DSL -*Since Camel 2.16* - -The Rest DSL supports the new .toD <toD> as dynamic -to in the rest-dsl. For example to do a request/reply +The Rest DSL supports xref:{eip-vc}:eips:toD-eip.adoc[Dynamic To] EIP (`toD`) +to in the rest-dsl. For example to do a xref:{eip-vc}:eips:requestReply-eip.adoc[Request Reply] over xref:components::jms-component.adoc[JMS] where the queue name is dynamic defined [source,java] ---- - public void configure() throws Exception { +public void configure() throws Exception { rest("/say") .get("/hello/{language}").toD("jms:queue:hello-${header.language}"); } ---- -== And in XML DSL +And in XML DSL [source,xml] ---- @@ -205,44 +191,37 @@ over xref:components::jms-component.adoc[JMS] where the queue name is dynamic de </rest> ---- -See more details at Message Endpoint about -the dynamic to, and what syntax it supports. By default it uses -the xref:components:languages:simple-language.adoc[Simple] language, but it has more power than so. - == Embedding Camel routes Each of the rest services becomes a Camel route, so in the first example we have 2 x get and 1 x post REST service, which each become a Camel -route. And we have 2 regular Camel routes, meaning we have 3 + 2 = 5 +route. We have 2 regular Camel routes, meaning we have 3 + 2 = 5 routes in total. -There are two route modes with the Rest DSL +There are two route modes with the Rest DSL: * mini using a singular to * embedding a Camel route using route -The first example is using the former with a singular to. And that is -why we end up with 3 + 2 = 5 total routes. +The first example is using the former with a singular to; then we +end up with 3 + 2 = 5 total routes. The same example could use embedded Camel routes, which is shown below: [source,java] ---- -protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - rest("/say/hello") - .get().route().transform().constant("Hello World"); - rest("/say/bye") - .get().consumes("application/json").route().transform().constant("Bye World").endRest() - .post().to("mock:update"); - }; +@Override +public void configure() throws Exception { + rest("/say/hello") + .get().route().transform().constant("Hello World"); + rest("/say/bye") + .get().consumes("application/json").route().transform().constant("Bye World").endRest() + .post().to("mock:update"); } ---- In the example above, we are embedding routes directly in the rest -service using .route(). Notice we need to use .endRest() to tell Camel +service using `.route()`. Notice we need to use `.endRest()` to tell Camel where the route ends, so we can _go back_ to the Rest DSL and continue defining REST services. @@ -259,6 +238,18 @@ today. .transform().constant("Hello World"); ---- +And in XML: + +[source,xml] +---- +<rest uri="/say"> + <get> + <route id="myRestRoute" autoStartup="false"> + <transform><constant>Hello World</constant></transform> + </route> + </get> +</rest> +---- == Managing Rest services @@ -268,6 +259,8 @@ route. This makes it _the same_ from Camel to manage and run these services - as they are just Camel routes. This means any tooling and API today that deals with Camel routes, also work with the REST services. +NOTE: To use JMX with Camel then `camel-management` JAR must be included in the classpath. + This means you can use JMX to stop/start routes, and also get the JMX metrics about the routes, such as number of message processed, and their performance statistics. @@ -278,7 +271,7 @@ REST services which has been defined. == Binding to POJOs using The Rest DSL supports automatic binding json/xml contents to/from POJOs -using Camels Data Format. By default the binding +using Camels Data Format. By default, the binding mode is off, meaning there is no automatic binding happening for incoming and outgoing messages. @@ -310,7 +303,7 @@ classpath. See the INFO box below for more details. be on the classpath. See the INFO box below for more details. |=== -TIP: From *Camel 2.14.1* onwards when using camel-jaxb for xml bindings, then +When using camel-jaxb for xml bindings, then you can use the option `mustBeJAXBElement` to relax the output message body must be a class with JAXB annotations. You can use this in situations where the message body is already in XML format, and you want @@ -318,10 +311,9 @@ to use the message body as-is as the output type. If that is the case, then set the dataFormatProperty option `mustBeJAXBElement` to `false` value. -NOTE: From *Camel 2.16.3* onwards the binding from POJO to JSon/JAXB will only -happen if the `content-type` header includes the -word `json` or `xml` representatively. This allows you to specify a -custom content-type if the message body should not attempt to be +The binding from POJO to JSon/JAXB will only happen if the `content-type` +header includes the word `json` or `xml` representatively. This allows you +to specify a custom content-type if the message body should not attempt to be marshalled using the binding. For example if the message body is a custom binary payload etc. @@ -330,14 +322,14 @@ classpath, such as `camel-jaxb` and/or `camel-jackson`. And then enable the binding mode. You can configure the binding mode globally on the rest configuration, and then override per rest service as well. -To enable binding you configure this in Java DSL as shown below +To enable binding you configure this in Java DSL as shown below: [source,java] ---- restConfiguration().component("netty-http").host("localhost").port(portNum).bindingMode(RestBindingMode.auto); ---- -And in XML DSL +And in XML DSL: [source,xml] ---- @@ -392,7 +384,7 @@ rest("/users/") Notice we use `type` to define the incoming type. We can optionally define an outgoing type (which can be a good idea, to make it known from the DSL and also for tooling and JMX APIs to know both the incoming and -outgoing types of the REST services.). To define the outgoing type, we +outgoing types of the REST services). To define the outgoing type, we use `outType` as shown below: [source,java] @@ -407,7 +399,7 @@ rest("/users/") .to("direct:newUser"); ---- -== And in XML DSL +And in XML DSL: [source,xml] ---- @@ -486,145 +478,61 @@ public class UserPojo { By having the JAXB annotations the POJO supports both json and xml bindings. -== Configuring Rest DSL -[width="100%",cols="20%,10%,30%",options="header",] -|=== -|Option |Default |Description -|component | - |The Camel Rest component to use for the REST transport, such as spark-rest. - - If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used. -|apiComponent | - |The Camel component to use as the REST API (such as swagger) -|producerComponent | - |The Camel component to use as the REST producer. -|producerApiDoc | - |The location of the api document (swagger api) the REST producer will use - to validate the REST uri and query parameters are valid accordingly to the api document. - - This requires adding camel-swagger-java to the classpath, and any miss configuration - will let Camel fail on startup and report the error(s). - - The location of the api document is loaded from classpath by default, but you can use - `file:` or `\http:` to refer to resources to load from file or http url. -|scheme | http|The scheme to use for exposing the REST service. Usually http or https is supported -|host |- |The hostname to use for exposing the REST service. -|useXForwardHeaders |true |Whether to use X-Forwarded-Host (or Host) from incoming HTTP Header to set the hostname -|apiHost |- |Specific hostname for the API documentation (eg swagger) - - This can be used to override the generated host with this configured hostname -|port |- |The port number to use for exposing the REST service. - -*NOTE*: if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using, e.g., if using Apache Tomcat its the tomcat HTTP port, if using Apache Karaf it's the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the serv [...] - -|contextPath |-|Leading context-path the REST services will be using. - This can be used when using components such as SERVLET where the deployed web application is deployed using a - context-path. Or for components such as `camel-jetty` or `camel-netty-http` that includes a HTTP server. -|apiContextPath | - |A leading API context-path the REST API services will be using. - - This can be used when using components such as `camel-servlet` where the deployed web application - is deployed using a context-path. -|apiContextRouteId | - |Route id to use for the route that services the REST API. - The route will by default use an auto assigned route id. -|apiContextIdPattern | - |Optional CamelContext id pattern to only allow Rest APIs from rest services within - CamelContext's which name matches the pattern. - - The pattern `\#name#` refers to the CamelContext name, to match on the current CamelContext only. - For any other value, the pattern uses the rules from {@link org.apache.camel.util. - EndpointHelper#matchPattern(String, String)} -|apiContextListing | - |Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. - If enabled it allows to discover these contexts, if <tt>false</tt> then only the current CamelContext is in use. -|apiVendorExtension | - |Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information - as vendor extension (eg keys starting with x-) such as route ids, class names etc. - - Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs. -|hostNameResolver | -|From *Camel 2.20* -If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using. - -The resolver supports: - -allLocalIp (from Camel 2.17) -localHostName -localIp -For Camel 2.16.x or older: localHostName +=== Camel Rest-DSL configurations -From Camel 2.17: allLocalIp -|restHostNameResolver | -|Camel 2.19 and before (now called "hostNameResolver") -|bindingMode | off|Whether binding is in use. See further above for more details. -|skipBindingOnErrorCode |true |Camel 2.14.1: Whether to skip binding on output if there is a custom HTTP error code header. +The Rest DSL supports the following options: - This allows to build custom error messages that do not bind to JSON/XML etc, as success messages otherwise will do. - - See below for an example. -|clientRequestValidation |false |From **Camel 2.22 ** Whether to enable validation of the client request to check -whether the Content-Type and Accept headers from - the client is supported by the Rest-DSL configuration of its consumes/produces settings. - - This can be turned on, to enable this check. In case of validation error, - then HTTP Status codes 415 or 406 is returned. -|enableCORS |false |Camel 2.14.1: Whether to enable CORS headers in the HTTP response. -|jsonDataFormat |- |Name of specific JSON data format to use. By default json-jackson will be used. - - *Important:* This option is only for setting a custom name of the data format, not to refer to an existing data format instance. - - *Note:* Currently Jackson is what we recommend and are using for testing. -|xmlDataFormat | -|Name of specific XML data format to use. By default jaxb will be used. - - *Important:* This option is only for setting a custom name of the data format, not to refer to an existing data format instance. - - *Note:* Currently only jaxb is supported. -|componentProperty | -|Allows to configure as many additional properties. - This is used to configure component specific options such as for netty-http, jetty, undertow etc. - The options value can use the # notation to refer to a bean to lookup in - the xref:registry.adoc[Registry] -|endpointProperty | -|Allows to configure as many additional properties. - This is used to configure endpoint specific options for netty-http, jetty, undertow. - The options value can use the # notation to refer to a bean to lookup in - the xref:registry.adoc[Registry] -|consumerProperty |- |Allows to configure as many additional properties. - This is used to configure consumer specific options for netty-http, jetty, undertow. - The options value can use the # notation to refer to a bean to lookup in - the xref:registry.adoc[Registry] -|dataFormatProperty |- |Allows to configure as many additional properties. - This is used to configure the data format specific options. - - For example set property prettyPrint=true to have JSON outputted in pretty mode. - - From Camel 2.14.1: the keys can be prefixed with either: - -*json.in. - -*json.out. - -* xml.in. - -* xml.out. - - to denote that the option is only for either JSON or XML data format, and only for either the in or the out going. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. - - A key without a prefix is a common key for all situations. - - From Camel 2.17: the options value can use the # notation to refer to a bean to lookup in the Registry -|apiProperty | -|Sets additional options on api level. -|corsHeaders | -|Allows to configure custom CORS headers. +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *apiComponent* | Sets the name of the Camel component to use as the REST API (such as swagger or openapi) | | String +| *apiContextIdPattern* | Optional CamelContext id pattern to only allow Rest APIs from rest services within CamelContext's which name matches the pattern. The pattern #name# refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from org.apache.camel.support.EndpointHelper#matchPattern(String,String) | | String +| *apiContextListing* | Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use. | false | boolean +| *apiContextPath* | Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. | | String +| *apiContextRouteId* | Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id. | | String +| *apiHost* | To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname | | String +| *apiProperties* | Sets additional options on api level | | Map +| *apiVendorExtension* | Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs. | false | boolean +| *bindingMode* | Sets the binding mode to be used by the REST consumer | RestBindingMode.off | RestBindingMode +| *clientRequestValidation* | Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false. | false | boolean +| *component* | Sets the name of the Camel component to use as the REST consumer | | String +| *componentProperties* | Sets additional options on component level | | Map +| *consumerProperties* | Sets additional options on consumer level | | Map +| *contextPath* | Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server. | | String +| *corsHeaders* | Sets the CORS headers to use if CORS has been enabled. | | Map +| *dataFormatProperties* | Sets additional options on data format level | | Map +| *enableCORS* | To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response. This option is default false | false | boolean +| *endpointProperties* | Sets additional options on endpoint level | | Map +| *host* | Sets the hostname to use by the REST consumer | | String +| *hostNameResolver* | Sets the resolver to use for resolving hostname | RestHostNameResolver.allLocalIp | RestHostNameResolver +| *jsonDataFormat* | Sets a custom json data format to be used Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. | | String +| *port* | Sets the port to use by the REST consumer | | int +| *producerApiDoc* | Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url. | | String +| *producerComponent* | Sets the name of the Camel component to use as the REST producer | | String +| *scheme* | Sets the scheme to use by the REST consumer | | String +| *skipBindingOnErrorCode* | Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true. | true | boolean +| *useXForwardHeaders* | Whether to use X-Forward headers to set host etc. for Swagger. This option is default true. | true | boolean +| *xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. | | String |=== -For example to configure to use the spark-rest component on port 9091, then we can do as follows: +For example to configure to use the jetty component on port 9091, then we can do as follows: [source,java] ---- -restConfiguration().component("spark-rest").port(9091).componentProperty("foo", "123"); +restConfiguration().component("jetty").port(9091).componentProperty("foo", "123"); ---- -And with XML DSL +And with XML DSL: + [source,xml] ---- -<restConfiguration component="spark-rest" port="9091"> +<restConfiguration component="jetty" port="9091"> <componentProperty key="foo" value="123"/> </restConfiguration> ---- - - If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used. - You can configure properties on these levels. * component - Is used to set any options on the Component class. You can @@ -641,12 +549,9 @@ header is set then that value takes precedence over the default value. You can set multiple options of the same level, so you can for example configure 2 component options, and 3 endpoint options etc. - == Enabling or disabling Jackson JSON features -*Since Camel 2.15* - When using JSON binding you may want to turn specific Jackson features on or off. For example to disable failing on unknown properties (eg json input has a property which cannot be mapped to a POJO) then configure @@ -683,7 +588,7 @@ classes * com.fasterxml.jackson.databind.DeserializationFeature * com.fasterxml.jackson.databind.MapperFeature -The rest configuration is of course also possible using XML DSL +The rest configuration is of course also possible using XML DSL: [source,xml] ---- @@ -695,8 +600,6 @@ The rest configuration is of course also possible using XML DSL == Default CORS headers -*Since Camel 2.14.1* - If CORS is enabled then the follow headers is in use by default. You can configure custom CORS headers which takes precedence over the default value. @@ -704,24 +607,19 @@ value. [width="100%",cols="50%,50%",options="header",] |=== |Key |Value - |Access-Control-Allow-Origin |* - |Access-Control-Allow-Methods |GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH - -|Access-Control-Allow-Headers |Origin, Accept, X-Requested-With, Content-Type, -Access-Control-Request-Method, Access-Control-Request-Headers - +|Access-Control-Allow-Headers |Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers |Access-Control-Max-Age |3600 |=== == Defining a custom error message as-is If you want to define custom error messages to be sent back to the -client with a HTTP error code (eg such as 400, 404 etc.) then -from *Camel 2.14.1* onwards you just set a header with the -key `Exchange.HTTP_RESPONSE_CODE` to the error code (must be 300+) such -as 404. And then the message body with any reply message, and optionally +client with a HTTP error code (eg such as 400, 404 etc.) +then you just set a header with the key `Exchange.HTTP_RESPONSE_CODE` +to the error code (must be 300+) such as 404. +And then the message body with any reply message, and optionally set the content-type header as well. There is a little example shown below: @@ -759,11 +657,11 @@ the HTTP error code to 400. This is important, as that tells rest-dsl that this is a custom error message, and the message should not use the output pojo binding (eg would otherwise bind to CountryPojo). -== Catching JsonParserException and returning a custom error message +=== Catching JsonParserException and returning a custom error message -From *Camel 2.14.1* onwards you return a custom message as-is (see -previous section). So we can leverage this with Camel error handler to -catch JsonParserException, handle that exception and build our custom +You can return a custom message as-is (see previous section). +So we can leverage this with Camel error handler to +catch `JsonParserException`, handle that exception and build our custom response message. For example to return a HTTP error code 400 with a hardcoded message, we can do as shown below: @@ -791,14 +689,13 @@ the verbose parameter below: .post("/neworder").to("direct:customerNewOrder"); ---- -From *Camel 2.17* onwards then the default value is automatic set as +The default value is automatic set as header on the incoming Camel `Message`. So if the call the `/customers/id/orders` do not include a query parameter with key `verbose` then Camel will now include a header with key `verbose` and the value `false` because it was declared as the default value. This functionality is only applicable for query parameters. - -From *Camel 3.3* onwards request headers may also be defaulted in the same way. +Request headers may also be defaulted in the same way. [source,java] ---- @@ -810,10 +707,9 @@ From *Camel 3.3* onwards request headers may also be defaulted in the same way. .post("/neworder").to("direct:customerNewOrder"); ---- - == Client Request Validation -From *Camel 2.22* onwards its possible to enable validation of the incoming client request. +It is possible to enable validation of the incoming client request. The validation checks for the following: - Content-Type header matches what the Rest DSL consumes. (Returns HTTP Status 415) @@ -832,27 +728,12 @@ restConfiguration().component("jetty").host("localhost") .clientRequestValidation(true); ---- +== OpenAPI / Swagger API -== Integrating a Camel component with Rest DSL - -Any Apache Camel component can integrate with the Rest DSL if they can -be used as a REST service (eg as a REST consumer in Camel lingo). To -integrate with the Rest DSL, then the component should implement -the `org.apache.camel.spi.RestConsumerFactory`. The Rest DSL will then -invoke the `createConsumer` method when it setup the Camel routes from -the defined DSL. The component should then implement logic to create a -Camel consumer that exposes the REST services based on the given -parameters, such as path, verb, and other options. For example see the -source code for camel-netty-http, camel-jetty, camel-undertow, camel-spark-rest. +The Rest DSL supports OpenAPI and Swagger by +the `camel-openapi-java` and `camel-swagger-java` modules. -== Swagger API - -The Rest DSL supports Swagger Java by -the `camel-swagger-java` module. See more details at - Swagger and the `camel-swagger-java` example -from the Apache Camel distribution. - -From *Camel 2.16* onwards you can define each parameter fine grained +You can define each parameter fine grained with details such as name, description, data type, parameter type and so on, using the <param>. For example to define the id path parameter you can do as shown below: @@ -889,7 +770,7 @@ example a REST PUT operation to create/update an user could be done as: </put> ---- -And in Java DSL +And in Java DSL: [source,java] ---- @@ -902,7 +783,7 @@ And in Java DSL The generated API documentation can be configured to include vendor extensions (https://swagger.io/specification/#specificationExtensions) which document the operations and definitions with additional information, such as class name of model classes, camel context id and route id's. -This information can aid developers and during trouble shooting. However at production usage you may wish to not have this turned +This information can aid developers and during troubleshooting. However, at production usage you may wish to not have this turned on to avoid leaking implementation details into your API docs. The vendor extension information is stored in the API documentation with keys starting with `x-`. @@ -924,6 +805,7 @@ restConfiguration() ---- And in XML DSL: + [source,xml] ---- <restConfiguration component="servlet" bindingMode="json"