title: Camel Simple Expression
body: <p>My Initial requirement is I need to call the web service for  n no times. If I get the response with in n times I need to update the status code success. If n time exceeds then i need to update the failure in DB. For this I try some POC. I am getting the Exception  while validating the simple expression the Code </p>
  
  <pre><code>   &lt;simple&gt;${body.counter} &lt; 4 &lt;/simple&gt;
  </code></pre>
  
  <p>I have attached the Entire source code.</p>
  
  <pre><code>public class MyBean {
      public String appendCamel(String msg, int i) throws Exception {
          System.out.println("The Value of i : " + i);
          i = i + 1;
          if (i &lt; 3)
              throw new Exception("Manually Throwed Error " + i);
          else            
          return "Camel ".concat(msg);
      }
      public Message increment(Message m) {
          m.setCounter(m.getCounter() + 1);
          return m;
      }
  }
  </code></pre>
  
  <p>Message:</p>
  
  <pre><code>    public class Message {
      String text;
      int counter;
  
      public String getText() {
          return text;
      }
  
      public void setText(String text) {
          this.text = text;
      }
  
      public int getCounter() {
          return counter;
      }
  
      public void setCounter(int counter) {
          this.counter = counter;
      }
  
      @Override
      public String toString() {
          return "Message [text=" + text + ", counter=" + counter + "]";
      }
  
  }
  </code></pre>
  
  <p>Camel Context:</p>
  
  <pre><code>&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
         &lt;route id="hello"&gt;
            &lt;from uri="direct:hello" /&gt;
               &lt;camel:doTry&gt;
                  &lt;to uri="bean:myBean?method=appendCamel(${body.text},${body.counter})" /&gt;
                  &lt;to uri="stream:out" /&gt;
                  &lt;camel:doCatch&gt;
                      &lt;exception&gt;java.lang.Exception&lt;/exception&gt;
                      &lt;camel:to uri="bean:myBean?method=increment(${header.originalvalue})" /&gt;
                      &lt;camel:choice&gt;
                          &lt;camel:when&gt;
                              &lt;simple&gt;${body.counter} &lt; 4 &lt;/simple&gt;
                              &lt;camel:to uri="direct:hello" /&gt;
                          &lt;/camel:when&gt;
                          &lt;camel:otherwise&gt;
                              &lt;camel:to uri="stream:out" /&gt;
                          &lt;/camel:otherwise&gt;
                      &lt;/camel:choice&gt;
                  &lt;/camel:doCatch&gt;
              &lt;/camel:doTry&gt;
          &lt;/route&gt;
      &lt;/camelContext&gt;
  </code></pre>
  
  <p>MyMain Class</p>
  
  <pre><code>public class CamelHelloWorldSpringExample {
  public static void main(String[] args) throws Exception {
      ApplicationContext appContext = new ClassPathXmlApplicationContext(
              "applicationContext.xml");
      CamelContext camelContext = SpringCamelContext.springCamelContext(
              appContext, false);
      try {
          ProducerTemplate template = camelContext.createProducerTemplate();
          camelContext.start();
          Message message = new Message();
          message.setCounter(0);
          message.setText("Hello World");
          template.sendBody("direct:hello", message);
          Thread.sleep(2000);
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          System.out.println("Stopping camel context");
          camelContext.stop();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Generated Exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 33; The content of elements must consist of well-formed character data or markup.
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
      at com.javacodegeeks.camel.CamelHelloWorldSpringExample.main(CamelHelloWorldSpringExample.java:11)
  Caused by: org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 33; The content of elements must consist of well-formed character data or markup.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
      at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1388)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.startOfMarkup(XMLDocumentFragmentScannerImpl.java:2567)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2665)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:237)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
      at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
      ... 14 more
  </code></pre>