Java Code Examples for org.apache.camel.CamelContext#getComponentNames()

The following examples show how to use org.apache.camel.CamelContext#getComponentNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentProxyWithCustomComponentTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void validate(Registry registry) throws Exception {
    final CamelContext context = new DefaultCamelContext(registry);

    try {
        context.setAutoStartup(false);
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                    .to("my-sql-proxy")
                    .to("mock:result");
            }
        });

        context.start();

        Collection<String> names = context.getComponentNames();

        assertThat(names).contains("my-sql-proxy");
        assertThat(names).contains("sql-my-sql-proxy");

        SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class);
        DataSource sqlDatasource = sqlComponent.getDataSource();

        assertThat(sqlDatasource).isEqualTo(this.ds);

        Map<String, Endpoint> endpoints = context.getEndpointMap();
        assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual");
    } finally {
        context.stop();
    }
}
 
Example 2
Source File: ActiveMQConnector.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private SjmsComponent lookupComponent() {
    final CamelContext context = getCamelContext();
    final List<String> names = context.getComponentNames();

    if (ObjectHelper.isEmpty(names)) {
        return null;
    }

    // Try to check if a component with same set-up has already been
    // configured, if so reuse it.
    for (String name : names) {
        Component cmp = context.getComponent(name, false, false);
        if (!(cmp instanceof SjmsComponent)) {
            continue;
        }

        ConnectionFactory factory = ((SjmsComponent) cmp).getConnectionFactory();
        if (factory instanceof ActiveMQConnectionFactory) {
            ActiveMQConnectionFactory amqFactory = (ActiveMQConnectionFactory) factory;

            if (!Objects.equals(brokerUrl, amqFactory.getBrokerURL())) {
                continue;
            }
            if (!Objects.equals(username, amqFactory.getUserName())) {
                continue;
            }
            if (!Objects.equals(password, amqFactory.getPassword())) {
                continue;
            }

            return (SjmsComponent) cmp;
        }
    }

    return null;
}
 
Example 3
Source File: ComponentOptionsTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private void validatePojoOption(CamelContext context) throws Exception {
    context.start();

    Collection<String> names = context.getComponentNames();

    assertThat(names).contains("my-sql-proxy");
    assertThat(names).contains("sql-my-sql-proxy");

    SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class);
    DataSource sqlDatasource = sqlComponent.getDataSource();

    assertThat(sqlDatasource).isEqualTo(this.ds);

    Map<String, Endpoint> endpoints = context.getEndpointMap();
    assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual");

    context.stop();
}
 
Example 4
Source File: ComponentOptionsTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static void validateRegistryOption(CamelContext context) throws Exception {
    context.start();

    Collection<String> names = context.getComponentNames();

    assertThat(names).contains("my-sql-proxy");
    assertThat(names).contains("sql");
    assertThat(names).doesNotContain("sql-my-sql-proxy");

    SqlComponent sqlComponent = context.getComponent("sql", SqlComponent.class);
    DataSource sqlDatasource = sqlComponent.getDataSource();

    assertThat(sqlDatasource).isNull();

    Map<String, Endpoint> endpoints = context.getEndpointMap();
    assertThat(endpoints).containsKey("sql://select%20from%20dual?dataSource=%23ds");


    context.stop();
}
 
Example 5
Source File: AMQPConnector.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private AMQPComponent lookupComponent() {
    final CamelContext context = getCamelContext();
    final List<String> names = context.getComponentNames();

    if (ObjectHelper.isEmpty(names)) {
        return null;
    }

    // lookup existing component with same configuration
    for (String name: names) {

        Component cmp = context.getComponent(name, false, false);
        if (cmp instanceof AMQPComponent) {

            final ConnectionFactory factory;
            try {
                factory = ((AMQPComponent)cmp).getConfiguration().getConnectionFactory();
            } catch (IllegalArgumentException e) {
                // ignore components without a connection factory
                continue;
            }

            if (factory instanceof JmsConnectionFactory) {
                JmsConnectionFactory jmsConnectionFactory = (JmsConnectionFactory)factory;

                if (!Objects.equals(connectionUri, jmsConnectionFactory.getRemoteURI())) {
                    continue;
                }
                if (!Objects.equals(username, jmsConnectionFactory.getUsername())) {
                    continue;
                }
                if (!Objects.equals(password, jmsConnectionFactory.getPassword())) {
                    continue;
                }
                if (!Objects.equals(clientId, jmsConnectionFactory.getClientID())) {
                    continue;
                }

                return (AMQPComponent) cmp;
            }
        }
    }

    return null;
}