Search in sources :

Example 41 with Component

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());
}
Also used : CamelContext(org.apache.camel.CamelContext) LogComponent(org.apache.camel.component.log.LogComponent) Component(org.apache.camel.Component) LogComponent(org.apache.camel.component.log.LogComponent)

Example 42 with Component

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");
    }
}
Also used : ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) Endpoint(org.apache.camel.Endpoint) UriEndpointComponent(org.apache.camel.impl.UriEndpointComponent) Component(org.apache.camel.Component)

Example 43 with Component

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);
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 44 with Component

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);
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 45 with Component

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

Aggregations

Component (org.apache.camel.Component)52 Test (org.junit.Test)24 ComponentConfiguration (org.apache.camel.ComponentConfiguration)14 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)9 SedaComponent (org.apache.camel.component.seda.SedaComponent)9 Map (java.util.Map)7 CamelContext (org.apache.camel.CamelContext)7 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)7 IOException (java.io.IOException)6 Endpoint (org.apache.camel.Endpoint)6 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)6 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)6 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 LinkedHashMap (java.util.LinkedHashMap)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)4 NoSuchBeanException (org.apache.camel.NoSuchBeanException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)4 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)4 DirectComponent (org.apache.camel.component.direct.DirectComponent)4