use of java.util.Map in project camel by apache.
the class EndpointHelper method lookupEndpointRegistryId.
/**
* Lookup the id the given endpoint has been enlisted with in the {@link org.apache.camel.spi.Registry}.
*
* @param endpoint the endpoint
* @return the endpoint id, or <tt>null</tt> if not found
*/
public static String lookupEndpointRegistryId(Endpoint endpoint) {
if (endpoint == null || endpoint.getCamelContext() == null) {
return null;
}
// it may be a delegate endpoint, which we need to match as well
Endpoint delegate = null;
if (endpoint instanceof DelegateEndpoint) {
delegate = ((DelegateEndpoint) endpoint).getEndpoint();
}
Map<String, Endpoint> map = endpoint.getCamelContext().getRegistry().findByTypeWithName(Endpoint.class);
for (Map.Entry<String, Endpoint> entry : map.entrySet()) {
if (entry.getValue().equals(endpoint) || entry.getValue().equals(delegate)) {
return entry.getKey();
}
}
// not found
return null;
}
use of java.util.Map in project camel by apache.
the class BindyAbstractDataFormat method tryToGetFactoryRegistry.
private FactoryRegistry tryToGetFactoryRegistry() {
Function<CamelContext, Registry> f = CamelContext::getRegistry;
Function<Registry, Set<FactoryRegistry>> g = r -> r.findByType(FactoryRegistry.class);
Function<Set<FactoryRegistry>, FactoryRegistry> h = factoryRegistries -> {
if (factoryRegistries.size() > 1) {
LOGGER.warn("Number of registered {}: {}", FactoryRegistry.class.getCanonicalName(), factoryRegistries.size());
}
if (factoryRegistries.iterator().hasNext()) {
return factoryRegistries.iterator().next();
} else {
return new DefaultFactoryRegistry();
}
};
return Optional.ofNullable(camelContext).map(f).map(g).map(h).orElse(new DefaultFactoryRegistry());
}
use of java.util.Map in project camel by apache.
the class CsvTest method assertRecord.
protected static void assertRecord(List<Map> results, int index, String expectedFirstName, String expectedLastName, int expectedAge) {
assertTrue("Not enough Map messages received: " + results.size(), results.size() > index);
Map map = results.get(index);
assertNotNull("No map result found for index " + index, map);
String text = "bodyAsMap(" + index + ") ";
assertEquals(text + "firstName", expectedFirstName, map.get("firstName"));
assertEquals(text + "lastName", expectedLastName, map.get("lastName"));
assertEquals(text + "age", expectedAge, map.get("age"));
}
use of java.util.Map in project camel by apache.
the class CsvTest method testUnmarshal.
/*
@Test
public void testMarshal() throws Exception {
List<Employee> employees = getEmployees();
MockEndpoint mock = getMockEndpoint("mock:beanio-marshal");
mock.expectedBodiesReceived(FIXED_DATA);
template.sendBody("direct:marshal", employees);
mock.assertIsSatisfied();
}
*/
@Test
public void testUnmarshal() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:beanio-unmarshal");
mock.expectedMessageCount(2);
template.sendBody("direct:unmarshal", FIXED_DATA);
mock.assertIsSatisfied();
List<Exchange> exchanges = mock.getExchanges();
if (verbose) {
for (Exchange exchange : exchanges) {
Object body = exchange.getIn().getBody();
log.info("received message {} of class {}", body, body.getClass().getName());
}
}
List<Map> results = new ArrayList<Map>();
for (Exchange exchange : exchanges) {
Map body = exchange.getIn().getBody(Map.class);
if (body != null) {
results.add(body);
}
}
assertRecord(results, 0, "James", "Strachan", 22);
assertRecord(results, 1, "Claus", "Ibsen", 21);
}
use of java.util.Map in project camel by apache.
the class DefaultCamelContext method explainComponentJson.
public String explainComponentJson(String componentName, boolean includeAllOptions) {
try {
String json = getComponentParameterJsonSchema(componentName);
if (json == null) {
return null;
}
List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("componentProperties", json, true);
// selected rows to use for answer
Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
// insert values from component
Component component = getComponent(componentName);
Map<String, Object> options = new HashMap<String, Object>();
IntrospectionSupport.getProperties(component, options, null);
for (Map.Entry<String, Object> entry : options.entrySet()) {
String name = entry.getKey();
// skip unwanted options which is default inherited from DefaultComponent
if ("camelContext".equals(name) || "endpointClass".equals(name)) {
continue;
}
String value = "";
if (entry.getValue() != null) {
value = entry.getValue().toString();
}
value = URISupport.sanitizePath(value);
// find type and description from the json schema
String type = null;
String kind = null;
String group = null;
String label = null;
String required = null;
String javaType = null;
String deprecated = null;
String secret = null;
String defaultValue = null;
String description = null;
for (Map<String, String> row : rows) {
if (name.equals(row.get("name"))) {
type = row.get("type");
kind = row.get("kind");
group = row.get("group");
label = row.get("label");
required = row.get("required");
javaType = row.get("javaType");
deprecated = row.get("deprecated");
secret = row.get("secret");
defaultValue = row.get("defaultValue");
description = row.get("description");
break;
}
}
// add as selected row
selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
}
// include other rows
for (Map<String, String> row : rows) {
String name = row.get("name");
String kind = row.get("kind");
String group = row.get("group");
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 secret = row.get("secret");
value = URISupport.sanitizePath(value);
String description = row.get("description");
// always include path options
if (includeAllOptions) {
// add as selected row
if (!selected.containsKey(name)) {
selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
}
}
}
json = ObjectHelper.before(json, " \"componentProperties\": {");
StringBuilder buffer = new StringBuilder(" \"componentProperties\": {");
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 group = row[2];
String label = row[3];
String required = row[4];
String type = row[5];
String javaType = row[6];
String deprecated = row[7];
String secret = row[8];
String value = row[9];
String defaultValue = row[10];
String description = row[11];
// add json of the option
buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
CollectionStringBuffer csb = new CollectionStringBuffer();
if (kind != null) {
csb.append("\"kind\": \"" + kind + "\"");
}
if (group != null) {
csb.append("\"group\": \"" + group + "\"");
}
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 (secret != null) {
csb.append("\"secret\": \"" + secret + "\"");
}
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();
} catch (Exception e) {
// ignore and return empty response
return null;
}
}
Aggregations