org.apache.camel.model.ProcessorDefinition Java Examples

The following examples show how to use org.apache.camel.model.ProcessorDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataMapperStepHandler.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * In case atlas mapping definition contains Json typed source documents we need to make sure to convert those from list to Json array Strings before passing those
 * source documents to the mapper.
 */
private static void addJsonTypeSourceProcessor(ProcessorDefinition<?> route, List<Map<String, Object>> dataSources) {
    List<Map<String, Object>> sourceDocuments = dataSources.stream()
                                        .filter(s -> "SOURCE".equals(s.get("dataSourceType")))
                                        .collect(Collectors.toList());

    List<String> jsonTypeSourceIds = sourceDocuments.stream()
                                        .filter(s -> ATLASMAP_JSON_DATA_SOURCE.equals(s.get("jsonType")))
                                        .filter(s -> ObjectHelper.isNotEmpty(s.get("id")))
                                        .map(s -> s.get("id").toString())
                                        .collect(Collectors.toList());

    if (ObjectHelper.isNotEmpty(jsonTypeSourceIds)) {
        route.process(new JsonTypeSourceProcessor(jsonTypeSourceIds, sourceDocuments.size()));
    }
}
 
Example #2
Source File: OnExceptionStepParser.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    final Definition definition = context.node(Definition.class);
    final OnExceptionDefinition onException = new OnExceptionDefinition();

    if (definition.exceptions == null) {
        definition.exceptions = List.of(Exception.class.getName());
    }

    onException.setExceptions(definition.exceptions);
    onException.setRouteScoped(true);

    mapToOnException(context, definition, onException);

    return StepParserSupport.convertSteps(
        context,
        onException,
        definition.steps);
}
 
Example #3
Source File: OnExceptionStepParser.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public ProcessorDefinition<?> toStartProcessor(Context context) {
    final Definition definition = context.node(Definition.class);
    final OnExceptionDefinition onException = context.builder().onException();

    if (definition.exceptions == null) {
        definition.exceptions = List.of(Exception.class.getName());
    }

    onException.setExceptions(definition.exceptions);
    onException.setRouteScoped(false);

    mapToOnException(context, definition, onException);

    return StepParserSupport.convertSteps(
        context,
        onException,
        definition.steps);
}
 
Example #4
Source File: HeadersStepHandler.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"PMD.AvoidReassigningParameters", "PMD.AvoidDeeplyNestedIfStmts"})
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, final ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    final Map<String, String> props = step.getConfiguredProperties();
    final String action = props.getOrDefault("action", "set");

    if (ObjectHelper.equal(action, "set", true)) {
        props.entrySet().stream()
            .filter(e -> !"action".equalsIgnoreCase(e.getKey()))
            .forEach(e-> route.setHeader(e.getKey()).constant(e.getValue()));
    } else if (ObjectHelper.equal(action, "remove", true)) {
        props.entrySet().stream()
            .filter(e -> !"action".equalsIgnoreCase(e.getKey()))
            .forEach(e-> route.removeHeaders(e.getKey()));
    } else {
        throw new IllegalArgumentException("Unknown action:" + action);
    }

    return Optional.of(route);
}
 
Example #5
Source File: CircuitBreakerStepParser.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    CBDefinition definition = context.node(CBDefinition.class);

    ProcessorDefinition<?> processor = StepParserSupport.convertSteps(
        context,
        definition.delegate,
        definition.steps
    );

    if (definition.onFallback != null) {
        StepParserSupport.convertSteps(
            context,
            definition.onFallback,
            definition.onFallback.steps
        );

        definition.delegate.setOnFallback(definition.onFallback);
    }

    return processor;
}
 
Example #6
Source File: ActivityTrackingInterceptStrategy.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Activities that do hold nested activities (such as {@link org.apache.camel.model.FilterDefinition}, {@link org.apache.camel.model.ChoiceDefinition})
 * should not track the done event because this leads to reversed order of log events.
 *
 * Only log done events with duration measurement for no output definitions like {@link org.apache.camel.model.ToDefinition}.
 */
