use of org.apache.camel.spi.Language in project camel by apache.
the class OsgiLanguageResolverTest method testOsgiResolverFindLanguageTest.
@Test
public void testOsgiResolverFindLanguageTest() throws IOException {
CamelContext camelContext = new DefaultCamelContext();
OsgiLanguageResolver resolver = new OsgiLanguageResolver(getBundleContext());
Language language = resolver.resolveLanguage("simple", camelContext);
assertNotNull("We should find simple language", language);
}
use of org.apache.camel.spi.Language in project camel by apache.
the class CamelMockBundleContext method getService.
public Object getService(@SuppressWarnings("rawtypes") ServiceReference reference) {
String[] classNames = (String[]) reference.getProperty(Constants.OBJECTCLASS);
String classNames0 = classNames != null ? classNames[0] : null;
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
if (classNames0 != null && classNames0.equals("org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (pid != null && pid.equals(SERVICE_PID_PREFIX + "org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (classNames0 != null && classNames0.equals(ComponentResolver.class.getName())) {
return new ComponentResolver() {
public Component resolveComponent(String name, CamelContext context) throws Exception {
if (name.equals("file_test")) {
return new FileComponent();
}
return null;
}
};
} else if (classNames0 != null && classNames0.equals(LanguageResolver.class.getName())) {
return new LanguageResolver() {
public Language resolveLanguage(String name, CamelContext context) {
if (name.equals("simple")) {
return new SimpleLanguage();
}
return null;
}
};
} else {
return null;
}
}
use of org.apache.camel.spi.Language in project camel by apache.
the class OsgiLanguageResolver method resolveLanguage.
public Language resolveLanguage(String name, CamelContext context) {
// lookup in registry first
Language lang = ResolverHelper.lookupLanguageInRegistryWithFallback(context, name);
if (lang != null) {
return lang;
}
lang = getLanguage(name, context);
if (lang != null) {
return lang;
}
LanguageResolver resolver = getLanguageResolver("default", context);
if (resolver != null) {
return resolver.resolveLanguage(name, context);
}
throw new NoSuchLanguageException(name);
}
use of org.apache.camel.spi.Language in project camel by apache.
the class ExpressionMapper method convert.
@Override
public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) {
try {
if (currentExchange.get() == null) {
throw new IllegalStateException("Current exchange has not been set for ExpressionMapper");
}
Expression exp;
// Resolve the language being used for this expression and evaluate
Exchange exchange = currentExchange.get();
Language expLang = exchange.getContext().resolveLanguage(getLanguagePart());
String scheme = getSchemePart();
if (scheme != null && (scheme.equalsIgnoreCase("classpath") || scheme.equalsIgnoreCase("file") || scheme.equalsIgnoreCase("http"))) {
String path = getPathPart();
try {
exp = expLang.createExpression(resolveScript(scheme + ":" + path));
} catch (IOException e) {
throw new IllegalStateException("Expression script specified but not found", e);
}
} else {
exp = expLang.createExpression(getExpressionPart());
}
return exp.evaluate(exchange, destinationClass);
} finally {
done();
}
}
use of org.apache.camel.spi.Language in project camel by apache.
the class LanguageComponent method createEndpoint.
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
String name = ObjectHelper.before(remaining, ":");
String script = ObjectHelper.after(remaining, ":");
// no script then remaining is the language name
if (name == null && script == null) {
name = remaining;
}
if (ObjectHelper.isEmpty(name)) {
throw new IllegalArgumentException("Illegal syntax. Name of language not given in uri: " + uri);
}
Language language = getCamelContext().resolveLanguage(name);
String resourceUri = null;
String resource = script;
if (resource != null) {
if (resource.startsWith(RESOURCE)) {
resource = resource.substring(RESOURCE.length());
}
if (ResourceHelper.hasScheme(resource)) {
// the script is a uri for a resource
resourceUri = resource;
// then the script should be null
script = null;
} else {
// the script is provided as text in the uri, so decode to utf-8
script = URLDecoder.decode(script, "UTF-8");
// then the resource should be null
resourceUri = null;
}
}
LanguageEndpoint endpoint = new LanguageEndpoint(uri, this, language, null, resourceUri);
endpoint.setScript(script);
setProperties(endpoint, parameters);
return endpoint;
}
Aggregations