Search in sources :

Example 16 with CollectionStringBuffer

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

the class ManagedFailoverLoadBalancer method getExceptions.

@Override
public String getExceptions() {
    if (exceptions != null) {
        return exceptions;
    }
    List<Class<?>> classes = processor.getExceptions();
    if (classes == null || classes.isEmpty()) {
        exceptions = "";
    } else {
        CollectionStringBuffer csb = new CollectionStringBuffer(",");
        for (Class<?> clazz : classes) {
            csb.append(clazz.getCanonicalName());
        }
        exceptions = csb.toString();
    }
    return exceptions;
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Example 17 with CollectionStringBuffer

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

the class LoadBalanceDefinition method getLabel.

@Override
public String getLabel() {
    CollectionStringBuffer buffer = new CollectionStringBuffer("loadBalance[");
    List<ProcessorDefinition<?>> list = getOutputs();
    for (ProcessorDefinition<?> processorType : list) {
        buffer.append(processorType.getLabel());
    }
    buffer.append("]");
    return buffer.toString();
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Example 18 with CollectionStringBuffer

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

the class CachedOutputStreamTest method toString.

private static String toString(InputStream input) throws IOException {
    BufferedReader reader = IOHelper.buffered(new InputStreamReader(input));
    CollectionStringBuffer builder = new CollectionStringBuffer();
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            return builder.toString();
        }
        builder.append(line);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) BufferedReader(java.io.BufferedReader)

Example 19 with CollectionStringBuffer

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

the class DefaultCamelContext method explainEipJson.

public String explainEipJson(String nameOrId, boolean includeAllOptions) {
    try {
        // try to find the id within all known routes and their eips
        String eipName = nameOrId;
        NamedNode target = null;
        for (RouteDefinition route : getRouteDefinitions()) {
            if (route.getId().equals(nameOrId)) {
                target = route;
                break;
            }
            for (FromDefinition from : route.getInputs()) {
                if (nameOrId.equals(from.getId())) {
                    target = route;
                    break;
                }
            }
            Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);
            while (it.hasNext()) {
                ProcessorDefinition def = it.next();
                if (nameOrId.equals(def.getId())) {
                    target = def;
                    break;
                }
            }
            if (target != null) {
                break;
            }
        }
        if (target != null) {
            eipName = target.getShortName();
        }
        String json = getEipParameterJsonSchema(eipName);
        if (json == null) {
            return null;
        }
        // overlay with runtime parameters that id uses at runtime
        if (target != null) {
            List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
            // selected rows to use for answer
            Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
            // extract options from the node
            Map<String, Object> options = new LinkedHashMap<String, Object>();
            IntrospectionSupport.getProperties(target, options, "", false);
            // remove outputs which we do not want to include
            options.remove("outputs");
            // include other rows
            for (Map<String, String> row : rows) {
                String name = row.get("name");
                String kind = row.get("kind");
                String label = row.get("label");
                String required = row.get("required");
                String value = row.get("value");
                String defaultValue = row.get("defaultValue");
                String type = row.get("type");
                String javaType = row.get("javaType");
                String deprecated = row.get("deprecated");
                String description = row.get("description");
                // find the configured option
                Object o = options.get(name);
                if (o != null) {
                    value = o.toString();
                }
                value = URISupport.sanitizePath(value);
                if (includeAllOptions || o != null) {
                    // add as selected row
                    if (!selected.containsKey(name)) {
                        selected.put(name, new String[] { name, kind, label, required, type, javaType, deprecated, value, defaultValue, description });
                    }
                }
            }
            json = ObjectHelper.before(json, "  \"properties\": {");
            StringBuilder buffer = new StringBuilder("  \"properties\": {");
            boolean first = true;
            for (String[] row : selected.values()) {
                if (first) {
                    first = false;
                } else {
                    buffer.append(",");
                }
                buffer.append("\n    ");
                String name = row[0];
                String kind = row[1];
                String label = row[2];
                String required = row[3];
                String type = row[4];
                String javaType = row[5];
                String deprecated = row[6];
                String value = row[7];
                String defaultValue = row[8];
                String description = row[9];
                // add json of the option
                buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
                CollectionStringBuffer csb = new CollectionStringBuffer();
                if (kind != null) {
                    csb.append("\"kind\": \"" + kind + "\"");
                }
                if (label != null) {
                    csb.append("\"label\": \"" + label + "\"");
                }
                if (required != null) {
                    csb.append("\"required\": \"" + required + "\"");
                }
                if (type != null) {
                    csb.append("\"type\": \"" + type + "\"");
                }
                if (javaType != null) {
                    csb.append("\"javaType\": \"" + javaType + "\"");
                }
                if (deprecated != null) {
                    csb.append("\"deprecated\": \"" + deprecated + "\"");
                }
                if (value != null) {
                    csb.append("\"value\": \"" + value + "\"");
                }
                if (defaultValue != null) {
                    csb.append("\"defaultValue\": \"" + defaultValue + "\"");
                }
                if (description != null) {
                    csb.append("\"description\": \"" + description + "\"");
                }
                if (!csb.isEmpty()) {
                    buffer.append(csb.toString());
                }
                buffer.append(" }");
            }
            buffer.append("\n  }\n}\n");
            // insert the original first part of the json into the start of the buffer
            buffer.insert(0, json);
            return buffer.toString();
        }
        return json;
    } catch (Exception e) {
        // ignore and return empty response
        return null;
    }
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) NamedNode(org.apache.camel.NamedNode) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) LinkedHashMap(java.util.LinkedHashMap) RouteDefinition(org.apache.camel.model.RouteDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 20 with CollectionStringBuffer

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

the class JsonDataFormat method setPermissions.

/**
     * To add permission for the given pojo classes.
     * @param type the pojo class(es) xstream should use as allowed permission
     * @see #setPermissions(String)
     */
public void setPermissions(Class<?>... type) {
    CollectionStringBuffer csb = new CollectionStringBuffer(",");
    for (Class<?> clazz : type) {
        csb.append("+");
        csb.append(clazz.getName());
    }
    setPermissions(csb.toString());
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Aggregations

CollectionStringBuffer (org.apache.camel.util.CollectionStringBuffer)21 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 TreeMap (java.util.TreeMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)4 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)4 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)4 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)4 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)4 LoadPropertiesException (org.apache.camel.util.LoadPropertiesException)4 RouteDefinition (org.apache.camel.model.RouteDefinition)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1