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