title: Getting a Return Value from a Bean in Camel (Java)
body: <p>I am having a bit of trouble getting a return value from a bean in camel and using it in my route.</p>
  
  <p>I have a route that looks like this:</p>
  
  <pre><code>from(file:test/?delete=true)
  .unmarshal(jaxb)
  .bean(testBean, "testMethod")
  .to(direct:nextRoute);
  </code></pre>
  
  <p>The bean looks something like this:</p>
  
  <pre><code>public void testBean (PojoName pojoInstance){
    //do stuff 
    int i= 75; //a number I generate within the bean after I've started this method
  }
  </code></pre>
  
  <p>I want to use the number I generate inside of my bean and in my route. Something like this:</p>
  
  <pre><code>from(file:test/?delete=true)
      .unmarshal(jaxb)
      .bean(testBean, "testMethod")
      .log(integer generated from testBean)
      .to(direct:nextRoute); 
  </code></pre>
  
  <p><strong>What I tried:<br></strong>
  So, instead of returning void in my bean, I changed the return type to an int and returned the integer. Then, I was hoping to do something like this in my route:</p>
  
  <pre><code>.log("${body.intFromBean}")
  </code></pre>
  
  <p>My thinking is that once I return the value from a bean, it should store that value in the exchange body (at least that's what I'm getting from the Camel documentation). Then, I could access it in my route.</p>
  
  <p><strong>The Problem:</strong><br>
  However, when I change the testBean return type to an int, I get the following errors:</p>
  
  <pre><code>org.apache.camel.CamelExecutionException: Execution occurred during execution on the exchange 
  Caused by: org.apache.camel.InvalidPayloadException: No body available of type: PojoName but has value: numberIGenerated of type java.lang.Integer
  </code></pre>
  
  <p>(Sorry I don't have the full stack trace. I'm using the s.o mobile app)</p>
  
  <p><strong>My question:</strong><br>
  From reading some other s.o. submissions, I think I understand the problem. The message body is of one type and the return type is another. However, even when I tried using .</p>
  
  <pre><code>.convertTo(Integer.class)
  </code></pre>
  
  <p>before calling the bean, but that didn't work either. (Conceptually, that wouldn't work either because if I converted it to an int right after I unmarshalled it, I wouldn't be able to use the unmarshalled data. But I thought I'd try it anyway).</p>
  
  <p>Can someone help me understand how I can properly return the integer and use it in my route?</p>
  
  <p>I've read the documentation on bean binding and the exchange, and I thought I understood it well enough to do this. But I must be missing something.</p>