// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-yaml-dsl"]
= YAML DSL
:linkattrs:
:cq-artifact-id: camel-quarkus-yaml-dsl
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: An YAML stack for parsing YAML route definitions
:cq-deprecated: false
:cq-jvm-since: 1.8.0
:cq-native-since: 1.8.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.8.0## [.badge-key]##Native since##[.badge-supported]##1.8.0##
endif::[]

An YAML stack for parsing YAML route definitions

[id="extensions-yaml-dsl-whats-inside"]
== What's inside

* xref:{cq-camel-components}:others:yaml-dsl.adoc[YAML DSL]

Please refer to the above link for usage and configuration details.

[id="extensions-yaml-dsl-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-yaml-dsl[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-yaml-dsl</artifactId>
</dependency>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-yaml-dsl-usage"]
== Usage
[id="extensions-yaml-dsl-usage-native-mode"]
=== Native mode

The following constructs when defined within Camel YAML DSL markup, require you to register classes for reflection. Refer to the xref:user-guide/native-mode.adoc#reflection[Native mode] guide for details.

[id="extensions-yaml-dsl-usage-bean-definitions"]
==== Bean definitions

The YAML DSL provides the capability to define beans as follows.

[source,yaml]
----
- beans:
    - name: "greetingBean"
      type: "org.acme.GreetingBean"
      properties:
        greeting: "Hello World!"
- route:
    id: "my-yaml-route"
    from:
      uri: "timer:from-yaml?period=1000"
      steps:
        - to: "bean:greetingBean"
----

In this example, the `GreetingBean` class needs to be registered for reflection. This applies to any types that you refer to under the `beans` key in your YAML routes.

[source,java]
----
@RegisterForReflection
public class GreetingBean {
}
----

[id="extensions-yaml-dsl-usage-exception-handling"]
==== Exception handling

Camel provides various methods of handling exceptions. Some of these require that any exception classes referenced in their DSL definitions are registered for reflection.

`*on-exception*`

[source,yaml]
----
- on-exception:
    handled:
      constant: "true"
    exception:
      - "org.acme.MyHandledException"
    steps:
      - transform:
          constant: "Sorry something went wrong"
----

[source,java]
----
@RegisterForReflection
public class MyHandledException {
}
----

`*throw-exception*`

[source,yaml]
----
- route:
    id: "my-yaml-route"
    from:
      uri: "direct:start"
      steps:
        - choice:
            when:
              - simple: "${body} == 'bad value'"
                steps:
                  - throw-exception:
                      exception-type: "org.acme.ForcedException"
                      message: "Forced exception"
            otherwise:
              steps:
                - to: "log:end"
----

[source,java]
----
@RegisterForReflection
public class ForcedException {
}
----

`*do-catch*`

[source,yaml]
----
- route:
    id: "my-yaml-route2"
    from:
      uri: "direct:tryCatch"
      steps:
        - do-try:
            steps:
              - to: "direct:readFile"
            do-catch:
              - exception:
                  - "java.io.FileNotFoundException"
                steps:
                  - transform:
                      constant: "do-catch caught an exception"
----

[source,java]
----
@RegisterForReflection(targets = FileNotFoundException.class)
public class MyClass {
}
----

