Java Code Examples for org.apache.camel.model.ProcessorDefinition#process()

The following examples show how to use org.apache.camel.model.ProcessorDefinition#process() . 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: 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 3
Source File: AggregateStepHandler.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) {
    if (step.hasUnifiedJsonSchemaOutputShape()) {
        route.process(new UnifiedJsonAggregationPostProcessor());
    }

    return Optional.of(route);
}
 
Example 4
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 5
Source File: TemplateStepHandler.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
private Optional<ProcessorDefinition<?>> handle(TemplateStepLanguage language, Step step, ProcessorDefinition<?> route, String flowIndex, String stepIndex) {
    Map<String, String> properties = step.getConfiguredProperties();
    String template = properties.get(TEMPLATE_PROPERTY);

    try {
        /*
         * Pre-process the template to ensure it conforms to the standard.
         */
        template = language.preProcess(template);
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }

    //
    // Convert the exchange's in message from JSON
    // to a HashMap since this is required by camel modules
    //
    route = route.process(jsonToMapProcessor);

    //
    // Apply the template to the header property
    // Then add to the route path
    //
    route.setHeader(language.camelHeader()).constant(template);

    //
    // Encode the delimiters since they are applied as URI query parameters
    //
    try {
        String id = flowIndex + HYPHEN + stepIndex;
        String uri = language.generateUri(id);
        Map<String, Object> params = language.getUriParams();
        if (params != null && !params.isEmpty()) {
            uri = URISupport.appendParametersToURI(uri, params);
        }
        route = route.to(uri);

        //
        // Post-process the output exchange into JSON
        // so it will be available as part of a JSON object
        //
        route = route.process(textToJsonProcessor);

        return Optional.ofNullable(route);

    } catch (UnsupportedEncodingException | URISyntaxException e) {
        throw new IllegalStateException(e);
    }
}