Search in sources :

Example 41 with Language

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

the class ToDynamicDefinition method createExpression.

protected Expression createExpression(RouteContext routeContext) {
    List<Expression> list = new ArrayList<Expression>();
    String[] parts = safeSplitRaw(uri);
    for (String part : parts) {
        // the part may have optional language to use, so you can mix languages
        String value = ObjectHelper.after(part, "language:");
        if (value != null) {
            String before = ObjectHelper.before(value, ":");
            String after = ObjectHelper.after(value, ":");
            if (before != null && after != null) {
                // maybe its a language, must have language: as prefix
                try {
                    Language partLanguage = routeContext.getCamelContext().resolveLanguage(before);
                    if (partLanguage != null) {
                        Expression exp = partLanguage.createExpression(after);
                        list.add(exp);
                        continue;
                    }
                } catch (NoSuchLanguageException e) {
                // ignore
                }
            }
        }
        // fallback and use simple language
        Language lan = routeContext.getCamelContext().resolveLanguage("simple");
        Expression exp = lan.createExpression(part);
        list.add(exp);
    }
    Expression exp;
    if (list.size() == 1) {
        exp = list.get(0);
    } else {
        exp = ExpressionBuilder.concatExpression(list);
    }
    return exp;
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Example 42 with Language

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

the class DefaultErrorHandlerBuilder method getRetryWhilePolicy.

public Predicate getRetryWhilePolicy(CamelContext context) {
    Predicate answer = getRetryWhile();
    if (getRetryWhileRef() != null) {
        // its a bean expression
        Language bean = context.resolveLanguage("bean");
        answer = bean.createPredicate(getRetryWhileRef());
    }
    return answer;
}
Also used : Language(org.apache.camel.spi.Language) Predicate(org.apache.camel.Predicate)

Example 43 with Language

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

the class OsgiLanguageResolverTest method testOsgiResolverFindLanguageFallbackTest.

@Test
public void testOsgiResolverFindLanguageFallbackTest() throws IOException {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("fuffy-language", new SampleLanguage(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    OsgiLanguageResolver resolver = new OsgiLanguageResolver(getBundleContext());
    Language language = resolver.resolveLanguage("fuffy", camelContext);
    assertNotNull("We should find fuffy language", language);
    assertTrue("We should find the fallback language", ((SampleLanguage) language).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Language(org.apache.camel.spi.Language) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 44 with Language

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

the class OsgiLanguageResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.

@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws IOException {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("fuffy", new SampleLanguage(false));
    registry.put("fuffy-language", new SampleLanguage(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    OsgiLanguageResolver resolver = new OsgiLanguageResolver(getBundleContext());
    Language language = resolver.resolveLanguage("fuffy", camelContext);
    assertNotNull("We should find fuffy language", language);
    assertFalse("We should NOT find the fallback language", ((SampleLanguage) language).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Language(org.apache.camel.spi.Language) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

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