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;
}
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;
}
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());
}
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());
}
Aggregations