Camel Components

CM SMS Gateway

Since Camel 2.18

Only producer is supported

Camel-Cm-Sms is an Apache Camel component for the CM SMS Gateway

It allows integrating CM SMS API in an application as a camel component.

You must have a valid account. More information is available at CM Telecom.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The CM SMS Gateway component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The CM SMS Gateway endpoint is configured using URI syntax:

cm-sms:host

With the following path and query parameters:

Path Parameters

Name Description Default Type

host (producer)

Required The host name and path of the CM.com SMS gateway, without a scheme, such as sgw01.cm.nl/gateway.ashx. The component prepends https:// and sends each message with an HTTP POST to this URL.

String

Query Parameters

Name Description Default Type

defaultFrom (producer)

Required The sender name (FROM) of the SMS, 1 to 11 characters, used when the SMSMessage has no from of its own. The from of an SMSMessage must be 1 to 11 letters or digits.

String

defaultMaxNumberOfParts (producer)

The maximum number of parts of a multipart message, from 1 to 8. A message that fits the GSM 03.38 character set and is longer than 160 characters is split into parts of 153 characters; any other message is sent as unicode (DCS 8) and is split into parts of 67 characters when it is longer than 70 characters. The component sets MAXIMUMNUMBEROFMESSAGEPARTS to the number of parts needed, capped at this value, and MINIMUMNUMBEROFMESSAGEPARTS to 1; it sets neither when one part is enough or when this value is 1. A message that needs more parts can be truncated.

8

int

productToken (producer)

Required The product token of the CM.com account, a UUID, that authenticates the requests. The component sends it in the AUTHENTICATION/PRODUCTTOKEN element of the XML body of each request. A value that is not a UUID fails when the producer is created.

String

testConnectionOnStartup (producer)

Whether the producer checks on startup that the gateway is reachable, by sending an HTTP HEAD request to the gateway URL. The startup fails with a HostUnavailableException when the request fails, such as for an unknown host or a TLS error; any HTTP status code counts as reachable, and the product token is not checked.

false

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

Message Body

The message body at each side of the CM SMS Gateway component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

pojo (org.apache.camel.component.cm.client.SMSMessage)

The SMS as an org.apache.camel.component.cm.client.SMSMessage with the text and the E.164 phone number; text, a Map or no body fails. A message that fails its validation, such as a phone number not in E.164 form, fails.

Producer output

unchanged

The body is left as it was; the call returns nothing and a rejected message fails the exchange.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Example

cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=DefaultSender&defaultMaxNumberOfParts=8&productToken=xxxxx

The message body is an org.apache.camel.component.cm.client.SMSMessage, with the text and the phone number. The following route sends the message body as an SMS to the number in the phoneNumber header:

- route:
    from:
      uri: direct:sms
      steps:
        - setBody:
            expression:
              groovy:
                expression: "new org.apache.camel.component.cm.client.SMSMessage(body, headers.phoneNumber)"
        - to:
            uri: cm-sms:sgw01.cm.nl/gateway.ashx
            parameters:
              defaultFrom: DefaultSender
              defaultMaxNumberOfParts: 8
              productToken: "{{cm.product-token}}"

You can try this project to see how camel-cm-sms can be integrated in a camel route.