@Override public Expression createExpression(CamelContext camelContext) { if (resultType == null && resultTypeName != null) { try { resultType = camelContext.getClassResolver().resolveMandatoryClass(resultTypeName); } catch (ClassNotFoundException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } String exp = getExpression(); // should be true by default boolean isTrim = getTrim() == null || getTrim(); if (exp != null && isTrim) { exp = exp.trim(); } SimpleBuilder answer = new SimpleBuilder(exp); answer.setResultType(resultType); return answer; }
/** * A property from the property component in a expression * is processed when the expression is evaluated with exchange * See https://issues.apache.org/jira/browse/CAMEL-4843 * Now camel doesn't support the properties expression of {{test}} */ @Test public void testProperty() throws Exception { System.setProperty("test", "testValue"); PropertiesComponent pc = new PropertiesComponent(); CamelContext context = new DefaultCamelContext(); context.addComponent("properties", pc); // try to setup the property Exchange exchange = new DefaultExchange(context); String result = SimpleBuilder.simple("${properties:test}").evaluate(exchange, String.class); Assert.assertEquals("testValue", result); System.clearProperty("test"); }
public void process(Exchange exchange) throws Exception { SimpleBuilder simple = new SimpleBuilder( "${body} contains 'Camel'"); if (!simple.matches(exchange)) { throw new Exception("This is NOT a Camel message"); } }
@Test public void testReplyingFromMockByExpression() throws InterruptedException { mockReplying.returnReplyBody(SimpleBuilder.simple("Hello ${body}")); mockOut.expectedBodiesReceived("Hello Camel"); in.sendBody("Camel"); assertMockEndpointsSatisfied(); }
public void setSimplePredicate(String expression) { this.predicate = SimpleBuilder.simple(expression, Boolean.class); }
/** * @param expression A regular expression to evaluate against the message body */ default Predicate regex(String expression) { return new SimpleBuilder("${body} regex '" + expression + "'"); }