private static boolean shouldTrackDoneEvent(NamedNode definition) {
    if (!(definition instanceof OutputDefinition)) {
      return false;
    }

    final OutputDefinition<?> outputDefinition = (OutputDefinition) definition;
    final List<ProcessorDefinition<?>> outputs = outputDefinition.getOutputs();

    if (ObjectHelper.isEmpty(outputs)) {
        return false;
    }

    int stepIndexInPipeline = 0;
    if (outputs.size() > 1) {
        // 1st output in the pipeline should be the set header processor for the step id
        // 2nd output in the pipeline should be the actual step processor
        stepIndexInPipeline = 1;
    }

    return outputs.get(stepIndexInPipeline) instanceof NoOutputDefinition ||
           outputs.get(stepIndexInPipeline) instanceof OutputExpressionNode;
}
 
Example #7
Source File: RestStepParser.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessorDefinition<?> toStartProcessor(Context context) {
    Definition definition = context.node(Definition.class);

    StepParserSupport.notNull(definition.uri, "uri");
    StepParserSupport.notNull(definition.verb, "verb");
    StepParserSupport.notNull(definition.steps, "steps");

    RestDefinition rest = context.builder().rest().verb(definition.verb, definition.uri);

    ObjectHelper.ifNotEmpty(definition.apiDocs, rest::apiDocs);
    ObjectHelper.ifNotEmpty(definition.enableCORS, rest::enableCORS);
    ObjectHelper.ifNotEmpty(definition.consumes, rest::consumes);
    ObjectHelper.ifNotEmpty(definition.produces, rest::produces);
    ObjectHelper.ifNotEmpty(definition.bindingMode, rest::bindingMode);
    ObjectHelper.ifNotEmpty(definition.type, rest::type);
    ObjectHelper.ifNotEmpty(definition.outType, rest::outType);
    ObjectHelper.ifNotEmpty(definition.id, rest::id);
    ObjectHelper.ifNotEmpty(definition.description, rest::description);

    return StepParserSupport.convertSteps(
        context,
        rest.route(),
        definition.steps
    );
}
 
Example #8
Source File: IntegrationRouteBuilder.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private ProcessorDefinition<?> closeParent(final ProcessorDefinition<?> parent, final String stepId,
    final BiFunction<ProcessorDefinition<?>, String, ProcessorDefinition<?>> fallback) {
    ProcessorDefinition<?> definition;

    if (parent instanceof PipelineDefinition) {
        definition = captureOutMessage(parent, stepId);
        definition = parent.end();
    } else if (parent instanceof ExpressionNode) {
        definition = captureOutMessage(parent, stepId);
        definition = parent.endParent();
    } else {
        definition = fallback.apply(parent, stepId);
    }

    return definition;
}
 
Example #9
Source File: StepParserSupport.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
public static ProcessorDefinition<?> convertSteps(ProcessorStepParser.Context context, ProcessorDefinition<?> parent, List<Step> steps) {
    ObjectHelper.notNull(context, "step context");
    ObjectHelper.notNull(parent, "parent");

    if (steps == null) {
        return parent;
    }

    ProcessorDefinition<?> current = parent;

    for (Step step : steps) {
        ProcessorDefinition<?> child = ProcessorStepParser.invoke(
            ProcessorStepParser.Context.of(context, current, step.node),
            step.id
        );

        current.addOutput(child);

        if (child instanceof OutputNode && child.getOutputs().isEmpty()) {
            current = child;
        }
    }

    return parent;
}
 
Example #10
Source File: CamelModelUtils.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static boolean canAcceptOutput(Class<?> aClass, ProcessorDefinition def) {
    if (aClass == null) {
        return false;
    }

    // special for bean/marshal/unmarshal, until their isOutputSupport would return false
    if (BeanDefinition.class.isAssignableFrom(aClass)) {
        return false;
    }
    if (MarshalDefinition.class.isAssignableFrom(aClass) ||
            UnmarshalDefinition.class.isAssignableFrom(aClass) ||
            TransactedDefinition.class.isAssignableFrom(aClass)) {
        return false;
    }

    // use isOutputSupport on camel model
    if (ProcessorDefinition.class.isAssignableFrom(aClass)) {
        if (def != null) {
            boolean answer = def.isOutputSupported();
            return answer;
        }
    }

    // assume no output is supported
    return false;
}
 
