use of org.apache.camel.k.SourceDefinition in project camel-k-runtime by apache.
the class Sources method fromBytes.
public static SourceDefinition fromBytes(String id, String name, String language, String loader, List<String> interceptors, byte[] content) {
SourceDefinition answer = new SourceDefinition();
answer.setId(id);
answer.setName(name);
answer.setLanguage(language);
answer.setLoader(loader);
answer.setInterceptors(interceptors != null ? interceptors : Collections.emptyList());
answer.setContent(content);
return answer;
}
use of org.apache.camel.k.SourceDefinition in project camel-k-runtime by apache.
the class Sources method computeDefinitionFromURI.
public static SourceDefinition computeDefinitionFromURI(String uri) throws Exception {
final String location = StringSupport.substringBefore(uri, "?");
if (!location.startsWith(Constants.SCHEME_PREFIX_CLASSPATH) && !location.startsWith(Constants.SCHEME_PREFIX_FILE)) {
throw new IllegalArgumentException("No valid resource format, expected scheme:path, found " + uri);
}
final String query = StringSupport.substringAfter(uri, "?");
final Map<String, Object> params = URISupport.parseQuery(query);
String language = (String) params.get("language");
if (ObjectHelper.isEmpty(language)) {
language = StringSupport.substringAfterLast(location, ":");
language = StringSupport.substringAfterLast(language, ".");
}
if (ObjectHelper.isEmpty(language)) {
throw new IllegalArgumentException("Unknown language " + language);
}
String name = (String) params.get("name");
if (name == null) {
name = StringSupport.substringAfter(location, ":");
name = StringSupport.substringBeforeLast(name, ".");
if (name.contains("/")) {
name = StringSupport.substringAfterLast(name, "/");
}
}
SourceDefinition answer = new SourceDefinition();
answer.setId((String) params.get("id"));
answer.setLocation(location);
answer.setName(name);
answer.setLanguage(language);
answer.setLoader((String) params.get("loader"));
answer.setInterceptors(StringSupport.split((String) params.get("interceptors"), ","));
answer.setCompressed(Boolean.parseBoolean((String) params.get("compression")));
return answer;
}
use of org.apache.camel.k.SourceDefinition in project camel-k-runtime by apache.
the class SourcesSupport method loadSources.
public static void loadSources(Runtime runtime, SourceDefinition... definitions) {
for (SourceDefinition definition : definitions) {
LOGGER.info("Loading routes from: {}", definition);
load(runtime, Sources.fromDefinition(definition));
}
}
Aggregations