Search in sources :

Example 11 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class SimpleTest method assertExpressionResultInstanceOf.

protected void assertExpressionResultInstanceOf(String expressionText, Class<?> expectedType) {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression(expressionText);
    assertNotNull("Cannot assert type when no type is provided", expectedType);
    assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
    Object answer = expression.evaluate(exchange, Object.class);
    assertIsInstanceOf(expectedType, answer);
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression)

Example 12 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class DefaultCamelContext method resolveLanguage.

// Helper methods
// -----------------------------------------------------------------------
public Language resolveLanguage(String language) {
    Language answer;
    synchronized (languages) {
        answer = languages.get(language);
        // check if the language is singleton, if so return the shared instance
        if (answer instanceof IsSingleton) {
            boolean singleton = ((IsSingleton) answer).isSingleton();
            if (singleton) {
                return answer;
            }
        }
        // language not known or not singleton, then use resolver
        answer = getLanguageResolver().resolveLanguage(language, this);
        // inject CamelContext if aware
        if (answer != null) {
            if (answer instanceof CamelContextAware) {
                ((CamelContextAware) answer).setCamelContext(this);
            }
            if (answer instanceof Service) {
                try {
                    startService((Service) answer);
                } catch (Exception e) {
                    throw ObjectHelper.wrapRuntimeCamelException(e);
                }
            }
            languages.put(language, answer);
        }
    }
    return answer;
}
Also used : IsSingleton(org.apache.camel.IsSingleton) CamelContextAware(org.apache.camel.CamelContextAware) Language(org.apache.camel.spi.Language) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SuspendableService(org.apache.camel.SuspendableService) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException)

Example 13 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class ManagedBacklogDebugger method validateConditionalBreakpoint.

public String validateConditionalBreakpoint(String language, String predicate) {
    Language lan = null;
    try {
        lan = camelContext.resolveLanguage(language);
        lan.createPredicate(predicate);
        return null;
    } catch (Exception e) {
        if (lan == null) {
            return e.getMessage();
        } else {
            return "Invalid syntax " + predicate + " due: " + e.getMessage();
        }
    }
}
Also used : Language(org.apache.camel.spi.Language) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException)

Example 14 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class ContextTestSupport method assertPredicate.

/**
     * Asserts that the given language name and predicate expression evaluates
     * to the expected value on the message exchange
     */
protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) {
    Language language = assertResolveLanguage(languageName);
    Predicate predicate = language.createPredicate(expressionText);
    assertNotNull("No Predicate could be created for text: " + expressionText + " language: " + language, predicate);
    assertPredicate(predicate, exchange, expected);
}
Also used : Language(org.apache.camel.spi.Language)

Example 15 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class LanguageTestSupport method evaluateExpression.

/**
     * Evaluates the expression
     */
protected Object evaluateExpression(String expressionText, String expectedValue) {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression(expressionText);
    assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
    Object value;
    if (expectedValue != null) {
        value = expression.evaluate(exchange, expectedValue.getClass());
    } else {
        value = expression.evaluate(exchange, Object.class);
    }
    log.debug("Evaluated expression: " + expression + " on exchange: " + exchange + " result: " + value);
    return value;
}
Also used : Language(org.apache.camel.spi.Language)

Aggregations

Language (org.apache.camel.spi.Language)44 Expression (org.apache.camel.Expression)15 Test (org.junit.Test)13 Exchange (org.apache.camel.Exchange)6 CamelContext (org.apache.camel.CamelContext)5 Predicate (org.apache.camel.Predicate)5 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)4 SqlTest (org.apache.camel.builder.sql.SqlTest)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 File (java.io.File)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 IOException (java.io.IOException)2 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 LanguageResolver (org.apache.camel.spi.LanguageResolver)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1