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;
}
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();
}
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);
}
}
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;
}
}
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());
}
Aggregations