I’m assuming the simple block you shared is for the when clause, but it doesn’t 
have a comparison - did you miss something? 

I put together a quick test that shows one way to do this
public class ScratchTest extends CamelTestSupport {
  static final String SOURCE_URI = "direct://source";
  static final String WHEN_TARGET = "mock://when-target";
  static final String OTHERWISE_TARGET = "mock://otherwise-target";

  static final String EXCHANGE_PROPERTY_KEY = "the-foo";

  Exchange exchange;

  @EndpointInject(uri = WHEN_TARGET)
  MockEndpoint whenTarget;

  @EndpointInject(uri = OTHERWISE_TARGET)
  MockEndpoint otherwiseTarget;

  @Override
  protected void doPostSetup() throws Exception {
    super.doPostSetup();

    template.setDefaultEndpointUri(SOURCE_URI);

    exchange = createExchangeWithBody("The Body");
  }

  @Override
  protected RoutesBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
      @Override
      public void configure() throws Exception {
        from(SOURCE_URI)
            .log("Property value is ${exchangeProperty." + 
EXCHANGE_PROPERTY_KEY + ".counter}")
            .choice()
              .when(simple("${exchangeProperty." + EXCHANGE_PROPERTY_KEY + 
".counter} > 0"))
                .to(WHEN_TARGET)
              .otherwise()
                .to(OTHERWISE_TARGET)
            .end();
      }
    };
  }

  @Test
  public void testCounterGreaterThanZero() throws Exception {
    whenTarget.expectedMessageCount(1);
    otherwiseTarget.expectedMessageCount(0);

    exchange.setProperty(EXCHANGE_PROPERTY_KEY, new CounterBean(5));

    template.send(exchange);

    assertMockEndpointsSatisfied();
  }

  @Test
  public void testCounterLessThanZero() throws Exception {
    whenTarget.expectedMessageCount(0);
    otherwiseTarget.expectedMessageCount(1);

    exchange.setProperty(EXCHANGE_PROPERTY_KEY, new CounterBean(-5));

    template.send(exchange);

    assertMockEndpointsSatisfied();
  }

  @Test
  public void testCounterEqualToZero() throws Exception {
    whenTarget.expectedMessageCount(0);
    otherwiseTarget.expectedMessageCount(1);

    exchange.setProperty(EXCHANGE_PROPERTY_KEY, new CounterBean(0));

    template.send(exchange);

    assertMockEndpointsSatisfied();
  }
}

And here’s the source for the CounterBean
public class CounterBean {
  int counter;

  public CounterBean(int counter) {
    this.counter = counter;
  }

  public int getCounter() {
    return counter;
  }

  public void setCounter(int counter) {
    this.counter = counter;
  }
}

HTH

> On Feb 23, 2018, at 2:28 AM, christian.ja...@innogy.com wrote:
> 
> Hi there,
> 
> I have an object of a class "Foo" in an exchange property named "the-foo". 
> The "Foo" class has an int property "counter" with a getter. In my route, I 
> have to check with a choice- and a when-clause if this counter is greater 
> than zero, then proceed with next step #1, otherwise proceed with next step 
> #2. I don't see how I could get the counter property.
> 
> simple("${exchangeProperty.the-foo.counter}")
> 
> did not work.
> 
> The only solution I found was to set the exchange property into the body and 
> then check the counter there, but this is not an ideal solution.
> 
> Any help is appreciated.
> 
> Kind regards,
> Christian Jacob
> 
> Innogy SE
> Retail IT
> Integration and Digital Solutions (AFS-IGI)
> Rellinghauser Str. 37
> 45128 Essen
> T intern: 70-20581
> T extern: +49 (0)201 12 20582
> T mobil: +49 (0)1622843981
> Fax: +49 (0)201 12 24796
> mailto: christian.ja...@innogy.com
> ----------------------------------------------------------------
> innogy SE
> Vorsitzender des Aufsichtsrates: Dr. Erhard Schipporeit
> Vorstand: Uwe Tigges (Vorsitzender), Dr. Hans Buenting,
> Dr. Bernhard Guenther, Martin Herrmann, Hildegard Mueller
> Sitz der Gesellschaft: Essen, Eingetragen beim Amtsgericht Essen,
> Handelsregister-Nr. HRB 27091, USt-IdNr. DE304171711

Reply via email to