Search in sources :

Example 96 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SimpleParserExpressionTest method testUnaryLenient.

public void testUnaryLenient() throws Exception {
    exchange.getIn().setHeader("JMSMessageID", "JMSMessageID-123");
    exchange.getIn().setBody("THE MSG ID ${header.JMSMessageID} isA --");
    SimpleExpressionParser parser = new SimpleExpressionParser("THE MSG ID ${header.JMSMessageID} isA --", true);
    Expression exp = parser.parseExpression();
    assertEquals("THE MSG ID JMSMessageID-123 isA --", exp.evaluate(exchange, String.class));
}
Also used : Expression(org.apache.camel.Expression)

Example 97 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SimpleParserExpressionTest method testSimpleSingleQuoteEol.

public void testSimpleSingleQuoteEol() throws Exception {
    SimpleExpressionParser parser = new SimpleExpressionParser("'Hello' World", true);
    Expression exp = parser.parseExpression();
    assertEquals("'Hello' World", exp.evaluate(exchange, String.class));
}
Also used : Expression(org.apache.camel.Expression)

Example 98 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SimpleParserExpressionTest method testSimpleSingleQuoteWithFunction.

public void testSimpleSingleQuoteWithFunction() throws Exception {
    exchange.getIn().setBody("World");
    SimpleExpressionParser parser = new SimpleExpressionParser("'Hello ${body} how are you?'", true);
    Expression exp = parser.parseExpression();
    assertEquals("'Hello World how are you?'", exp.evaluate(exchange, String.class));
}
Also used : Expression(org.apache.camel.Expression)

Example 99 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SqlLanguageTest method testExpressionWithHeaderVariable.

@Test
public void testExpressionWithHeaderVariable() throws Exception {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression("SELECT * FROM org.apache.camel.builder.sql.Person where name = :fooHeader");
    List<?> value = expression.evaluate(exchange, List.class);
    assertEquals("List size", 1, value.size());
    for (Object person : value) {
        log.info("Found: " + person);
        assertEquals("name", "James", ((Person) person).getName());
    }
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression) SqlTest(org.apache.camel.builder.sql.SqlTest) Test(org.junit.Test)

Example 100 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class BeanInfo method createParameterUnmarshalExpressionForAnnotation.

private Expression createParameterUnmarshalExpressionForAnnotation(Class<?> clazz, Method method, Class<?> parameterType, Annotation annotation) {
    if (annotation instanceof AttachmentObjects) {
        return ExpressionBuilder.attachmentObjectsExpression();
    } else if (annotation instanceof Attachments) {
        return ExpressionBuilder.attachmentsExpression();
    } else if (annotation instanceof Property) {
        Property propertyAnnotation = (Property) annotation;
        return ExpressionBuilder.exchangePropertyExpression(propertyAnnotation.value());
    } else if (annotation instanceof ExchangeProperty) {
        ExchangeProperty propertyAnnotation = (ExchangeProperty) annotation;
        return ExpressionBuilder.exchangePropertyExpression(propertyAnnotation.value());
    } else if (annotation instanceof Properties) {
        return ExpressionBuilder.exchangePropertiesExpression();
    } else if (annotation instanceof ExchangeProperties) {
        return ExpressionBuilder.exchangePropertiesExpression();
    } else if (annotation instanceof Header) {
        Header headerAnnotation = (Header) annotation;
        return ExpressionBuilder.headerExpression(headerAnnotation.value());
    } else if (annotation instanceof Headers) {
        return ExpressionBuilder.headersExpression();
    } else if (annotation instanceof OutHeaders) {
        return ExpressionBuilder.outHeadersExpression();
    } else if (annotation instanceof ExchangeException) {
        return ExpressionBuilder.exchangeExceptionExpression(CastUtils.cast(parameterType, Exception.class));
    } else if (annotation instanceof PropertyInject) {
        PropertyInject propertyAnnotation = (PropertyInject) annotation;
        Expression inject = ExpressionBuilder.propertiesComponentExpression(propertyAnnotation.value(), null, propertyAnnotation.defaultValue());
        return ExpressionBuilder.convertToExpression(inject, parameterType);
    } else {
        LanguageAnnotation languageAnnotation = annotation.annotationType().getAnnotation(LanguageAnnotation.class);
        if (languageAnnotation != null) {
            Class<?> type = languageAnnotation.factory();
            Object object = camelContext.getInjector().newInstance(type);
            if (object instanceof AnnotationExpressionFactory) {
                AnnotationExpressionFactory expressionFactory = (AnnotationExpressionFactory) object;
                return expressionFactory.createExpression(camelContext, annotation, languageAnnotation, parameterType);
            } else {
                LOG.warn("Ignoring bad annotation: " + languageAnnotation + "on method: " + method + " which declares a factory: " + type.getName() + " which does not implement " + AnnotationExpressionFactory.class.getName());
            }
        }
    }
    return null;
}
Also used : OutHeaders(org.apache.camel.OutHeaders) Headers(org.apache.camel.Headers) OutHeaders(org.apache.camel.OutHeaders) ExchangeProperty(org.apache.camel.ExchangeProperty) ExchangeProperties(org.apache.camel.ExchangeProperties) Properties(org.apache.camel.Properties) AttachmentObjects(org.apache.camel.AttachmentObjects) Attachments(org.apache.camel.Attachments) ExchangeProperties(org.apache.camel.ExchangeProperties) Header(org.apache.camel.Header) Expression(org.apache.camel.Expression) ExchangeException(org.apache.camel.ExchangeException) Property(org.apache.camel.Property) ExchangeProperty(org.apache.camel.ExchangeProperty) PropertyInject(org.apache.camel.PropertyInject) LanguageAnnotation(org.apache.camel.language.LanguageAnnotation)

Aggregations

Expression (org.apache.camel.Expression)184 Exchange (org.apache.camel.Exchange)44 Processor (org.apache.camel.Processor)24 Predicate (org.apache.camel.Predicate)22 DefaultExchange (org.apache.camel.impl.DefaultExchange)21 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)18 Language (org.apache.camel.spi.Language)16 ArrayList (java.util.ArrayList)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)15 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 SendProcessor (org.apache.camel.processor.SendProcessor)14 Test (org.junit.Test)8 SimpleParserException (org.apache.camel.language.simple.types.SimpleParserException)7 File (java.io.File)4 ExecutorService (java.util.concurrent.ExecutorService)4 SimpleIllegalSyntaxException (org.apache.camel.language.simple.types.SimpleIllegalSyntaxException)4 HashMap (java.util.HashMap)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CamelExchangeException (org.apache.camel.CamelExchangeException)3