Search in sources :

Example 46 with Component

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

the class RouteBuilder method propertyInject.

/**
     * Injects a property placeholder value with the given key converted to the given type.
     *
     * @param key  the property key
     * @param type the type to convert the value as
     * @return the value, or <tt>null</tt> if value is empty
     * @throws Exception is thrown if property with key not found or error converting to the given type.
     */
public <T> T propertyInject(String key, Class<T> type) throws Exception {
    ObjectHelper.notEmpty(key, "key");
    ObjectHelper.notNull(type, "Class type");
    // the properties component is mandatory
    Component component = getContext().hasComponent("properties");
    if (component == null) {
        throw new IllegalArgumentException("PropertiesComponent with name properties must be defined" + " in CamelContext to support property placeholders in expressions");
    }
    PropertiesComponent pc = getContext().getTypeConverter().mandatoryConvertTo(PropertiesComponent.class, component);
    // enclose key with {{ }} to force parsing
    Object value = pc.parseUri(pc.getPrefixToken() + key + pc.getSuffixToken());
    if (value != null) {
        return getContext().getTypeConverter().mandatoryConvertTo(type, value);
    } else {
        return null;
    }
}
Also used : Component(org.apache.camel.Component) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 47 with Component

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

the class BlueprintComponentResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.

@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar", new SampleComponent(false));
    registry.put("allstar-component", new SampleComponent(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
    Component component = resolver.resolveComponent("allstar", camelContext);
    assertNotNull("We should find the super component", component);
    assertTrue("We should get the super component here", component instanceof SampleComponent);
    assertFalse("We should NOT find the fallback component", ((SampleComponent) component).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) Component(org.apache.camel.Component) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 48 with Component

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

the class BlueprintComponentResolverTest method testOsgiResolverFindComponentFallbackTest.

@Test
public void testOsgiResolverFindComponentFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar-component", new SampleComponent(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
    Component component = resolver.resolveComponent("allstar", camelContext);
    assertNotNull("We should find the super component", component);
    assertTrue("We should get the super component here", component instanceof SampleComponent);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) Component(org.apache.camel.Component) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 49 with Component

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

the class OsgiComponentResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.

@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar", new SampleComponent(false));
    registry.put("allstar-component", new SampleComponent(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    OsgiComponentResolver resolver = new OsgiComponentResolver(getBundleContext());
    Component component = resolver.resolveComponent("allstar", camelContext);
    assertNotNull("We should find the super component", component);
    assertTrue("We should get the super component here", component instanceof SampleComponent);
    assertFalse("We should NOT find the fallback component", ((SampleComponent) component).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) Component(org.apache.camel.Component) FileComponent(org.apache.camel.component.file.FileComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 50 with Component

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

the class OsgiComponentResolverTest method testOsgiResolverFindComponentTest.

@Test
public void testOsgiResolverFindComponentTest() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    OsgiComponentResolver resolver = new OsgiComponentResolver(getBundleContext());
    Component component = resolver.resolveComponent("file_test", camelContext);
    assertNotNull("We should find file_test component", component);
    assertTrue("We should get the file component here", component instanceof FileComponent);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FileComponent(org.apache.camel.component.file.FileComponent) Component(org.apache.camel.Component) FileComponent(org.apache.camel.component.file.FileComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) 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