Example #11
Source File: RouteStepParser.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessorDefinition<?> toStartProcessor(Context context) {
    final Definition definition = context.node(Definition.class);

    final ProcessorDefinition<?> root = StartStepParser.invoke(
        ProcessorStepParser.Context.of(context, definition.getRoot().getData()),
        definition.getRoot().getType());

    if (root == null) {
        throw new IllegalStateException("No route definition");
    }
    if (!(root instanceof RouteDefinition)) {
        throw new IllegalStateException("Root definition should be of type RouteDefinition");
    }

    definition.getId().ifPresent(root::routeId);
    definition.getGroup().ifPresent(root::routeGroup);

    return root;
}
 
Example #12
Source File: TelegramBotAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    ObjectHelper.notNull(route, "route");
    ObjectHelper.notNull(engine, "engine");
    StringHelper.notEmpty(commandname, "commandname");
    StringHelper.notEmpty(commandimpl, "commandimpl");

    return Optional.of(route.process(this::process));
}
 
Example #13
Source File: ValidateAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    ObjectHelper.notNull(route, "route");
    ObjectHelper.notNull(rule, "rule");

    return Optional.of(route.validate(predicate(rule)));
}
 
Example #14
Source File: JsonUnmarshalAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
   public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
	ObjectHelper.notNull(route, "route");
	ObjectHelper.notNull(kind, "kind");

	return Optional.of(route.unmarshal().json(JsonLibrary.valueOf(kind.toString())));
}
 
Example #15
Source File: AbstractFilterStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    final String expression = ObjectHelper.notNull(getFilterExpression(step), "expression");
    final CamelContext context = builder.getContext();
    final Predicate predicate = new JsonSimplePredicate(expression, context);
    final FilterDefinition filter = route.filter(predicate);

    return Optional.of(filter);
}
 
Example #16
Source File: YamlMarshalAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
   public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
	ObjectHelper.notNull(route, "route");
	ObjectHelper.notNull(kind, "kind");

	return Optional.of(route.marshal().yaml(YAMLLibrary.valueOf(kind.toString())));
}
 
Example #17
Source File: JsonMarshalAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
   public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
	ObjectHelper.notNull(route, "route");
	ObjectHelper.notNull(kind, "kind");

	return Optional.of(route.marshal().json(JsonLibrary.valueOf(kind.toString())));
}
 
Example #18
Source File: SplitAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    String languageName = language;
    String expressionDefinition = expression;

    if (ObjectHelper.isEmpty(languageName) && ObjectHelper.isEmpty(expressionDefinition)) {
        route = route.split(Builder.body());
    } else if (ObjectHelper.isNotEmpty(expressionDefinition)) {

        if (ObjectHelper.isEmpty(languageName)) {
            languageName = "simple";
        }

        // A small hack until https://issues.apache.org/jira/browse/CAMEL-12079
        // gets fixed so we can support the 'bean::method' annotation as done by
        // Function step definition
        if ("bean".equals(languageName) && expressionDefinition.contains("::")) {
            expressionDefinition = expressionDefinition.replace("::", "?method=");
        }

        final Language splitLanguage = context.resolveLanguage(languageName);
        final Expression splitExpression = splitLanguage.createExpression(expressionDefinition);

        route = route.split(splitExpression).aggregationStrategy(new UseOriginalAggregationStrategy(null, false));
    }

    return Optional.of(route);
}
 
Example #19
Source File: ConvertBodyAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
   public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
	ObjectHelper.notNull(route, "route");

	route.convertBodyTo(String.class);
	return Optional.empty();
}
 
Example #20
Source File: IntegrationTestSupport.java    From syndesis with Apache License 2.0 5 votes vote down vote up
protected ProcessorDefinition<?> getOutput(RouteDefinition definition, int... indices) {
    ProcessorDefinition<?> output = definition;
    for (int index : indices) {
        output = output.getOutputs().get(index);
    }

    return output;
}
 
