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