Search in sources :

Example 26 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ManagedCamelContext method componentParameterJsonSchema.

public String componentParameterJsonSchema(String componentName) throws Exception {
    // favor using pre generated schema if component has that
    String json = context.getComponentParameterJsonSchema(componentName);
    if (json == null) {
        // okay this requires having the component on the classpath and being instantiated
        Component component = context.getComponent(componentName);
        if (component != null) {
            ComponentConfiguration configuration = component.createComponentConfiguration();
            json = configuration.createParameterJsonSchema();
        }
    }
    return json;
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component)

Example 27 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ComponentConfigurationTest method testCreateUriStringFromParametersOnDefaultComponent.

/**
     * Show we can create a URI from the base URI and the underlying query parameter values
     * on any endpoint (even if its not a {@link UriEndpointComponent})
     */
@Test
public void testCreateUriStringFromParametersOnDefaultComponent() throws Exception {
    Component component = context.getComponent("cheese");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the base URI properties
    configuration.setBaseUri("somePath");
    // lets try set and get a valid parameter
    configuration.setParameter("foo", "something");
    configuration.setParameter("bar", 123);
    String uriString = configuration.getUriString();
    assertEquals("uriString", "somePath?bar=123&foo=something", uriString);
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 28 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ComponentConfigurationTest method testCreateUriStringFromParameters.

/**
     * Show we can create a URI from the base URI and the underlying query parameter values
     */
@Test
public void testCreateUriStringFromParameters() throws Exception {
    Component component = context.getComponent("seda");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the base URI properties
    configuration.setBaseUri("foo");
    // lets try set and get a valid parameter
    configuration.setParameter("concurrentConsumers", 5);
    configuration.setParameter("size", 1000);
    String uriString = configuration.getUriString();
    assertEquals("uriString", "foo?concurrentConsumers=5&size=1000", uriString);
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 29 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ComponentConfigurationTest method testConfigureAnExistingDefaultEndpoint.

/**
     * Shows how we can use the configuration to get and set parameters directly on the endpoint
     * which is typesafe and performs validation even if the component is not a {@link UriEndpointComponent}
     */
@Test
public void testConfigureAnExistingDefaultEndpoint() throws Exception {
    NonUriEndpoint endpoint = context.getEndpoint("cheese:somePath?bar=123&foo=something", NonUriEndpoint.class);
    Component component = endpoint.getComponent();
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertEquals("bar", 123, endpoint.getBar());
    assertEquals("bar", 123, configuration.getEndpointParameter(endpoint, "bar"));
    // lets try set and get some valid parameters
    configuration.setEndpointParameter(endpoint, "bar", 10);
    Object bar = configuration.getEndpointParameter(endpoint, "bar");
    assertEquals("endpoint.bar", 10, bar);
    configuration.setEndpointParameter(endpoint, "foo", "anotherThing");
    Object foo = configuration.getEndpointParameter(endpoint, "foo");
    assertEquals("endpoint.foo", "anotherThing", foo);
    // lets try set an invalid parameter
    try {
        configuration.setEndpointParameter(endpoint, "doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 30 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ComponentConfigurationTest method testIntrospectSedaEndpointParameters.

/**
     * Shows we can introspect a {@link UriEndpointComponent} and find all the available parameters
     * along with their types and {@link ParameterConfiguration}
     */
@Test
public void testIntrospectSedaEndpointParameters() throws Exception {
    Component component = context.getComponent("seda");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    SortedMap<String, ParameterConfiguration> parameterMap = configuration.getParameterConfigurationMap();
    assertTrue("getParameterConfigurationMap() should not be empty!", !parameterMap.isEmpty());
    ParameterConfiguration concurrentConsumersConfig = parameterMap.get("concurrentConsumers");
    assertNotNull("parameterMap[concurrentConsumers] should not be null!", concurrentConsumersConfig);
    assertEquals("concurrentConsumersConfig.getName()", "concurrentConsumers", concurrentConsumersConfig.getName());
    assertEquals("concurrentConsumersConfig.getParameterType()", int.class, concurrentConsumersConfig.getParameterType());
    LOG.info("{} has has configuration properties {}", component, parameterMap.keySet());
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Aggregations

ComponentConfiguration (org.apache.camel.ComponentConfiguration)31 Test (org.junit.Test)29 EndpointConfiguration (org.apache.camel.EndpointConfiguration)16 Component (org.apache.camel.Component)14 SedaComponent (org.apache.camel.component.seda.SedaComponent)11 InvalidPropertyException (org.apache.camel.InvalidPropertyException)4 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 MSPTest (org.apache.camel.component.salesforce.dto.generated.MSPTest)2 SedaEndpoint (org.apache.camel.component.seda.SedaEndpoint)2 ParameterConfiguration (org.apache.camel.impl.ParameterConfiguration)2 ArrayList (java.util.ArrayList)1 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)1 BeanComponent (org.apache.camel.component.bean.BeanComponent)1 BrowseComponent (org.apache.camel.component.browse.BrowseComponent)1 ControlBusComponent (org.apache.camel.component.controlbus.ControlBusComponent)1 DataFormatComponent (org.apache.camel.component.dataformat.DataFormatComponent)1 DataSetComponent (org.apache.camel.component.dataset.DataSetComponent)1 DirectComponent (org.apache.camel.component.direct.DirectComponent)1 DirectVmComponent (org.apache.camel.component.directvm.DirectVmComponent)1