title: Apache Camel: Send Text Message with Twilio
body: <p>I'm trying to send a text message over Apache Camel using the <a href="https://github.com/apache/camel/blob/master/components/camel-twilio/src/main/docs/twilio-component.adoc" rel="nofollow noreferrer"><code>camel-twilio</code> component</a>. Since I never used the Twilio API (neither natively nor using Apache Camel), I'm not sure if I got the parameters right. Here's the method I wrote:</p>
  
  <pre><code>/**
   * Sends a text message to the given recipient's number (parameter to)
   * 
   * @param username:
   *            Twilio username (email)
   * @param password:
   *            Twilio password (in plain text)
   * @param accountSid:
   *            Twilio account sid (from the dashboard)
   * @param from:
   *            registered phone number (starting with country prefix +XX)
   * @param to:
   *            the recipient's phone number (starting with country prefix +XX)
   * @param message:
   *            the message to be sent (plain text)
   * @throws Exception
   */
  public static void sendTextMessage(String username, String password, String accountSid, String from, String to,
          String message) throws Exception {
      String route = String.format("twilio:message/creator?username=%s&amp;password=%s&amp;accountSid=%s&amp;from=%s&amp;to=%s",
              username, password, accountSid, from, to);
      CamelContext context = new DefaultCamelContext();
      context.addRoutes(new RouteBuilder() {
          @Override
          public void configure() throws Exception {
              from("direct:message").to(route);
          }
      });
      context.start();
      ProducerTemplate producer = context.createProducerTemplate();
      producer.sendBody("direct:message", message);
      context.stop();
  }
  </code></pre>
  
  <p>The most important line is the creation of the route, the first of the method. When I'm running this method with parameters according to the JavaDoc, I get this error:</p>
  
  <pre><code>Caused by: org.apache.camel.RuntimeCamelException: Missing properties for creator, need one or more from [pathAccountSid, mediaUrl, messagingServiceSid, body]
  </code></pre>
  
  <p>So I thought to add the parameter <code>messagingServiceSid</code>, providing my <code>accountSid</code> again:</p>
  
  <pre><code>String route = String.format("twilio:message/creator?username=%s&amp;password=%s&amp;accountSid=%s&amp;from=%s&amp;to=%s&amp;messagingServiceSid=%s",
              username, password, accountSid, from, to, accountSid);
  </code></pre>
  
  <p>Now I get this error message:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: No matching method for message/creator, with arguments [messagingServiceSid, from, to]
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT: These are my Maven dependencies:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
          &lt;artifactId&gt;camel-core&lt;/artifactId&gt;
          &lt;version&gt;2.20.1&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
          &lt;artifactId&gt;camel-twilio&lt;/artifactId&gt;
          &lt;version&gt;2.20.1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>EDIT 2: Here's the modified and working version of the method:</p>
  
  <pre><code>/**
   * Sends a text message to the given recipient's number (parameter to)
   * 
   * @param accountSid:
   *            Twilio account sid (from the dashboard)
   * @param authToken:
   *            Twilio auth token (from the dashboard)
   * @param from:
   *            registered phone number (starting with country prefix +XX)
   * @param to:
   *            the recipient's phone number (starting with country prefix +XX)
   * @param message:
   *            the message to be sent (plain text)
   * @throws Exception
   */
  public static void sendTextMessage(String accountSid, String authToken, String from, String to, String message)
          throws Exception {
      CamelContext context = new DefaultCamelContext();
      TwilioComponent twilio = context.getComponent("twilio", TwilioComponent.class);
      twilio.getConfiguration().setUsername(accountSid);
      twilio.getConfiguration().setPassword(authToken);
      context.addRoutes(new RouteBuilder() {
          @Override
          public void configure() throws Exception {
              from("direct:message")
                      .setHeader("CamelTwilioTo", constant(new PhoneNumber(to)))
                      .setHeader("CamelTwilioFrom", constant(new PhoneNumber(from)))
                      .setHeader("CamelTwilioBody", constant(message))
                      .to("twilio://message/creator");
  
          }
      });
      context.start();
      ProducerTemplate producer = context.createProducerTemplate();
      producer.sendBody("direct:message", message);
      context.stop();
  }
  </code></pre>