use of org.apache.camel.Component in project camel by apache.
the class MultipleLifecycleStrategyTest method testMultipleLifecycleStrategies.
public void testMultipleLifecycleStrategies() throws Exception {
CamelContext context = createCamelContext();
context.start();
Component log = new LogComponent();
context.addComponent("log", log);
context.addEndpoint("log:/foo", log.createEndpoint("log://foo"));
context.removeComponent("log");
context.stop();
List<String> expectedEvents = Arrays.asList("onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop");
assertEquals(expectedEvents, dummy1.getEvents());
assertEquals(expectedEvents, dummy2.getEvents());
}
use of org.apache.camel.Component in project camel by apache.
the class QualifiedContextComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
String[] splitURI = ObjectHelper.splitOnCharacter(remaining, ":", 2);
if (splitURI[1] != null) {
String contextId = splitURI[0];
String localEndpoint = splitURI[1];
Component component = getCamelContext().getComponent(contextId);
if (component != null) {
LOG.debug("Attempting to create local endpoint: {} inside the component: {}", localEndpoint, component);
Endpoint endpoint = component.createEndpoint(localEndpoint);
if (endpoint == null) {
// throw the exception tell we cannot find an then endpoint from the given context
throw new ResolveEndpointFailedException("Cannot create a endpoint with uri" + localEndpoint + " for the CamelContext Component " + contextId);
} else {
ContextEndpoint answer = new ContextEndpoint(uri, this, endpoint);
answer.setContextId(contextId);
answer.setLocalEndpointUrl(localEndpoint);
return answer;
}
} else {
throw new ResolveEndpointFailedException("Cannot create the camel context component for context " + contextId);
}
} else {
// the uri is wrong
throw new ResolveEndpointFailedException("The uri " + remaining + "from camel context component is wrong");
}
}
use of org.apache.camel.Component 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.Component 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.Component 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);
}
}
Aggregations