use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class FtpEndpoint method createFtpClient.
protected FTPClient createFtpClient() throws Exception {
FTPClient client = new FTPClient();
// default ParserFactory
if (isOsgi()) {
ClassResolver cr = getCamelContext().getClassResolver();
OsgiParserFactory opf = new OsgiParserFactory(cr);
client.setParserFactory(opf);
}
return client;
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class KafkaEndpoint method updateClassProperties.
public void updateClassProperties(Properties props) {
try {
if (getCamelContext() != null) {
ClassResolver resolver = getCamelContext().getClassResolver();
replaceWithClass(props, ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, resolver, Serializer.class);
replaceWithClass(props, ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, resolver, Serializer.class);
replaceWithClass(props, ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, resolver, Deserializer.class);
replaceWithClass(props, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, resolver, Deserializer.class);
try {
//doesn't exist in old version of Kafka client so detect and only call the method if
//the field/config actually exists
Field f = ProducerConfig.class.getDeclaredField("PARTITIONER_CLASS_CONFIG");
if (f != null) {
loadParitionerClass(resolver, props);
}
} catch (NoSuchFieldException e) {
//ignore
} catch (SecurityException e) {
//ignore
}
//doesn't work as it needs to be List<String> :(
//replaceWithClass(props, "partition.assignment.strategy", resolver, PartitionAssignor.class);
}
} catch (Throwable t) {
//can ignore and Kafka itself might be able to handle it, if not, it will throw an exception
LOG.debug("Problem loading classes for Serializers", t);
}
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class CamelContextHelper method findEips.
/**
* Find information about all the EIPs from camel-core.
*/
public static SortedMap<String, Properties> findEips(CamelContext camelContext) throws LoadPropertiesException {
SortedMap<String, Properties> answer = new TreeMap<String, Properties>();
ClassResolver resolver = camelContext.getClassResolver();
LOG.debug("Finding all EIPs using class resolver: {} -> {}", new Object[] { resolver });
URL url = resolver.loadResourceAsURL(MODEL_DESCRIPTOR);
if (url != null) {
InputStream is = null;
try {
is = url.openStream();
String all = IOHelper.loadText(is);
String[] lines = all.split("\n");
for (String line : lines) {
if (line.startsWith("#")) {
continue;
}
Properties prop = new Properties();
prop.put("name", line);
String description = null;
String label = null;
String javaType = null;
String title = null;
// enrich with more meta-data
String json = camelContext.explainEipJson(line, false);
if (json != null) {
List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("model", json, false);
for (Map<String, String> row : rows) {
if (row.get("title") != null) {
title = row.get("title");
}
if (row.get("description") != null) {
description = row.get("description");
}
if (row.get("label") != null) {
label = row.get("label");
}
if (row.get("javaType") != null) {
javaType = row.get("javaType");
}
}
}
if (title != null) {
prop.put("title", title);
}
if (description != null) {
prop.put("description", description);
}
if (label != null) {
prop.put("label", label);
}
if (javaType != null) {
prop.put("class", javaType);
}
answer.put(line, prop);
}
} catch (IOException e) {
throw new LoadPropertiesException(url, e);
} finally {
IOHelper.close(is);
}
}
return answer;
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class CamelContextHelper method findComponents.
/**
* Finds all possible Components on the classpath, already registered in {@link org.apache.camel.CamelContext},
* and from the {@link org.apache.camel.spi.Registry}.
*/
public static SortedMap<String, Properties> findComponents(CamelContext camelContext) throws LoadPropertiesException {
ClassResolver resolver = camelContext.getClassResolver();
LOG.debug("Finding all components using class resolver: {} -> {}", new Object[] { resolver });
Enumeration<URL> iter = resolver.loadAllResourcesAsURL(COMPONENT_DESCRIPTOR);
return findComponents(camelContext, iter);
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class DefaultCamelContext method getEipParameterJsonSchema.
public String getEipParameterJsonSchema(String eipName) throws IOException {
// the eip json schema may be in some of the sub-packages so look until we find it
String[] subPackages = new String[] { "", "/config", "/dataformat", "/language", "/loadbalancer", "/rest" };
for (String sub : subPackages) {
String path = CamelContextHelper.MODEL_DOCUMENTATION_PREFIX + sub + "/" + eipName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
if (inputStream != null) {
log.debug("Loading eip JSON Schema for: {} using class resolver: {} -> {}", new Object[] { eipName, resolver, inputStream });
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
}
return null;
}
Aggregations