// This module is included in the following assembly:
// as_develop-step-extensions.adoc

[id='example-route-builder_{context}']
= Example of developing a Camel route with `RouteBuilder`

You can implement a custom step by developing an action as a Camel
route with the support of the `RouteBuilder` class. Such a route
has an input such as `direct`. Syndesis invokes this route in the same
way that it invokes any other Camel route. 

To implement the example that creates a step that logs the body of a 
message with an optional prefix, you can write something like this: 

[source,java]
----
import org.apache.camel.builder.RouteBuilder;

import io.syndesis.extension.api.annotations.Action;
import io.syndesis.extension.api.annotations.ConfigurationProperty;

@Action( // <1>
    id = "log-body-with-prefix",
    name = "Log body with prefix",
    description = "A simple body log with a prefix",
    entrypoint = "direct:log")
public class LogAction extends RouteBuilder {
    @ConfigurationProperty( // <2>
        name = "prefix",
        description = "The Log body prefix message",
        displayName = "Log Prefix",
        type = "string")
    private String prefix;

    @Override
    public void configure() throws Exception {
        from("direct::start") // <3>
            .choice()
                .when(simple("${header.prefix} != ''"))
                    .log("${header.prefix} ${body}")
                .otherwise()
                    .log("Output ${body}")
            .endChoice();
    }
}
----
<1> The `@Action` annotation indicates the action definition.
<2> The `@ConfigurationProperty` annotation indicates definitions of
user interface form controls. For details, see 
link:{LinkSyndesisIntegrationGuide}#descriptions-of-user-interface-properties-in-extension-definitions_extensions[Descriptions of user interface properties].
<3> This is the action implementation. 

This Java code uses Syndesis annotations, which means that the
`extension-maven-plugin` can automatically generate the action definition.
In the extension definition JSON file, the action definition will look 
like this: 

[source,json]
----
{
  "id": "log-body-with-prefix",
  "name": "Log body with prefix",
  "description": "A simple body log with a prefix",
  "descriptor": {
    "kind": "ENDPOINT", <1>
    "entrypoint": "direct:log", <2>
    "resource": "class:io.syndesis.extension.log.LogAction", <3>
    "inputDataShape": {
      "kind": "none"
    },
    "outputDataShape": {
      "kind": "none"
    },
    "propertyDefinitionSteps": [ {
      "description": "extension-properties",
      "name": "extension-properties",
      "properties": { <4>
        "prefix": {
          "componentProperty": false,
          "deprecated": false,
          "description": "The Log body prefix message",
          "displayName": "Log Prefix",
          "javaType": "java.lang.String",
          "kind": "parameter",
          "required": false,
          "secret": false,
          "type": "string",
          "raw": false
        }
      }
    } ]
  },
  "actionType": "step"
}
----
<1> The type of action is `ENDPOINT`. The runtime invokes a Camel endpoint to execute the action that this step implements.
<2> This is the Camel endpoint to invoke. It is the `from` specification in the route.
<3> This is the class that implements `RoutesBuilder`.
<4> These are the properties that the action defined in this custom step
exposes to the integrator who will be adding this step to an integration. In 
{prodname}, each value that the integrator specifies in the user interface
gets mapped to a message header that has the same name as the property. 
In this example, the integrator will see one input field, with the
*Log Prefix* display name. For more information, see 
link:{LinkSyndesisIntegrationGuide}#descriptions-of-user-interface-properties-in-extension-definitions_extensions[Descriptions of user interface properties].
