Search in sources :

Example 6 with ClassResolver

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;
}
Also used : ClassResolver(org.apache.camel.spi.ClassResolver) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 7 with ClassResolver

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);
    }
}
Also used : Field(java.lang.reflect.Field) ClassResolver(org.apache.camel.spi.ClassResolver)

Example 8 with ClassResolver

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;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Properties(java.util.Properties) URL(java.net.URL) ClassResolver(org.apache.camel.spi.ClassResolver) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 9 with ClassResolver

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);
}
Also used : ClassResolver(org.apache.camel.spi.ClassResolver) URL(java.net.URL)

Example 10 with ClassResolver

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;
}
Also used : InputStream(java.io.InputStream) PackageScanClassResolver(org.apache.camel.spi.PackageScanClassResolver) ClassResolver(org.apache.camel.spi.ClassResolver)

Aggregations

ClassResolver (org.apache.camel.spi.ClassResolver)13 InputStream (java.io.InputStream)6 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)5 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)3 FactoryFinder (org.apache.camel.spi.FactoryFinder)3 Test (org.junit.Test)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Properties (java.util.Properties)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 CamelContext (org.apache.camel.CamelContext)1 Component (org.apache.camel.Component)1 XsltBuilder (org.apache.camel.builder.xml.XsltBuilder)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1