Search in sources :

Example 1 with ComponentProxyComponent

use of io.syndesis.integration.component.proxy.ComponentProxyComponent in project syndesis by syndesisio.

the class DataShapeCustomizerTest method shouldUnmarshallToSpecifiedOutputType.

@Test
public void shouldUnmarshallToSpecifiedOutputType() throws Exception {
    final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject");
    final Exchange exchange = new DefaultExchange(context);
    final Message out = exchange.getOut();
    out.setBody("{}");
    component.getAfterProducer().process(exchange);
    Assertions.assertThat(out.getBody()).isInstanceOf(AbstractDTOBase.class);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) Message(org.apache.camel.Message) Test(org.junit.Test)

Example 2 with ComponentProxyComponent

use of io.syndesis.integration.component.proxy.ComponentProxyComponent in project syndesis by syndesisio.

the class DataShapeCustomizerTest method shouldNotRemoveExistingProcessors.

// ********************
// 
// ********************
@Test
public void shouldNotRemoveExistingProcessors() {
    final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject");
    final Processor createdBeforeProducer = component.getBeforeProducer();
    Assertions.assertThat(createdBeforeProducer).isInstanceOf(Pipeline.class);
    final Pipeline beforePipeline = (Pipeline) createdBeforeProducer;
    Assertions.assertThat(beforePipeline.getProcessors()).isInstanceOf(List.class).hasSize(2);
    Assertions.assertThat(((List<Processor>) beforePipeline.getProcessors()).get(0)).isInstanceOf(DataShapeCustomizer.UnmarshallProcessor.class);
    Assertions.assertThat(((List<Processor>) beforePipeline.getProcessors()).get(1)).isSameAs(BEFORE_PROCESSOR);
    final Processor createdAfterProducer = component.getAfterProducer();
    Assertions.assertThat(createdAfterProducer).isInstanceOf(Pipeline.class);
    final Pipeline afterPipeline = (Pipeline) createdAfterProducer;
    Assertions.assertThat(afterPipeline.getProcessors()).isInstanceOf(List.class).hasSize(2);
    Assertions.assertThat(((List<Processor>) afterPipeline.getProcessors()).get(0)).isInstanceOf(DataShapeCustomizer.UnmarshallProcessor.class);
    Assertions.assertThat(((List<Processor>) afterPipeline.getProcessors()).get(1)).isSameAs(AFTER_PROCESSOR);
}
Also used : ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) Processor(org.apache.camel.Processor) List(java.util.List) Pipeline(org.apache.camel.processor.Pipeline) Test(org.junit.Test)

Example 3 with ComponentProxyComponent

use of io.syndesis.integration.component.proxy.ComponentProxyComponent in project syndesis by syndesisio.

the class DataShapeCustomizerTest method shouldNotConvertFailedExchanges.

@Test
public void shouldNotConvertFailedExchanges() throws Exception {
    final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject");
    final Exchange exchange = new DefaultExchange(context);
    final Message out = exchange.getOut();
    exchange.setException(new Exception());
    out.setBody("wat");
    component.getAfterProducer().process(exchange);
    Assertions.assertThat(out.getBody()).isEqualTo("wat");
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) Message(org.apache.camel.Message) Test(org.junit.Test)

Example 4 with ComponentProxyComponent

use of io.syndesis.integration.component.proxy.ComponentProxyComponent in project syndesis by syndesisio.

the class DataShapeCustomizerTest method setUpComponent.

// ********************
// 
// ********************
protected ComponentProxyComponent setUpComponent(String actionId) {
    Connector connector = mandatoryLookupConnector();
    ConnectorAction action = mandatoryLookupAction(connector, actionId);
    ComponentProxyComponent component = new ComponentProxyComponent("salesforce-1", "salesforce");
    component.setBeforeProducer(BEFORE_PROCESSOR);
    component.setAfterProducer(AFTER_PROCESSOR);
    DataShapeCustomizer customizer = new DataShapeCustomizer();
    customizer.setCamelContext(context());
    action.getDescriptor().getInputDataShape().ifPresent(customizer::setInputDataShape);
    action.getDescriptor().getOutputDataShape().ifPresent(customizer::setOutputDataShape);
    customizer.customize(component, Collections.emptyMap());
    return component;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ConnectorAction(io.syndesis.common.model.action.ConnectorAction)

Example 5 with ComponentProxyComponent

use of io.syndesis.integration.component.proxy.ComponentProxyComponent in project syndesis by syndesisio.

the class ConnectorStepHandler method handle.

@SuppressWarnings("PMD")
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final Connection connection = step.getConnection().get();
    final Connector connector = connection.getConnector().get();
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String scheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
    final CamelContext context = builder.getContext();
    final String componentId = scheme + "-" + index;
    final ComponentProxyComponent component = resolveComponent(componentId, scheme, context, connector, descriptor);
    final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers());
    final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
    final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
    // Workaround for https://github.com/syndesisio/syndesis/issues/1713
    for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
        if (ObjectHelper.isNotEmpty(entry.getValue().getDefaultValue())) {
            properties.putIfAbsent(entry.getKey(), entry.getValue().getDefaultValue());
        }
    }
    // if the option is marked as secret use property placeholder as the
    // value is added to the integration secret.
    properties.entrySet().stream().filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", scheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // Connector/Action properties have the precedence
    connector.getConfiguredProperties().forEach(properties::put);
    descriptor.getConfiguredProperties().forEach(properties::put);
    try {
        final Map<String, Object> proxyProperties = new HashMap<>(properties);
        // Set input/output data shape if the component proxy implements
        // Input/OutputDataShapeAware
        descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds));
        descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));
        // Try to set properties to the component
        setProperties(context, component, proxyProperties);
        for (String customizerType : customizers) {
            final ComponentProxyCustomizer customizer = resolveCustomizer(context, customizerType);
            // Set the camel context if the customizer implements
            // the CamelContextAware interface.
            ObjectHelper.trySetCamelContext(customizer, context);
            // Set input/output data shape if the customizer implements
            // Input/OutputDataShapeAware
            descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds));
            descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds));
            // Try to set properties to the component
            setProperties(context, customizer, proxyProperties);
            // Invoke the customizer
            customizer.customize(component, proxyProperties);
        }
        component.setCamelContext(context);
        component.setOptions(proxyProperties);
        // Remove component
        context.removeComponent(component.getComponentId());
        context.removeService(component);
        // Register component
        context.addService(component, true, true);
        context.addComponent(component.getComponentId(), component);
        if (route == null) {
            route = builder.from(componentId);
        } else {
            route = route.to(componentId);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return Optional.ofNullable(route);
}
Also used : CamelContext(org.apache.camel.CamelContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ComponentProxyCustomizer(io.syndesis.integration.component.proxy.ComponentProxyCustomizer) HashMap(java.util.HashMap) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ComponentProxyComponent (io.syndesis.integration.component.proxy.ComponentProxyComponent)8 Test (org.junit.Test)6 Exchange (org.apache.camel.Exchange)5 Message (org.apache.camel.Message)5 DefaultExchange (org.apache.camel.impl.DefaultExchange)5 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 Connector (io.syndesis.common.model.connection.Connector)2 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connection (io.syndesis.common.model.connection.Connection)1 ComponentProxyCustomizer (io.syndesis.integration.component.proxy.ComponentProxyCustomizer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CamelContext (org.apache.camel.CamelContext)1 Processor (org.apache.camel.Processor)1 Pipeline (org.apache.camel.processor.Pipeline)1