Search in sources :

Example 26 with Component

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

the class DefaultConnectorComponent method getVerifier.

@SuppressWarnings("unchecked")
@Override
public ComponentVerifier getVerifier() {
    final String scheme = model.getBaseScheme();
    final Component component = getCamelContext().getComponent(scheme);
    if (component instanceof VerifiableComponent) {
        return (scope, map) -> {
            Map<String, Object> options;
            try {
                // A little nasty hack required as verifier uses Map<String, Object>
                // to be compatible with all the methods in CamelContext whereas
                // catalog deals with Map<String, String>
                options = (Map) buildEndpointOptions(null, map);
            } catch (URISyntaxException e) {
                // and stop the validation step.
                return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
            }
            return ((VerifiableComponent) component).getVerifier().verify(scope, options);
        };
    } else {
        return (scope, map) -> {
            return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, scope).error(ResultErrorBuilder.withCode("unsupported").attribute("camel.connector.name", getConnectorName()).attribute("camel.component.name", getComponentName()).build()).build();
        };
    }
}
Also used : Logger(org.slf4j.Logger) ComponentVerifier(org.apache.camel.ComponentVerifier) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) Component(org.apache.camel.Component) Endpoint(org.apache.camel.Endpoint) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultCamelCatalog(org.apache.camel.catalog.DefaultCamelCatalog) Constructor(java.lang.reflect.Constructor) LinkedHashMap(java.util.LinkedHashMap) CamelCatalog(org.apache.camel.catalog.CamelCatalog) IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) ResultErrorBuilder(org.apache.camel.impl.verifier.ResultErrorBuilder) DefaultComponent(org.apache.camel.impl.DefaultComponent) URISyntaxException(java.net.URISyntaxException) Component(org.apache.camel.Component) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultComponent(org.apache.camel.impl.DefaultComponent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VerifiableComponent(org.apache.camel.VerifiableComponent)

Example 27 with Component

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

the class SalesforceComponentConfigurationIntegrationTest method testEndpointCompletion.

@Test
public void testEndpointCompletion() throws Exception {
    Component component = context().getComponent(componentName);
    ComponentConfiguration configuration = component.createComponentConfiguration();
    // get operation names
    assertCompletionOptions(configuration.completeEndpointPath(""), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "createSObject", "updateSObject", "deleteSObject", "getSObjectWithId", "upsertSObject", "deleteSObjectWithId", "getBlobField", "query", "queryMore", "queryAll", "search", "apexCall", "recent", "createJob", "getJob", "closeJob", "abortJob", "createBatch", "getBatch", "getAllBatches", "getRequest", "getResults", "createBatchQuery", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "executeSyncReport", "executeAsyncReport", "getReportInstances", "getReportResults", "limits", "approval", "approvals", "composite-batch", "composite-tree", "[PushTopicName]");
    // get filtered operation names
    assertCompletionOptions(configuration.completeEndpointPath("get"), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "getSObjectWithId", "getBlobField", "getJob", "getBatch", "getAllBatches", "getRequest", "getResults", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "getReportInstances", "getReportResults");
    /* TODO support parameter completion
        // get ALL REST operation parameters
        // TODO support operation specific parameter completion
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?"),
            "apiVersion", "httpClient", "format", "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");

        // get filtered REST parameters
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?format=XML&"),
            "apiVersion", "httpClient", "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");

        // get ALL Bulk operation parameters
        // TODO support operation specific parameter completion
        assertCompletionOptions(configuration.completeEndpointPath("createJob?"),
            "apiVersion", "httpClient", "sObjectQuery", "contentType", "jobId", "batchId", "resultId");

        // get filtered Bulk operation parameters
        assertCompletionOptions(configuration.completeEndpointPath("createJob?contentType=XML&"),
            "apiVersion", "httpClient", "sObjectQuery", "jobId", "batchId", "resultId");

        // get ALL topic parameters for consumers
        assertCompletionOptions(configuration.completeEndpointPath("myTopic?"),
            "apiVersion", "httpClient", "updateTopic", "notifyForFields", "notifyForOperations");

        // get filtered topic parameters for consumers
        assertCompletionOptions(configuration.completeEndpointPath("myTopic?updateTopic=true&"),
            "apiVersion", "httpClient", "notifyForFields", "notifyForOperations");

        // get parameters from partial name
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObject"),
            "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");
*/
    // get sObjectName values, from scanned DTO packages
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName="), "Account", "Asset", "Contact", "Task", "Line_Item__c", "Merchandise__c", "Document", "MSPTest");
    // get sObjectFields values, from scanned DTO
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName=Merchandise__c&sObjectFields="), "Description__c", "Price__c", "Total_Inventory__c", "attributes", "Id", "OwnerId", "IsDeleted", "Name", "CreatedDate", "CreatedById", "LastModifiedDate", "LastModifiedById", "SystemModstamp", "LastActivityDate", "LastViewedDate", "LastReferencedDate");
    // get sObjectClass values, from scanned DTO packages
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectClass="), Account.class.getName(), Asset.class.getName(), Contact.class.getName(), Task.class.getName(), Line_Item__c.class.getName(), Merchandise__c.class.getName(), Document.class.getName(), MSPTest.class.getName(), QueryRecordsLine_Item__c.class.getName());
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Account(org.apache.camel.component.salesforce.dto.generated.Account) Task(org.apache.camel.component.salesforce.dto.generated.Task) Line_Item__c(org.apache.camel.component.salesforce.dto.generated.Line_Item__c) QueryRecordsLine_Item__c(org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c) Asset(org.apache.camel.component.salesforce.dto.generated.Asset) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Component(org.apache.camel.Component) Document(org.apache.camel.component.salesforce.dto.generated.Document) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest) Contact(org.apache.camel.component.salesforce.dto.generated.Contact) QueryRecordsLine_Item__c(org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c) Test(org.junit.Test) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest)

