use of io.syndesis.integration.runtime.IntegrationRouteBuilder in project syndesis by syndesisio.
the class SplitStepHandlerJsonTest method testTokenizeBodyStep.
@Test
public void testTokenizeBodyStep() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = new IntegrationRouteBuilder("classpath:/syndesis/integration/SplitStepHandlerJsonTest.json", Collections.emptyList());
// Set up the camel context
context.addRoutes(routes);
context.start();
// Dump routes as XML for troubleshooting
dumpRoutes(context);
final ProducerTemplate template = context.createProducerTemplate();
final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
final String[] expected = { "a", "b", "c" };
final List<String> body = Arrays.asList(expected);
result.expectedMessageCount(3);
result.expectedBodiesReceived((Object[]) expected);
template.sendBody("direct:expression", body);
result.assertIsSatisfied();
} finally {
context.stop();
}
}
use of io.syndesis.integration.runtime.IntegrationRouteBuilder in project syndesis by syndesisio.
the class ExtensionStepHandler method handle.
@SuppressWarnings("PMD")
@Override
public Optional<ProcessorDefinition> handle(io.syndesis.common.model.integration.Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, String stepIndex) {
ObjectHelper.notNull(route, "route");
// Model
final StepAction action = step.getActionAs(StepAction.class).get();
// Camel
final Map<String, String> properties = step.getConfiguredProperties();
final CamelContext context = builder.getContext();
if (action.getDescriptor().getKind() == StepAction.Kind.ENDPOINT) {
for (Map.Entry<String, String> entry : properties.entrySet()) {
route.setHeader(entry.getKey(), builder.constant(entry.getValue()));
}
route = route.to(action.getDescriptor().getEntrypoint());
} else if (action.getDescriptor().getKind() == StepAction.Kind.BEAN) {
String method = null;
String function = action.getDescriptor().getEntrypoint();
String options = null;
if (ObjectHelper.isEmpty(function)) {
return Optional.empty();
}
int idx = function.indexOf("::");
if (idx > 0 && !function.endsWith("::")) {
method = function.substring(idx + 2);
function = function.substring(0, idx);
}
if (ObjectHelper.isNotEmpty(properties)) {
options = properties.entrySet().stream().filter(entry -> ObjectHelper.isNotEmpty(entry.getKey())).filter(entry -> ObjectHelper.isNotEmpty(entry.getValue())).map(entry -> "bean." + entry.getKey() + "=" + StringHelpers.sanitizeForURI(entry.getValue())).collect(Collectors.joining("&"));
}
String uri = "class:" + function;
if (method != null) {
uri += "?method=" + method;
if (options != null) {
uri += "&" + options;
}
} else if (options != null) {
uri += "?" + options;
}
route = route.to(uri);
} else if (action.getDescriptor().getKind() == StepAction.Kind.STEP) {
final String target = action.getDescriptor().getEntrypoint();
final TypeConverter converter = context.getTypeConverter();
if (!ObjectHelper.isEmpty(target)) {
try {
final Class<Step> clazz = context.getClassResolver().resolveMandatoryClass(target, Step.class);
final Step stepExtension = context.getInjector().newInstance(clazz);
final Map<String, Object> props = new HashMap<>(properties);
try {
IntrospectionSupport.setProperties(context, converter, stepExtension, props);
} catch (Exception e) {
throw new IllegalStateException(e);
}
// Set the camel context if the step extension object implements
// CamelContextAware, this is a shortcut to retrieve it from
// the handler method.
ObjectHelper.trySetCamelContext(stepExtension, context);
return stepExtension.configure(context, route, props);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
}
}
return Optional.of(route);
}
Aggregations