Example #21
Source File: MyInterceptor.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public Processor wrapProcessorInInterceptors(CamelContext context,
        ProcessorDefinition<?> definition, final Processor target,
        Processor nextTarget) throws Exception {

	return new DelegateAsyncProcessor(new Processor() {

		public void process(Exchange exchange) throws Exception {
			LOG.info("Before the processor...");
			target.process(exchange);
			LOG.info("After the processor...");
		}
	});
}
 
Example #22
Source File: IntegrationTestSupport.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public static ProcessorDefinition<?> getOutput(RouteDefinition definition, int... indices) {
    ProcessorDefinition<?> output = definition;
    for (int index : indices) {
        output = output.getOutputs().get(index);
    }

    return output;
}
 
Example #23
Source File: SetHeaderAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    ObjectHelper.notNull(route, "route");
    ObjectHelper.notNull(name, "name");
    ObjectHelper.notNull(value, "value");

    route.setHeader(name).constant(value);
    return Optional.empty();
}
 
Example #24
Source File: DataMapperStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * In case mapping definition has Json typed target document we need to make sure to convert the output. This is because mapper provides Json target collection as Json array String representation.
 * We prefer to use list objects where each element is a Json Object String.
 */
private static void addJsonTypeTargetProcessor(ProcessorDefinition<?> route, List<Map<String, Object>> dataSources) {
    boolean isJsonTypeTarget = dataSources.stream()
            .anyMatch(s -> ATLASMAP_JSON_DATA_SOURCE.equals(s.get("jsonType")) && "TARGET".equals(s.get("dataSourceType")));

    if (isJsonTypeTarget) {
        route.process(new JsonTypeTargetProcessor());
    }
}
 
Example #25
Source File: FilterStepParser.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    Definition definition = context.node(Definition.class);

    return StepParserSupport.convertSteps(
        context,
        definition,
        definition.steps
    );
}
 
Example #26
Source File: ResequenceStepParser.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    Definition definition = context.node(Definition.class);

    return StepParserSupport.convertSteps(
        context,
        definition,
        definition.steps
    );
}
 
Example #27
Source File: IntegrationRouteBuilder.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * If the integration has a scheduler, start the route with a timer or quartz2
 * endpoint.
 */
private ProcessorDefinition<?> configureRouteScheduler(final Flow flow) throws URISyntaxException {
    if (flow.getScheduler().isPresent()) {
        Scheduler scheduler = flow.getScheduler().get();

        // We now support simple timer only, cron support will be supported
        // later on.
        if (scheduler.isTimer()) {
            Map<String, String> properties = new HashMap<>();
            properties.put("timerName", "integration");
            properties.put("period", scheduler.getExpression());

            final RuntimeCamelCatalog catalog = getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog();
            final String uri = catalog.asEndpointUri("timer", properties, false);

            RouteDefinition route = this.from(uri);
            route.getInput().setId("integration-scheduler");
            flow.getId().ifPresent(route::setId);

            return route;
        }

        throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getType());
    }

    return null;
}
 
Example #28
Source File: LogsAndErrorsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> definition, Map<String, Object> parameters) {
    ProcessorDefinition<?> processor = definition.process(exchange -> {
        count++;
        if( count == 2 ) {
            throw new IOException("Bean Error");
        }
    });
    return Optional.of(processor);
}
 
Example #29
Source File: SplitStepParser.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    Definition definition = context.node(Definition.class);

    return StepParserSupport.convertSteps(
        context,
        definition,
        definition.steps);
}
 
Example #30
Source File: TemplateStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    Map<String, String> properties = step.getConfiguredProperties();
    String languageId = properties.get(TemplateStepLanguage.LANGUAGE_PROPERTY);
    //
    // If languageId is null then defaults to mustache
    //
    TemplateStepLanguage language = TemplateStepLanguage.stepLanguage(languageId);
    return this.handle(language, step, route, flowIndex, stepIndex);
}