Search in sources :

Example 1 with CollectionStringBuffer

use of org.apache.camel.catalog.CollectionStringBuffer in project camel by apache.

the class ConnectorCatalogNexusRepository method addCustomCamelConnectorFromArtifact.

/**
     * Adds any discovered third party Camel connectors from the artifact.
     */
private void addCustomCamelConnectorFromArtifact(NexusArtifactDto dto, URL jarUrl) {
    try (URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl })) {
        String[] json = loadConnectorJSonSchema(classLoader);
        if (json != null) {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode tree = mapper.readTree(json[0]);
            String name = tree.get("name").textValue();
            String scheme = tree.get("scheme").textValue();
            String javaType = tree.get("javaType").textValue();
            String description = tree.get("description").textValue();
            Iterator<JsonNode> it = tree.withArray("labels").iterator();
            CollectionStringBuffer csb = new CollectionStringBuffer(",");
            while (it.hasNext()) {
                String text = it.next().textValue();
                csb.append(text);
            }
            addConnector(dto, name, scheme, javaType, description, csb.toString(), json[0], json[1], json[2]);
        }
    } catch (IOException e) {
        log.warn("Error scanning JAR for custom Camel components", e);
    }
}
Also used : CollectionStringBuffer(org.apache.camel.catalog.CollectionStringBuffer) URLClassLoader(java.net.URLClassLoader) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with CollectionStringBuffer

use of org.apache.camel.catalog.CollectionStringBuffer in project camel by apache.

the class DefaultMavenArtifactProvider method scanCamelConnectors.

protected void scanCamelConnectors(CamelConnectorCatalog camelConnectorCatalog, ClassLoader classLoader, String groupId, String artifactId, String version, Set<String> names) {
    String[] json = loadJSonSchemas(classLoader);
    if (json != null) {
        if (!camelConnectorCatalog.hasConnector(groupId, artifactId, version)) {
            try {
                ObjectMapper mapper = new ObjectMapper();
                JsonNode tree = mapper.readTree(json[0]);
                String name = tree.get("name").textValue();
                String scheme = tree.get("scheme").textValue();
                String javaType = tree.get("javaType").textValue();
                String description = tree.get("description").textValue();
                Iterator<JsonNode> it = tree.withArray("labels").iterator();
                CollectionStringBuffer csb = new CollectionStringBuffer(",");
                while (it.hasNext()) {
                    String text = it.next().textValue();
                    csb.append(text);
                }
                LOG.debug("Adding connector: {} with scheme: {}", name, scheme);
                camelConnectorCatalog.addConnector(groupId, artifactId, version, name, scheme, javaType, description, csb.toString(), json[0], json[1], json[2]);
                names.add(name);
            } catch (Throwable e) {
                LOG.warn("Error parsing Connector JSon due " + e.getMessage(), e);
            }
        }
    }
}
Also used : CollectionStringBuffer(org.apache.camel.catalog.CollectionStringBuffer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CollectionStringBuffer (org.apache.camel.catalog.CollectionStringBuffer)2 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1