title: Using camel to route from webapp
body: <p>I am trying to use camel to route a message from my web app to a queue and I am using a bean reference to grab the message from a function that is run whenever an input is given to the browser. However, camel creates a Null exception when it continues to poll because there isn't always an input every half second. How can I make the camel only pick up the message when there is one to pick up? Browserbean is the function that returns the message from the browser.</p>
  
  <p>Here is my camel route:</p>
  
  <pre><code>&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;route&gt;
      &lt;from uri="browserBean"/&gt;
      &lt;to uri="jms:queue:testQSource"/&gt;
      &lt;to uri="myBean"/&gt;
      &lt;log message="Routing message from testQSource to testQDestination queue with data ${body}"/&gt;
      &lt;to uri="jms:queue:testQDestination"/&gt;
      &lt;to uri="finalBean"/&gt;
      &lt;log message="message: ${body}"/&gt;
  &lt;/route&gt;
  &lt;/camelContext&gt;
  
  &lt;camel:camelContext id="camel-client"&gt;
      &lt;camel:template id="camelTemplate" /&gt;
  &lt;/camel:camelContext&gt;
  
      &lt;bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent"&gt;
          &lt;property name="brokerURL" value="tcp://localhost:61616" /&gt;
      &lt;/bean&gt;
      &lt;bean id="myBean" class="com.example.integration.modifier"/&gt;
      &lt;bean id="finalBean" class="com.example.integration.ActionApp"/&gt;
      &lt;bean id="browserBean" class="com.hello.integration.GreetingController"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Here is the stack trace I get every second or so:</p>
  
  <pre><code>Message History
  ---------------------------------------------------------------------------------------         ------------------------------------------------
  RouteId              ProcessorId          Processor                                                                            Elapsed (ms)
  [route1            ] [route1            ] [browserBean                                                                      ] [         0]
  [route1            ] [to1               ] [jms:queue:testQSource                                                         ] [         0]
  
  Exchange
  ---------------------------------------------------------------------------------------------------------------------------------------
  Exchange[
  Id                  ID-CO183LTCS06-59664-1403735006145-0-16
  ExchangePattern     InOnly
  Headers             {breadcrumbId=ID-CO183LTCS06-59664-1403735006145-0-15,          CamelRedelivered=false, CamelRedeliveryCounter=0}
  BodyType            null
  Body                [Body is null]
  ]
  
  Stacktrace
  ---------------------------------------------------------------------------------------    ------------------------------------------------
  
  java.lang.NullPointerException: null
  at com.hello.integration.GreetingController.greeting(GreetingController.java:15)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:407)
  at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:278)
  at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:251)
  at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:166)
  at     org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
  at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:67)
  at    org.apache.camel.impl.ProcessorPollingConsumer.receive(ProcessorPollingConsumer.java:58)
  at    org.apache.camel.impl.ProcessorPollingConsumer.receiveNoWait(ProcessorPollingConsumer.java:    66)
  at     org.apache.camel.impl.DefaultScheduledPollConsumer.poll(DefaultScheduledPollConsumer.java:4    8)
  at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
  at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
  at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
  at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
  at     java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown      Source)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown     Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>