Example 28 with Component

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

the class DefaultConnectorComponent method createNewBaseComponent.

// ***************************************
// Helpers
// ***************************************
private Component createNewBaseComponent(String scheme) throws Exception {
    String baseClassName = model.getBaseJavaType();
    if (baseClassName != null) {
        // create a new instance of this base component
        Class<?> type = Class.forName(baseClassName);
        Constructor ctr = getPublicDefaultConstructor(type);
        if (ctr != null) {
            // call default no-arg constructor
            Object base = ctr.newInstance();
            // the connector may have default values for the component level also
            // and if so we need to prepare these values and set on this component before we can start
            Map<String, String> defaultOptions = model.getDefaultComponentOptions();
            if (!defaultOptions.isEmpty()) {
                Map<String, Object> copy = new LinkedHashMap<>();
                for (Map.Entry<String, String> entry : defaultOptions.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (value != null) {
                        // also support {{ }} placeholders so resolve those first
                        value = getCamelContext().resolvePropertyPlaceholders(value);
                        log.debug("Using component option: {}={}", key, value);
                        copy.put(key, value);
                    }
                }
                IntrospectionSupport.setProperties(getCamelContext(), getCamelContext().getTypeConverter(), base, copy);
            }
            // configure component with extra options
            if (componentOptions != null && !componentOptions.isEmpty()) {
                Map<String, Object> copy = new LinkedHashMap<>(componentOptions);
                IntrospectionSupport.setProperties(getCamelContext(), getCamelContext().getTypeConverter(), base, copy);
            }
            if (base instanceof Component) {
                getCamelContext().removeComponent(scheme);
                // ensure component is started and stopped when Camel shutdown
                getCamelContext().addService(base, true, true);
                getCamelContext().addComponent(scheme, (Component) base);
                return (Component) base;
            }
        }
    }
    return null;
}
Also used : Constructor(java.lang.reflect.Constructor) Component(org.apache.camel.Component) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultComponent(org.apache.camel.impl.DefaultComponent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with Component

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

the class AbstractFeatureTest method testComponent.

protected void testComponent(String mainFeature, String component) throws Exception {
    LOG.info("Looking up CamelContext(myCamel) in OSGi Service Registry");
    installCamelFeature(mainFeature);
    CamelContext camelContext = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", SERVICE_TIMEOUT);
    assertNotNull("Cannot find CamelContext with name myCamel", camelContext);
    LOG.info("Getting Camel component: {}", component);
    // do not auto start the component as it may not have been configured properly and fail in its start method
    Component comp = camelContext.getComponent(component, true, false);
    assertNotNull("Cannot get component with name: " + component, comp);
    LOG.info("Found Camel component: {} instance: {} with className: {}", component, comp, comp.getClass());
}
Also used : CamelContext(org.apache.camel.CamelContext) Component(org.apache.camel.Component)

Example 30 with Component

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

the class SalesforceComponentConfigurationIntegrationTest method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    Component component = context().getComponent(componentName);
    ComponentConfiguration configuration = component.createComponentConfiguration();
    SortedMap<String, ParameterConfiguration> parameterConfigurationMap = configuration.getParameterConfigurationMap();
    if (verbose) {
        Set<Map.Entry<String, ParameterConfiguration>> entries = parameterConfigurationMap.entrySet();
        for (Map.Entry<String, ParameterConfiguration> entry : entries) {
            String name = entry.getKey();
            ParameterConfiguration config = entry.getValue();
            LOG.info("Has name: {} with type {}", name, config.getParameterType().getName());
        }
    }
    assertParameterConfig(configuration, "format", PayloadFormat.class);
    assertParameterConfig(configuration, "sObjectName", String.class);
    assertParameterConfig(configuration, "sObjectFields", String.class);
    assertParameterConfig(configuration, "updateTopic", boolean.class);
    configuration.setParameter("format", PayloadFormat.XML);
    configuration.setParameter("sObjectName", "Merchandise__c");
    configuration.setParameter("sObjectFields", "Description__c,Total_Inventory__c");
    configuration.setParameter("updateTopic", false);
    // operation name is base uri
    configuration.setBaseUri(componentName + ":getSObject");
    SalesforceEndpoint endpoint = assertIsInstanceOf(SalesforceEndpoint.class, configuration.createEndpoint());
    final SalesforceEndpointConfig endpointConfig = endpoint.getConfiguration();
    assertEquals("endpoint.format", PayloadFormat.XML, endpointConfig.getFormat());
    assertEquals("endpoint.sObjectName", "Merchandise__c", endpointConfig.getSObjectName());
    assertEquals("endpoint.sObjectFields", "Description__c,Total_Inventory__c", endpointConfig.getSObjectFields());
    assertEquals("endpoint.updateTopic", false, endpointConfig.isUpdateTopic());
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) ParameterConfiguration(org.apache.camel.impl.ParameterConfiguration) Map(java.util.Map) SortedMap(java.util.SortedMap) Test(org.junit.Test) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest)

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