Search in sources :

Example 26 with Map

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;
}
Also used : Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) BrowsableEndpoint(org.apache.camel.spi.BrowsableEndpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with Map

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());
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelContext(org.apache.camel.CamelContext) CamelContextAware(org.apache.camel.CamelContextAware) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) Field(java.lang.reflect.Field) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) DataFormatName(org.apache.camel.spi.DataFormatName) Link(org.apache.camel.dataformat.bindy.annotation.Link) DataFormat(org.apache.camel.spi.DataFormat) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) ServiceSupport(org.apache.camel.support.ServiceSupport) FormatFactoryInterface(org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface) FormatFactories(org.apache.camel.dataformat.bindy.annotation.FormatFactories) Collections(java.util.Collections) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) Set(java.util.Set) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry)

Example 28 with Map

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"));
}
Also used : Map(java.util.Map)

Example 29 with Map

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);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Example 30 with Map

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;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) 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) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Component(org.apache.camel.Component) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Map (java.util.Map)15646 HashMap (java.util.HashMap)9529 ArrayList (java.util.ArrayList)3619 List (java.util.List)2988 Test (org.junit.Test)2558 Set (java.util.Set)1837 HashSet (java.util.HashSet)1646 IOException (java.io.IOException)1486 Iterator (java.util.Iterator)1307 LinkedHashMap (java.util.LinkedHashMap)1284 TreeMap (java.util.TreeMap)1022 ImmutableMap (com.google.common.collect.ImmutableMap)879 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)729 File (java.io.File)662 Collection (java.util.Collection)576 Collectors (java.util.stream.Collectors)436 ConcurrentMap (java.util.concurrent.ConcurrentMap)375 LinkedList (java.util.LinkedList)333 SSOException (com.iplanet.sso.SSOException)294 Collections (java.util.Collections)288