use of io.syndesis.integration.component.proxy.ComponentProxyCustomizer 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);
}
use of io.syndesis.integration.component.proxy.ComponentProxyCustomizer in project syndesis by syndesisio.
the class ConnectorStepHandler method resolveCustomizer.
private ComponentProxyCustomizer resolveCustomizer(CamelContext context, String customizerType) {
Class<ComponentProxyCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentProxyCustomizer.class);
if (type == null) {
throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType);
}
final ComponentProxyCustomizer customizer = context.getInjector().newInstance(type);
if (customizer == null) {
throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType);
}
return customizer;
}
Aggregations